From nobody Fri Dec 27 18:48:35 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1501781436266736.7180940900274; Thu, 3 Aug 2017 10:30:36 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 907A921C9127E; Thu, 3 Aug 2017 10:28:20 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 227B421C9125D for ; Thu, 3 Aug 2017 10:28:19 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP; 03 Aug 2017 10:30:30 -0700 Received: from mdkinney-mobl1.amr.corp.intel.com ([10.254.75.199]) by fmsmga006.fm.intel.com with ESMTP; 03 Aug 2017 10:30:30 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,317,1498546800"; d="scan'208";a="135756525" From: Michael D Kinney To: edk2-devel@lists.01.org Date: Thu, 3 Aug 2017 10:30:21 -0700 Message-Id: <20170803173023.2452-2-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.13.1.windows.2 In-Reply-To: <20170803173023.2452-1-michael.d.kinney@intel.com> References: <20170803173023.2452-1-michael.d.kinney@intel.com> Subject: [edk2] [RFC Patch 1/3] BaseTools/build: Expand PREBUILD/POSTBUILD DSC actions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" * Extend PREBUILD/POSTBUILD define values to support more than one argument. * Delay normalization of PREBUILD/POSTBUILD define values until all arguments in the define values can be processed. * Convert PREBUILD/POSTBUILD build define value arguments that are WORKSPACE or PACKAGES_PATH relative paths to absolute paths. * Append -p PlatformFile, --conf=3DConfDirectory, and build target flags to command line used to execute PREBUILD/POSTBUILD actions. * Remove PrebuildScript and PostbuildScript fields from the Build class and use Prebuild and Postbuild fields instead. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney --- .../Source/Python/Workspace/WorkspaceDatabase.py | 4 +- BaseTools/Source/Python/build/build.py | 108 +++++++++++++++--= ---- 2 files changed, 82 insertions(+), 30 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseT= ools/Source/Python/Workspace/WorkspaceDatabase.py index 73b3fe7134..fe2c7c17c4 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py @@ -237,7 +237,7 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('build', FORMAT_INVALID, 'Missing = double quotes in the end of %s statement.' % TAB_DSC_PREBUILD, File=3Dself.MetaFile, Line=3DRecord[-1= ]) PrebuildValue =3D Record[2][1:-1] - self._Prebuild =3D PathClass(NormPath(PrebuildValue, self.= _Macros), GlobalData.gWorkspace) + self._Prebuild =3D PrebuildValue elif Name =3D=3D TAB_DSC_POSTBUILD: PostbuildValue =3D Record[2] if Record[2][0] =3D=3D '"': @@ -245,7 +245,7 @@ class DscBuildData(PlatformBuildClassObject): EdkLogger.error('build', FORMAT_INVALID, 'Missing = double quotes in the end of %s statement.' % TAB_DSC_POSTBUILD, File=3Dself.MetaFile, Line=3DRecord[-1= ]) PostbuildValue =3D Record[2][1:-1] - self._Postbuild =3D PathClass(NormPath(PostbuildValue, sel= f._Macros), GlobalData.gWorkspace) + self._Postbuild =3D PostbuildValue elif Name =3D=3D TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES: self._SupArchList =3D GetSplitValueList(Record[2], TAB_VAL= UE_SPLIT) elif Name =3D=3D TAB_DSC_DEFINES_BUILD_TARGETS: diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Pyth= on/build/build.py index 4d05ee2761..7436453582 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -796,8 +796,6 @@ class Build(): self.BuildModules =3D [] self.Db_Flag =3D False self.LaunchPrebuildFlag =3D False - self.PrebuildScript =3D '' - self.PostbuildScript =3D '' self.PlatformBuildPath =3D os.path.join(GlobalData.gConfDirectory,= '.cache', '.PlatformBuild') if BuildOptions.CommandLength: GlobalData.gCommandMaxLength =3D BuildOptions.CommandLength @@ -819,11 +817,11 @@ class Build(): EdkLogger.quiet("%-16s =3D %s" % ("CONF_PATH", GlobalData.gConfDir= ectory)) self.InitPreBuild() self.InitPostBuild() - if self.PrebuildScript: - EdkLogger.quiet("%-16s =3D %s" % ("PREBUILD", self.PrebuildScr= ipt)) - if self.PostbuildScript: - EdkLogger.quiet("%-16s =3D %s" % ("POSTBUILD", self.PostbuildS= cript)) - if self.PrebuildScript: + if self.Prebuild: + EdkLogger.quiet("%-16s =3D %s" % ("PREBUILD", self.Prebuild)) + if self.Postbuild: + EdkLogger.quiet("%-16s =3D %s" % ("POSTBUILD", self.Postbuild)) + if self.Prebuild: self.LaunchPrebuild() self.TargetTxt =3D TargetTxtClassObject() self.ToolDef =3D ToolDefClassObject() @@ -964,16 +962,37 @@ class Build(): Platform =3D self.Db._MapPlatform(str(self.PlatformFile)) self.Prebuild =3D str(Platform.Prebuild) if self.Prebuild: - PrebuildList =3D self.Prebuild.split() - if not os.path.isabs(PrebuildList[0]): - PrebuildList[0] =3D mws.join(self.WorkspaceDir, PrebuildLi= st[0]) - if os.path.isfile(PrebuildList[0]): - self.PrebuildScript =3D PrebuildList[0] - self.Prebuild =3D ' '.join(PrebuildList) - self.Prebuild +=3D self.PassCommandOption(self.BuildTarget= List, self.ArchList, self.ToolChainList) - #self.LaunchPrebuild() - else: - EdkLogger.error("Prebuild", PREBUILD_ERROR, "the prebuild = script %s is not exist.\n If you'd like to disable the Prebuild process, pl= ease use the format: -D PREBUILD=3D\"\" " %(PrebuildList[0])) + PrebuildList =3D [] + # + # Evaluate all arguments and convert arguments that are WORKSP= ACE + # relative paths to absolute paths. Filter arguments that loo= k like + # flags or do not follow the file/dir naming rules to avoid fa= lse + # positives on this conversion. + # + for Arg in self.Prebuild.split(): + # + # Do not modify Arg if it looks like a flag or an absolute= file path + # + if Arg.startswith('-') or os.path.isabs(Arg): + PrebuildList.append(Arg) + continue + # + # Do not modify Arg if it does not look like a Workspace r= elative + # path that starts with a valid package directory name + # + if not Arg[0].isalpha() or os.path.dirname(Arg) =3D=3D '': + PrebuildList.append(Arg) + continue + # + # If Arg looks like a WORKSPACE relative path, then conver= t to an + # absolute path and check to see if the file exists. + # + Temp =3D mws.join(self.WorkspaceDir, Arg) + if os.path.isfile(Temp): + Arg =3D Temp + PrebuildList.append(Arg) + self.Prebuild =3D ' '.join(PrebuildList) + self.Prebuild +=3D self.PassCommandOption(self.BuildTargetList= , self.ArchList, self.ToolChainList, self.PlatformFile, self.Target) =20 def InitPostBuild(self): if 'POSTBUILD' in GlobalData.gCommandLineDefines.keys(): @@ -982,23 +1001,46 @@ class Build(): Platform =3D self.Db._MapPlatform(str(self.PlatformFile)) self.Postbuild =3D str(Platform.Postbuild) if self.Postbuild: - PostbuildList =3D self.Postbuild.split() - if not os.path.isabs(PostbuildList[0]): - PostbuildList[0] =3D mws.join(self.WorkspaceDir, Postbuild= List[0]) - if os.path.isfile(PostbuildList[0]): - self.PostbuildScript =3D PostbuildList[0] - self.Postbuild =3D ' '.join(PostbuildList) - self.Postbuild +=3D self.PassCommandOption(self.BuildTarge= tList, self.ArchList, self.ToolChainList) - else: - EdkLogger.error("Postbuild", POSTBUILD_ERROR, "the postbui= ld script %s is not exist.\n If you'd like to disable the Postbuild process= , please use the format: -D POSTBUILD=3D\"\" " %(PostbuildList[0])) - - def PassCommandOption(self, BuildTarget, TargetArch, ToolChain): + PostbuildList =3D [] + # + # Evaluate all arguments and convert arguments that are WORKSP= ACE + # relative paths to absolute paths. Filter arguments that loo= k like + # flags or do not follow the file/dir naming rules to avoid fa= lse + # positives on this conversion. + # + for Arg in self.Postbuild.split(): + # + # Do not modify Arg if it looks like a flag or an absolute= file path + # + if Arg.startswith('-') or os.path.isabs(Arg): + PostbuildList.append(Arg) + continue + # + # Do not modify Arg if it does not look like a Workspace r= elative + # path that starts with a valid package directory name + # + if not Arg[0].isalpha() or os.path.dirname(Arg) =3D=3D '': + PostbuildList.append(Arg) + continue + # + # If Arg looks like a WORKSPACE relative path, then conver= t to an + # absolute path and check to see if the file exists. + # + Temp =3D mws.join(self.WorkspaceDir, Arg) + if os.path.isfile(Temp): + Arg =3D Temp + PostbuildList.append(Arg) + self.Postbuild =3D ' '.join(PostbuildList) + self.Postbuild +=3D self.PassCommandOption(self.BuildTargetLis= t, self.ArchList, self.ToolChainList, self.PlatformFile, self.Target) + + def PassCommandOption(self, BuildTarget, TargetArch, ToolChain, Platfo= rmFile, Target): BuildStr =3D '' if GlobalData.gCommand and isinstance(GlobalData.gCommand, list): BuildStr +=3D ' ' + ' '.join(GlobalData.gCommand) TargetFlag =3D False ArchFlag =3D False ToolChainFlag =3D False + PlatformFileFlag =3D False =20 if GlobalData.gOptions and not GlobalData.gOptions.BuildTarget: TargetFlag =3D True @@ -1006,6 +1048,8 @@ class Build(): ArchFlag =3D True if GlobalData.gOptions and not GlobalData.gOptions.ToolChain: ToolChainFlag =3D True + if GlobalData.gOptions and not GlobalData.gOptions.PlatformFile: + PlatformFileFlag =3D True =20 if TargetFlag and BuildTarget: if isinstance(BuildTarget, list) or isinstance(BuildTarget, tu= ple): @@ -1022,6 +1066,14 @@ class Build(): BuildStr +=3D ' -t ' + ' -t '.join(ToolChain) elif isinstance(ToolChain, str): BuildStr +=3D ' -t ' + ToolChain + if PlatformFileFlag and PlatformFile: + if isinstance(PlatformFile, list) or isinstance(PlatformFile, = tuple): + BuildStr +=3D ' -p ' + ' -p '.join(PlatformFile) + elif isinstance(PlatformFile, str): + BuildStr +=3D ' -p' + PlatformFile + BuildStr +=3D ' --conf=3D' + GlobalData.gConfDirectory + if Target: + BuildStr +=3D ' ' + Target =20 return BuildStr =20 --=20 2.13.1.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel