]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index c4cfe38ad96af90e6d0f481e8f8d0dd64b3f0728..51fb1f433eb7878d3721e882a7ff8e19cfee4297 100755 (executable)
@@ -2,9 +2,9 @@
 # build a platform or a module\r
 #\r
 #  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
-#  Copyright (c) 2007 - 2020, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>\r
 #  Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
-#  Copyright (c) 2020, ARM Limited. All rights reserved.<BR>\r
+#  Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.<BR>\r
 #\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
@@ -62,14 +62,11 @@ from AutoGen.ModuleAutoGenHelper import WorkSpaceInfo, PlatformInfo
 from GenFds.FdfParser import FdfParser\r
 from AutoGen.IncludesAutoGen import IncludesAutoGen\r
 from GenFds.GenFds import resetFdsGlobalVariable\r
+from AutoGen.AutoGen import CalculatePriorityValue\r
 \r
 ## standard targets of build command\r
 gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']\r
 \r
-## build configuration file\r
-gBuildConfiguration = "target.txt"\r
-gToolsDefinition = "tools_def.txt"\r
-\r
 TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$')\r
 TmpTableDict = {}\r
 \r
@@ -196,7 +193,7 @@ def ReadMessage(From, To, ExitFlag,MemTo=None):
                 To(LineStr)\r
         else:\r
             break\r
-        if ExitFlag.isSet():\r
+        if ExitFlag.is_set():\r
             break\r
 \r
 class MakeSubProc(Popen):\r
@@ -208,7 +205,7 @@ class MakeSubProc(Popen):
 #\r
 # This method will call subprocess.Popen to execute an external program with\r
 # given options in specified directory. Because of the dead-lock issue during\r
-# redirecting output of the external program, threads are used to to do the\r
+# redirecting output of the external program, threads are used to do the\r
 # redirection work.\r
 #\r
 # @param  Command               A list or string containing the call of the program\r
@@ -240,8 +237,8 @@ def LaunchCommand(Command, WorkingDir,ModuleAuto = None):
         EndOfProcedure.clear()\r
         if Proc.stdout:\r
             StdOutThread = Thread(target=ReadMessage, args=(Proc.stdout, EdkLogger.info, EndOfProcedure,Proc.ProcOut))\r
-            StdOutThread.setName("STDOUT-Redirector")\r
-            StdOutThread.setDaemon(False)\r
+            StdOutThread.name = "STDOUT-Redirector"\r
+            StdOutThread.daemon = False\r
             StdOutThread.start()\r
 \r
 \r
@@ -432,8 +429,8 @@ class BuildTask:
     @staticmethod\r
     def StartScheduler(MaxThreadNumber, ExitFlag):\r
         SchedulerThread = Thread(target=BuildTask.Scheduler, args=(MaxThreadNumber, ExitFlag))\r
-        SchedulerThread.setName("Build-Task-Scheduler")\r
-        SchedulerThread.setDaemon(False)\r
+        SchedulerThread.name = "Build-Task-Scheduler"\r
+        SchedulerThread.daemon = False\r
         SchedulerThread.start()\r
         # wait for the scheduler to be started, especially useful in Linux\r
         while not BuildTask.IsOnGoing():\r
@@ -455,7 +452,7 @@ class BuildTask:
             # indicated to do so, or there's error in running thread\r
             #\r
             while (len(BuildTask._PendingQueue) > 0 or len(BuildTask._ReadyQueue) > 0 \\r
-                   or not ExitFlag.isSet()) and not BuildTask._ErrorFlag.isSet():\r
+                   or not ExitFlag.is_set()) and not BuildTask._ErrorFlag.is_set():\r
                 EdkLogger.debug(EdkLogger.DEBUG_8, "Pending Queue (%d), Ready Queue (%d)"\r
                                 % (len(BuildTask._PendingQueue), len(BuildTask._ReadyQueue)))\r
 \r
@@ -473,7 +470,7 @@ class BuildTask:
                 BuildTask._PendingQueueLock.release()\r
 \r
                 # launch build thread until the maximum number of threads is reached\r
