# 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
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
To(LineStr)\r
else:\r
break\r
- if ExitFlag.isSet():\r
+ if ExitFlag.is_set():\r
break\r
\r
class MakeSubProc(Popen):\r
#\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
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
@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
# 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
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
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
#\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
#\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
# 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
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
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
\r
PcdMa.CreateCodeFile(False)\r
PcdMa.CreateMakeFile(False,GenFfsList = DataPipe.Get("FfsCommand").get((PcdMa.MetaFile.Path, PcdMa.Arch),[]))\r
-\r
+ PcdMa.CreateAsBuiltInf()\r
# Force cache miss for PCD driver\r
if GlobalData.gBinCacheSource and self.Target in [None, "", "all"]:\r
cqueue.put((PcdMa.MetaFile.Path, PcdMa.Arch, "MakeCache", False))\r
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
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
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
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
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
mqueue = mp.Queue()\r
for m in AutoGenObject.GetAllModuleInfo:\r
mqueue.put(m)\r
-\r
+ mqueue.put((None,None,None,None,None,None,None))\r
AutoGenObject.DataPipe.DataContainer = {"CommandTarget": self.Target}\r
AutoGenObject.DataPipe.DataContainer = {"Workspace_timestamp": AutoGenObject.Workspace._SrcTimeStamp}\r
AutoGenObject.CreateLibModuelDirs()\r
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
LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)\r
- self.CreateAsBuiltInf()\r
if GlobalData.gBinCacheDest:\r
self.GenDestCache()\r
elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
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
data_pipe_file = os.path.join(Pa.BuildDir, "GlobalVar_%s_%s.bin" % (str(Pa.Guid),Pa.Arch))\r
Pa.DataPipe.dump(data_pipe_file)\r
\r
+ mqueue.put((None,None,None,None,None,None,None))\r
autogen_rt, errorcode = self.StartAutoGen(mqueue, Pa.DataPipe, self.SkipAutoGen, PcdMaList, cqueue)\r
\r
if not autogen_rt:\r
#\r
ExitFlag.set()\r
BuildTask.WaitForComplete()\r
- self.CreateAsBuiltInf()\r
if GlobalData.gBinCacheDest:\r
self.GenDestCache()\r
elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
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
Conclusion = "Done"\r
except:\r
Conclusion = "Failed"\r
+ ReturnCode = POSTBUILD_ERROR\r
elif ReturnCode == ABORT_ERROR:\r
Conclusion = "Aborted"\r
else:\r