All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Anthony PERARD <anthony.perard@citrix.com>
Subject: [XEN PATCH v4 18/18] build,include: rework compat-build-header.py
Date: Tue, 31 Mar 2020 11:31:02 +0100	[thread overview]
Message-ID: <20200331103102.1105674-19-anthony.perard@citrix.com> (raw)
In-Reply-To: <20200331103102.1105674-1-anthony.perard@citrix.com>

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

Remove the unnecessary "grep -v '^# [0-9]'". It is to hide the
linemarkers generated by the preprocessor. But adding -P inhibit there
generation, thus the grep isn't needed anymore.

gcc -E -P and clang -E -P have different behavior. While both don't
generates linemarkers, gcc also removes all empty lines while clang
keep them all. We don't need those empty lines, so we don't generates
them in the final compat/%.h headers. (This replace `uniq` which was
only de-duplicating empty line.)

The only changes in the final generated headers it that they don't
have empty lines anymore.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---

Notes:
    v4:
    - new patch

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

diff --git a/xen/include/Makefile b/xen/include/Makefile
index 74b26a028902..7e2d0ff667e8 100644
--- a/xen/include/Makefile
+++ b/xen/include/Makefile
@@ -53,20 +53,11 @@ all: $(headers-y)
 xlat_lst = xlat.lst
 
 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;) \