-                while not BuildTask._ErrorFlag.isSet():\r
+                while not BuildTask._ErrorFlag.is_set():\r
                     # empty ready queue, do nothing further\r
                     if len(BuildTask._ReadyQueue) == 0:\r
                         break\r
@@ -497,12 +494,12 @@ class BuildTask:
                 time.sleep(0.01)\r
 \r
             # wait for all running threads exit\r
-            if BuildTask._ErrorFlag.isSet():\r
+            if BuildTask._ErrorFlag.is_set():\r
                 EdkLogger.quiet("\nWaiting for all build threads exit...")\r
-            # while not BuildTask._ErrorFlag.isSet() and \\r
+            # while not BuildTask._ErrorFlag.is_set() and \\r
             while len(BuildTask._RunningQueue) > 0:\r
                 EdkLogger.verbose("Waiting for thread ending...(%d)" % len(BuildTask._RunningQueue))\r
-                EdkLogger.debug(EdkLogger.DEBUG_8, "Threads [%s]" % ", ".join(Th.getName() for Th in threading.enumerate()))\r
+                EdkLogger.debug(EdkLogger.DEBUG_8, "Threads [%s]" % ", ".join(Th.name for Th in threading.enumerate()))\r
                 # avoid tense loop\r
                 time.sleep(0.1)\r
         except BaseException as X:\r
@@ -530,7 +527,7 @@ class BuildTask:
     #\r
     @staticmethod\r
     def IsOnGoing():\r
-        return not BuildTask._SchedulerStopped.isSet()\r
+        return not BuildTask._SchedulerStopped.is_set()\r
 \r
     ## Abort the build\r
     @staticmethod\r
@@ -546,7 +543,7 @@ class BuildTask:
     #\r
     @staticmethod\r
     def HasError():\r
-        return BuildTask._ErrorFlag.isSet()\r
+        return BuildTask._ErrorFlag.is_set()\r
 \r
     ## Get error message in running thread\r
     #\r
@@ -643,7 +640,7 @@ class BuildTask:
             # TRICK: hide the output of threads left running, so that the user can\r
             #        catch the error message easily\r
             #\r
