[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN PATCH v6 08/31] build,include: rework compat-build-header.py


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Date: Thu, 1 Jul 2021 15:09:48 +0100
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "Julien Grall" <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Thu, 01 Jul 2021 14:10:37 +0000
  • Ironport-hdrordr: A9a23:2+1tPq6o+GDVMMmE2APXwM7XdLJyesId70hD6qhwISY7TiX+rb HIoB17726MtN9/YhAdcLy7VZVoBEmsl6KdgrNhWYtKPjOHhILAFugLhuHfKn/bakjDH4ZmpM FdmsNFZuEYY2IXsS+D2njaL+od
  • Ironport-sdr: grgSpt4fWT8iOSPspjf8uGICLMQU/Xg+FsFXwSYR71Q1UMQ4NXITI5Ow9zIJmjSDTLUBsLj4jg aJ6z9LmtP+5zzltsferH1oYFnsZq0MwBaMpxYjdmGoShRUxE0zMoVmlsXVzpACaIuNzfcgg7H+ +p0Wd02cOtVzWOGVP+sEpW4lBhuJFxX/VBWwwibFp89aAg5m0EoNZYpAe8oRpObtzuJEKkZp3h 1EGdSuFWbRjkiQVVccDCelGLnUvEJ0hHq/Nx6lc0sKJim81fqlIIb6feaEZv7dS3K2IPpbcQQZ JDw=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Replace a mix of shell script and python script by all python script.

Also remove dependency on Makefile as the file generation doesn't
depend on it anymore.

No change to the final generated headers.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Acked-by: Wei Liu <wl@xxxxxxx>
---

Notes:
    v6:
    - removed handling of $(prefix-y) and $(suffix-y), they've been removed.
    - remove dependency on Makefile as it's not needed anymore
    - rebased
    
    v5:
    - Removed -P from CPP when generating compat/%.i
      -> keep removing linemarkers and keep de-duplicating empty lines.
      So that all the blank line that currently exist in the generated
      headers stays in place.
    
    v4:
    - new patch

 xen/include/Makefile             | 11 ++------
 xen/tools/compat-build-header.py | 44 ++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/xen/include/Makefile b/xen/include/Makefile
index be3b81485bdc..9feb57545ef1 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -45,15 +45,8 @@ public-$(CONFIG_ARM) := $(wildcard public/arch-arm/*.h 
public/arch-arm/*/*.h)
 .PHONY: all
 all: $(headers-y)
 
-compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py
-       set -e; id=_$$(echo $@ | tr '[:lower:]-/.' '[:upper:]___'); \
-       echo "#ifndef $$id" >$@.new; \
-       echo "#define $$id" >>$@.new; \
-       echo "#include <xen/compat.h>" >>$@.new; \
-       $(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst 
compat/%,public/%,$@)>" >>$@.new;) \
-       grep -v '^# [0-9]' $< | \
-       $(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \
-       echo "#endif /* $$id */" >>$@.new
+compat/%.h: compat/%.i $(BASEDIR)/tools/compat-build-header.py
+       $(PYTHON) $(BASEDIR)/tools/compat-build-header.py <$< $@ >>$@.new; \
        mv -f $@.new $@
 
 compat/%.i: compat/%.c Makefile
diff --git a/xen/tools/compat-build-header.py b/xen/tools/compat-build-header.py
index 065d3b1b6ee8..5f5474fba051 100755
--- a/xen/tools/compat-build-header.py
+++ b/xen/tools/compat-build-header.py
@@ -2,6 +2,12 @@
 
 import re,sys
 
+try:
+    maketrans = str.maketrans
+except AttributeError:
+    # For python2
+    from string import maketrans
+
 pats = [
  [ r"__InClUdE__(.*)", r"#include\1" ],
  [ r"__IfDeF__ (XEN_HAVE.*)", r"#ifdef \1" ],
@@ -23,7 +29,41 @@ pats = [
  [ r"(^|[^\w])long([^\w]|$$)", r"\1int\2" ]
 ];
 
+output_filename = sys.argv[1]
+
+# tr '[:lower:]-/.' '[:upper:]___'
+header_id = '_' + \
+    output_filename.upper().translate(maketrans('-/.','___'))
+
+header = """#ifndef {0}
+#define {0}
+#include <xen/compat.h>""".format(header_id)
+
+print(header)
+
+if not re.match("compat/arch-.*.h$", output_filename):
+    x = output_filename.replace("compat/","public/")
+    print('#include <%s>' % x)
+
+last_line_empty = False
 for line in sys.stdin.readlines():
+    line = line.rstrip()
+
+    # Remove linemarkers generated by the preprocessor.
+    if re.match(r"^# \d", line):
+        continue
+
+    # De-duplicate empty lines.
+    if len(line) == 0:
+        if not last_line_empty:
+            print(line)
+            last_line_empty = True
+        continue
+    else:
+        last_line_empty = False
+
     for pat in pats:
-        line = re.subn(pat[0], pat[1], line)[0]
-    print(line.rstrip())
+        line = re.sub(pat[0], pat[1], line)
+    print(line)
+
+print("#endif /* %s */" % header_id)
-- 
Anthony PERARD




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.