From patchwork Thu Jul 1 14:09:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 12354151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAACBC11F64 for ; Thu, 1 Jul 2021 14:10:42 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 94C4C613B7 for ; Thu, 1 Jul 2021 14:10:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94C4C613B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.148709.274862 (Exim 4.92) (envelope-from ) id 1lyxOn-00073f-Fi; Thu, 01 Jul 2021 14:10:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 148709.274862; Thu, 01 Jul 2021 14:10:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lyxOn-00072Q-BJ; Thu, 01 Jul 2021 14:10:37 +0000 Received: by outflank-mailman (input) for mailman id 148709; Thu, 01 Jul 2021 14:10:36 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lyxOl-0005tj-Vm for xen-devel@lists.xenproject.org; Thu, 01 Jul 2021 14:10:36 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 09ef554a-cc6f-4393-bec9-018267e96a0b; Thu, 01 Jul 2021 14:10:30 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 09ef554a-cc6f-4393-bec9-018267e96a0b DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1625148630; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P2E0W/gctKSv9qL8/o+vMgXc//AFHVWuP07uAhIiJh4=; b=h5xlRTJERNCZIb4MfXn0paw4thhIvhuz4PWdYI5X/5WeGLwmd0TTHhcj TLco105FdRIfN/THbmt5aCfmuEYBZijGMYw24xYgDsxx7iqSvdrH3t0Z8 SliOPRpgmjl99il0uI1biOQyIm5D0wrpcr0+wlp9tjl74Y4LgZ0iXbhDG c=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: grgSpt4fWT8iOSPspjf8uGICLMQU/Xg+FsFXwSYR71Q1UMQ4NXITI5Ow9zIJmjSDTLUBsLj4jg aJ6z9LmtP+5zzltsferH1oYFnsZq0MwBaMpxYjdmGoShRUxE0zMoVmlsXVzpACaIuNzfcgg7H+ +p0Wd02cOtVzWOGVP+sEpW4lBhuJFxX/VBWwwibFp89aAg5m0EoNZYpAe8oRpObtzuJEKkZp3h 1EGdSuFWbRjkiQVVccDCelGLnUvEJ0hHq/Nx6lc0sKJim81fqlIIb6feaEZv7dS3K2IPpbcQQZ JDw= X-SBRS: 5.1 X-MesageID: 47446790 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:2+1tPq6o+GDVMMmE2APXwM7XdLJyesId70hD6qhwISY7TiX+rb HIoB17726MtN9/YhAdcLy7VZVoBEmsl6KdgrNhWYtKPjOHhILAFugLhuHfKn/bakjDH4ZmpM FdmsNFZuEYY2IXsS+D2njaL+od X-IronPort-AV: E=Sophos;i="5.83,314,1616472000"; d="scan'208";a="47446790" From: Anthony PERARD To: CC: Anthony PERARD , Wei Liu , "Andrew Cooper" , George Dunlap , Ian Jackson , Jan Beulich , "Julien Grall" , Stefano Stabellini Subject: [XEN PATCH v6 08/31] build,include: rework compat-build-header.py Date: Thu, 1 Jul 2021 15:09:48 +0100 Message-ID: <20210701141011.785641-9-anthony.perard@citrix.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210701141011.785641-1-anthony.perard@citrix.com> References: <20210701141011.785641-1-anthony.perard@citrix.com> MIME-Version: 1.0 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 Acked-by: Wei Liu --- 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 " >>$@.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 """.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)