diff mbox series

[XEN,for-4.17,v2,3/6] tools/include/xen-foreign: Add SPDX identifier to generated headers

Message ID 20221103115204.49610-4-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show
Series Fixing some licences issue in public headers | expand

Commit Message

Anthony PERARD Nov. 3, 2022, 11:52 a.m. UTC
The headers install in "/usr/include/xen/foreign/" are missing a
licence header. This patch adds a SPDX identifier to clarify that
the MIT licence is used.

The script now check that the licence of the input file is also MIT,
by checking for the presence of the SPDX identifier.

Also add information about which files are used to generate the
headers.

Reported-by: Andrew Cooper <Andrew.Cooper3@citrix.com>
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---

Notes:
    v2:
    - Add a SPDX identifier instead of trying to capture the original
      licence text.
    - Check the SPDX identifier of the input headers.
    - Add information about which headers are used as input.

 tools/include/xen-foreign/mkheader.py | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

Comments

Andrew Cooper Nov. 16, 2022, 2:59 p.m. UTC | #1
On 03/11/2022 11:52, Anthony PERARD wrote:
> diff --git a/tools/include/xen-foreign/mkheader.py b/tools/include/xen-foreign/mkheader.py
> index fb268f0dce..ec8a321395 100644
> --- a/tools/include/xen-foreign/mkheader.py
> +++ b/tools/include/xen-foreign/mkheader.py
> @@ -1,5 +1,6 @@
>  #!/usr/bin/python
>  
> +from __future__ import print_function
>  import sys, re;
>  from structs import unions, structs, defines;
>  
> @@ -114,23 +115,37 @@ input  = "";
>  output = "";
>  fileid = re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper());
>  
> -# read input header files
>  for name in infiles:
>      f = open(name, "r");
> +    # Check the licence of the input file, only SPDX identifier is accepted by
> +    # this script.
> +    line = f.readline()
> +    if not line == "/* SPDX-License-Identifier: MIT */\n":

!=

> +        print("%s: Error: %s is missing SPDX identifier" % (sys.argv[0], name), file=sys.stderr)

I've reworked this a little to provide more information in the case that
something actually goes wrong.

xen.git/tools/include/xen-foreign$ make all
python3 mkheader.py arm32 arm32.h.tmp
/local/xen.git/tools/include/xen-foreign/../../../xen/include/public/arch-arm.h
/local/xen.git/tools/include/xen-foreign/../../../xen/include/public/xen.h
mkheader.py
/local/xen.git/tools/include/xen-foreign/../../../xen/include/public/xen.h:
Error: Missing or unexpected SPDX tag '/* SPDX-Licens-Identifier: MIT */'
Makefile:29: recipe for target 'arm32.h' failed
make: *** [arm32.h] Error 1

~Andrew
diff mbox series

Patch

diff --git a/tools/include/xen-foreign/mkheader.py b/tools/include/xen-foreign/mkheader.py
index fb268f0dce..ec8a321395 100644
--- a/tools/include/xen-foreign/mkheader.py
+++ b/tools/include/xen-foreign/mkheader.py
@@ -1,5 +1,6 @@ 
 #!/usr/bin/python
 
+from __future__ import print_function
 import sys, re;
 from structs import unions, structs, defines;
 
@@ -114,23 +115,37 @@  input  = "";
 output = "";
 fileid = re.sub("[-.]", "_", "__FOREIGN_%s__" % outfile.upper());
 
-# read input header files
 for name in infiles:
     f = open(name, "r");
+    # Check the licence of the input file, only SPDX identifier is accepted by
+    # this script.
+    line = f.readline()
+    if not line == "/* SPDX-License-Identifier: MIT */\n":
+        print("%s: Error: %s is missing SPDX identifier" % (sys.argv[0], name), file=sys.stderr)
+        exit(1)
     input += f.read();
     f.close();
 
+# replace path in "infiles" by path in '/usr/include' to avoid exposing the
+# build directory path in the generated headers.
+headers_name_list = ""
+public_headers_location = 'xen/include/public/'
+for name in infiles:
+    i = name.rindex(public_headers_location)
+    i += len(public_headers_location)
+    headers_name_list += " xen/%s" % (name[i:])
+
 # add header
-output += """
+output += """/* SPDX-License-Identifier: MIT */
 /*
  * public xen defines and struct for %s
- * generated by %s -- DO NOT EDIT
+ * generated from%s by %s -- DO NOT EDIT
  */
 
 #ifndef %s
 #define %s 1
 
-""" % (arch, sys.argv[0], fileid, fileid)
+""" % (arch, headers_name_list, sys.argv[0], fileid, fileid)
 
 if arch in header:
     output += header[arch];