The headers install in "/usr/include/xen/foreign/" are missing a
licence.

While we could probably just add the MIT licence to the generated
file, this patch instead try to grab the licence from the original
input file.

Since licences are in the first multiline C comments, we just look for
that. Also with this patch, the possible licences will not be in the
"input" variable anymore, but it should be unnecessary to generate the
foreign header.

With this change, the licence will be copied 2 or 3 time in the
install headers depending on the number of input headers.

Reported-by: Andrew Cooper <andrew.coop...@citrix.com>
Signed-off-by: Anthony PERARD <anthony.per...@citrix.com>
---

Notes:
    Maybe instead of this, we should just stamp this on the generated header
        /* SPDX-License-Identifier: MIT */
    
    but we would be missing the "Copyright" informations. I guess we could
    look for those line with Copyright and copy them.
    
    Or, we could replace the licence in the input header by a SPDX and have
    the script parse that. (Probably still need to grab the Copyright lines)
    
    CC: Andrew Cooper <andrew.coop...@citrix.com>
    CC: George Dunlap <george.dun...@citrix.com>
    CC: Jan Beulich <jbeul...@suse.com>
    CC: Julien Grall <jul...@xen.org>
    CC: Stefano Stabellini <sstabell...@kernel.org>
    CC: Wei Liu <w...@xen.org>

 tools/include/xen-foreign/mkheader.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/tools/include/xen-foreign/mkheader.py 
b/tools/include/xen-foreign/mkheader.py
index fb268f0dce..07a9bcbd01 100644
--- a/tools/include/xen-foreign/mkheader.py
+++ b/tools/include/xen-foreign/mkheader.py
@@ -114,9 +114,19 @@ input  = "";
 output = "";
 fileid = re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper());
 
-# read input header files
+# Try to captures licences headers from original files.
+# heuristic: just look for the end of the first multiline comment.
+licence_headers = "";
+
 for name in infiles:
     f = open(name, "r");
+    while True:
+        line = f.readline()
+        if not line:
+            break
+        licence_headers += line
+        if line == " */\n":
+            break
     input += f.read();
     f.close();
 
@@ -126,11 +136,12 @@ output += """
  * public xen defines and struct for %s
  * generated by %s -- DO NOT EDIT
  */
+%s
 
 #ifndef %s
 #define %s 1
 
-""" % (arch, sys.argv[0], fileid, fileid)
+""" % (arch, sys.argv[0], licence_headers, fileid, fileid)
 
 if arch in header:
     output += header[arch];
-- 
Anthony PERARD


Reply via email to