From nobody Tue Dec 23 12:39:50 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585651689; cv=none; d=zohomail.com; s=zohoarc; b=QWAgw+pZ7XSSbP51pLHacsxfvHu0zMgfYF8L7NqYs3/DJjHiAPmgE60k65OZvZ1VSaude3Y+vySHxdw3TS+qW9ADc2vXiRH8Byt865nv/RaP15NoBRRCScM6HflwQkJz2VRzywMdkNyZb8G8b195KzcIMZX/ua2tY4ZFUtbwoks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585651689; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ATYHfr/NTe1ZwwVdoG9DI49dMI/lBC4DFBQw3BIcmx0=; b=bAgA3MtbHcztq5YRcZMcaErrdkaIsw1SsrmgOOW3/eNxY7/7Oxv4HoFv9kY8UCgXRvsSl8uz3soBofvPpOv1r0pHGSf+UWWiKfsZyI8iTJbSwg/mRNR1T96U+3PZYCfQS82Z0LeHCy+zbgxg/2ZP8sopfWkSfHXNdlun3IOlnyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585651689222154.72410041761907; Tue, 31 Mar 2020 03:48:09 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jJEQe-0002zD-Sz; Tue, 31 Mar 2020 10:47:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jJEQe-0002yr-8N for xen-devel@lists.xenproject.org; Tue, 31 Mar 2020 10:47:32 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 05b79fde-733d-11ea-ba0c-12813bfff9fa; Tue, 31 Mar 2020 10:47:31 +0000 (UTC) X-Inumbo-ID: 05b79fde-733d-11ea-ba0c-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585651652; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=N7cdETdSaKZOO05IMNGn7YDoG1qlk9BVAckRaXOBzec=; b=NH3xMd0tnYb3VnRu7YlQYKvEKY3WjS1SfHV+l8Kkf+rNCK+umM+qYqtp vxnouSW1KoVSwemNIiPDAhXn7t+VBrGPhwUkulLqkH+EE6HQCCIBgHOWR 4ELeda9AkCWC+oGuPmKqDIhMnQ03X7ufdNwqgJQ7neeEykYfUIcg7Kzpa E=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 7oqI99Sx8QxzF42MQfY6RaxBGM1ZoLJQb+hXhhUCKUVygx9S5kOmct60LpSyeImn4Tq7pOqOe0 aqU8QY8S5kbkgGbLv0qVXViTV5FjFbBIn3n9iDPf9aSkylHItwKoh4vreqxxrzaT5X42g3Cxi9 +eDz/lLme9k0lLBfBB9MTXFzxlsebNSONTLlm3wSE5pqGRt5td4EvayUEYGY6nkrwFPI6iTA11 Wop4KByle/BQK+WDI5wc2saDEmIL2wAzgZ2XOnuhjgtjCuckZfvePdls1sivFq0SGiUc5ySP63 /qA= X-SBRS: 2.7 X-MesageID: 14904510 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,327,1580792400"; d="scan'208";a="14904510" From: Anthony PERARD To: Subject: [XEN PATCH v4 18/18] build,include: rework compat-build-header.py Date: Tue, 31 Mar 2020 11:31:02 +0100 Message-ID: <20200331103102.1105674-19-anthony.perard@citrix.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200331103102.1105674-1-anthony.perard@citrix.com> References: <20200331103102.1105674-1-anthony.perard@citrix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich , Anthony PERARD Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D xlat.lst =20 compat/%.h: compat/%.i Makefile $(BASEDIR)/tools/compat-build-header.py - set -e; id=3D_$$(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;) \ - $(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 $@ =20 compat/%.i: compat/%.c Makefile - $(CPP) $(filter-out -Wa$(comma)% -include %/include/xen/config.h,$(XEN_CF= LAGS)) $(cppflags-y) -o $@ $< + $(CPP) -P $(filter-out -Wa$(comma)% -include %/include/xen/config.h,$(XEN= _CFLAGS)) $(cppflags-y) -o $@ $< =20 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-head= er.py index b85c43f13faf..d89a900ea02c 100755 --- a/xen/tools/compat-build-header.py +++ b/xen/tools/compat-build-header.py @@ -2,6 +2,12 @@ =20 import re,sys =20 +try: + type(str.maketrans) +except AttributeError: + # For python2 + import string as str + pats =3D [ [ r"__InClUdE__(.*)", r"#include\1\n#pragma pack(4)" ], [ r"__IfDeF__ (XEN_HAVE.*)", r"#ifdef \1" ], @@ -20,7 +26,33 @@ pats =3D [ [ r"(^|[^\w])long([^\w]|$$)", r"\1int\2" ] ]; =20 +output_filename =3D sys.argv[1] + +# tr '[:lower:]-/.' '[:upper:]___' +header_id =3D '_' + \ + output_filename.upper().translate(str.maketrans('-/.','___')) + +header =3D """#ifndef {0} +#define {0} +#include """.format(header_id) + +print(header) + +if not re.match("compat/arch-.*.h$", output_filename): + x =3D 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 =3D re.subn(pat[0], pat[1], line)[0] - print(line.rstrip()) + line =3D re.sub(pat[0], pat[1], line.rstrip()) + print_if_nonempty(line) + +print_if_nonempty(sys.argv[3]) + +print("#endif /* %s */" % header_id) --=20 Anthony PERARD