-            if not BuildTask._ErrorFlag.isSet():\r
+            if not BuildTask._ErrorFlag.is_set():\r
                 GlobalData.gBuildingModule = "%s [%s, %s, %s]" % (str(self.BuildItem.BuildObject),\r
                                                                   self.BuildItem.BuildObject.Arch,\r
                                                                   self.BuildItem.BuildObject.ToolChain,\r
@@ -652,7 +649,7 @@ class BuildTask:
             EdkLogger.SetLevel(EdkLogger.ERROR)\r
             BuildTask._ErrorFlag.set()\r
             BuildTask._ErrorMessage = "%s broken\n    %s [%s]" % \\r
-                                      (threading.currentThread().getName(), Command, WorkingDir)\r
+                                      (threading.current_thread().name, Command, WorkingDir)\r
 \r
         # indicate there's a thread is available for another build task\r
         BuildTask._RunningQueueLock.acquire()\r
@@ -666,8 +663,8 @@ class BuildTask:
         EdkLogger.quiet("Building ... %s" % repr(self.BuildItem))\r
         Command = self.BuildItem.BuildCommand + [self.BuildItem.Target]\r
         self.BuildTread = Thread(target=self._CommandThread, args=(Command, self.BuildItem.WorkingDir))\r
-        self.BuildTread.setName("build thread")\r
-        self.BuildTread.setDaemon(False)\r
+        self.BuildTread.name = "build thread"\r
+        self.BuildTread.daemon = False\r
         self.BuildTread.start()\r
 \r
 ## The class contains the information related to EFI image\r
@@ -889,6 +886,49 @@ class Build():
         except:\r
             return False, UNKNOWN_ERROR\r
 \r
+    ## Add TOOLCHAIN and FAMILY declared in DSC [BuildOptions] to ToolsDefTxtDatabase.\r
+    #\r
+    # Loop through the set of build targets, tool chains, and archs provided on either\r
+    # the command line or in target.txt to discover FAMILY and TOOLCHAIN delclarations\r
+    # in [BuildOptions] sections that may be within !if expressions that may use\r
+    # $(TARGET), $(TOOLCHAIN), $(TOOLCHAIN_TAG), or $(ARCH) operands.\r
+    #\r
+    def GetToolChainAndFamilyFromDsc (self, File):\r
+        SavedGlobalDefines = GlobalData.gGlobalDefines.copy()\r
+        for BuildTarget in self.BuildTargetList:\r
+            GlobalData.gGlobalDefines['TARGET'] = BuildTarget\r
+            for BuildToolChain in self.ToolChainList:\r
+                GlobalData.gGlobalDefines['TOOLCHAIN']      = BuildToolChain\r
+                GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = BuildToolChain\r
+                for BuildArch in self.ArchList:\r
+                    GlobalData.gGlobalDefines['ARCH'] = BuildArch\r
+                    dscobj = self.BuildDatabase[File, BuildArch]\r
+                    for KeyFamily, Key, KeyCodeBase in dscobj.BuildOptions:\r
+                        try:\r
+                            Target, ToolChain, Arch, Tool, Attr = Key.split('_')\r
+                        except:\r
+                            continue\r
+                        if ToolChain == TAB_STAR or Attr != TAB_TOD_DEFINES_FAMILY:\r
+                            continue\r
+                        try:\r
+                            Family = dscobj.BuildOptions[(KeyFamily, Key, KeyCodeBase)]\r
+                            Family = Family.strip().strip('=').strip()\r
+                        except:\r
+                            continue\r
+                        if TAB_TOD_DEFINES_FAMILY not in self.ToolDef.ToolsDefTxtDatabase:\r
+                            self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY] = {}\r
+                        if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]:\r
+                            self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][ToolChain] = Family\r
+                        if TAB_TOD_DEFINES_BUILDRULEFAMILY not in self.ToolDef.ToolsDefTxtDatabase:\r
+                            self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY] = {}\r
+                        if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
+                            self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][ToolChain] = Family\r
+                        if TAB_TOD_DEFINES_TOOL_CHAIN_TAG not in self.ToolDef.ToolsDefTxtDatabase:\r
+                            self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = []\r
+                        if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]:\r
+                            self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].append(ToolChain)\r
+        GlobalData.gGlobalDefines = SavedGlobalDefines\r
+\r
     ## Load configuration\r
     #\r
     #   This method will parse target.txt and get the build configurations.\r
@@ -910,6 +950,26 @@ class Build():
             if self.ToolChainList is None or len(self.ToolChainList) == 0:\r
                 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.\n")\r
 \r
+        if not self.PlatformFile:\r
+            PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM]\r
+            if not PlatformFile:\r
+                # Try to find one in current directory\r
+                WorkingDirectory = os.getcwd()\r
+                FileList = glob.glob(os.path.normpath(os.path.join(WorkingDirectory, '*.dsc')))\r
+                FileNum = len(FileList)\r
+                if FileNum >= 2:\r
+                    EdkLogger.error("build", OPTION_MISSING,\r
+                                    ExtraData="There are %d DSC files in %s. Use '-p' to specify one.\n" % (FileNum, WorkingDirectory))\r
+                elif FileNum == 1:\r
+                    PlatformFile = FileList[0]\r
+                else:\r
+                    EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
+                                    ExtraData="No active platform specified in target.txt or command line! Nothing can be built.\n")\r
+\r
+            self.PlatformFile = PathClass(NormFile(PlatformFile, self.WorkspaceDir), self.WorkspaceDir)\r
+\r
+        self.GetToolChainAndFamilyFromDsc (self.PlatformFile)\r
+\r
         # check if the tool chains are defined or not\r
         NewToolChainList = []\r
         for ToolChain in self.ToolChainList:\r
