]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
BaseTools: enhance error handling for option --binary-source
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index 4f73bba3bdf1efe55e30f9bf336b392637b453f6..e4adee2bebca101623369b7e4857a4c342ca6981 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 - 2017, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2018, 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
@@ -26,6 +26,7 @@ import platform
 import traceback\r
 import encodings.ascii\r
 import itertools\r
+import multiprocessing\r
 \r
 from struct import *\r
 from threading import *\r
@@ -50,6 +51,7 @@ from PatchPcdValue.PatchPcdValue import *
 \r
 import Common.EdkLogger\r
 import Common.GlobalData as GlobalData\r
+from GenFds.GenFds import GenFds\r
 \r
 # Version and Copyright\r
 VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
@@ -760,6 +762,8 @@ class Build():
         self.SkipAutoGen    = BuildOptions.SkipAutoGen\r
         self.Reparse        = BuildOptions.Reparse\r
         self.SkuId          = BuildOptions.SkuId\r
+        if self.SkuId:\r
+            GlobalData.gSKUID_CMD = self.SkuId\r
         self.ConfDirectory = BuildOptions.ConfDirectory\r
         self.SpawnMode      = True\r
         self.BuildReport    = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)\r
@@ -774,6 +778,7 @@ class Build():
         GlobalData.gUseHashCache = BuildOptions.UseHashCache\r
         GlobalData.gBinCacheDest   = BuildOptions.BinCacheDest\r
         GlobalData.gBinCacheSource = BuildOptions.BinCacheSource\r
+        GlobalData.gEnableGenfdsMultiThread = BuildOptions.GenfdsMultiThread\r
 \r
         if GlobalData.gBinCacheDest and not GlobalData.gUseHashCache:\r
             EdkLogger.error("build", OPTION_NOT_SUPPORTED, ExtraData="--binary-destination must be used together with --hash.")\r
@@ -789,12 +794,18 @@ class Build():
             if not os.path.isabs(BinCacheSource):\r
                 BinCacheSource = mws.join(self.WorkspaceDir, BinCacheSource)\r
             GlobalData.gBinCacheSource = BinCacheSource\r
+        else:\r
+            if GlobalData.gBinCacheSource != None:\r
+                EdkLogger.error("build", OPTION_VALUE_INVALID, ExtraData="Invalid value of option --binary-source.")\r
 \r
         if GlobalData.gBinCacheDest:\r
             BinCacheDest = os.path.normpath(GlobalData.gBinCacheDest)\r
             if not os.path.isabs(BinCacheDest):\r
                 BinCacheDest = mws.join(self.WorkspaceDir, BinCacheDest)\r
             GlobalData.gBinCacheDest = BinCacheDest\r
+        else:\r
+            if GlobalData.gBinCacheDest != None:\r
+                EdkLogger.error("build", OPTION_VALUE_INVALID, ExtraData="Invalid value of option --binary-destination.")\r
 \r
         if self.ConfDirectory:\r
             # Get alternate Conf location, if it is absolute, then just use the absolute directory name\r
@@ -823,6 +834,7 @@ class Build():
         self.LoadFixAddress = 0\r
         self.UniFlag        = BuildOptions.Flag\r
         self.BuildModules = []\r
+        self.HashSkipModules = []\r
         self.Db_Flag = False\r
         self.LaunchPrebuildFlag = False\r
         self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory,'.cache', '.PlatformBuild')\r
@@ -931,7 +943,10 @@ class Build():
                 self.ThreadNumber = int(self.ThreadNumber, 0)\r
 \r
         if self.ThreadNumber == 0:\r
-            self.ThreadNumber = 1\r
+            try:\r
+                self.ThreadNumber = multiprocessing.cpu_count()\r
+            except (ImportError, NotImplementedError):\r
+                self.ThreadNumber = 1\r
 \r
         if not self.PlatformFile:\r
             PlatformFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM]\r
@@ -1208,7 +1223,7 @@ class Build():
     #   @param  CreateDepModuleMakeFile     Flag used to indicate creating makefile\r
     #                                       for dependent modules/Libraries\r
     #\r
-    def _BuildPa(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeFile=True, BuildModule=False):\r
+    def _BuildPa(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeFile=True, BuildModule=False, FfsCommand={}):\r
         if AutoGenObject == None:\r
             return False\r
 \r
@@ -1224,7 +1239,7 @@ class Build():
 \r
             if not self.SkipAutoGen or Target == 'genmake':\r
                 self.Progress.Start("Generating makefile")\r
-                AutoGenObject.CreateMakeFile(CreateDepsMakeFile)\r
+                AutoGenObject.CreateMakeFile(CreateDepsMakeFile, FfsCommand)\r
                 self.Progress.Stop("done!")\r
             if Target == "genmake":\r
                 return True\r
@@ -1731,6 +1746,12 @@ class Build():
                 self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
                 self.BuildReport.AddPlatformReport(Wa)\r
                 self.Progress.Stop("done!")\r
+\r
+                # Add ffs build to makefile\r
+                CmdListDict = {}\r
+                if GlobalData.gEnableGenfdsMultiThread and self.Fdf:\r
+                    CmdListDict = self._GenFfsCmd()\r
+\r
                 for Arch in Wa.ArchList:\r
                     GlobalData.gGlobalDefines['ARCH'] = Arch\r
                     Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)\r
@@ -1740,7 +1761,7 @@ class Build():
                         if Ma == None:\r
                             continue\r
                         self.BuildModules.append(Ma)\r
-                    self._BuildPa(self.Target, Pa)\r
+                    self._BuildPa(self.Target, Pa, FfsCommand=CmdListDict)\r
 \r
                 # Create MAP file when Load Fix Address is enabled.\r
                 if self.Target in ["", "all", "fds"]:\r
