From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C74EA21180F4F for ; Thu, 1 Nov 2018 20:40:15 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Nov 2018 20:40:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,454,1534834800"; d="scan'208";a="104769234" Received: from bfeng1-mobl1.ccr.corp.intel.com ([10.239.196.48]) by orsmga001.jf.intel.com with ESMTP; 01 Nov 2018 20:40:14 -0700 From: BobCF To: edk2-devel@lists.01.org Cc: Bob Feng , Liming Gao Date: Fri, 2 Nov 2018 11:40:05 +0800 Message-Id: <20181102034005.54064-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Subject: [Patch V2] BaseTools: Use common cc flag for building PcdValueInit. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2018 03:40:16 -0000 V2: Support to extract the common cc flag from a combined cc flag string. For example MSFT:*_*_IA32_CC_FLAGS = /D DISABLE_NEW_DEPRECATED_INTERFACES /DDEF_IA32 MSFT:*_*_X64_CC_FLAGS = /DDEF_X64 /D DISABLE_NEW_DEPRECATED_INTERFACES V1: Use common cc flags for building pcdinitvalue. The common cc flags include the cc flag which is under common arch and under all build arches. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Bob Feng Cc: Liming Gao --- .../Source/Python/Workspace/DscBuildData.py | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index 6d596b2b54..0173323b36 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -2182,10 +2182,23 @@ class DscBuildData(PlatformBuildClassObject): for key in OverrideValues: if OverrideValues[key]: return False return True + def ParseCCFlags(self, ccflag): + ccflags = set() + flag = "" + for ch in ccflag: + if ch in (r"/", "-"): + if flag.strip(): + ccflags.add(flag.strip()) + flag = ch + else: + flag += ch + if flag.strip(): + ccflags.add(flag.strip()) + return ccflags def GenerateByteArrayValue (self, StructuredPcds): # # Generate/Compile/Run C application to determine if there are any flexible array members # if not StructuredPcds: @@ -2298,38 +2311,32 @@ class DscBuildData(PlatformBuildClassObject): if Family and Family != self.ToolChainFamily: continue Target, Tag, Arch, Tool, Attr = Options[1].split("_") if Tool != 'CC': continue - + if Attr != "FLAGS": + continue if Target == "*" or Target == self._Target: if Tag == "*" or Tag == self._Toolchain: + if 'COMMON' not in BuildOptions: + BuildOptions['COMMON'] = set() if Arch == "*": - if Tool not in BuildOptions: - BuildOptions[Tool] = OrderedDict() - if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or self.BuildOptions[Options].startswith('='): - BuildOptions[Tool][Attr] = self.BuildOptions[Options] - else: - # append options for the same tool except PATH - if Attr != 'PATH': - BuildOptions[Tool][Attr] += " " + self.BuildOptions[Options] - else: - BuildOptions[Tool][Attr] = self.BuildOptions[Options] + BuildOptions['COMMON'].add(self.BuildOptions[Options]) + if Arch in self.SupArchList: + if Arch not in BuildOptions: + BuildOptions[Arch] = set() + BuildOptions[Arch] |= self.ParseCCFlags(self.BuildOptions[Options]) + if BuildOptions: - for Tool in BuildOptions: - for Attr in BuildOptions[Tool]: - if Attr == "FLAGS": - Value = BuildOptions[Tool][Attr] - ValueList = Value.split() - if ValueList: - for Id, Item in enumerate(ValueList): - if Item in ['-D', '/D', '-U', '/U']: - CC_FLAGS += ' ' + Item - if Id + 1 < len(ValueList): - CC_FLAGS += ' ' + ValueList[Id + 1] - elif Item.startswith(('-D', '/D', '-U', '/U')): - CC_FLAGS += ' ' + Item + ArchBuildOptions = {arch:flags for arch,flags in BuildOptions.items() if arch != 'COMMON'} + if len(ArchBuildOptions.keys()) == 1: + BuildOptions['COMMON'] |= (ArchBuildOptions.values()[0]) + else: + CommonBuildOptions = reduce(lambda x,y: x&y, ArchBuildOptions.values()) + BuildOptions['COMMON'] |= CommonBuildOptions + ValueList = list(BuildOptions['COMMON']) + CC_FLAGS += " ".join([item for item in ValueList if item.startswith(('-D', '/D', '-U', '/U'))]) MakeApp += CC_FLAGS if sys.platform == "win32": MakeApp = MakeApp + PcdMakefileEnd MakeApp = MakeApp + AppTarget % ("""\tcopy $(APPLICATION) $(APPFILE) /y """) -- 2.18.0.windows.1