self.BuildModules = []\r
self.Db_Flag = False\r
self.LaunchPrebuildFlag = False\r
- self.PrebuildScript = ''\r
- self.PostbuildScript = ''\r
self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory,'.cache', '.PlatformBuild')\r
if BuildOptions.CommandLength:\r
GlobalData.gCommandMaxLength = BuildOptions.CommandLength\r
EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", GlobalData.gConfDirectory))\r
self.InitPreBuild()\r
self.InitPostBuild()\r
- if self.PrebuildScript:\r
- EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.PrebuildScript))\r
- if self.PostbuildScript:\r
- EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.PostbuildScript))\r
- if self.PrebuildScript:\r
+ if self.Prebuild:\r
+ EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))\r
+ if self.Postbuild:\r
+ EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.Postbuild))\r
+ if self.Prebuild:\r
self.LaunchPrebuild()\r
self.TargetTxt = TargetTxtClassObject()\r
self.ToolDef = ToolDefClassObject()\r
Platform = self.Db._MapPlatform(str(self.PlatformFile))\r
self.Prebuild = str(Platform.Prebuild)\r
if self.Prebuild:\r
- PrebuildList = self.Prebuild.split()\r
- if not os.path.isabs(PrebuildList[0]):\r
- PrebuildList[0] = mws.join(self.WorkspaceDir, PrebuildList[0])\r
- if os.path.isfile(PrebuildList[0]):\r
- self.PrebuildScript = PrebuildList[0]\r
- self.Prebuild = ' '.join(PrebuildList)\r
- self.Prebuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList)\r
- #self.LaunchPrebuild()\r
- else:\r
- EdkLogger.error("Prebuild", PREBUILD_ERROR, "the prebuild script %s is not exist.\n If you'd like to disable the Prebuild process, please use the format: -D PREBUILD=\"\" " %(PrebuildList[0]))\r
+ PrebuildList = []\r
+ #\r
+ # Evaluate all arguments and convert arguments that are WORKSPACE\r
+ # relative paths to absolute paths. Filter arguments that look like\r
+ # flags or do not follow the file/dir naming rules to avoid false\r
+ # positives on this conversion.\r
+ #\r
+ for Arg in self.Prebuild.split():\r
+ #\r
+ # Do not modify Arg if it looks like a flag or an absolute file path\r
+ #\r
+ if Arg.startswith('-') or os.path.isabs(Arg):\r
+ PrebuildList.append(Arg)\r
+ continue\r
+ #\r
+ # Do not modify Arg if it does not look like a Workspace relative\r
+ # path that starts with a valid package directory name\r
+ #\r
+ if not Arg[0].isalpha() or os.path.dirname(Arg) == '':\r
+ PrebuildList.append(Arg)\r
+ continue\r
+ #\r
+ # If Arg looks like a WORKSPACE relative path, then convert to an\r
+ # absolute path and check to see if the file exists.\r
+ #\r
+ Temp = mws.join(self.WorkspaceDir, Arg)\r
+ if os.path.isfile(Temp):\r
+ Arg = Temp\r
+ PrebuildList.append(Arg)\r
+ self.Prebuild = ' '.join(PrebuildList)\r
+ self.Prebuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList, self.PlatformFile, self.Target)\r
\r
def InitPostBuild(self):\r
if 'POSTBUILD' in GlobalData.gCommandLineDefines.keys():\r
Platform = self.Db._MapPlatform(str(self.PlatformFile))\r
self.Postbuild = str(Platform.Postbuild)\r
if self.Postbuild:\r
- PostbuildList = self.Postbuild.split()\r
- if not os.path.isabs(PostbuildList[0]):\r
- PostbuildList[0] = mws.join(self.WorkspaceDir, PostbuildList[0])\r
- if os.path.isfile(PostbuildList[0]):\r
- self.PostbuildScript = PostbuildList[0]\r
- self.Postbuild = ' '.join(PostbuildList)\r
- self.Postbuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList)\r
- else:\r
- EdkLogger.error("Postbuild", POSTBUILD_ERROR, "the postbuild script %s is not exist.\n If you'd like to disable the Postbuild process, please use the format: -D POSTBUILD=\"\" " %(PostbuildList[0]))\r
-\r
- def PassCommandOption(self, BuildTarget, TargetArch, ToolChain):\r
+ PostbuildList = []\r
+ #\r
+ # Evaluate all arguments and convert arguments that are WORKSPACE\r
+ # relative paths to absolute paths. Filter arguments that look like\r
+ # flags or do not follow the file/dir naming rules to avoid false\r
+ # positives on this conversion.\r
+ #\r
+ for Arg in self.Postbuild.split():\r
+ #\r
+ # Do not modify Arg if it looks like a flag or an absolute file path\r
+ #\r
+ if Arg.startswith('-') or os.path.isabs(Arg):\r
+ PostbuildList.append(Arg)\r
+ continue\r
+ #\r
+ # Do not modify Arg if it does not look like a Workspace relative\r
+ # path that starts with a valid package directory name\r
+ #\r
+ if not Arg[0].isalpha() or os.path.dirname(Arg) == '':\r
+ PostbuildList.append(Arg)\r
+ continue\r
+ #\r
+ # If Arg looks like a WORKSPACE relative path, then convert to an\r
+ # absolute path and check to see if the file exists.\r
+ #\r
+ Temp = mws.join(self.WorkspaceDir, Arg)\r
+ if os.path.isfile(Temp):\r
+ Arg = Temp\r
+ PostbuildList.append(Arg)\r
+ self.Postbuild = ' '.join(PostbuildList)\r
+ self.Postbuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList, self.PlatformFile, self.Target)\r
+\r
+ def PassCommandOption(self, BuildTarget, TargetArch, ToolChain, PlatformFile, Target):\r
BuildStr = ''\r
if GlobalData.gCommand and isinstance(GlobalData.gCommand, list):\r
BuildStr += ' ' + ' '.join(GlobalData.gCommand)\r
TargetFlag = False\r
ArchFlag = False\r
ToolChainFlag = False\r
+ PlatformFileFlag = False\r
\r
if GlobalData.gOptions and not GlobalData.gOptions.BuildTarget:\r
TargetFlag = True\r
ArchFlag = True\r
if GlobalData.gOptions and not GlobalData.gOptions.ToolChain:\r
ToolChainFlag = True\r
+ if GlobalData.gOptions and not GlobalData.gOptions.PlatformFile:\r
+ PlatformFileFlag = True\r
\r
if TargetFlag and BuildTarget:\r
if isinstance(BuildTarget, list) or isinstance(BuildTarget, tuple):\r
BuildStr += ' -t ' + ' -t '.join(ToolChain)\r
elif isinstance(ToolChain, str):\r
BuildStr += ' -t ' + ToolChain\r
+ if PlatformFileFlag and PlatformFile:\r
+ if isinstance(PlatformFile, list) or isinstance(PlatformFile, tuple):\r
+ BuildStr += ' -p ' + ' -p '.join(PlatformFile)\r
+ elif isinstance(PlatformFile, str):\r
+ BuildStr += ' -p' + PlatformFile\r
+ BuildStr += ' --conf=' + GlobalData.gConfDirectory\r
+ if Target:\r
+ BuildStr += ' ' + Target\r
\r
return BuildStr\r
\r