@@ -1819,6 +1840,10 @@ class Build():
                 self.Fdf = Wa.FdfFile\r
                 self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
                 Wa.CreateMakeFile(False)\r
+                # Add ffs build to makefile\r
+                CmdListDict = None\r
+                if GlobalData.gEnableGenfdsMultiThread and self.Fdf:\r
+                    CmdListDict = self._GenFfsCmd()\r
                 self.Progress.Stop("done!")\r
                 MaList = []\r
                 ExitFlag = threading.Event()\r
@@ -1832,19 +1857,21 @@ class Build():
                         if self.ModuleFile.Dir == Module.Dir and self.ModuleFile.Name == Module.Name:\r
                             Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile)\r
                             if Ma == None: continue\r
+                            MaList.append(Ma)\r
+                            if Ma.CanSkipbyHash():\r
+                                self.HashSkipModules.append(Ma)\r
+                                continue\r
                             # Not to auto-gen for targets 'clean', 'cleanlib', 'cleanall', 'run', 'fds'\r
                             if self.Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:\r
                                 # for target which must generate AutoGen code and makefile\r
                                 if not self.SkipAutoGen or self.Target == 'genc':\r
                                     Ma.CreateCodeFile(True)\r
-                                if self.Target == "genc":\r
-                                    continue\r
-\r
                                 if not self.SkipAutoGen or self.Target == 'genmake':\r
-                                    Ma.CreateMakeFile(True)\r
-                                if self.Target == "genmake":\r
-                                    continue\r
-                            MaList.append(Ma)\r
+                                    if CmdListDict and self.Fdf and (Module.File, Arch) in CmdListDict:\r
+                                        Ma.CreateMakeFile(True, CmdListDict[Module.File, Arch])\r
+                                        del CmdListDict[Module.File, Arch]\r
+                                    else:\r
+                                        Ma.CreateMakeFile(True)\r
                             self.BuildModules.append(Ma)\r
                     self.AutoGenTime += int(round((time.time() - AutoGenStart)))\r
                     MakeStart = time.time()\r
@@ -1927,6 +1954,17 @@ class Build():
                     #\r
                     self._SaveMapFile (MapBuffer, Wa)\r
 \r
+    def _GenFfsCmd(self):\r
+        CmdListDict = {}\r
+        GenFfsDict = GenFds.GenFfsMakefile('', GlobalData.gFdfParser, self, self.ArchList, GlobalData)\r
+        for Cmd in GenFfsDict:\r
+            tmpInf, tmpArch = GenFfsDict[Cmd]\r
+            if (tmpInf, tmpArch) not in CmdListDict.keys():\r
+                CmdListDict[tmpInf, tmpArch] = [Cmd]\r
+            else:\r
+                CmdListDict[tmpInf, tmpArch].append(Cmd)\r
+        return CmdListDict\r
+\r
     ## Build a platform in multi-thread mode\r
     #\r
     def _MultiThreadBuildPlatform(self):\r
@@ -1962,6 +2000,11 @@ class Build():
                 self.BuildReport.AddPlatformReport(Wa)\r
                 Wa.CreateMakeFile(False)\r
 \r
+                # Add ffs build to makefile\r
+                CmdListDict = None\r
+                if GlobalData.gEnableGenfdsMultiThread and self.Fdf:\r
+                    CmdListDict = self._GenFfsCmd()\r
+\r
                 # multi-thread exit flag\r
                 ExitFlag = threading.Event()\r
                 ExitFlag.clear()\r
@@ -1989,6 +2032,7 @@ class Build():
                         if Ma == None:\r
                             continue\r
                         if Ma.CanSkipbyHash():\r
+                            self.HashSkipModules.append(Ma)\r
                             continue\r
 \r
                         # Not to auto-gen for targets 'clean', 'cleanlib', 'cleanall', 'run', 'fds'\r
@@ -2000,7 +2044,11 @@ class Build():
                                 continue\r
 \r
                             if not self.SkipAutoGen or self.Target == 'genmake':\r
-                                Ma.CreateMakeFile(True)\r
+                                if CmdListDict and self.Fdf and (Module.File, Arch) in CmdListDict:\r
+                                    Ma.CreateMakeFile(True, CmdListDict[Module.File, Arch])\r
+                                    del CmdListDict[Module.File, Arch]\r
+                                else:\r
+                                    Ma.CreateMakeFile(True)\r
                             if self.Target == "genmake":\r
                                 continue\r
                         self.BuildModules.append(Ma)\r
@@ -2183,7 +2231,10 @@ class Build():
     def CreateAsBuiltInf(self):\r
         for Module in self.BuildModules:\r
             Module.CreateAsBuiltInf()\r
+        for Module in self.HashSkipModules:\r
+            Module.CreateAsBuiltInf(True)\r
         self.BuildModules = []\r
+        self.HashSkipModules = []\r
     ## Do some clean-up works when error occurred\r
     def Relinquish(self):\r
         OldLogLevel = EdkLogger.GetLevel()\r
@@ -2316,7 +2367,7 @@ def MyOptionParser():
     Parser.add_option("--hash", action="store_true", dest="UseHashCache", default=False, help="Enable hash-based caching during build process.")\r
     Parser.add_option("--binary-destination", action="store", type="string", dest="BinCacheDest", help="Generate a cache of binary files in the specified directory.")\r
     Parser.add_option("--binary-source", action="store", type="string", dest="BinCacheSource", help="Consume a cache of binary files from the specified directory.")\r
-\r
+    Parser.add_option("--genfds-multi-thread", action="store_true", dest="GenfdsMultiThread", default=False, help="Enable GenFds multi thread to generate ffs file.")\r
     (Opt, Args) = Parser.parse_args()\r
     return (Opt, Args)\r
 \r