@@ -935,23 +995,6 @@ class Build():
                 ToolChainFamily.append(ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool])\r
         self.ToolChainFamily = ToolChainFamily\r
 \r
-        if not self.PlatformFile:\r
-            PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM]\r
-            if not PlatformFile:\r
-                # Try to find one in current directory\r
-                WorkingDirectory = os.getcwd()\r
-                FileList = glob.glob(os.path.normpath(os.path.join(WorkingDirectory, '*.dsc')))\r
-                FileNum = len(FileList)\r
-                if FileNum >= 2:\r
-                    EdkLogger.error("build", OPTION_MISSING,\r
-                                    ExtraData="There are %d DSC files in %s. Use '-p' to specify one.\n" % (FileNum, WorkingDirectory))\r
-                elif FileNum == 1:\r
-                    PlatformFile = FileList[0]\r
-                else:\r
-                    EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
-                                    ExtraData="No active platform specified in target.txt or command line! Nothing can be built.\n")\r
-\r
-            self.PlatformFile = PathClass(NormFile(PlatformFile, self.WorkspaceDir), self.WorkspaceDir)\r
         self.ThreadNumber   = ThreadNum()\r
     ## Initialize build configuration\r
     #\r
@@ -1130,14 +1173,14 @@ class Build():
             EndOfProcedure.clear()\r
             if Process.stdout:\r
                 StdOutThread = Thread(target=ReadMessage, args=(Process.stdout, EdkLogger.info, EndOfProcedure))\r
-                StdOutThread.setName("STDOUT-Redirector")\r
-                StdOutThread.setDaemon(False)\r
+                StdOutThread.name = "STDOUT-Redirector"\r
+                StdOutThread.daemon = False\r
                 StdOutThread.start()\r
 \r
             if Process.stderr:\r
                 StdErrThread = Thread(target=ReadMessage, args=(Process.stderr, EdkLogger.quiet, EndOfProcedure))\r
-                StdErrThread.setName("STDERR-Redirector")\r
-                StdErrThread.setDaemon(False)\r
+                StdErrThread.name = "STDERR-Redirector"\r
+                StdErrThread.daemon = False\r
                 StdErrThread.start()\r
             # waiting for program exit\r
             Process.wait()\r
@@ -1170,14 +1213,14 @@ class Build():
             EndOfProcedure.clear()\r
             if Process.stdout:\r
                 StdOutThread = Thread(target=ReadMessage, args=(Process.stdout, EdkLogger.info, EndOfProcedure))\r
-                StdOutThread.setName("STDOUT-Redirector")\r
-                StdOutThread.setDaemon(False)\r
+                StdOutThread.name = "STDOUT-Redirector"\r
+                StdOutThread.daemon = False\r
                 StdOutThread.start()\r
 \r
             if Process.stderr:\r
                 StdErrThread = Thread(target=ReadMessage, args=(Process.stderr, EdkLogger.quiet, EndOfProcedure))\r
-                StdErrThread.setName("STDERR-Redirector")\r
-                StdErrThread.setDaemon(False)\r
+                StdErrThread.name = "STDERR-Redirector"\r
+                StdErrThread.daemon = False\r
                 StdErrThread.start()\r
             # waiting for program exit\r
             Process.wait()\r
@@ -1261,6 +1304,9 @@ class Build():
         if Target == 'run':\r
             return True\r
 \r
+        # Fetch the MakeFileName.\r
+        self.MakeFileName = AutoGenObject.MakeFileName\r
+\r
         # build modules\r
         if BuildModule:\r
             BuildCommand = BuildCommand + [Target]\r
@@ -2136,8 +2182,6 @@ class Build():
             Pa.CreateLibModuelDirs()\r
             # Fetch the MakeFileName.\r
             self.MakeFileName = Pa.MakeFileName\r