-	$(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \
-	grep -v '^# [0-9]' $< | \
-	$(PYTHON) $(BASEDIR)/tools/compat-build-header.py | uniq >>$@.new; \
-	$(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \
-	echo "#endif /* $$id */" >>$@.new
+	$(PYTHON) $(BASEDIR)/tools/compat-build-header.py <$< $@ "$(prefix-y)" "$(suffix-y)" >>$@.new; \
 	mv -f $@.new $@
 
 compat/%.i: compat/%.c Makefile
-	$(CPP) $(filter-out -Wa$(comma)% -include %/include/xen/config.h,$(XEN_CFLAGS)) $(cppflags-y) -o $@ $<
+	$(CPP) -P $(filter-out -Wa$(comma)% -include %/include/xen/config.h,$(XEN_CFLAGS)) $(cppflags-y) -o $@ $<
 
 compat/%.c: public/%.h $(xlat_lst) Makefile $(BASEDIR)/tools/compat-build-source.py
 	mkdir -p $(@D)
diff --git a/xen/tools/compat-build-header.py b/xen/tools/compat-build-header.py
index b85c43f13faf..d89a900ea02c 100755
--- a/xen/tools/compat-build-header.py
+++ b/xen/tools/compat-build-header.py
@@ -2,6 +2,12 @@
 
 import re,sys
 
+try:
+    type(str.maketrans)
+except AttributeError:
+    # For python2
+    import string as str
+
 pats = [
  [ r"__InClUdE__(.*)", r"#include\1\n#pragma pack(4)" ],
  [ r"__IfDeF__ (XEN_HAVE.*)", r"#ifdef \1" ],
@@ -20,7 +26,33 @@ pats = [
  [ r"(^|[^\w])long([^\w]|$$)", r"\1int\2" ]
 ];
 
+output_filename = sys.argv[1]
+
+# tr '[:lower:]-/.' '[:upper:]___'
+header_id = '_' + \
+    output_filename.upper().translate(str.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)
+
+def print_if_nonempty(s):
+    if len(s):
+        print(s)
+
+print_if_nonempty(sys.argv[2])
+
 for line in sys.stdin.readlines():
     for pat in pats:
-        line = re.subn(pat[0], pat[1], line)[0]
-    print(line.rstrip())
+        line = re.sub(pat[0], pat[1], line.rstrip())
+    print_if_nonempty(line)
+
+print_if_nonempty(sys.argv[3])
+
+print("#endif /* %s */" % header_id)
-- 
Anthony PERARD



  parent reply	other threads:[~2020-03-31 10:47 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 10:30 [XEN PATCH v4 00/18] xen: Build system improvements Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 01/18] xen/arm: Rename all early printk macro Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 02/18] xen/arm: Configure early printk via Kconfig Anthony PERARD
2020-04-01  9:22   ` Julien Grall
2020-03-31 10:30 ` [XEN PATCH v4 03/18] build,arm: Fix deps check of head.o Anthony PERARD
2020-04-01  9:42   ` Julien Grall
2020-03-31 10:30 ` [XEN PATCH v4 04/18] xen/build: include include/config/auto.conf in main Makefile Anthony PERARD
2020-04-08 11:33   ` Jan Beulich
2020-04-14 12:24     ` Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 05/18] xen/build: use new $(c_flags) and $(a_flags) instead of $(CFLAGS) Anthony PERARD
2020-04-08 11:36   ` Jan Beulich
2020-03-31 10:30 ` [XEN PATCH v4 06/18] xen/build: have the root Makefile generates the CFLAGS Anthony PERARD
2020-04-08 11:50   ` Jan Beulich
2020-04-15 14:10     ` Anthony PERARD
2020-04-15 15:55       ` Jan Beulich
2020-03-31 10:30 ` [XEN PATCH v4 07/18] build: Introduce documentation for xen Makefiles Anthony PERARD
2020-04-08 12:00   ` Jan Beulich
2020-04-15 14:38     ` Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 08/18] xen/build: introduce if_changed and if_changed_rule Anthony PERARD
2020-04-08 12:05   ` Jan Beulich
2020-03-31 10:30 ` [XEN PATCH v4 09/18] xen/build: Start using if_changed Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 10/18] xen/build: use if_changed on built_in.o Anthony PERARD
2020-04-08 12:40   ` Jan Beulich
2020-04-08 13:13     ` Andrew Cooper
2020-04-08 13:35       ` Jan Beulich
2020-04-15 16:06         ` Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 11/18] xen/build: Use if_changed_rules with %.o:%.c targets Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 12/18] xen/build: factorise generation of the linker scripts Anthony PERARD
2020-04-08 12:46   ` Jan Beulich
2020-04-15 16:58     ` Anthony PERARD
2020-04-16  7:36       ` Jan Beulich
2020-04-16  9:57         ` Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 13/18] xen/build: Use if_changed for prelink*.o Anthony PERARD
2020-03-31 10:30 ` [XEN PATCH v4 14/18] xen,symbols: rework file symbols selection Anthony PERARD
2020-04-08 12:54   ` Jan Beulich
2020-04-16 12:44     ` Anthony PERARD
2020-04-16 14:22       ` Jan Beulich
2020-04-16 15:09         ` Anthony PERARD
2020-04-17  7:12           ` Jan Beulich
2020-04-17 13:19             ` Anthony PERARD
2020-04-17 13:39               ` Jan Beulich
2020-04-17 14:42                 ` Anthony PERARD
2020-04-20 13:39                   ` Jan Beulich
2020-03-31 10:30 ` [XEN PATCH v4 15/18] xen/build: use if_changed to build guest_%.o Anthony PERARD
2020-04-08 13:02   ` Jan Beulich
2020-04-16 12:57     ` Anthony PERARD
2020-04-16 14:28       ` Jan Beulich
2020-03-31 10:31 ` [XEN PATCH v4 16/18] build,xsm: Fix multiple call Anthony PERARD
2020-04-08 13:28   ` Jan Beulich
2020-04-16 13:02     ` Anthony PERARD
2020-04-16 14:30       ` Jan Beulich
2020-03-31 10:31 ` [XEN PATCH v4 17/18] build,include: rework compat-build-source.py Anthony PERARD
2020-04-08 13:53   ` [XEN PATCH v4 17/18] build, include: " Jan Beulich
2020-04-16 13:07     ` Anthony PERARD
2020-03-31 10:31 ` Anthony PERARD [this message]
2020-04-08 13:56   ` [XEN PATCH v4 18/18] build, include: rework compat-build-header.py Jan Beulich
2020-04-16 14:17     ` Anthony PERARD
2020-04-16 14:34       ` Jan Beulich
2020-04-01  9:52 ` [XEN PATCH v4 00/18] xen: Build system improvements Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200331103102.1105674-19-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.