]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
BaseTools/Build: Support python scripts in PREBUILD/POSTBUILD
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index b003c6740356df8b9109087797562735ec10bb90..1e14fb4dcc7d259f48347fc9a6f61a36e7930ef5 100644 (file)
@@ -2,7 +2,7 @@
 # build a platform or a module\r
 #\r
 #  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
-#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -54,7 +54,7 @@ import Common.GlobalData as GlobalData
 # Version and Copyright\r
 VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
 __version__ = "%prog Version " + VersionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2016, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation  All rights reserved."\r
 \r
 ## standard targets of build command\r
 gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']\r
@@ -265,10 +265,10 @@ def LaunchCommand(Command, WorkingDir):
     # It could be a string or sequence. We find that if command is a string in following Popen(),\r
     # ubuntu may fail with an error message that the command is not found.\r
     # So here we may need convert command from string to list instance.\r
-    if not isinstance(Command, list):\r
-        if platform.system() != 'Windows':\r
+    if platform.system() != 'Windows':\r
+        if not isinstance(Command, list):\r
             Command = Command.split()\r
-            Command = ' '.join(Command)\r
+        Command = ' '.join(Command)\r
 \r
     Proc = None\r
     EndOfProcedure = None\r
@@ -825,6 +825,8 @@ class Build():
             EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.PostbuildScript))\r
         if self.PrebuildScript:\r
             self.LaunchPrebuild()\r
+            self.TargetTxt = TargetTxtClassObject()\r
+            self.ToolDef   = ToolDefClassObject()\r
         if not (self.LaunchPrebuildFlag and os.path.exists(self.PlatformBuildPath)):\r
             self.InitBuild()\r
 \r
@@ -987,7 +989,6 @@ class Build():
                 self.PostbuildScript = PostbuildList[0]\r
                 self.Postbuild = ' '.join(PostbuildList)\r
                 self.Postbuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList)\r
-                #self.LanuchPostbuild()\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
@@ -1035,10 +1036,10 @@ class Build():
                 os.remove(self.PlatformBuildPath)\r
             if sys.platform == "win32":\r
                 args = ' && '.join((self.Prebuild, 'set > ' + PrebuildEnvFile))\r
-                Process = Popen(args, stdout=PIPE, stderr=PIPE)\r
+                Process = Popen(args, stdout=PIPE, stderr=PIPE, shell=True)\r
             else:\r
                 args = ' && '.join((self.Prebuild, 'env > ' + PrebuildEnvFile))\r
-                Process = Popen(args, stdout=PIPE, stderr=PIPE, shell=True, executable="/bin/bash")\r
+                Process = Popen(args, stdout=PIPE, stderr=PIPE, shell=True)\r
 \r
             # launch two threads to read the STDOUT and STDERR\r
             EndOfProcedure = Event()\r
@@ -1074,13 +1075,13 @@ class Build():
                 os.environ.update(dict(envs))\r
             EdkLogger.info("\n- Prebuild Done -\n")\r
 \r
-    def LanuchPostbuild(self):\r
+    def LaunchPostbuild(self):\r
         if self.Postbuild:\r
             EdkLogger.info("\n- Postbuild Start -\n")\r
             if sys.platform == "win32":\r
-                Process = Popen(self.Postbuild, stdout=PIPE, stderr=PIPE)\r
+                Process = Popen(self.Postbuild, stdout=PIPE, stderr=PIPE, shell=True)\r
             else:\r
-                Process = Popen(self.Postbuild, stdout=PIPE, stderr=PIPE, shell=True, executable="/bin/bash")\r
+                Process = Popen(self.Postbuild, stdout=PIPE, stderr=PIPE, shell=True)\r
             # launch two threads to read the STDOUT and STDERR\r
             EndOfProcedure = Event()\r
             EndOfProcedure.clear()\r
@@ -1498,7 +1499,7 @@ class Build():
                         if IsIpfPlatform and ImageInfo.Image.Size % 0x2000 != 0:\r
                             ImageInfo.Image.Size = (ImageInfo.Image.Size / 0x2000 + 1) * 0x2000\r
                         RtSize += ImageInfo.Image.Size\r
-                    elif Module.ModuleType in ['SMM_CORE', 'DXE_SMM_DRIVER']:\r
+                    elif Module.ModuleType in ['SMM_CORE', 'DXE_SMM_DRIVER', 'MM_STANDALONE', 'MM_CORE_STANDALONE']:\r
                         SmmModuleList[Module.MetaFile] = ImageInfo\r
                         SmmSize += ImageInfo.Image.Size\r
                         if Module.ModuleType == 'DXE_SMM_DRIVER':\r
@@ -1735,12 +1736,15 @@ class Build():
                 MaList = []\r
                 for Arch in Wa.ArchList:\r
                     GlobalData.gGlobalDefines['ARCH'] = Arch\r
-                    Ma = ModuleAutoGen(Wa, self.ModuleFile, BuildTarget, ToolChain, Arch, self.PlatformFile)\r
-                    if Ma == None: continue\r
-                    MaList.append(Ma)\r
-                    self.BuildModules.append(Ma)\r
-                    if not Ma.IsBinaryModule:\r
-                        self._Build(self.Target, Ma, BuildModule=True)\r
+                    Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)\r
+                    for Module in Pa.Platform.Modules:\r
+                        if self.ModuleFile.Dir == Module.Dir and self.ModuleFile.File == Module.File:\r
+                            Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile)\r
+                            if Ma == None: continue\r
+                            MaList.append(Ma)\r
+                            self.BuildModules.append(Ma)\r
+                            if not Ma.IsBinaryModule:\r
+                                self._Build(self.Target, Ma, BuildModule=True)\r
 \r
                 self.BuildReport.AddPlatformReport(Wa, MaList)\r
                 if MaList == []:\r
@@ -2329,7 +2333,7 @@ def Main():
 \r
     if ReturnCode == 0:\r
         try:\r
-            MyBuild.LanuchPostbuild()\r
+            MyBuild.LaunchPostbuild()\r
             Conclusion = "Done"\r
         except:\r
             Conclusion = "Failed"\r