-            if not self.MakeFileName:\r
-                self.MakeFileName = Pa.MakeFile\r
 \r
             Pa.DataPipe.DataContainer = {"LibraryBuildDirectoryList":Pa.LibraryBuildDirectoryList}\r
             Pa.DataPipe.DataContainer = {"ModuleBuildDirectoryList":Pa.ModuleBuildDirectoryList}\r
@@ -2379,26 +2423,42 @@ class Build():
                 FvDir = Wa.FvDir\r
                 if not os.path.exists(FvDir):\r
                     continue\r
-\r
                 for Arch in self.ArchList:\r
-                    # Build up the list of supported architectures for this build\r
-                    prefix = '%s_%s_%s_' % (BuildTarget, ToolChain, Arch)\r
-\r
-                    # Look through the tool definitions for GUIDed tools\r
+                    guidList = []\r
+                    tooldefguidList = []\r
                     guidAttribs = []\r
-                    for (attrib, value) in self.ToolDef.ToolsDefTxtDictionary.items():\r
-                        if attrib.upper().endswith('_GUID'):\r
-                            split = attrib.split('_')\r
-                            thisPrefix = '_'.join(split[0:3]) + '_'\r
-                            if thisPrefix == prefix:\r
-                                guid = self.ToolDef.ToolsDefTxtDictionary[attrib]\r
-                                guid = guid.lower()\r
-                                toolName = split[3]\r
-                                path = '_'.join(split[0:4]) + '_PATH'\r
-                                path = self.ToolDef.ToolsDefTxtDictionary[path]\r
-                                path = self.GetRealPathOfTool(path)\r
-                                guidAttribs.append((guid, toolName, path))\r
-\r
+                    for Platform in Wa.AutoGenObjectList:\r
+                        if Platform.BuildTarget != BuildTarget:\r
+                            continue\r
+                        if Platform.ToolChain != ToolChain:\r
+                            continue\r
+                        if Platform.Arch != Arch:\r
+                            continue\r
+                        if hasattr (Platform, 'BuildOption'):\r
+                            for Tool in Platform.BuildOption:\r
+                                if 'GUID' in Platform.BuildOption[Tool]:\r
+                                    if 'PATH' in Platform.BuildOption[Tool]:\r
+                                        value = Platform.BuildOption[Tool]['GUID']\r
+                                        if value in guidList:\r
+                                            EdkLogger.error("build", FORMAT_INVALID, "Duplicate GUID value %s used with Tool %s in DSC [BuildOptions]." % (value, Tool))\r
+                                        path = Platform.BuildOption[Tool]['PATH']\r
+                                        guidList.append(value)\r
+                                        guidAttribs.append((value, Tool, path))\r
+                        for Tool in Platform.ToolDefinition:\r
+                            if 'GUID' in Platform.ToolDefinition[Tool]:\r
+                                if 'PATH' in Platform.ToolDefinition[Tool]:\r
+                                    value = Platform.ToolDefinition[Tool]['GUID']\r
+                                    if value in tooldefguidList:\r
+                                        EdkLogger.error("build", FORMAT_INVALID, "Duplicate GUID value %s used with Tool %s in tools_def.txt." % (value, Tool))\r
+                                    tooldefguidList.append(value)\r
+                                    if value in guidList:\r
+                                        # Already added by platform\r
+                                        continue\r
+                                    path = Platform.ToolDefinition[Tool]['PATH']\r
+                                    guidList.append(value)\r
+                                    guidAttribs.append((value, Tool, path))\r
+                    # Sort by GuidTool name\r
+                    guidAttribs = sorted (guidAttribs, key=lambda x: x[1])\r
                     # Write out GuidedSecTools.txt\r
                     toolsFile = os.path.join(FvDir, 'GuidedSectionTools.txt')\r
                     toolsFile = open(toolsFile, 'wt')\r
@@ -2694,6 +2754,7 @@ def Main():
             Conclusion = "Done"\r
         except:\r
             Conclusion = "Failed"\r
+            ReturnCode = POSTBUILD_ERROR\r
     elif ReturnCode == ABORT_ERROR:\r
         Conclusion = "Aborted"\r
     else:\r