]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/build/build.py
BaseTools: build: Set ReturnCode on POSTBUILD fail
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
... / ...
CommitLineData
1## @file\r
2# build a platform or a module\r
3#\r
4# Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
5# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>\r
6# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
7# Copyright (c) 2020, ARM Limited. All rights reserved.<BR>\r
8#\r
9# SPDX-License-Identifier: BSD-2-Clause-Patent\r
10#\r
11\r
12##\r
13# Import Modules\r
14#\r
15from __future__ import print_function\r
16from __future__ import absolute_import\r
17import os.path as path\r
18import sys\r
19import os\r
20import re\r
21import glob\r
22import time\r
23import platform\r
24import traceback\r
25import multiprocessing\r
26from threading import Thread,Event,BoundedSemaphore\r
27import threading\r
28from linecache import getlines\r
29from subprocess import Popen,PIPE, STDOUT\r
30from collections import OrderedDict, defaultdict\r
31\r
32from AutoGen.PlatformAutoGen import PlatformAutoGen\r
33from AutoGen.ModuleAutoGen import ModuleAutoGen\r
34from AutoGen.WorkspaceAutoGen import WorkspaceAutoGen\r
35from AutoGen.AutoGenWorker import AutoGenWorkerInProcess,AutoGenManager,\\r
36 LogAgent\r
37from AutoGen import GenMake\r
38from Common import Misc as Utils\r
39\r
40from Common.TargetTxtClassObject import TargetTxtDict\r
41from Common.ToolDefClassObject import ToolDefDict\r
42from buildoptions import MyOptionParser\r
43from Common.Misc import PathClass,SaveFileOnChange,RemoveDirectory\r
44from Common.StringUtils import NormPath\r
45from Common.MultipleWorkspace import MultipleWorkspace as mws\r
46from Common.BuildToolError import *\r
47from Common.DataType import *\r
48import Common.EdkLogger as EdkLogger\r
49\r
50from Workspace.WorkspaceDatabase import BuildDB\r
51\r
52from BuildReport import BuildReport\r
53from GenPatchPcdTable.GenPatchPcdTable import PeImageClass,parsePcdInfoFromMapFile\r
54from PatchPcdValue.PatchPcdValue import PatchBinaryFile\r
55\r
56import Common.GlobalData as GlobalData\r
57from GenFds.GenFds import GenFds, GenFdsApi\r
58import multiprocessing as mp\r
59from multiprocessing import Manager\r
60from AutoGen.DataPipe import MemoryDataPipe\r
61from AutoGen.ModuleAutoGenHelper import WorkSpaceInfo, PlatformInfo\r
62from GenFds.FdfParser import FdfParser\r
63from AutoGen.IncludesAutoGen import IncludesAutoGen\r
64from GenFds.GenFds import resetFdsGlobalVariable\r
65from AutoGen.AutoGen import CalculatePriorityValue\r
66\r
67## standard targets of build command\r
68gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']\r
69\r
70## build configuration file\r
71gBuildConfiguration = "target.txt"\r
72gToolsDefinition = "tools_def.txt"\r
73\r
74TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$')\r
75TmpTableDict = {}\r
76\r
77## Check environment PATH variable to make sure the specified tool is found\r
78#\r
79# If the tool is found in the PATH, then True is returned\r
80# Otherwise, False is returned\r
81#\r
82def IsToolInPath(tool):\r
83 if 'PATHEXT' in os.environ:\r
84 extns = os.environ['PATHEXT'].split(os.path.pathsep)\r
85 else:\r
86 extns = ('',)\r
87 for pathDir in os.environ['PATH'].split(os.path.pathsep):\r
88 for ext in extns:\r
89 if os.path.exists(os.path.join(pathDir, tool + ext)):\r
90 return True\r
91 return False\r
92\r
93## Check environment variables\r
94#\r
95# Check environment variables that must be set for build. Currently they are\r
96#\r
97# WORKSPACE The directory all packages/platforms start from\r
98# EDK_TOOLS_PATH The directory contains all tools needed by the build\r
99# PATH $(EDK_TOOLS_PATH)/Bin/<sys> must be set in PATH\r
100#\r
101# If any of above environment variable is not set or has error, the build\r
102# will be broken.\r
103#\r
104def CheckEnvVariable():\r
105 # check WORKSPACE\r
106 if "WORKSPACE" not in os.environ:\r
107 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",\r
108 ExtraData="WORKSPACE")\r
109\r
110 WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"]))\r
111 if not os.path.exists(WorkspaceDir):\r
112 EdkLogger.error("build", FILE_NOT_FOUND, "WORKSPACE doesn't exist", ExtraData=WorkspaceDir)\r
113 elif ' ' in WorkspaceDir:\r
114 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in WORKSPACE path",\r
115 ExtraData=WorkspaceDir)\r
116 os.environ["WORKSPACE"] = WorkspaceDir\r
117\r
118 # set multiple workspace\r
119 PackagesPath = os.getenv("PACKAGES_PATH")\r
120 mws.setWs(WorkspaceDir, PackagesPath)\r
121 if mws.PACKAGES_PATH:\r
122 for Path in mws.PACKAGES_PATH:\r
123 if not os.path.exists(Path):\r
124 EdkLogger.error("build", FILE_NOT_FOUND, "One Path in PACKAGES_PATH doesn't exist", ExtraData=Path)\r
125 elif ' ' in Path:\r
126 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in PACKAGES_PATH", ExtraData=Path)\r
127\r
128\r
129 os.environ["EDK_TOOLS_PATH"] = os.path.normcase(os.environ["EDK_TOOLS_PATH"])\r
130\r
131 # check EDK_TOOLS_PATH\r
132 if "EDK_TOOLS_PATH" not in os.environ:\r
133 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",\r
134 ExtraData="EDK_TOOLS_PATH")\r
135\r
136 # check PATH\r
137 if "PATH" not in os.environ:\r
138 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",\r
139 ExtraData="PATH")\r
140\r
141 GlobalData.gWorkspace = WorkspaceDir\r
142\r
143 GlobalData.gGlobalDefines["WORKSPACE"] = WorkspaceDir\r
144 GlobalData.gGlobalDefines["EDK_TOOLS_PATH"] = os.environ["EDK_TOOLS_PATH"]\r
145\r
146## Get normalized file path\r
147#\r
148# Convert the path to be local format, and remove the WORKSPACE path at the\r
149# beginning if the file path is given in full path.\r
150#\r
151# @param FilePath File path to be normalized\r
152# @param Workspace Workspace path which the FilePath will be checked against\r
153#\r
154# @retval string The normalized file path\r
155#\r
156def NormFile(FilePath, Workspace):\r
157 # check if the path is absolute or relative\r
158 if os.path.isabs(FilePath):\r
159 FileFullPath = os.path.normpath(FilePath)\r
160 else:\r
161 FileFullPath = os.path.normpath(mws.join(Workspace, FilePath))\r
162 Workspace = mws.getWs(Workspace, FilePath)\r
163\r
164 # check if the file path exists or not\r
165 if not os.path.isfile(FileFullPath):\r
166 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData="\t%s (Please give file in absolute path or relative to WORKSPACE)" % FileFullPath)\r
167\r
168 # remove workspace directory from the beginning part of the file path\r
169 if Workspace[-1] in ["\\", "/"]:\r
170 return FileFullPath[len(Workspace):]\r
171 else:\r
172 return FileFullPath[(len(Workspace) + 1):]\r
173\r
174## Get the output of an external program\r
175#\r
176# This is the entrance method of thread reading output of an external program and\r
177# putting them in STDOUT/STDERR of current program.\r
178#\r
179# @param From The stream message read from\r
180# @param To The stream message put on\r
181# @param ExitFlag The flag used to indicate stopping reading\r
182#\r
183def ReadMessage(From, To, ExitFlag,MemTo=None):\r
184 while True:\r
185 # read one line a time\r
186 Line = From.readline()\r
187 # empty string means "end"\r
188 if Line is not None and Line != b"":\r
189 LineStr = Line.rstrip().decode(encoding='utf-8', errors='ignore')\r
190 if MemTo is not None:\r
191 if "Note: including file:" == LineStr.lstrip()[:21]:\r
192 MemTo.append(LineStr)\r
193 else:\r
194 To(LineStr)\r
195 MemTo.append(LineStr)\r
196 else:\r
197 To(LineStr)\r
198 else:\r
199 break\r
200 if ExitFlag.isSet():\r
201 break\r
202\r
203class MakeSubProc(Popen):\r
204 def __init__(self,*args, **argv):\r
205 super(MakeSubProc,self).__init__(*args, **argv)\r
206 self.ProcOut = []\r
207\r
208## Launch an external program\r
209#\r
210# This method will call subprocess.Popen to execute an external program with\r
211# given options in specified directory. Because of the dead-lock issue during\r
212# redirecting output of the external program, threads are used to to do the\r
213# redirection work.\r
214#\r
215# @param Command A list or string containing the call of the program\r
216# @param WorkingDir The directory in which the program will be running\r
217#\r
218def LaunchCommand(Command, WorkingDir,ModuleAuto = None):\r
219 BeginTime = time.time()\r
220 # if working directory doesn't exist, Popen() will raise an exception\r
221 if not os.path.isdir(WorkingDir):\r
222 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=WorkingDir)\r
223\r
224 # Command is used as the first Argument in following Popen().\r
225 # It could be a string or sequence. We find that if command is a string in following Popen(),\r
226 # ubuntu may fail with an error message that the command is not found.\r
227 # So here we may need convert command from string to list instance.\r
228 if platform.system() != 'Windows':\r
229 if not isinstance(Command, list):\r
230 Command = Command.split()\r
231 Command = ' '.join(Command)\r
232\r
233 Proc = None\r
234 EndOfProcedure = None\r
235 try:\r
236 # launch the command\r
237 Proc = MakeSubProc(Command, stdout=PIPE, stderr=STDOUT, env=os.environ, cwd=WorkingDir, bufsize=-1, shell=True)\r
238\r
239 # launch two threads to read the STDOUT and STDERR\r
240 EndOfProcedure = Event()\r
241 EndOfProcedure.clear()\r
242 if Proc.stdout:\r
243 StdOutThread = Thread(target=ReadMessage, args=(Proc.stdout, EdkLogger.info, EndOfProcedure,Proc.ProcOut))\r
244 StdOutThread.setName("STDOUT-Redirector")\r
245 StdOutThread.setDaemon(False)\r
246 StdOutThread.start()\r
247\r
248\r
249 # waiting for program exit\r
250 Proc.wait()\r
251 except: # in case of aborting\r
252 # terminate the threads redirecting the program output\r
253 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
254 if EndOfProcedure is not None:\r
255 EndOfProcedure.set()\r
256 if Proc is None:\r
257 if not isinstance(Command, type("")):\r
258 Command = " ".join(Command)\r
259 EdkLogger.error("build", COMMAND_FAILURE, "Failed to start command", ExtraData="%s [%s]" % (Command, WorkingDir))\r
260\r
261 if Proc.stdout:\r
262 StdOutThread.join()\r
263\r
264 # check the return code of the program\r
265 if Proc.returncode != 0:\r
266 if not isinstance(Command, type("")):\r
267 Command = " ".join(Command)\r
268 # print out the Response file and its content when make failure\r
269 RespFile = os.path.join(WorkingDir, 'OUTPUT', 'respfilelist.txt')\r
270 if os.path.isfile(RespFile):\r
271 f = open(RespFile)\r
272 RespContent = f.read()\r
273 f.close()\r
274 EdkLogger.info(RespContent)\r
275\r
276 EdkLogger.error("build", COMMAND_FAILURE, ExtraData="%s [%s]" % (Command, WorkingDir))\r
277 if ModuleAuto:\r
278 iau = IncludesAutoGen(WorkingDir,ModuleAuto)\r
279 if ModuleAuto.ToolChainFamily == TAB_COMPILER_MSFT:\r
280 iau.CreateDepsFileForMsvc(Proc.ProcOut)\r
281 else:\r
282 iau.UpdateDepsFileforNonMsvc()\r
283 iau.UpdateDepsFileforTrim()\r
284 iau.CreateModuleDeps()\r
285 iau.CreateDepsInclude()\r
286 iau.CreateDepsTarget()\r
287 return "%dms" % (int(round((time.time() - BeginTime) * 1000)))\r
288\r
289## The smallest unit that can be built in multi-thread build mode\r
290#\r
291# This is the base class of build unit. The "Obj" parameter must provide\r
292# __str__(), __eq__() and __hash__() methods. Otherwise there could be build units\r
293# missing build.\r
294#\r
295# Currently the "Obj" should be only ModuleAutoGen or PlatformAutoGen objects.\r
296#\r
297class BuildUnit:\r
298 ## The constructor\r
299 #\r
300 # @param self The object pointer\r
301 # @param Obj The object the build is working on\r
302 # @param Target The build target name, one of gSupportedTarget\r
303 # @param Dependency The BuildUnit(s) which must be completed in advance\r
304 # @param WorkingDir The directory build command starts in\r
305 #\r
306 def __init__(self, Obj, BuildCommand, Target, Dependency, WorkingDir="."):\r
307 self.BuildObject = Obj\r
308 self.Dependency = Dependency\r
309 self.WorkingDir = WorkingDir\r
310 self.Target = Target\r
311 self.BuildCommand = BuildCommand\r
312 if not BuildCommand:\r
313 EdkLogger.error("build", OPTION_MISSING,\r
314 "No build command found for this module. "\r
315 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %\r
316 (Obj.BuildTarget, Obj.ToolChain, Obj.Arch),\r
317 ExtraData=str(Obj))\r
318\r
319\r
320 ## str() method\r
321 #\r
322 # It just returns the string representation of self.BuildObject\r
323 #\r
324 # @param self The object pointer\r
325 #\r
326 def __str__(self):\r
327 return str(self.BuildObject)\r
328\r
329 ## "==" operator method\r
330 #\r
331 # It just compares self.BuildObject with "Other". So self.BuildObject must\r
332 # provide its own __eq__() method.\r
333 #\r
334 # @param self The object pointer\r
335 # @param Other The other BuildUnit object compared to\r
336 #\r
337 def __eq__(self, Other):\r
338 return Other and self.BuildObject == Other.BuildObject \\r
339 and Other.BuildObject \\r
340 and self.BuildObject.Arch == Other.BuildObject.Arch\r
341\r
342 ## hash() method\r
343 #\r
344 # It just returns the hash value of self.BuildObject which must be hashable.\r
345 #\r
346 # @param self The object pointer\r
347 #\r
348 def __hash__(self):\r
349 return hash(self.BuildObject) + hash(self.BuildObject.Arch)\r
350\r
351 def __repr__(self):\r
352 return repr(self.BuildObject)\r
353\r
354## The smallest module unit that can be built by nmake/make command in multi-thread build mode\r
355#\r
356# This class is for module build by nmake/make build system. The "Obj" parameter\r
357# must provide __str__(), __eq__() and __hash__() methods. Otherwise there could\r
358# be make units missing build.\r
359#\r
360# Currently the "Obj" should be only ModuleAutoGen object.\r
361#\r
362class ModuleMakeUnit(BuildUnit):\r
363 ## The constructor\r
364 #\r
365 # @param self The object pointer\r
366 # @param Obj The ModuleAutoGen object the build is working on\r
367 # @param Target The build target name, one of gSupportedTarget\r
368 #\r
369 def __init__(self, Obj, BuildCommand,Target):\r
370 Dependency = [ModuleMakeUnit(La, BuildCommand,Target) for La in Obj.LibraryAutoGenList]\r
371 BuildUnit.__init__(self, Obj, BuildCommand, Target, Dependency, Obj.MakeFileDir)\r
372 if Target in [None, "", "all"]:\r
373 self.Target = "tbuild"\r
374\r
375## The smallest platform unit that can be built by nmake/make command in multi-thread build mode\r
376#\r
377# This class is for platform build by nmake/make build system. The "Obj" parameter\r
378# must provide __str__(), __eq__() and __hash__() methods. Otherwise there could\r
379# be make units missing build.\r
380#\r
381# Currently the "Obj" should be only PlatformAutoGen object.\r
382#\r
383class PlatformMakeUnit(BuildUnit):\r
384 ## The constructor\r
385 #\r
386 # @param self The object pointer\r
387 # @param Obj The PlatformAutoGen object the build is working on\r
388 # @param Target The build target name, one of gSupportedTarget\r
389 #\r
390 def __init__(self, Obj, BuildCommand, Target):\r
391 Dependency = [ModuleMakeUnit(Lib, BuildCommand, Target) for Lib in self.BuildObject.LibraryAutoGenList]\r
392 Dependency.extend([ModuleMakeUnit(Mod, BuildCommand,Target) for Mod in self.BuildObject.ModuleAutoGenList])\r
393 BuildUnit.__init__(self, Obj, BuildCommand, Target, Dependency, Obj.MakeFileDir)\r
394\r
395## The class representing the task of a module build or platform build\r
396#\r
397# This class manages the build tasks in multi-thread build mode. Its jobs include\r
398# scheduling thread running, catching thread error, monitor the thread status, etc.\r
399#\r
400class BuildTask:\r
401 # queue for tasks waiting for schedule\r
402 _PendingQueue = OrderedDict()\r
403 _PendingQueueLock = threading.Lock()\r
404\r
405 # queue for tasks ready for running\r
406 _ReadyQueue = OrderedDict()\r
407 _ReadyQueueLock = threading.Lock()\r
408\r
409 # queue for run tasks\r
410 _RunningQueue = OrderedDict()\r
411 _RunningQueueLock = threading.Lock()\r
412\r
413 # queue containing all build tasks, in case duplicate build\r
414 _TaskQueue = OrderedDict()\r
415\r
416 # flag indicating error occurs in a running thread\r
417 _ErrorFlag = threading.Event()\r
418 _ErrorFlag.clear()\r
419 _ErrorMessage = ""\r
420\r
421 # BoundedSemaphore object used to control the number of running threads\r
422 _Thread = None\r
423\r
424 # flag indicating if the scheduler is started or not\r
425 _SchedulerStopped = threading.Event()\r
426 _SchedulerStopped.set()\r
427\r
428 ## Start the task scheduler thread\r
429 #\r
430 # @param MaxThreadNumber The maximum thread number\r
431 # @param ExitFlag Flag used to end the scheduler\r
432 #\r
433 @staticmethod\r
434 def StartScheduler(MaxThreadNumber, ExitFlag):\r
435 SchedulerThread = Thread(target=BuildTask.Scheduler, args=(MaxThreadNumber, ExitFlag))\r
436 SchedulerThread.setName("Build-Task-Scheduler")\r
437 SchedulerThread.setDaemon(False)\r
438 SchedulerThread.start()\r
439 # wait for the scheduler to be started, especially useful in Linux\r
440 while not BuildTask.IsOnGoing():\r
441 time.sleep(0.01)\r
442\r
443 ## Scheduler method\r
444 #\r
445 # @param MaxThreadNumber The maximum thread number\r
446 # @param ExitFlag Flag used to end the scheduler\r
447 #\r
448 @staticmethod\r
449 def Scheduler(MaxThreadNumber, ExitFlag):\r
450 BuildTask._SchedulerStopped.clear()\r
451 try:\r
452 # use BoundedSemaphore to control the maximum running threads\r
453 BuildTask._Thread = BoundedSemaphore(MaxThreadNumber)\r
454 #\r
455 # scheduling loop, which will exits when no pending/ready task and\r
456 # indicated to do so, or there's error in running thread\r
457 #\r
458 while (len(BuildTask._PendingQueue) > 0 or len(BuildTask._ReadyQueue) > 0 \\r
459 or not ExitFlag.isSet()) and not BuildTask._ErrorFlag.isSet():\r
460 EdkLogger.debug(EdkLogger.DEBUG_8, "Pending Queue (%d), Ready Queue (%d)"\r
461 % (len(BuildTask._PendingQueue), len(BuildTask._ReadyQueue)))\r
462\r
463 # get all pending tasks\r
464 BuildTask._PendingQueueLock.acquire()\r
465 BuildObjectList = list(BuildTask._PendingQueue.keys())\r
466 #\r
467 # check if their dependency is resolved, and if true, move them\r
468 # into ready queue\r
469 #\r
470 for BuildObject in BuildObjectList:\r
471 Bt = BuildTask._PendingQueue[BuildObject]\r
472 if Bt.IsReady():\r
473 BuildTask._ReadyQueue[BuildObject] = BuildTask._PendingQueue.pop(BuildObject)\r
474 BuildTask._PendingQueueLock.release()\r
475\r
476 # launch build thread until the maximum number of threads is reached\r
477 while not BuildTask._ErrorFlag.isSet():\r
478 # empty ready queue, do nothing further\r
479 if len(BuildTask._ReadyQueue) == 0:\r
480 break\r
481\r
482 # wait for active thread(s) exit\r
483 BuildTask._Thread.acquire(True)\r
484\r
485 # start a new build thread\r
486 Bo, Bt = BuildTask._ReadyQueue.popitem()\r
487\r
488 # move into running queue\r
489 BuildTask._RunningQueueLock.acquire()\r
490 BuildTask._RunningQueue[Bo] = Bt\r
491 BuildTask._RunningQueueLock.release()\r
492\r
493 Bt.Start()\r
494 # avoid tense loop\r
495 time.sleep(0.01)\r
496\r
497 # avoid tense loop\r
498 time.sleep(0.01)\r
499\r
500 # wait for all running threads exit\r
501 if BuildTask._ErrorFlag.isSet():\r
502 EdkLogger.quiet("\nWaiting for all build threads exit...")\r
503 # while not BuildTask._ErrorFlag.isSet() and \\r
504 while len(BuildTask._RunningQueue) > 0:\r
505 EdkLogger.verbose("Waiting for thread ending...(%d)" % len(BuildTask._RunningQueue))\r
506 EdkLogger.debug(EdkLogger.DEBUG_8, "Threads [%s]" % ", ".join(Th.getName() for Th in threading.enumerate()))\r
507 # avoid tense loop\r
508 time.sleep(0.1)\r
509 except BaseException as X:\r
510 #\r
511 # TRICK: hide the output of threads left running, so that the user can\r
512 # catch the error message easily\r
513 #\r
514 EdkLogger.SetLevel(EdkLogger.ERROR)\r
515 BuildTask._ErrorFlag.set()\r
516 BuildTask._ErrorMessage = "build thread scheduler error\n\t%s" % str(X)\r
517\r
518 BuildTask._PendingQueue.clear()\r
519 BuildTask._ReadyQueue.clear()\r
520 BuildTask._RunningQueue.clear()\r
521 BuildTask._TaskQueue.clear()\r
522 BuildTask._SchedulerStopped.set()\r
523\r
524 ## Wait for all running method exit\r
525 #\r
526 @staticmethod\r
527 def WaitForComplete():\r
528 BuildTask._SchedulerStopped.wait()\r
529\r
530 ## Check if the scheduler is running or not\r
531 #\r
532 @staticmethod\r
533 def IsOnGoing():\r
534 return not BuildTask._SchedulerStopped.isSet()\r
535\r
536 ## Abort the build\r
537 @staticmethod\r
538 def Abort():\r
539 if BuildTask.IsOnGoing():\r
540 BuildTask._ErrorFlag.set()\r
541 BuildTask.WaitForComplete()\r
542\r
543 ## Check if there's error in running thread\r
544 #\r
545 # Since the main thread cannot catch exceptions in other thread, we have to\r
546 # use threading.Event to communicate this formation to main thread.\r
547 #\r
548 @staticmethod\r
549 def HasError():\r
550 return BuildTask._ErrorFlag.isSet()\r
551\r
552 ## Get error message in running thread\r
553 #\r
554 # Since the main thread cannot catch exceptions in other thread, we have to\r
555 # use a static variable to communicate this message to main thread.\r
556 #\r
557 @staticmethod\r
558 def GetErrorMessage():\r
559 return BuildTask._ErrorMessage\r
560\r
561 ## Factory method to create a BuildTask object\r
562 #\r
563 # This method will check if a module is building or has been built. And if\r
564 # true, just return the associated BuildTask object in the _TaskQueue. If\r
565 # not, create and return a new BuildTask object. The new BuildTask object\r
566 # will be appended to the _PendingQueue for scheduling later.\r
567 #\r
568 # @param BuildItem A BuildUnit object representing a build object\r
569 # @param Dependency The dependent build object of BuildItem\r
570 #\r
571 @staticmethod\r
572 def New(BuildItem, Dependency=None):\r
573 if BuildItem in BuildTask._TaskQueue:\r
574 Bt = BuildTask._TaskQueue[BuildItem]\r
575 return Bt\r
576\r
577 Bt = BuildTask()\r
578 Bt._Init(BuildItem, Dependency)\r
579 BuildTask._TaskQueue[BuildItem] = Bt\r
580\r
581 BuildTask._PendingQueueLock.acquire()\r
582 BuildTask._PendingQueue[BuildItem] = Bt\r
583 BuildTask._PendingQueueLock.release()\r
584\r
585 return Bt\r
586\r
587 ## The real constructor of BuildTask\r
588 #\r
589 # @param BuildItem A BuildUnit object representing a build object\r
590 # @param Dependency The dependent build object of BuildItem\r
591 #\r
592 def _Init(self, BuildItem, Dependency=None):\r
593 self.BuildItem = BuildItem\r
594\r
595 self.DependencyList = []\r
596 if Dependency is None:\r
597 Dependency = BuildItem.Dependency\r
598 else:\r
599 Dependency.extend(BuildItem.Dependency)\r
600 self.AddDependency(Dependency)\r
601 # flag indicating build completes, used to avoid unnecessary re-build\r
602 self.CompleteFlag = False\r
603\r
604 ## Check if all dependent build tasks are completed or not\r
605 #\r
606 def IsReady(self):\r
607 ReadyFlag = True\r
608 for Dep in self.DependencyList:\r
609 if Dep.CompleteFlag == True:\r
610 continue\r
611 ReadyFlag = False\r
612 break\r
613\r
614 return ReadyFlag\r
615\r
616 ## Add dependent build task\r
617 #\r
618 # @param Dependency The list of dependent build objects\r
619 #\r
620 def AddDependency(self, Dependency):\r
621 for Dep in Dependency:\r
622 if not Dep.BuildObject.IsBinaryModule and not Dep.BuildObject.CanSkipbyCache(GlobalData.gModuleCacheHit):\r
623 self.DependencyList.append(BuildTask.New(Dep)) # BuildTask list\r
624\r
625 ## The thread wrapper of LaunchCommand function\r
626 #\r
627 # @param Command A list or string contains the call of the command\r
628 # @param WorkingDir The directory in which the program will be running\r
629 #\r
630 def _CommandThread(self, Command, WorkingDir):\r
631 try:\r
632 self.BuildItem.BuildObject.BuildTime = LaunchCommand(Command, WorkingDir,self.BuildItem.BuildObject)\r
633 self.CompleteFlag = True\r
634\r
635 # Run hash operation post dependency to account for libs\r
636 # Run if --hash or --binary-destination\r
637 if GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
638 self.BuildItem.BuildObject.GenModuleHash()\r
639 if GlobalData.gBinCacheDest:\r
640 self.BuildItem.BuildObject.GenCMakeHash()\r
641\r
642 except:\r
643 #\r
644 # TRICK: hide the output of threads left running, so that the user can\r
645 # catch the error message easily\r
646 #\r
647 if not BuildTask._ErrorFlag.isSet():\r
648 GlobalData.gBuildingModule = "%s [%s, %s, %s]" % (str(self.BuildItem.BuildObject),\r
649 self.BuildItem.BuildObject.Arch,\r
650 self.BuildItem.BuildObject.ToolChain,\r
651 self.BuildItem.BuildObject.BuildTarget\r
652 )\r
653 EdkLogger.SetLevel(EdkLogger.ERROR)\r
654 BuildTask._ErrorFlag.set()\r
655 BuildTask._ErrorMessage = "%s broken\n %s [%s]" % \\r
656 (threading.currentThread().getName(), Command, WorkingDir)\r
657\r
658 # indicate there's a thread is available for another build task\r
659 BuildTask._RunningQueueLock.acquire()\r
660 BuildTask._RunningQueue.pop(self.BuildItem)\r
661 BuildTask._RunningQueueLock.release()\r
662 BuildTask._Thread.release()\r
663\r
664 ## Start build task thread\r
665 #\r
666 def Start(self):\r
667 EdkLogger.quiet("Building ... %s" % repr(self.BuildItem))\r
668 Command = self.BuildItem.BuildCommand + [self.BuildItem.Target]\r
669 self.BuildTread = Thread(target=self._CommandThread, args=(Command, self.BuildItem.WorkingDir))\r
670 self.BuildTread.setName("build thread")\r
671 self.BuildTread.setDaemon(False)\r
672 self.BuildTread.start()\r
673\r
674## The class contains the information related to EFI image\r
675#\r
676class PeImageInfo():\r
677 ## Constructor\r
678 #\r
679 # Constructor will load all required image information.\r
680 #\r
681 # @param BaseName The full file path of image.\r
682 # @param Guid The GUID for image.\r
683 # @param Arch Arch of this image.\r
684 # @param OutputDir The output directory for image.\r
685 # @param DebugDir The debug directory for image.\r
686 # @param ImageClass PeImage Information\r
687 #\r
688 def __init__(self, BaseName, Guid, Arch, OutputDir, DebugDir, ImageClass):\r
689 self.BaseName = BaseName\r
690 self.Guid = Guid\r
691 self.Arch = Arch\r
692 self.OutputDir = OutputDir\r
693 self.DebugDir = DebugDir\r
694 self.Image = ImageClass\r
695 self.Image.Size = (self.Image.Size // 0x1000 + 1) * 0x1000\r
696\r
697## The class implementing the EDK2 build process\r
698#\r
699# The build process includes:\r
700# 1. Load configuration from target.txt and tools_def.txt in $(WORKSPACE)/Conf\r
701# 2. Parse DSC file of active platform\r
702# 3. Parse FDF file if any\r
703# 4. Establish build database, including parse all other files (module, package)\r
704# 5. Create AutoGen files (C code file, depex file, makefile) if necessary\r
705# 6. Call build command\r
706#\r
707class Build():\r
708 ## Constructor\r
709 #\r
710 # Constructor will load all necessary configurations, parse platform, modules\r
711 # and packages and the establish a database for AutoGen.\r
712 #\r
713 # @param Target The build command target, one of gSupportedTarget\r
714 # @param WorkspaceDir The directory of workspace\r
715 # @param BuildOptions Build options passed from command line\r
716 #\r
717 def __init__(self, Target, WorkspaceDir, BuildOptions,log_q):\r
718 self.WorkspaceDir = WorkspaceDir\r
719 self.Target = Target\r
720 self.PlatformFile = BuildOptions.PlatformFile\r
721 self.ModuleFile = BuildOptions.ModuleFile\r
722 self.ArchList = BuildOptions.TargetArch\r
723 self.ToolChainList = BuildOptions.ToolChain\r
724 self.BuildTargetList= BuildOptions.BuildTarget\r
725 self.Fdf = BuildOptions.FdfFile\r
726 self.FdList = BuildOptions.RomImage\r
727 self.FvList = BuildOptions.FvImage\r
728 self.CapList = BuildOptions.CapName\r
729 self.SilentMode = BuildOptions.SilentMode\r
730 self.ThreadNumber = 1\r
731 self.SkipAutoGen = BuildOptions.SkipAutoGen\r
732 self.Reparse = BuildOptions.Reparse\r
733 self.SkuId = BuildOptions.SkuId\r
734 if self.SkuId:\r
735 GlobalData.gSKUID_CMD = self.SkuId\r
736 self.ConfDirectory = BuildOptions.ConfDirectory\r
737 self.SpawnMode = True\r
738 self.BuildReport = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)\r
739 self.AutoGenTime = 0\r
740 self.MakeTime = 0\r
741 self.GenFdsTime = 0\r
742 self.MakeFileName = ""\r
743 TargetObj = TargetTxtDict()\r
744 ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf")))\r
745 self.TargetTxt = TargetObj.Target\r
746 self.ToolDef = ToolDefObj.ToolDef\r
747 GlobalData.BuildOptionPcd = BuildOptions.OptionPcd if BuildOptions.OptionPcd else []\r
748 #Set global flag for build mode\r
749 GlobalData.gIgnoreSource = BuildOptions.IgnoreSources\r
750 GlobalData.gUseHashCache = BuildOptions.UseHashCache\r
751 GlobalData.gBinCacheDest = BuildOptions.BinCacheDest\r
752 GlobalData.gBinCacheSource = BuildOptions.BinCacheSource\r
753 GlobalData.gEnableGenfdsMultiThread = not BuildOptions.NoGenfdsMultiThread\r
754 GlobalData.gDisableIncludePathCheck = BuildOptions.DisableIncludePathCheck\r
755\r
756 if GlobalData.gBinCacheDest and not GlobalData.gUseHashCache:\r
757 EdkLogger.error("build", OPTION_NOT_SUPPORTED, ExtraData="--binary-destination must be used together with --hash.")\r
758\r
759 if GlobalData.gBinCacheSource and not GlobalData.gUseHashCache:\r
760 EdkLogger.error("build", OPTION_NOT_SUPPORTED, ExtraData="--binary-source must be used together with --hash.")\r
761\r
762 if GlobalData.gBinCacheDest and GlobalData.gBinCacheSource:\r
763 EdkLogger.error("build", OPTION_NOT_SUPPORTED, ExtraData="--binary-destination can not be used together with --binary-source.")\r
764\r
765 if GlobalData.gBinCacheSource:\r
766 BinCacheSource = os.path.normpath(GlobalData.gBinCacheSource)\r
767 if not os.path.isabs(BinCacheSource):\r
768 BinCacheSource = mws.join(self.WorkspaceDir, BinCacheSource)\r
769 GlobalData.gBinCacheSource = BinCacheSource\r
770 else:\r
771 if GlobalData.gBinCacheSource is not None:\r
772 EdkLogger.error("build", OPTION_VALUE_INVALID, ExtraData="Invalid value of option --binary-source.")\r
773\r
774 if GlobalData.gBinCacheDest:\r
775 BinCacheDest = os.path.normpath(GlobalData.gBinCacheDest)\r
776 if not os.path.isabs(BinCacheDest):\r
777 BinCacheDest = mws.join(self.WorkspaceDir, BinCacheDest)\r
778 GlobalData.gBinCacheDest = BinCacheDest\r
779 else:\r
780 if GlobalData.gBinCacheDest is not None:\r
781 EdkLogger.error("build", OPTION_VALUE_INVALID, ExtraData="Invalid value of option --binary-destination.")\r
782\r
783 GlobalData.gDatabasePath = os.path.normpath(os.path.join(GlobalData.gConfDirectory, GlobalData.gDatabasePath))\r
784 if not os.path.exists(os.path.join(GlobalData.gConfDirectory, '.cache')):\r
785 os.makedirs(os.path.join(GlobalData.gConfDirectory, '.cache'))\r
786 self.Db = BuildDB\r
787 self.BuildDatabase = self.Db.BuildObject\r
788 self.Platform = None\r
789 self.ToolChainFamily = None\r
790 self.LoadFixAddress = 0\r
791 self.UniFlag = BuildOptions.Flag\r
792 self.BuildModules = []\r
793 self.HashSkipModules = []\r
794 self.Db_Flag = False\r
795 self.LaunchPrebuildFlag = False\r
796 self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory, '.cache', '.PlatformBuild')\r
797 if BuildOptions.CommandLength:\r
798 GlobalData.gCommandMaxLength = BuildOptions.CommandLength\r
799\r
800 # print dot character during doing some time-consuming work\r
801 self.Progress = Utils.Progressor()\r
802 # print current build environment and configuration\r
803 EdkLogger.quiet("%-16s = %s" % ("WORKSPACE", os.environ["WORKSPACE"]))\r
804 if "PACKAGES_PATH" in os.environ:\r
805 # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env.\r
806 EdkLogger.quiet("%-16s = %s" % ("PACKAGES_PATH", os.path.normcase(os.path.normpath(os.environ["PACKAGES_PATH"]))))\r
807 EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"]))\r
808 if "EDK_TOOLS_BIN" in os.environ:\r
809 # Print the same path style with WORKSPACE env.\r
810 EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"]))))\r
811 EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", GlobalData.gConfDirectory))\r
812 if "PYTHON3_ENABLE" in os.environ:\r
813 PYTHON3_ENABLE = os.environ["PYTHON3_ENABLE"]\r
814 if PYTHON3_ENABLE != "TRUE":\r
815 PYTHON3_ENABLE = "FALSE"\r
816 EdkLogger.quiet("%-16s = %s" % ("PYTHON3_ENABLE", PYTHON3_ENABLE))\r
817 if "PYTHON_COMMAND" in os.environ:\r
818 EdkLogger.quiet("%-16s = %s" % ("PYTHON_COMMAND", os.environ["PYTHON_COMMAND"]))\r
819 self.InitPreBuild()\r
820 self.InitPostBuild()\r
821 if self.Prebuild:\r
822 EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))\r
823 if self.Postbuild:\r
824 EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.Postbuild))\r
825 if self.Prebuild:\r
826 self.LaunchPrebuild()\r
827 TargetObj = TargetTxtDict()\r
828 ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
829 self.TargetTxt = TargetObj.Target\r
830 self.ToolDef = ToolDefObj.ToolDef\r
831 if not (self.LaunchPrebuildFlag and os.path.exists(self.PlatformBuildPath)):\r
832 self.InitBuild()\r
833\r
834 self.AutoGenMgr = None\r
835 EdkLogger.info("")\r
836 os.chdir(self.WorkspaceDir)\r
837 self.log_q = log_q\r
838 GlobalData.file_lock = mp.Lock()\r
839 # Init cache data for local only\r
840 GlobalData.gPackageHashFile = dict()\r
841 GlobalData.gModulePreMakeCacheStatus = dict()\r
842 GlobalData.gModuleMakeCacheStatus = dict()\r
843 GlobalData.gHashChainStatus = dict()\r
844 GlobalData.gCMakeHashFile = dict()\r
845 GlobalData.gModuleHashFile = dict()\r
846 GlobalData.gFileHashDict = dict()\r
847 GlobalData.gModuleAllCacheStatus = set()\r
848 GlobalData.gModuleCacheHit = set()\r
849\r
850 def StartAutoGen(self,mqueue, DataPipe,SkipAutoGen,PcdMaList,cqueue):\r
851 try:\r
852 if SkipAutoGen:\r
853 return True,0\r
854 feedback_q = mp.Queue()\r
855 error_event = mp.Event()\r
856 FfsCmd = DataPipe.Get("FfsCommand")\r
857 if FfsCmd is None:\r
858 FfsCmd = {}\r
859 GlobalData.FfsCmd = FfsCmd\r
860 auto_workers = [AutoGenWorkerInProcess(mqueue,DataPipe.dump_file,feedback_q,GlobalData.file_lock,cqueue,self.log_q,error_event) for _ in range(self.ThreadNumber)]\r
861 self.AutoGenMgr = AutoGenManager(auto_workers,feedback_q,error_event)\r
862 self.AutoGenMgr.start()\r
863 for w in auto_workers:\r
864 w.start()\r
865 if PcdMaList is not None:\r
866 for PcdMa in PcdMaList:\r
867 # SourceFileList calling sequence impact the makefile string sequence.\r
868 # Create cached SourceFileList here to unify its calling sequence for both\r
869 # CanSkipbyPreMakeCache and CreateCodeFile/CreateMakeFile.\r
870 RetVal = PcdMa.SourceFileList\r
871 # Force cache miss for PCD driver\r
872 if GlobalData.gUseHashCache and not GlobalData.gBinCacheDest and self.Target in [None, "", "all"]:\r
873 cqueue.put((PcdMa.MetaFile.Path, PcdMa.Arch, "PreMakeCache", False))\r
874\r
875 PcdMa.CreateCodeFile(False)\r
876 PcdMa.CreateMakeFile(False,GenFfsList = DataPipe.Get("FfsCommand").get((PcdMa.MetaFile.Path, PcdMa.Arch),[]))\r
877 PcdMa.CreateAsBuiltInf()\r
878 # Force cache miss for PCD driver\r
879 if GlobalData.gBinCacheSource and self.Target in [None, "", "all"]:\r
880 cqueue.put((PcdMa.MetaFile.Path, PcdMa.Arch, "MakeCache", False))\r
881\r
882 self.AutoGenMgr.join()\r
883 rt = self.AutoGenMgr.Status\r
884 err = 0\r
885 if not rt:\r
886 err = UNKNOWN_ERROR\r
887 return rt, err\r
888 except FatalError as e:\r
889 return False, e.args[0]\r
890 except:\r
891 return False, UNKNOWN_ERROR\r
892\r
893 ## Add TOOLCHAIN and FAMILY declared in DSC [BuildOptions] to ToolsDefTxtDatabase.\r
894 #\r
895 # Loop through the set of build targets, tool chains, and archs provided on either\r
896 # the command line or in target.txt to discover FAMILY and TOOLCHAIN delclarations\r
897 # in [BuildOptions] sections that may be within !if expressions that may use\r
898 # $(TARGET), $(TOOLCHAIN), $(TOOLCHAIN_TAG), or $(ARCH) operands.\r
899 #\r
900 def GetToolChainAndFamilyFromDsc (self, File):\r
901 SavedGlobalDefines = GlobalData.gGlobalDefines.copy()\r
902 for BuildTarget in self.BuildTargetList:\r
903 GlobalData.gGlobalDefines['TARGET'] = BuildTarget\r
904 for BuildToolChain in self.ToolChainList:\r
905 GlobalData.gGlobalDefines['TOOLCHAIN'] = BuildToolChain\r
906 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = BuildToolChain\r
907 for BuildArch in self.ArchList:\r
908 GlobalData.gGlobalDefines['ARCH'] = BuildArch\r
909 dscobj = self.BuildDatabase[File, BuildArch]\r
910 for KeyFamily, Key, KeyCodeBase in dscobj.BuildOptions:\r
911 try:\r
912 Target, ToolChain, Arch, Tool, Attr = Key.split('_')\r
913 except:\r
914 continue\r
915 if ToolChain == TAB_STAR or Attr != TAB_TOD_DEFINES_FAMILY:\r
916 continue\r
917 try:\r
918 Family = dscobj.BuildOptions[(KeyFamily, Key, KeyCodeBase)]\r
919 Family = Family.strip().strip('=').strip()\r
920 except:\r
921 continue\r
922 if TAB_TOD_DEFINES_FAMILY not in self.ToolDef.ToolsDefTxtDatabase:\r
923 self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY] = {}\r
924 if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]:\r
925 self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][ToolChain] = Family\r
926 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in self.ToolDef.ToolsDefTxtDatabase:\r
927 self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY] = {}\r
928 if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
929 self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][ToolChain] = Family\r
930 if TAB_TOD_DEFINES_TOOL_CHAIN_TAG not in self.ToolDef.ToolsDefTxtDatabase:\r
931 self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = []\r
932 if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]:\r
933 self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].append(ToolChain)\r
934 GlobalData.gGlobalDefines = SavedGlobalDefines\r
935\r
936 ## Load configuration\r
937 #\r
938 # This method will parse target.txt and get the build configurations.\r
939 #\r
940 def LoadConfiguration(self):\r
941\r
942 # if no ARCH given in command line, get it from target.txt\r
943 if not self.ArchList:\r
944 self.ArchList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]\r
945 self.ArchList = tuple(self.ArchList)\r
946\r
947 # if no build target given in command line, get it from target.txt\r
948 if not self.BuildTargetList:\r
949 self.BuildTargetList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET]\r
950\r
951 # if no tool chain given in command line, get it from target.txt\r
952 if not self.ToolChainList:\r
953 self.ToolChainList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_TAG]\r
954 if self.ToolChainList is None or len(self.ToolChainList) == 0:\r
955 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.\n")\r
956\r
957 if not self.PlatformFile:\r
958 PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM]\r
959 if not PlatformFile:\r
960 # Try to find one in current directory\r
961 WorkingDirectory = os.getcwd()\r
962 FileList = glob.glob(os.path.normpath(os.path.join(WorkingDirectory, '*.dsc')))\r
963 FileNum = len(FileList)\r
964 if FileNum >= 2:\r
965 EdkLogger.error("build", OPTION_MISSING,\r
966 ExtraData="There are %d DSC files in %s. Use '-p' to specify one.\n" % (FileNum, WorkingDirectory))\r
967 elif FileNum == 1:\r
968 PlatformFile = FileList[0]\r
969 else:\r
970 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
971 ExtraData="No active platform specified in target.txt or command line! Nothing can be built.\n")\r
972\r
973 self.PlatformFile = PathClass(NormFile(PlatformFile, self.WorkspaceDir), self.WorkspaceDir)\r
974\r
975 self.GetToolChainAndFamilyFromDsc (self.PlatformFile)\r
976\r
977 # check if the tool chains are defined or not\r
978 NewToolChainList = []\r
979 for ToolChain in self.ToolChainList:\r
980 if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]:\r
981 EdkLogger.warn("build", "Tool chain [%s] is not defined" % ToolChain)\r
982 else:\r
983 NewToolChainList.append(ToolChain)\r
984 # if no tool chain available, break the build\r
985 if len(NewToolChainList) == 0:\r
986 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
987 ExtraData="[%s] not defined. No toolchain available for build!\n" % ", ".join(self.ToolChainList))\r
988 else:\r
989 self.ToolChainList = NewToolChainList\r
990\r
991 ToolChainFamily = []\r
992 ToolDefinition = self.ToolDef.ToolsDefTxtDatabase\r
993 for Tool in self.ToolChainList:\r
994 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition or Tool not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
995 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool]:\r
996 EdkLogger.warn("build", "No tool chain family found in configuration for %s. Default to MSFT." % Tool)\r
997 ToolChainFamily.append(TAB_COMPILER_MSFT)\r
998 else:\r
999 ToolChainFamily.append(ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool])\r
1000 self.ToolChainFamily = ToolChainFamily\r
1001\r
1002 self.ThreadNumber = ThreadNum()\r
1003 ## Initialize build configuration\r
1004 #\r
1005 # This method will parse DSC file and merge the configurations from\r
1006 # command line and target.txt, then get the final build configurations.\r
1007 #\r
1008 def InitBuild(self):\r
1009 # parse target.txt, tools_def.txt, and platform file\r
1010 self.LoadConfiguration()\r
1011\r
1012 # Allow case-insensitive for those from command line or configuration file\r
1013 ErrorCode, ErrorInfo = self.PlatformFile.Validate(".dsc", False)\r
1014 if ErrorCode != 0:\r
1015 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)\r
1016\r
1017\r
1018 def InitPreBuild(self):\r
1019 self.LoadConfiguration()\r
1020 ErrorCode, ErrorInfo = self.PlatformFile.Validate(".dsc", False)\r
1021 if ErrorCode != 0:\r
1022 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)\r
1023 if self.BuildTargetList:\r
1024 GlobalData.gGlobalDefines['TARGET'] = self.BuildTargetList[0]\r
1025 if self.ArchList:\r
1026 GlobalData.gGlobalDefines['ARCH'] = self.ArchList[0]\r
1027 if self.ToolChainList:\r
1028 GlobalData.gGlobalDefines['TOOLCHAIN'] = self.ToolChainList[0]\r
1029 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = self.ToolChainList[0]\r
1030 if self.ToolChainFamily:\r
1031 GlobalData.gGlobalDefines['FAMILY'] = self.ToolChainFamily[0]\r
1032 if 'PREBUILD' in GlobalData.gCommandLineDefines:\r
1033 self.Prebuild = GlobalData.gCommandLineDefines.get('PREBUILD')\r
1034 else:\r
1035 self.Db_Flag = True\r
1036 Platform = self.Db.MapPlatform(str(self.PlatformFile))\r
1037 self.Prebuild = str(Platform.Prebuild)\r
1038 if self.Prebuild:\r
1039 PrebuildList = []\r
1040 #\r
1041 # Evaluate all arguments and convert arguments that are WORKSPACE\r
1042 # relative paths to absolute paths. Filter arguments that look like\r
1043 # flags or do not follow the file/dir naming rules to avoid false\r
1044 # positives on this conversion.\r
1045 #\r
1046 for Arg in self.Prebuild.split():\r
1047 #\r
1048 # Do not modify Arg if it looks like a flag or an absolute file path\r
1049 #\r
1050 if Arg.startswith('-') or os.path.isabs(Arg):\r
1051 PrebuildList.append(Arg)\r
1052 continue\r
1053 #\r
1054 # Do not modify Arg if it does not look like a Workspace relative\r
1055 # path that starts with a valid package directory name\r
1056 #\r
1057 if not Arg[0].isalpha() or os.path.dirname(Arg) == '':\r
1058 PrebuildList.append(Arg)\r
1059 continue\r
1060 #\r
1061 # If Arg looks like a WORKSPACE relative path, then convert to an\r
1062 # absolute path and check to see if the file exists.\r
1063 #\r
1064 Temp = mws.join(self.WorkspaceDir, Arg)\r
1065 if os.path.isfile(Temp):\r
1066 Arg = Temp\r
1067 PrebuildList.append(Arg)\r
1068 self.Prebuild = ' '.join(PrebuildList)\r
1069 self.Prebuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList, self.PlatformFile, self.Target)\r
1070\r
1071 def InitPostBuild(self):\r
1072 if 'POSTBUILD' in GlobalData.gCommandLineDefines:\r
1073 self.Postbuild = GlobalData.gCommandLineDefines.get('POSTBUILD')\r
1074 else:\r
1075 Platform = self.Db.MapPlatform(str(self.PlatformFile))\r
1076 self.Postbuild = str(Platform.Postbuild)\r
1077 if self.Postbuild:\r
1078 PostbuildList = []\r
1079 #\r
1080 # Evaluate all arguments and convert arguments that are WORKSPACE\r
1081 # relative paths to absolute paths. Filter arguments that look like\r
1082 # flags or do not follow the file/dir naming rules to avoid false\r
1083 # positives on this conversion.\r
1084 #\r
1085 for Arg in self.Postbuild.split():\r
1086 #\r
1087 # Do not modify Arg if it looks like a flag or an absolute file path\r
1088 #\r
1089 if Arg.startswith('-') or os.path.isabs(Arg):\r
1090 PostbuildList.append(Arg)\r
1091 continue\r
1092 #\r
1093 # Do not modify Arg if it does not look like a Workspace relative\r
1094 # path that starts with a valid package directory name\r
1095 #\r
1096 if not Arg[0].isalpha() or os.path.dirname(Arg) == '':\r
1097 PostbuildList.append(Arg)\r
1098 continue\r
1099 #\r
1100 # If Arg looks like a WORKSPACE relative path, then convert to an\r
1101 # absolute path and check to see if the file exists.\r
1102 #\r
1103 Temp = mws.join(self.WorkspaceDir, Arg)\r
1104 if os.path.isfile(Temp):\r
1105 Arg = Temp\r
1106 PostbuildList.append(Arg)\r
1107 self.Postbuild = ' '.join(PostbuildList)\r
1108 self.Postbuild += self.PassCommandOption(self.BuildTargetList, self.ArchList, self.ToolChainList, self.PlatformFile, self.Target)\r
1109\r
1110 def PassCommandOption(self, BuildTarget, TargetArch, ToolChain, PlatformFile, Target):\r
1111 BuildStr = ''\r
1112 if GlobalData.gCommand and isinstance(GlobalData.gCommand, list):\r
1113 BuildStr += ' ' + ' '.join(GlobalData.gCommand)\r
1114 TargetFlag = False\r
1115 ArchFlag = False\r
1116 ToolChainFlag = False\r
1117 PlatformFileFlag = False\r
1118\r
1119 if GlobalData.gOptions and not GlobalData.gOptions.BuildTarget:\r
1120 TargetFlag = True\r
1121 if GlobalData.gOptions and not GlobalData.gOptions.TargetArch:\r
1122 ArchFlag = True\r
1123 if GlobalData.gOptions and not GlobalData.gOptions.ToolChain:\r
1124 ToolChainFlag = True\r
1125 if GlobalData.gOptions and not GlobalData.gOptions.PlatformFile:\r
1126 PlatformFileFlag = True\r
1127\r
1128 if TargetFlag and BuildTarget:\r
1129 if isinstance(BuildTarget, list) or isinstance(BuildTarget, tuple):\r
1130 BuildStr += ' -b ' + ' -b '.join(BuildTarget)\r
1131 elif isinstance(BuildTarget, str):\r
1132 BuildStr += ' -b ' + BuildTarget\r
1133 if ArchFlag and TargetArch:\r
1134 if isinstance(TargetArch, list) or isinstance(TargetArch, tuple):\r
1135 BuildStr += ' -a ' + ' -a '.join(TargetArch)\r
1136 elif isinstance(TargetArch, str):\r
1137 BuildStr += ' -a ' + TargetArch\r
1138 if ToolChainFlag and ToolChain:\r
1139 if isinstance(ToolChain, list) or isinstance(ToolChain, tuple):\r
1140 BuildStr += ' -t ' + ' -t '.join(ToolChain)\r
1141 elif isinstance(ToolChain, str):\r
1142 BuildStr += ' -t ' + ToolChain\r
1143 if PlatformFileFlag and PlatformFile:\r
1144 if isinstance(PlatformFile, list) or isinstance(PlatformFile, tuple):\r
1145 BuildStr += ' -p ' + ' -p '.join(PlatformFile)\r
1146 elif isinstance(PlatformFile, str):\r
1147 BuildStr += ' -p' + PlatformFile\r
1148 BuildStr += ' --conf=' + GlobalData.gConfDirectory\r
1149 if Target:\r
1150 BuildStr += ' ' + Target\r
1151\r
1152 return BuildStr\r
1153\r
1154 def LaunchPrebuild(self):\r
1155 if self.Prebuild:\r
1156 EdkLogger.info("\n- Prebuild Start -\n")\r
1157 self.LaunchPrebuildFlag = True\r
1158 #\r
1159 # The purpose of .PrebuildEnv file is capture environment variable settings set by the prebuild script\r
1160 # and preserve them for the rest of the main build step, because the child process environment will\r
1161 # evaporate as soon as it exits, we cannot get it in build step.\r
1162 #\r
1163 PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory, '.cache', '.PrebuildEnv')\r
1164 if os.path.isfile(PrebuildEnvFile):\r
1165 os.remove(PrebuildEnvFile)\r
1166 if os.path.isfile(self.PlatformBuildPath):\r
1167 os.remove(self.PlatformBuildPath)\r
1168 if sys.platform == "win32":\r
1169 args = ' && '.join((self.Prebuild, 'set > ' + PrebuildEnvFile))\r
1170 Process = Popen(args, stdout=PIPE, stderr=PIPE, shell=True)\r
1171 else:\r
1172 args = ' && '.join((self.Prebuild, 'env > ' + PrebuildEnvFile))\r
1173 Process = Popen(args, stdout=PIPE, stderr=PIPE, shell=True)\r
1174\r
1175 # launch two threads to read the STDOUT and STDERR\r
1176 EndOfProcedure = Event()\r
1177 EndOfProcedure.clear()\r
1178 if Process.stdout:\r
1179 StdOutThread = Thread(target=ReadMessage, args=(Process.stdout, EdkLogger.info, EndOfProcedure))\r
1180 StdOutThread.setName("STDOUT-Redirector")\r
1181 StdOutThread.setDaemon(False)\r
1182 StdOutThread.start()\r
1183\r
1184 if Process.stderr:\r
1185 StdErrThread = Thread(target=ReadMessage, args=(Process.stderr, EdkLogger.quiet, EndOfProcedure))\r
1186 StdErrThread.setName("STDERR-Redirector")\r
1187 StdErrThread.setDaemon(False)\r
1188 StdErrThread.start()\r
1189 # waiting for program exit\r
1190 Process.wait()\r
1191\r
1192 if Process.stdout:\r
1193 StdOutThread.join()\r
1194 if Process.stderr:\r
1195 StdErrThread.join()\r
1196 if Process.returncode != 0 :\r
1197 EdkLogger.error("Prebuild", PREBUILD_ERROR, 'Prebuild process is not success!')\r
1198\r
1199 if os.path.exists(PrebuildEnvFile):\r
1200 f = open(PrebuildEnvFile)\r
1201 envs = f.readlines()\r
1202 f.close()\r
1203 envs = [l.split("=", 1) for l in envs ]\r
1204 envs = [[I.strip() for I in item] for item in envs if len(item) == 2]\r
1205 os.environ.update(dict(envs))\r
1206 EdkLogger.info("\n- Prebuild Done -\n")\r
1207\r
1208 def LaunchPostbuild(self):\r
1209 if self.Postbuild:\r
1210 EdkLogger.info("\n- Postbuild Start -\n")\r
1211 if sys.platform == "win32":\r
1212 Process = Popen(self.Postbuild, stdout=PIPE, stderr=PIPE, shell=True)\r
1213 else:\r
1214 Process = Popen(self.Postbuild, stdout=PIPE, stderr=PIPE, shell=True)\r
1215 # launch two threads to read the STDOUT and STDERR\r
1216 EndOfProcedure = Event()\r
1217 EndOfProcedure.clear()\r
1218 if Process.stdout:\r
1219 StdOutThread = Thread(target=ReadMessage, args=(Process.stdout, EdkLogger.info, EndOfProcedure))\r
1220 StdOutThread.setName("STDOUT-Redirector")\r
1221 StdOutThread.setDaemon(False)\r
1222 StdOutThread.start()\r
1223\r
1224 if Process.stderr:\r
1225 StdErrThread = Thread(target=ReadMessage, args=(Process.stderr, EdkLogger.quiet, EndOfProcedure))\r
1226 StdErrThread.setName("STDERR-Redirector")\r
1227 StdErrThread.setDaemon(False)\r
1228 StdErrThread.start()\r
1229 # waiting for program exit\r
1230 Process.wait()\r
1231\r
1232 if Process.stdout:\r
1233 StdOutThread.join()\r
1234 if Process.stderr:\r
1235 StdErrThread.join()\r
1236 if Process.returncode != 0 :\r
1237 EdkLogger.error("Postbuild", POSTBUILD_ERROR, 'Postbuild process is not success!')\r
1238 EdkLogger.info("\n- Postbuild Done -\n")\r
1239\r
1240 ## Build a module or platform\r
1241 #\r
1242 # Create autogen code and makefile for a module or platform, and the launch\r
1243 # "make" command to build it\r
1244 #\r
1245 # @param Target The target of build command\r
1246 # @param Platform The platform file\r
1247 # @param Module The module file\r
1248 # @param BuildTarget The name of build target, one of "DEBUG", "RELEASE"\r
1249 # @param ToolChain The name of toolchain to build\r
1250 # @param Arch The arch of the module/platform\r
1251 # @param CreateDepModuleCodeFile Flag used to indicate creating code\r
1252 # for dependent modules/Libraries\r
1253 # @param CreateDepModuleMakeFile Flag used to indicate creating makefile\r
1254 # for dependent modules/Libraries\r
1255 #\r
1256 def _BuildPa(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeFile=True, BuildModule=False, FfsCommand=None, PcdMaList=None):\r
1257 if AutoGenObject is None:\r
1258 return False\r
1259 if FfsCommand is None:\r
1260 FfsCommand = {}\r
1261 # skip file generation for cleanxxx targets, run and fds target\r
1262 if Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:\r
1263 # for target which must generate AutoGen code and makefile\r
1264 mqueue = mp.Queue()\r
1265 for m in AutoGenObject.GetAllModuleInfo:\r
1266 mqueue.put(m)\r
1267 mqueue.put((None,None,None,None,None,None,None))\r
1268 AutoGenObject.DataPipe.DataContainer = {"CommandTarget": self.Target}\r
1269 AutoGenObject.DataPipe.DataContainer = {"Workspace_timestamp": AutoGenObject.Workspace._SrcTimeStamp}\r
1270 AutoGenObject.CreateLibModuelDirs()\r
1271 AutoGenObject.DataPipe.DataContainer = {"LibraryBuildDirectoryList":AutoGenObject.LibraryBuildDirectoryList}\r
1272 AutoGenObject.DataPipe.DataContainer = {"ModuleBuildDirectoryList":AutoGenObject.ModuleBuildDirectoryList}\r
1273 AutoGenObject.DataPipe.DataContainer = {"FdsCommandDict": AutoGenObject.Workspace.GenFdsCommandDict}\r
1274 self.Progress.Start("Generating makefile and code")\r
1275 data_pipe_file = os.path.join(AutoGenObject.BuildDir, "GlobalVar_%s_%s.bin" % (str(AutoGenObject.Guid),AutoGenObject.Arch))\r
1276 AutoGenObject.DataPipe.dump(data_pipe_file)\r
1277 cqueue = mp.Queue()\r
1278 autogen_rt,errorcode = self.StartAutoGen(mqueue, AutoGenObject.DataPipe, self.SkipAutoGen, PcdMaList, cqueue)\r
1279 AutoGenIdFile = os.path.join(GlobalData.gConfDirectory,".AutoGenIdFile.txt")\r
1280 with open(AutoGenIdFile,"w") as fw:\r
1281 fw.write("Arch=%s\n" % "|".join((AutoGenObject.Workspace.ArchList)))\r
1282 fw.write("BuildDir=%s\n" % AutoGenObject.Workspace.BuildDir)\r
1283 fw.write("PlatformGuid=%s\n" % str(AutoGenObject.Guid))\r
1284 self.Progress.Stop("done!")\r
1285 if not autogen_rt:\r
1286 self.AutoGenMgr.TerminateWorkers()\r
1287 self.AutoGenMgr.join(1)\r
1288 raise FatalError(errorcode)\r
1289 AutoGenObject.CreateCodeFile(False)\r
1290 AutoGenObject.CreateMakeFile(False)\r
1291 else:\r
1292 # always recreate top/platform makefile when clean, just in case of inconsistency\r
1293 AutoGenObject.CreateCodeFile(True)\r
1294 AutoGenObject.CreateMakeFile(True)\r
1295\r
1296 if EdkLogger.GetLevel() == EdkLogger.QUIET:\r
1297 EdkLogger.quiet("Building ... %s" % repr(AutoGenObject))\r
1298\r
1299 BuildCommand = AutoGenObject.BuildCommand\r
1300 if BuildCommand is None or len(BuildCommand) == 0:\r
1301 EdkLogger.error("build", OPTION_MISSING,\r
1302 "No build command found for this module. "\r
1303 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %\r
1304 (AutoGenObject.BuildTarget, AutoGenObject.ToolChain, AutoGenObject.Arch),\r
1305 ExtraData=str(AutoGenObject))\r
1306\r
1307 # run\r
1308 if Target == 'run':\r
1309 return True\r
1310\r
1311 # build modules\r
1312 if BuildModule:\r
1313 BuildCommand = BuildCommand + [Target]\r
1314 LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)\r
1315 if GlobalData.gBinCacheDest:\r
1316 self.GenDestCache()\r
1317 elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
1318 # Only for --hash\r
1319 # Update PreMakeCacheChain files\r
1320 self.GenLocalPreMakeCache()\r
1321 self.BuildModules = []\r
1322 return True\r
1323\r
1324 # build library\r
1325 if Target == 'libraries':\r
1326 DirList = []\r
1327 for Lib in AutoGenObject.LibraryAutoGenList:\r
1328 if not Lib.IsBinaryModule:\r
1329 DirList.append((os.path.join(AutoGenObject.BuildDir, Lib.BuildDir),Lib))\r
1330 for Lib, LibAutoGen in DirList:\r
1331 NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Lib, self.MakeFileName)), 'pbuild']\r
1332 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir,LibAutoGen)\r
1333 return True\r
1334\r
1335 # build module\r
1336 if Target == 'modules':\r
1337 DirList = []\r
1338 for Lib in AutoGenObject.LibraryAutoGenList:\r
1339 if not Lib.IsBinaryModule:\r
1340 DirList.append((os.path.join(AutoGenObject.BuildDir, Lib.BuildDir),Lib))\r
1341 for Lib, LibAutoGen in DirList:\r
1342 NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Lib, self.MakeFileName)), 'pbuild']\r
1343 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir,LibAutoGen)\r
1344\r
1345 DirList = []\r
1346 for ModuleAutoGen in AutoGenObject.ModuleAutoGenList:\r
1347 if not ModuleAutoGen.IsBinaryModule:\r
1348 DirList.append((os.path.join(AutoGenObject.BuildDir, ModuleAutoGen.BuildDir),ModuleAutoGen))\r
1349 for Mod,ModAutoGen in DirList:\r
1350 NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Mod, self.MakeFileName)), 'pbuild']\r
1351 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir,ModAutoGen)\r
1352 self.CreateAsBuiltInf()\r
1353 if GlobalData.gBinCacheDest:\r
1354 self.GenDestCache()\r
1355 elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
1356 # Only for --hash\r
1357 # Update PreMakeCacheChain files\r
1358 self.GenLocalPreMakeCache()\r
1359 self.BuildModules = []\r
1360 return True\r
1361\r
1362 # cleanlib\r
1363 if Target == 'cleanlib':\r
1364 for Lib in AutoGenObject.LibraryBuildDirectoryList:\r
1365 LibMakefile = os.path.normpath(os.path.join(Lib, self.MakeFileName))\r
1366 if os.path.exists(LibMakefile):\r
1367 NewBuildCommand = BuildCommand + ['-f', LibMakefile, 'cleanall']\r
1368 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)\r
1369 return True\r
1370\r
1371 # clean\r
1372 if Target == 'clean':\r
1373 for Mod in AutoGenObject.ModuleBuildDirectoryList:\r
1374 ModMakefile = os.path.normpath(os.path.join(Mod, self.MakeFileName))\r
1375 if os.path.exists(ModMakefile):\r
1376 NewBuildCommand = BuildCommand + ['-f', ModMakefile, 'cleanall']\r
1377 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)\r
1378 for Lib in AutoGenObject.LibraryBuildDirectoryList:\r
1379 LibMakefile = os.path.normpath(os.path.join(Lib, self.MakeFileName))\r
1380 if os.path.exists(LibMakefile):\r
1381 NewBuildCommand = BuildCommand + ['-f', LibMakefile, 'cleanall']\r
1382 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)\r
1383 return True\r
1384\r
1385 # cleanall\r
1386 if Target == 'cleanall':\r
1387 try:\r
1388 #os.rmdir(AutoGenObject.BuildDir)\r
1389 RemoveDirectory(AutoGenObject.BuildDir, True)\r
1390 except WindowsError as X:\r
1391 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))\r
1392 return True\r
1393\r
1394 ## Build a module or platform\r
1395 #\r
1396 # Create autogen code and makefile for a module or platform, and the launch\r
1397 # "make" command to build it\r
1398 #\r
1399 # @param Target The target of build command\r
1400 # @param Platform The platform file\r
1401 # @param Module The module file\r
1402 # @param BuildTarget The name of build target, one of "DEBUG", "RELEASE"\r
1403 # @param ToolChain The name of toolchain to build\r
1404 # @param Arch The arch of the module/platform\r
1405 # @param CreateDepModuleCodeFile Flag used to indicate creating code\r
1406 # for dependent modules/Libraries\r
1407 # @param CreateDepModuleMakeFile Flag used to indicate creating makefile\r
1408 # for dependent modules/Libraries\r
1409 #\r
1410 def _Build(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeFile=True, BuildModule=False):\r
1411 if AutoGenObject is None:\r
1412 return False\r
1413\r
1414 # skip file generation for cleanxxx targets, run and fds target\r
1415 if Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:\r
1416 # for target which must generate AutoGen code and makefile\r
1417 if not self.SkipAutoGen or Target == 'genc':\r
1418 self.Progress.Start("Generating code")\r
1419 AutoGenObject.CreateCodeFile(CreateDepsCodeFile)\r
1420 self.Progress.Stop("done!")\r
1421 if Target == "genc":\r
1422 return True\r
1423\r
1424 if not self.SkipAutoGen or Target == 'genmake':\r
1425 self.Progress.Start("Generating makefile")\r
1426 AutoGenObject.CreateMakeFile(CreateDepsMakeFile)\r
1427 #AutoGenObject.CreateAsBuiltInf()\r
1428 self.Progress.Stop("done!")\r
1429 if Target == "genmake":\r
1430 return True\r
1431 else:\r
1432 # always recreate top/platform makefile when clean, just in case of inconsistency\r
1433 AutoGenObject.CreateCodeFile(True)\r
1434 AutoGenObject.CreateMakeFile(True)\r
1435\r
1436 if EdkLogger.GetLevel() == EdkLogger.QUIET:\r
1437 EdkLogger.quiet("Building ... %s" % repr(AutoGenObject))\r
1438\r
1439 BuildCommand = AutoGenObject.BuildCommand\r
1440 if BuildCommand is None or len(BuildCommand) == 0:\r
1441 EdkLogger.error("build", OPTION_MISSING,\r
1442 "No build command found for this module. "\r
1443 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %\r
1444 (AutoGenObject.BuildTarget, AutoGenObject.ToolChain, AutoGenObject.Arch),\r
1445 ExtraData=str(AutoGenObject))\r
1446\r
1447 # build modules\r
1448 if BuildModule:\r
1449 if Target != 'fds':\r
1450 BuildCommand = BuildCommand + [Target]\r
1451 AutoGenObject.BuildTime = LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)\r
1452 self.CreateAsBuiltInf()\r
1453 if GlobalData.gBinCacheDest:\r
1454 self.GenDestCache()\r
1455 elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
1456 # Only for --hash\r
1457 # Update PreMakeCacheChain files\r
1458 self.GenLocalPreMakeCache()\r
1459 self.BuildModules = []\r
1460 return True\r
1461\r
1462 # genfds\r
1463 if Target == 'fds':\r
1464 if GenFdsApi(AutoGenObject.GenFdsCommandDict, self.Db):\r
1465 EdkLogger.error("build", COMMAND_FAILURE)\r
1466 Threshold = self.GetFreeSizeThreshold()\r
1467 if Threshold:\r
1468 self.CheckFreeSizeThreshold(Threshold, AutoGenObject.FvDir)\r
1469 return True\r
1470\r
1471 # run\r
1472 if Target == 'run':\r
1473 return True\r
1474\r
1475 # build library\r
1476 if Target == 'libraries':\r
1477 pass\r
1478\r
1479 # not build modules\r
1480\r
1481\r
1482 # cleanall\r
1483 if Target == 'cleanall':\r
1484 try:\r
1485 #os.rmdir(AutoGenObject.BuildDir)\r
1486 RemoveDirectory(AutoGenObject.BuildDir, True)\r
1487 except WindowsError as X:\r
1488 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))\r
1489 return True\r
1490\r
1491 ## Rebase module image and Get function address for the input module list.\r
1492 #\r
1493 def _RebaseModule (self, MapBuffer, BaseAddress, ModuleList, AddrIsOffset = True, ModeIsSmm = False):\r
1494 if ModeIsSmm:\r
1495 AddrIsOffset = False\r
1496 for InfFile in ModuleList:\r
1497 sys.stdout.write (".")\r
1498 sys.stdout.flush()\r
1499 ModuleInfo = ModuleList[InfFile]\r
1500 ModuleName = ModuleInfo.BaseName\r
1501 ModuleOutputImage = ModuleInfo.Image.FileName\r
1502 ModuleDebugImage = os.path.join(ModuleInfo.DebugDir, ModuleInfo.BaseName + '.efi')\r
1503 ## for SMM module in SMRAM, the SMRAM will be allocated from base to top.\r
1504 if not ModeIsSmm:\r
1505 BaseAddress = BaseAddress - ModuleInfo.Image.Size\r
1506 #\r
1507 # Update Image to new BaseAddress by GenFw tool\r
1508 #\r
1509 LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
1510 LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)\r
1511 else:\r
1512 #\r
1513 # Set new address to the section header only for SMM driver.\r
1514 #\r
1515 LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)\r
1516 LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)\r
1517 #\r
1518 # Collect function address from Map file\r
1519 #\r
1520 ImageMapTable = ModuleOutputImage.replace('.efi', '.map')\r
1521 FunctionList = []\r
1522 if os.path.exists(ImageMapTable):\r
1523 OrigImageBaseAddress = 0\r
1524 ImageMap = open(ImageMapTable, 'r')\r
1525 for LinStr in ImageMap:\r
1526 if len (LinStr.strip()) == 0:\r
1527 continue\r
1528 #\r
1529 # Get the preferred address set on link time.\r
1530 #\r
1531 if LinStr.find ('Preferred load address is') != -1:\r
1532 StrList = LinStr.split()\r
1533 OrigImageBaseAddress = int (StrList[len(StrList) - 1], 16)\r
1534\r
1535 StrList = LinStr.split()\r
1536 if len (StrList) > 4:\r
1537 if StrList[3] == 'f' or StrList[3] == 'F':\r
1538 Name = StrList[1]\r
1539 RelativeAddress = int (StrList[2], 16) - OrigImageBaseAddress\r
1540 FunctionList.append ((Name, RelativeAddress))\r
1541\r
1542 ImageMap.close()\r
1543 #\r
1544 # Add general information.\r
1545 #\r
1546 if ModeIsSmm:\r
1547 MapBuffer.append('\n\n%s (Fixed SMRAM Offset, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))\r
1548 elif AddrIsOffset:\r
1549 MapBuffer.append('\n\n%s (Fixed Memory Offset, BaseAddress=-0x%010X, EntryPoint=-0x%010X)\n' % (ModuleName, 0 - BaseAddress, 0 - (BaseAddress + ModuleInfo.Image.EntryPoint)))\r
1550 else:\r
1551 MapBuffer.append('\n\n%s (Fixed Memory Address, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))\r
1552 #\r
1553 # Add guid and general seciton section.\r
1554 #\r
1555 TextSectionAddress = 0\r
1556 DataSectionAddress = 0\r
1557 for SectionHeader in ModuleInfo.Image.SectionHeaderList:\r
1558 if SectionHeader[0] == '.text':\r
1559 TextSectionAddress = SectionHeader[1]\r
1560 elif SectionHeader[0] in ['.data', '.sdata']:\r
1561 DataSectionAddress = SectionHeader[1]\r
1562 if AddrIsOffset:\r
1563 MapBuffer.append('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n' % (ModuleInfo.Guid, 0 - (BaseAddress + TextSectionAddress), 0 - (BaseAddress + DataSectionAddress)))\r
1564 else:\r
1565 MapBuffer.append('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n' % (ModuleInfo.Guid, BaseAddress + TextSectionAddress, BaseAddress + DataSectionAddress))\r
1566 #\r
1567 # Add debug image full path.\r
1568 #\r
1569 MapBuffer.append('(IMAGE=%s)\n\n' % (ModuleDebugImage))\r
1570 #\r
1571 # Add function address\r
1572 #\r
1573 for Function in FunctionList:\r
1574 if AddrIsOffset:\r
1575 MapBuffer.append(' -0x%010X %s\n' % (0 - (BaseAddress + Function[1]), Function[0]))\r
1576 else:\r
1577 MapBuffer.append(' 0x%010X %s\n' % (BaseAddress + Function[1], Function[0]))\r
1578 ImageMap.close()\r
1579\r
1580 #\r
1581 # for SMM module in SMRAM, the SMRAM will be allocated from base to top.\r
1582 #\r
1583 if ModeIsSmm:\r
1584 BaseAddress = BaseAddress + ModuleInfo.Image.Size\r
1585\r
1586 ## Collect MAP information of all FVs\r
1587 #\r
1588 def _CollectFvMapBuffer (self, MapBuffer, Wa, ModuleList):\r
1589 if self.Fdf:\r
1590 # First get the XIP base address for FV map file.\r
1591 GuidPattern = re.compile("[-a-fA-F0-9]+")\r
1592 GuidName = re.compile(r"\(GUID=[-a-fA-F0-9]+")\r
1593 for FvName in Wa.FdfProfile.FvDict:\r
1594 FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')\r
1595 if not os.path.exists(FvMapBuffer):\r
1596 continue\r
1597 FvMap = open(FvMapBuffer, 'r')\r
1598 #skip FV size information\r
1599 FvMap.readline()\r
1600 FvMap.readline()\r
1601 FvMap.readline()\r
1602 FvMap.readline()\r
1603 for Line in FvMap:\r
1604 MatchGuid = GuidPattern.match(Line)\r
1605 if MatchGuid is not None:\r
1606 #\r
1607 # Replace GUID with module name\r
1608 #\r
1609 GuidString = MatchGuid.group()\r
1610 if GuidString.upper() in ModuleList:\r
1611 Line = Line.replace(GuidString, ModuleList[GuidString.upper()].Name)\r
1612 MapBuffer.append(Line)\r
1613 #\r
1614 # Add the debug image full path.\r
1615 #\r
1616 MatchGuid = GuidName.match(Line)\r
1617 if MatchGuid is not None:\r
1618 GuidString = MatchGuid.group().split("=")[1]\r
1619 if GuidString.upper() in ModuleList:\r
1620 MapBuffer.append('(IMAGE=%s)\n' % (os.path.join(ModuleList[GuidString.upper()].DebugDir, ModuleList[GuidString.upper()].Name + '.efi')))\r
1621\r
1622 FvMap.close()\r
1623\r
1624 ## Collect MAP information of all modules\r
1625 #\r
1626 def _CollectModuleMapBuffer (self, MapBuffer, ModuleList):\r
1627 sys.stdout.write ("Generate Load Module At Fix Address Map")\r
1628 sys.stdout.flush()\r
1629 PatchEfiImageList = []\r
1630 PeiModuleList = {}\r
1631 BtModuleList = {}\r
1632 RtModuleList = {}\r
1633 SmmModuleList = {}\r
1634 PeiSize = 0\r
1635 BtSize = 0\r
1636 RtSize = 0\r
1637 # reserve 4K size in SMRAM to make SMM module address not from 0.\r
1638 SmmSize = 0x1000\r
1639 for ModuleGuid in ModuleList:\r
1640 Module = ModuleList[ModuleGuid]\r
1641 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (Module.MetaFile, Module.Arch, Module.ToolChain, Module.BuildTarget)\r
1642\r
1643 OutputImageFile = ''\r
1644 for ResultFile in Module.CodaTargetList:\r
1645 if str(ResultFile.Target).endswith('.efi'):\r
1646 #\r
1647 # module list for PEI, DXE, RUNTIME and SMM\r
1648 #\r
1649 OutputImageFile = os.path.join(Module.OutputDir, Module.Name + '.efi')\r
1650 ImageClass = PeImageClass (OutputImageFile)\r
1651 if not ImageClass.IsValid:\r
1652 EdkLogger.error("build", FILE_PARSE_FAILURE, ExtraData=ImageClass.ErrorInfo)\r
1653 ImageInfo = PeImageInfo(Module.Name, Module.Guid, Module.Arch, Module.OutputDir, Module.DebugDir, ImageClass)\r
1654 if Module.ModuleType in [SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, EDK_COMPONENT_TYPE_COMBINED_PEIM_DRIVER, EDK_COMPONENT_TYPE_PIC_PEIM, EDK_COMPONENT_TYPE_RELOCATABLE_PEIM, SUP_MODULE_DXE_CORE]:\r
1655 PeiModuleList[Module.MetaFile] = ImageInfo\r
1656 PeiSize += ImageInfo.Image.Size\r
1657 elif Module.ModuleType in [EDK_COMPONENT_TYPE_BS_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_UEFI_DRIVER]:\r
1658 BtModuleList[Module.MetaFile] = ImageInfo\r
1659 BtSize += ImageInfo.Image.Size\r
1660 elif Module.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, EDK_COMPONENT_TYPE_RT_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, EDK_COMPONENT_TYPE_SAL_RT_DRIVER]:\r
1661 RtModuleList[Module.MetaFile] = ImageInfo\r
1662 RtSize += ImageInfo.Image.Size\r
1663 elif Module.ModuleType in [SUP_MODULE_SMM_CORE, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]:\r
1664 SmmModuleList[Module.MetaFile] = ImageInfo\r
1665 SmmSize += ImageInfo.Image.Size\r
1666 if Module.ModuleType == SUP_MODULE_DXE_SMM_DRIVER:\r
1667 PiSpecVersion = Module.Module.Specification.get('PI_SPECIFICATION_VERSION', '0x00000000')\r
1668 # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver.\r
1669 if int(PiSpecVersion, 16) < 0x0001000A:\r
1670 BtModuleList[Module.MetaFile] = ImageInfo\r
1671 BtSize += ImageInfo.Image.Size\r
1672 break\r
1673 #\r
1674 # EFI image is final target.\r
1675 # Check EFI image contains patchable FixAddress related PCDs.\r
1676 #\r
1677 if OutputImageFile != '':\r
1678 ModuleIsPatch = False\r
1679 for Pcd in Module.ModulePcdList:\r
1680 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET:\r
1681 ModuleIsPatch = True\r
1682 break\r
1683 if not ModuleIsPatch:\r
1684 for Pcd in Module.LibraryPcdList:\r
1685 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET:\r
1686 ModuleIsPatch = True\r
1687 break\r
1688\r
1689 if not ModuleIsPatch:\r
1690 continue\r
1691 #\r
1692 # Module includes the patchable load fix address PCDs.\r
1693 # It will be fixed up later.\r
1694 #\r
1695 PatchEfiImageList.append (OutputImageFile)\r
1696\r
1697 #\r
1698 # Get Top Memory address\r
1699 #\r
1700 ReservedRuntimeMemorySize = 0\r
1701 TopMemoryAddress = 0\r
1702 if self.LoadFixAddress == 0xFFFFFFFFFFFFFFFF:\r
1703 TopMemoryAddress = 0\r
1704 else:\r
1705 TopMemoryAddress = self.LoadFixAddress\r
1706 if TopMemoryAddress < RtSize + BtSize + PeiSize:\r
1707 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is too low to load driver")\r
1708\r
1709 #\r
1710 # Patch FixAddress related PCDs into EFI image\r
1711 #\r
1712 for EfiImage in PatchEfiImageList:\r
1713 EfiImageMap = EfiImage.replace('.efi', '.map')\r
1714 if not os.path.exists(EfiImageMap):\r
1715 continue\r
1716 #\r
1717 # Get PCD offset in EFI image by GenPatchPcdTable function\r
1718 #\r
1719 PcdTable = parsePcdInfoFromMapFile(EfiImageMap, EfiImage)\r
1720 #\r
1721 # Patch real PCD value by PatchPcdValue tool\r
1722 #\r
1723 for PcdInfo in PcdTable:\r
1724 ReturnValue = 0\r
1725 if PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE:\r
1726 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize // 0x1000))\r
1727 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE:\r
1728 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize // 0x1000))\r
1729 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE:\r
1730 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize // 0x1000))\r
1731 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0:\r
1732 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize // 0x1000))\r
1733 if ReturnValue != 0:\r
1734 EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD value failed", ExtraData=ErrorInfo)\r
1735\r
1736 MapBuffer.append('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize // 0x1000))\r
1737 MapBuffer.append('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize // 0x1000))\r
1738 MapBuffer.append('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize // 0x1000))\r
1739 if len (SmmModuleList) > 0:\r
1740 MapBuffer.append('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize // 0x1000))\r
1741\r
1742 PeiBaseAddr = TopMemoryAddress - RtSize - BtSize\r
1743 BtBaseAddr = TopMemoryAddress - RtSize\r
1744 RtBaseAddr = TopMemoryAddress - ReservedRuntimeMemorySize\r
1745\r
1746 self._RebaseModule (MapBuffer, PeiBaseAddr, PeiModuleList, TopMemoryAddress == 0)\r
1747 self._RebaseModule (MapBuffer, BtBaseAddr, BtModuleList, TopMemoryAddress == 0)\r
1748 self._RebaseModule (MapBuffer, RtBaseAddr, RtModuleList, TopMemoryAddress == 0)\r
1749 self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset=False, ModeIsSmm=True)\r
1750 MapBuffer.append('\n\n')\r
1751 sys.stdout.write ("\n")\r
1752 sys.stdout.flush()\r
1753\r
1754 ## Save platform Map file\r
1755 #\r
1756 def _SaveMapFile (self, MapBuffer, Wa):\r
1757 #\r
1758 # Map file path is got.\r
1759 #\r
1760 MapFilePath = os.path.join(Wa.BuildDir, Wa.Name + '.map')\r
1761 #\r
1762 # Save address map into MAP file.\r
1763 #\r
1764 SaveFileOnChange(MapFilePath, ''.join(MapBuffer), False)\r
1765 if self.LoadFixAddress != 0:\r
1766 sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" % (MapFilePath))\r
1767 sys.stdout.flush()\r
1768\r
1769 ## Build active platform for different build targets and different tool chains\r
1770 #\r
1771 def _BuildPlatform(self):\r
1772 SaveFileOnChange(self.PlatformBuildPath, '# DO NOT EDIT \n# FILE auto-generated\n', False)\r
1773 for BuildTarget in self.BuildTargetList:\r
1774 GlobalData.gGlobalDefines['TARGET'] = BuildTarget\r
1775 index = 0\r
1776 for ToolChain in self.ToolChainList:\r
1777 GlobalData.gGlobalDefines['TOOLCHAIN'] = ToolChain\r
1778 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = ToolChain\r
1779 GlobalData.gGlobalDefines['FAMILY'] = self.ToolChainFamily[index]\r
1780 index += 1\r
1781 Wa = WorkspaceAutoGen(\r
1782 self.WorkspaceDir,\r
1783 self.PlatformFile,\r
1784 BuildTarget,\r
1785 ToolChain,\r
1786 self.ArchList,\r
1787 self.BuildDatabase,\r
1788 self.TargetTxt,\r
1789 self.ToolDef,\r
1790 self.Fdf,\r
1791 self.FdList,\r
1792 self.FvList,\r
1793 self.CapList,\r
1794 self.SkuId,\r
1795 self.UniFlag,\r
1796 self.Progress\r
1797 )\r
1798 self.Fdf = Wa.FdfFile\r
1799 self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
1800 self.BuildReport.AddPlatformReport(Wa)\r
1801 self.Progress.Stop("done!")\r
1802\r
1803 # Add ffs build to makefile\r
1804 CmdListDict = {}\r
1805 if GlobalData.gEnableGenfdsMultiThread and self.Fdf:\r
1806 CmdListDict = self._GenFfsCmd(Wa.ArchList)\r
1807\r
1808 for Arch in Wa.ArchList:\r
1809 PcdMaList = []\r
1810 GlobalData.gGlobalDefines['ARCH'] = Arch\r
1811 Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)\r
1812 for Module in Pa.Platform.Modules:\r
1813 # Get ModuleAutoGen object to generate C code file and makefile\r
1814 Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile,Pa.DataPipe)\r
1815 if Ma is None:\r
1816 continue\r
1817 if Ma.PcdIsDriver:\r
1818 Ma.PlatformInfo = Pa\r
1819 Ma.Workspace = Wa\r
1820 PcdMaList.append(Ma)\r
1821 self.BuildModules.append(Ma)\r
1822 Pa.DataPipe.DataContainer = {"FfsCommand":CmdListDict}\r
1823 Pa.DataPipe.DataContainer = {"Workspace_timestamp": Wa._SrcTimeStamp}\r
1824 self._BuildPa(self.Target, Pa, FfsCommand=CmdListDict,PcdMaList=PcdMaList)\r
1825\r
1826 # Create MAP file when Load Fix Address is enabled.\r
1827 if self.Target in ["", "all", "fds"]:\r
1828 for Arch in Wa.ArchList:\r
1829 GlobalData.gGlobalDefines['ARCH'] = Arch\r
1830 #\r
1831 # Check whether the set fix address is above 4G for 32bit image.\r
1832 #\r
1833 if (Arch == 'IA32' or Arch == 'ARM') and self.LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self.LoadFixAddress >= 0x100000000:\r
1834 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS can't be set to larger than or equal to 4G for the platform with IA32 or ARM arch modules")\r
1835 #\r
1836 # Get Module List\r
1837 #\r
1838 ModuleList = {}\r
1839 for Pa in Wa.AutoGenObjectList:\r
1840 for Ma in Pa.ModuleAutoGenList:\r
1841 if Ma is None:\r
1842 continue\r
1843 if not Ma.IsLibrary:\r
1844 ModuleList[Ma.Guid.upper()] = Ma\r
1845\r
1846 MapBuffer = []\r
1847 if self.LoadFixAddress != 0:\r
1848 #\r
1849 # Rebase module to the preferred memory address before GenFds\r
1850 #\r
1851 self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
1852 if self.Fdf:\r
1853 #\r
1854 # create FDS again for the updated EFI image\r
1855 #\r
1856 self._Build("fds", Wa)\r
1857 #\r
1858 # Create MAP file for all platform FVs after GenFds.\r
1859 #\r
1860 self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)\r
1861 #\r
1862 # Save MAP buffer into MAP file.\r
1863 #\r
1864 self._SaveMapFile (MapBuffer, Wa)\r
1865 self.CreateGuidedSectionToolsFile(Wa)\r
1866\r
1867 ## Build active module for different build targets, different tool chains and different archs\r
1868 #\r
1869 def _BuildModule(self):\r
1870 for BuildTarget in self.BuildTargetList:\r
1871 GlobalData.gGlobalDefines['TARGET'] = BuildTarget\r
1872 index = 0\r
1873 for ToolChain in self.ToolChainList:\r
1874 WorkspaceAutoGenTime = time.time()\r
1875 GlobalData.gGlobalDefines['TOOLCHAIN'] = ToolChain\r
1876 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = ToolChain\r
1877 GlobalData.gGlobalDefines['FAMILY'] = self.ToolChainFamily[index]\r
1878 index += 1\r
1879 #\r
1880 # module build needs platform build information, so get platform\r
1881 # AutoGen first\r
1882 #\r
1883 Wa = WorkspaceAutoGen(\r
1884 self.WorkspaceDir,\r
1885 self.PlatformFile,\r
1886 BuildTarget,\r
1887 ToolChain,\r
1888 self.ArchList,\r
1889 self.BuildDatabase,\r
1890 self.TargetTxt,\r
1891 self.ToolDef,\r
1892 self.Fdf,\r
1893 self.FdList,\r
1894 self.FvList,\r
1895 self.CapList,\r
1896 self.SkuId,\r
1897 self.UniFlag,\r
1898 self.Progress,\r
1899 self.ModuleFile\r
1900 )\r
1901 self.Fdf = Wa.FdfFile\r
1902 self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
1903 Wa.CreateMakeFile(False)\r
1904 # Add ffs build to makefile\r
1905 CmdListDict = None\r
1906 if GlobalData.gEnableGenfdsMultiThread and self.Fdf:\r
1907 CmdListDict = self._GenFfsCmd(Wa.ArchList)\r
1908\r
1909 GlobalData.file_lock = mp.Lock()\r
1910 GlobalData.FfsCmd = CmdListDict\r
1911\r
1912 self.Progress.Stop("done!")\r
1913 MaList = []\r
1914 ExitFlag = threading.Event()\r
1915 ExitFlag.clear()\r
1916 self.AutoGenTime += int(round((time.time() - WorkspaceAutoGenTime)))\r
1917 for Arch in Wa.ArchList:\r
1918 AutoGenStart = time.time()\r
1919 GlobalData.gGlobalDefines['ARCH'] = Arch\r
1920 Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)\r
1921 for Module in Pa.Platform.Modules:\r
1922 if self.ModuleFile.Dir == Module.Dir and self.ModuleFile.Name == Module.Name:\r
1923 Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile,Pa.DataPipe)\r
1924 if Ma is None:\r
1925 continue\r
1926 if Ma.PcdIsDriver:\r
1927 Ma.PlatformInfo = Pa\r
1928 Ma.Workspace = Wa\r
1929 MaList.append(Ma)\r
1930\r
1931 if GlobalData.gUseHashCache and not GlobalData.gBinCacheDest and self.Target in [None, "", "all"]:\r
1932 if Ma.CanSkipbyPreMakeCache():\r
1933 continue\r
1934 else:\r
1935 self.PreMakeCacheMiss.add(Ma)\r
1936\r
1937 # Not to auto-gen for targets 'clean', 'cleanlib', 'cleanall', 'run', 'fds'\r
1938 if self.Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:\r
1939 # for target which must generate AutoGen code and makefile\r
1940 if not self.SkipAutoGen or self.Target == 'genc':\r
1941 self.Progress.Start("Generating code")\r
1942 Ma.CreateCodeFile(True)\r
1943 self.Progress.Stop("done!")\r
1944 if self.Target == "genc":\r
1945 return True\r
1946 if not self.SkipAutoGen or self.Target == 'genmake':\r
1947 self.Progress.Start("Generating makefile")\r
1948 if CmdListDict and self.Fdf and (Module.Path, Arch) in CmdListDict:\r
1949 Ma.CreateMakeFile(True, CmdListDict[Module.Path, Arch])\r
1950 del CmdListDict[Module.Path, Arch]\r
1951 else:\r
1952 Ma.CreateMakeFile(True)\r
1953 self.Progress.Stop("done!")\r
1954 if self.Target == "genmake":\r
1955 return True\r
1956\r
1957 if GlobalData.gBinCacheSource and self.Target in [None, "", "all"]:\r
1958 if Ma.CanSkipbyMakeCache():\r
1959 continue\r
1960 else:\r
1961 self.MakeCacheMiss.add(Ma)\r
1962\r
1963 self.BuildModules.append(Ma)\r
1964 self.AutoGenTime += int(round((time.time() - AutoGenStart)))\r
1965 MakeStart = time.time()\r
1966 for Ma in self.BuildModules:\r
1967 if not Ma.IsBinaryModule:\r
1968 Bt = BuildTask.New(ModuleMakeUnit(Ma, Pa.BuildCommand,self.Target))\r
1969 # Break build if any build thread has error\r
1970 if BuildTask.HasError():\r
1971 # we need a full version of makefile for platform\r
1972 ExitFlag.set()\r
1973 BuildTask.WaitForComplete()\r
1974 Pa.CreateMakeFile(False)\r
1975 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
1976 # Start task scheduler\r
1977 if not BuildTask.IsOnGoing():\r
1978 BuildTask.StartScheduler(self.ThreadNumber, ExitFlag)\r
1979\r
1980 # in case there's an interruption. we need a full version of makefile for platform\r
1981 Pa.CreateMakeFile(False)\r
1982 if BuildTask.HasError():\r
1983 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
1984 self.MakeTime += int(round((time.time() - MakeStart)))\r
1985\r
1986 MakeContiue = time.time()\r
1987 ExitFlag.set()\r
1988 BuildTask.WaitForComplete()\r
1989 self.CreateAsBuiltInf()\r
1990 if GlobalData.gBinCacheDest:\r
1991 self.GenDestCache()\r
1992 elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
1993 # Only for --hash\r
1994 # Update PreMakeCacheChain files\r
1995 self.GenLocalPreMakeCache()\r
1996 self.BuildModules = []\r
1997 self.MakeTime += int(round((time.time() - MakeContiue)))\r
1998 if BuildTask.HasError():\r
1999 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
2000\r
2001 self.BuildReport.AddPlatformReport(Wa, MaList)\r
2002 if MaList == []:\r
2003 EdkLogger.error(\r
2004 'build',\r
2005 BUILD_ERROR,\r
2006 "Module for [%s] is not a component of active platform."\\r
2007 " Please make sure that the ARCH and inf file path are"\\r
2008 " given in the same as in [%s]" % \\r
2009 (', '.join(Wa.ArchList), self.PlatformFile),\r
2010 ExtraData=self.ModuleFile\r
2011 )\r
2012 # Create MAP file when Load Fix Address is enabled.\r
2013 if self.Target == "fds" and self.Fdf:\r
2014 for Arch in Wa.ArchList:\r
2015 #\r
2016 # Check whether the set fix address is above 4G for 32bit image.\r
2017 #\r
2018 if (Arch == 'IA32' or Arch == 'ARM') and self.LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self.LoadFixAddress >= 0x100000000:\r
2019 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS can't be set to larger than or equal to 4G for the platorm with IA32 or ARM arch modules")\r
2020 #\r
2021 # Get Module List\r
2022 #\r
2023 ModuleList = {}\r
2024 for Pa in Wa.AutoGenObjectList:\r
2025 for Ma in Pa.ModuleAutoGenList:\r
2026 if Ma is None:\r
2027 continue\r
2028 if not Ma.IsLibrary:\r
2029 ModuleList[Ma.Guid.upper()] = Ma\r
2030\r
2031 MapBuffer = []\r
2032 if self.LoadFixAddress != 0:\r
2033 #\r
2034 # Rebase module to the preferred memory address before GenFds\r
2035 #\r
2036 self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
2037 #\r
2038 # create FDS again for the updated EFI image\r
2039 #\r
2040 GenFdsStart = time.time()\r
2041 self._Build("fds", Wa)\r
2042 self.GenFdsTime += int(round((time.time() - GenFdsStart)))\r
2043 #\r
2044 # Create MAP file for all platform FVs after GenFds.\r
2045 #\r
2046 self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)\r
2047 #\r
2048 # Save MAP buffer into MAP file.\r
2049 #\r
2050 self._SaveMapFile (MapBuffer, Wa)\r
2051\r
2052 def _GenFfsCmd(self,ArchList):\r
2053 # convert dictionary of Cmd:(Inf,Arch)\r
2054 # to a new dictionary of (Inf,Arch):Cmd,Cmd,Cmd...\r
2055 CmdSetDict = defaultdict(set)\r
2056 GenFfsDict = GenFds.GenFfsMakefile('', GlobalData.gFdfParser, self, ArchList, GlobalData)\r
2057 for Cmd in GenFfsDict:\r
2058 tmpInf, tmpArch = GenFfsDict[Cmd]\r
2059 CmdSetDict[tmpInf, tmpArch].add(Cmd)\r
2060 return CmdSetDict\r
2061 def VerifyAutoGenFiles(self):\r
2062 AutoGenIdFile = os.path.join(GlobalData.gConfDirectory,".AutoGenIdFile.txt")\r
2063 try:\r
2064 with open(AutoGenIdFile) as fd:\r
2065 lines = fd.readlines()\r
2066 except:\r
2067 return None\r
2068 for line in lines:\r
2069 if "Arch" in line:\r
2070 ArchList = line.strip().split("=")[1].split("|")\r
2071 if "BuildDir" in line:\r
2072 BuildDir = line.split("=")[1].strip()\r
2073 if "PlatformGuid" in line:\r
2074 PlatformGuid = line.split("=")[1].strip()\r
2075 GlobalVarList = []\r
2076 for arch in ArchList:\r
2077 global_var = os.path.join(BuildDir, "GlobalVar_%s_%s.bin" % (str(PlatformGuid),arch))\r
2078 if not os.path.exists(global_var):\r
2079 return None\r
2080 GlobalVarList.append(global_var)\r
2081 for global_var in GlobalVarList:\r
2082 data_pipe = MemoryDataPipe()\r
2083 data_pipe.load(global_var)\r
2084 target = data_pipe.Get("P_Info").get("Target")\r
2085 toolchain = data_pipe.Get("P_Info").get("ToolChain")\r
2086 archlist = data_pipe.Get("P_Info").get("ArchList")\r
2087 Arch = data_pipe.Get("P_Info").get("Arch")\r
2088 active_p = data_pipe.Get("P_Info").get("ActivePlatform")\r
2089 workspacedir = data_pipe.Get("P_Info").get("WorkspaceDir")\r
2090 PackagesPath = os.getenv("PACKAGES_PATH")\r
2091 mws.setWs(workspacedir, PackagesPath)\r
2092 LibraryBuildDirectoryList = data_pipe.Get("LibraryBuildDirectoryList")\r
2093 ModuleBuildDirectoryList = data_pipe.Get("ModuleBuildDirectoryList")\r
2094\r
2095 for m_build_dir in LibraryBuildDirectoryList:\r
2096 if not os.path.exists(os.path.join(m_build_dir,self.MakeFileName)):\r
2097 return None\r
2098 for m_build_dir in ModuleBuildDirectoryList:\r
2099 if not os.path.exists(os.path.join(m_build_dir,self.MakeFileName)):\r
2100 return None\r
2101 Wa = WorkSpaceInfo(\r
2102 workspacedir,active_p,target,toolchain,archlist\r
2103 )\r
2104 Pa = PlatformInfo(Wa, active_p, target, toolchain, Arch,data_pipe)\r
2105 Wa.AutoGenObjectList.append(Pa)\r
2106 return Wa\r
2107 def SetupMakeSetting(self,Wa):\r
2108 BuildModules = []\r
2109 for Pa in Wa.AutoGenObjectList:\r
2110 for m in Pa._MbList:\r
2111 ma = ModuleAutoGen(Wa,m.MetaFile, Pa.BuildTarget, Wa.ToolChain, Pa.Arch, Pa.MetaFile,Pa.DataPipe)\r
2112 BuildModules.append(ma)\r
2113 fdf_file = Wa.FlashDefinition\r
2114 if fdf_file:\r
2115 Fdf = FdfParser(fdf_file.Path)\r
2116 Fdf.ParseFile()\r
2117 GlobalData.gFdfParser = Fdf\r
2118 if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:\r
2119 FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
2120 for FdRegion in FdDict.RegionList:\r
2121 if str(FdRegion.RegionType) == 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
2122 if int(FdRegion.Offset) % 8 != 0:\r
2123 EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
2124 Wa.FdfProfile = Fdf.Profile\r
2125 self.Fdf = Fdf\r
2126 else:\r
2127 self.Fdf = None\r
2128 return BuildModules\r
2129\r
2130 ## Build a platform in multi-thread mode\r
2131 #\r
2132 def PerformAutoGen(self,BuildTarget,ToolChain):\r
2133 WorkspaceAutoGenTime = time.time()\r
2134 Wa = WorkspaceAutoGen(\r
2135 self.WorkspaceDir,\r
2136 self.PlatformFile,\r
2137 BuildTarget,\r
2138 ToolChain,\r
2139 self.ArchList,\r
2140 self.BuildDatabase,\r
2141 self.TargetTxt,\r
2142 self.ToolDef,\r
2143 self.Fdf,\r
2144 self.FdList,\r
2145 self.FvList,\r
2146 self.CapList,\r
2147 self.SkuId,\r
2148 self.UniFlag,\r
2149 self.Progress\r
2150 )\r
2151 self.Fdf = Wa.FdfFile\r
2152 self.LoadFixAddress = Wa.Platform.LoadFixAddress\r
2153 self.BuildReport.AddPlatformReport(Wa)\r
2154 Wa.CreateMakeFile(False)\r
2155\r
2156 # Add ffs build to makefile\r
2157 CmdListDict = {}\r
2158 if GlobalData.gEnableGenfdsMultiThread and self.Fdf:\r
2159 CmdListDict = self._GenFfsCmd(Wa.ArchList)\r
2160\r
2161 self.AutoGenTime += int(round((time.time() - WorkspaceAutoGenTime)))\r
2162 BuildModules = []\r
2163 for Arch in Wa.ArchList:\r
2164 PcdMaList = []\r
2165 AutoGenStart = time.time()\r
2166 GlobalData.gGlobalDefines['ARCH'] = Arch\r
2167 Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)\r
2168 if Pa is None:\r
2169 continue\r
2170 ModuleList = []\r
2171 for Inf in Pa.Platform.Modules:\r
2172 ModuleList.append(Inf)\r
2173 # Add the INF only list in FDF\r
2174 if GlobalData.gFdfParser is not None:\r
2175 for InfName in GlobalData.gFdfParser.Profile.InfList:\r
2176 Inf = PathClass(NormPath(InfName), self.WorkspaceDir, Arch)\r
2177 if Inf in Pa.Platform.Modules:\r
2178 continue\r
2179 ModuleList.append(Inf)\r
2180 Pa.DataPipe.DataContainer = {"FfsCommand":CmdListDict}\r
2181 Pa.DataPipe.DataContainer = {"Workspace_timestamp": Wa._SrcTimeStamp}\r
2182 Pa.DataPipe.DataContainer = {"CommandTarget": self.Target}\r
2183 Pa.CreateLibModuelDirs()\r
2184 # Fetch the MakeFileName.\r
2185 self.MakeFileName = Pa.MakeFileName\r
2186 if not self.MakeFileName:\r
2187 self.MakeFileName = Pa.MakeFile\r
2188\r
2189 Pa.DataPipe.DataContainer = {"LibraryBuildDirectoryList":Pa.LibraryBuildDirectoryList}\r
2190 Pa.DataPipe.DataContainer = {"ModuleBuildDirectoryList":Pa.ModuleBuildDirectoryList}\r
2191 Pa.DataPipe.DataContainer = {"FdsCommandDict": Wa.GenFdsCommandDict}\r
2192 # Prepare the cache share data for multiprocessing\r
2193 Pa.DataPipe.DataContainer = {"gPlatformHashFile":GlobalData.gPlatformHashFile}\r
2194 ModuleCodaFile = {}\r
2195 for ma in Pa.ModuleAutoGenList:\r
2196 ModuleCodaFile[(ma.MetaFile.File,ma.MetaFile.Root,ma.Arch,ma.MetaFile.Path)] = [item.Target for item in ma.CodaTargetList]\r
2197 Pa.DataPipe.DataContainer = {"ModuleCodaFile":ModuleCodaFile}\r
2198 # ModuleList contains all driver modules only\r
2199 for Module in ModuleList:\r
2200 # Get ModuleAutoGen object to generate C code file and makefile\r
2201 Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile,Pa.DataPipe)\r
2202 if Ma is None:\r
2203 continue\r
2204 if Ma.PcdIsDriver:\r
2205 Ma.PlatformInfo = Pa\r
2206 Ma.Workspace = Wa\r
2207 PcdMaList.append(Ma)\r
2208 self.AllDrivers.add(Ma)\r
2209 self.AllModules.add(Ma)\r
2210\r
2211 mqueue = mp.Queue()\r
2212 cqueue = mp.Queue()\r
2213 for m in Pa.GetAllModuleInfo:\r
2214 mqueue.put(m)\r
2215 module_file,module_root,module_path,module_basename,\\r
2216 module_originalpath,module_arch,IsLib = m\r
2217 Ma = ModuleAutoGen(Wa, PathClass(module_path, Wa), BuildTarget,\\r
2218 ToolChain, Arch, self.PlatformFile,Pa.DataPipe)\r
2219 self.AllModules.add(Ma)\r
2220 data_pipe_file = os.path.join(Pa.BuildDir, "GlobalVar_%s_%s.bin" % (str(Pa.Guid),Pa.Arch))\r
2221 Pa.DataPipe.dump(data_pipe_file)\r
2222\r
2223 mqueue.put((None,None,None,None,None,None,None))\r
2224 autogen_rt, errorcode = self.StartAutoGen(mqueue, Pa.DataPipe, self.SkipAutoGen, PcdMaList, cqueue)\r
2225\r
2226 if not autogen_rt:\r
2227 self.AutoGenMgr.TerminateWorkers()\r
2228 self.AutoGenMgr.join(1)\r
2229 raise FatalError(errorcode)\r
2230\r
2231 if GlobalData.gUseHashCache:\r
2232 for item in GlobalData.gModuleAllCacheStatus:\r
2233 (MetaFilePath, Arch, CacheStr, Status) = item\r
2234 Ma = ModuleAutoGen(Wa, PathClass(MetaFilePath, Wa), BuildTarget,\\r
2235 ToolChain, Arch, self.PlatformFile,Pa.DataPipe)\r
2236 if CacheStr == "PreMakeCache" and Status == False:\r
2237 self.PreMakeCacheMiss.add(Ma)\r
2238 if CacheStr == "PreMakeCache" and Status == True:\r
2239 self.PreMakeCacheHit.add(Ma)\r
2240 GlobalData.gModuleCacheHit.add(Ma)\r
2241 if CacheStr == "MakeCache" and Status == False:\r
2242 self.MakeCacheMiss.add(Ma)\r
2243 if CacheStr == "MakeCache" and Status == True:\r
2244 self.MakeCacheHit.add(Ma)\r
2245 GlobalData.gModuleCacheHit.add(Ma)\r
2246 self.AutoGenTime += int(round((time.time() - AutoGenStart)))\r
2247 AutoGenIdFile = os.path.join(GlobalData.gConfDirectory,".AutoGenIdFile.txt")\r
2248 with open(AutoGenIdFile,"w") as fw:\r
2249 fw.write("Arch=%s\n" % "|".join((Wa.ArchList)))\r
2250 fw.write("BuildDir=%s\n" % Wa.BuildDir)\r
2251 fw.write("PlatformGuid=%s\n" % str(Wa.AutoGenObjectList[0].Guid))\r
2252\r
2253 if GlobalData.gBinCacheSource:\r
2254 BuildModules.extend(self.MakeCacheMiss)\r
2255 elif GlobalData.gUseHashCache and not GlobalData.gBinCacheDest:\r
2256 BuildModules.extend(self.PreMakeCacheMiss)\r
2257 else:\r
2258 BuildModules.extend(self.AllDrivers)\r
2259\r
2260 self.Progress.Stop("done!")\r
2261 return Wa, BuildModules\r
2262\r
2263 def _MultiThreadBuildPlatform(self):\r
2264 SaveFileOnChange(self.PlatformBuildPath, '# DO NOT EDIT \n# FILE auto-generated\n', False)\r
2265 for BuildTarget in self.BuildTargetList:\r
2266 GlobalData.gGlobalDefines['TARGET'] = BuildTarget\r
2267 index = 0\r
2268 for ToolChain in self.ToolChainList:\r
2269 resetFdsGlobalVariable()\r
2270 GlobalData.gGlobalDefines['TOOLCHAIN'] = ToolChain\r
2271 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = ToolChain\r
2272 GlobalData.gGlobalDefines['FAMILY'] = self.ToolChainFamily[index]\r
2273 index += 1\r
2274 ExitFlag = threading.Event()\r
2275 ExitFlag.clear()\r
2276 if self.SkipAutoGen:\r
2277 Wa = self.VerifyAutoGenFiles()\r
2278 if Wa is None:\r
2279 self.SkipAutoGen = False\r
2280 Wa, self.BuildModules = self.PerformAutoGen(BuildTarget,ToolChain)\r
2281 else:\r
2282 GlobalData.gAutoGenPhase = True\r
2283 self.BuildModules = self.SetupMakeSetting(Wa)\r
2284 else:\r
2285 Wa, self.BuildModules = self.PerformAutoGen(BuildTarget,ToolChain)\r
2286 Pa = Wa.AutoGenObjectList[0]\r
2287 GlobalData.gAutoGenPhase = False\r
2288\r
2289 if GlobalData.gBinCacheSource:\r
2290 EdkLogger.quiet("[cache Summary]: Total module num: %s" % len(self.AllModules))\r
2291 EdkLogger.quiet("[cache Summary]: PreMakecache miss num: %s " % len(self.PreMakeCacheMiss))\r
2292 EdkLogger.quiet("[cache Summary]: Makecache miss num: %s " % len(self.MakeCacheMiss))\r
2293\r
2294 for Arch in Wa.ArchList:\r
2295 MakeStart = time.time()\r
2296 for Ma in set(self.BuildModules):\r
2297 # Generate build task for the module\r
2298 if not Ma.IsBinaryModule:\r
2299 Bt = BuildTask.New(ModuleMakeUnit(Ma, Pa.BuildCommand,self.Target))\r
2300 # Break build if any build thread has error\r
2301 if BuildTask.HasError():\r
2302 # we need a full version of makefile for platform\r
2303 ExitFlag.set()\r
2304 BuildTask.WaitForComplete()\r
2305 Pa.CreateMakeFile(False)\r
2306 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
2307 # Start task scheduler\r
2308 if not BuildTask.IsOnGoing():\r
2309 BuildTask.StartScheduler(self.ThreadNumber, ExitFlag)\r
2310\r
2311 # in case there's an interruption. we need a full version of makefile for platform\r
2312\r
2313 if BuildTask.HasError():\r
2314 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
2315 self.MakeTime += int(round((time.time() - MakeStart)))\r
2316\r
2317 MakeContiue = time.time()\r
2318 #\r
2319 #\r
2320 # All modules have been put in build tasks queue. Tell task scheduler\r
2321 # to exit if all tasks are completed\r
2322 #\r
2323 ExitFlag.set()\r
2324 BuildTask.WaitForComplete()\r
2325 if GlobalData.gBinCacheDest:\r
2326 self.GenDestCache()\r
2327 elif GlobalData.gUseHashCache and not GlobalData.gBinCacheSource:\r
2328 # Only for --hash\r
2329 # Update PreMakeCacheChain files\r
2330 self.GenLocalPreMakeCache()\r
2331 #\r
2332 # Get Module List\r
2333 #\r
2334 ModuleList = {ma.Guid.upper(): ma for ma in self.BuildModules}\r
2335 self.BuildModules = []\r
2336 self.MakeTime += int(round((time.time() - MakeContiue)))\r
2337 #\r
2338 # Check for build error, and raise exception if one\r
2339 # has been signaled.\r
2340 #\r
2341 if BuildTask.HasError():\r
2342 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
2343\r
2344 # Create MAP file when Load Fix Address is enabled.\r
2345 if self.Target in ["", "all", "fds"]:\r
2346 for Arch in Wa.ArchList:\r
2347 #\r
2348 # Check whether the set fix address is above 4G for 32bit image.\r
2349 #\r
2350 if (Arch == 'IA32' or Arch == 'ARM') and self.LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self.LoadFixAddress >= 0x100000000:\r
2351 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS can't be set to larger than or equal to 4G for the platorm with IA32 or ARM arch modules")\r
2352\r
2353 #\r
2354 # Rebase module to the preferred memory address before GenFds\r
2355 #\r
2356 MapBuffer = []\r
2357 if self.LoadFixAddress != 0:\r
2358 self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
2359\r
2360 if self.Fdf:\r
2361 #\r
2362 # Generate FD image if there's a FDF file found\r
2363 #\r
2364 GenFdsStart = time.time()\r
2365 if GenFdsApi(Wa.GenFdsCommandDict, self.Db):\r
2366 EdkLogger.error("build", COMMAND_FAILURE)\r
2367 Threshold = self.GetFreeSizeThreshold()\r
2368 if Threshold:\r
2369 self.CheckFreeSizeThreshold(Threshold, Wa.FvDir)\r
2370\r
2371 #\r
2372 # Create MAP file for all platform FVs after GenFds.\r
2373 #\r
2374 self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)\r
2375 self.GenFdsTime += int(round((time.time() - GenFdsStart)))\r
2376 #\r
2377 # Save MAP buffer into MAP file.\r
2378 #\r
2379 self._SaveMapFile(MapBuffer, Wa)\r
2380 self.CreateGuidedSectionToolsFile(Wa)\r
2381\r
2382 ## GetFreeSizeThreshold()\r
2383 #\r
2384 # @retval int Threshold value\r
2385 #\r
2386 def GetFreeSizeThreshold(self):\r
2387 Threshold = None\r
2388 Threshold_Str = GlobalData.gCommandLineDefines.get('FV_SPARE_SPACE_THRESHOLD')\r
2389 if Threshold_Str:\r
2390 try:\r
2391 if Threshold_Str.lower().startswith('0x'):\r
2392 Threshold = int(Threshold_Str, 16)\r
2393 else:\r
2394 Threshold = int(Threshold_Str)\r
2395 except:\r
2396 EdkLogger.warn("build", 'incorrect value for FV_SPARE_SPACE_THRESHOLD %s.Only decimal or hex format is allowed.' % Threshold_Str)\r
2397 return Threshold\r
2398\r
2399 def CheckFreeSizeThreshold(self, Threshold=None, FvDir=None):\r
2400 if not isinstance(Threshold, int):\r
2401 return\r
2402 if not isinstance(FvDir, str) or not FvDir:\r
2403 return\r
2404 FdfParserObject = GlobalData.gFdfParser\r
2405 FvRegionNameList = [FvName for FvName in FdfParserObject.Profile.FvDict if FdfParserObject.Profile.FvDict[FvName].FvRegionInFD]\r
2406 for FvName in FdfParserObject.Profile.FvDict:\r
2407 if FvName in FvRegionNameList:\r
2408 FvSpaceInfoFileName = os.path.join(FvDir, FvName.upper() + '.Fv.map')\r
2409 if os.path.exists(FvSpaceInfoFileName):\r
2410 FileLinesList = getlines(FvSpaceInfoFileName)\r
2411 for Line in FileLinesList:\r
2412 NameValue = Line.split('=')\r
2413 if len(NameValue) == 2 and NameValue[0].strip() == 'EFI_FV_SPACE_SIZE':\r
2414 FreeSizeValue = int(NameValue[1].strip(), 0)\r
2415 if FreeSizeValue < Threshold:\r
2416 EdkLogger.error("build", FV_FREESIZE_ERROR,\r
2417 '%s FV free space %d is not enough to meet with the required spare space %d set by -D FV_SPARE_SPACE_THRESHOLD option.' % (\r
2418 FvName, FreeSizeValue, Threshold))\r
2419 break\r
2420\r
2421 ## Generate GuidedSectionTools.txt in the FV directories.\r
2422 #\r
2423 def CreateGuidedSectionToolsFile(self,Wa):\r
2424 for BuildTarget in self.BuildTargetList:\r
2425 for ToolChain in self.ToolChainList:\r
2426 FvDir = Wa.FvDir\r
2427 if not os.path.exists(FvDir):\r
2428 continue\r
2429 for Arch in self.ArchList:\r
2430 guidList = []\r
2431 tooldefguidList = []\r
2432 guidAttribs = []\r
2433 for Platform in Wa.AutoGenObjectList:\r
2434 if Platform.BuildTarget != BuildTarget:\r
2435 continue\r
2436 if Platform.ToolChain != ToolChain:\r
2437 continue\r
2438 if Platform.Arch != Arch:\r
2439 continue\r
2440 if hasattr (Platform, 'BuildOption'):\r
2441 for Tool in Platform.BuildOption:\r
2442 if 'GUID' in Platform.BuildOption[Tool]:\r
2443 if 'PATH' in Platform.BuildOption[Tool]:\r
2444 value = Platform.BuildOption[Tool]['GUID']\r
2445 if value in guidList:\r
2446 EdkLogger.error("build", FORMAT_INVALID, "Duplicate GUID value %s used with Tool %s in DSC [BuildOptions]." % (value, Tool))\r
2447 path = Platform.BuildOption[Tool]['PATH']\r
2448 guidList.append(value)\r
2449 guidAttribs.append((value, Tool, path))\r
2450 for Tool in Platform.ToolDefinition:\r
2451 if 'GUID' in Platform.ToolDefinition[Tool]:\r
2452 if 'PATH' in Platform.ToolDefinition[Tool]:\r
2453 value = Platform.ToolDefinition[Tool]['GUID']\r
2454 if value in tooldefguidList:\r
2455 EdkLogger.error("build", FORMAT_INVALID, "Duplicate GUID value %s used with Tool %s in tools_def.txt." % (value, Tool))\r
2456 tooldefguidList.append(value)\r
2457 if value in guidList:\r
2458 # Already added by platform\r
2459 continue\r
2460 path = Platform.ToolDefinition[Tool]['PATH']\r
2461 guidList.append(value)\r
2462 guidAttribs.append((value, Tool, path))\r
2463 # Sort by GuidTool name\r
2464 guidAttribs = sorted (guidAttribs, key=lambda x: x[1])\r
2465 # Write out GuidedSecTools.txt\r
2466 toolsFile = os.path.join(FvDir, 'GuidedSectionTools.txt')\r
2467 toolsFile = open(toolsFile, 'wt')\r
2468 for guidedSectionTool in guidAttribs:\r
2469 print(' '.join(guidedSectionTool), file=toolsFile)\r
2470 toolsFile.close()\r
2471\r
2472 ## Returns the real path of the tool.\r
2473 #\r
2474 def GetRealPathOfTool (self, tool):\r
2475 if os.path.exists(tool):\r
2476 return os.path.realpath(tool)\r
2477 return tool\r
2478\r
2479 ## Launch the module or platform build\r
2480 #\r
2481 def Launch(self):\r
2482 self.AllDrivers = set()\r
2483 self.AllModules = set()\r
2484 self.PreMakeCacheMiss = set()\r
2485 self.PreMakeCacheHit = set()\r
2486 self.MakeCacheMiss = set()\r
2487 self.MakeCacheHit = set()\r
2488 if not self.ModuleFile:\r
2489 if not self.SpawnMode or self.Target not in ["", "all"]:\r
2490 self.SpawnMode = False\r
2491 self._BuildPlatform()\r
2492 else:\r
2493 self._MultiThreadBuildPlatform()\r
2494 else:\r
2495 self.SpawnMode = False\r
2496 self._BuildModule()\r
2497\r
2498 if self.Target == 'cleanall':\r
2499 RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True)\r
2500\r
2501 def CreateAsBuiltInf(self):\r
2502 for Module in self.BuildModules:\r
2503 Module.CreateAsBuiltInf()\r
2504\r
2505 def GenDestCache(self):\r
2506 for Module in self.AllModules:\r
2507 Module.GenPreMakefileHashList()\r
2508 Module.GenMakefileHashList()\r
2509 Module.CopyModuleToCache()\r
2510\r
2511 def GenLocalPreMakeCache(self):\r
2512 for Module in self.PreMakeCacheMiss:\r
2513 Module.GenPreMakefileHashList()\r
2514\r
2515 ## Do some clean-up works when error occurred\r
2516 def Relinquish(self):\r
2517 OldLogLevel = EdkLogger.GetLevel()\r
2518 EdkLogger.SetLevel(EdkLogger.ERROR)\r
2519 Utils.Progressor.Abort()\r
2520 if self.SpawnMode == True:\r
2521 BuildTask.Abort()\r
2522 EdkLogger.SetLevel(OldLogLevel)\r
2523\r
2524def ParseDefines(DefineList=[]):\r
2525 DefineDict = {}\r
2526 if DefineList is not None:\r
2527 for Define in DefineList:\r
2528 DefineTokenList = Define.split("=", 1)\r
2529 if not GlobalData.gMacroNamePattern.match(DefineTokenList[0]):\r
2530 EdkLogger.error('build', FORMAT_INVALID,\r
2531 "The macro name must be in the pattern [A-Z][A-Z0-9_]*",\r
2532 ExtraData=DefineTokenList[0])\r
2533\r
2534 if len(DefineTokenList) == 1:\r
2535 DefineDict[DefineTokenList[0]] = "TRUE"\r
2536 else:\r
2537 DefineDict[DefineTokenList[0]] = DefineTokenList[1].strip()\r
2538 return DefineDict\r
2539\r
2540\r
2541\r
2542def LogBuildTime(Time):\r
2543 if Time:\r
2544 TimeDurStr = ''\r
2545 TimeDur = time.gmtime(Time)\r
2546 if TimeDur.tm_yday > 1:\r
2547 TimeDurStr = time.strftime("%H:%M:%S", TimeDur) + ", %d day(s)" % (TimeDur.tm_yday - 1)\r
2548 else:\r
2549 TimeDurStr = time.strftime("%H:%M:%S", TimeDur)\r
2550 return TimeDurStr\r
2551 else:\r
2552 return None\r
2553def ThreadNum():\r
2554 OptionParser = MyOptionParser()\r
2555 if not OptionParser.BuildOption and not OptionParser.BuildTarget:\r
2556 OptionParser.GetOption()\r
2557 BuildOption, BuildTarget = OptionParser.BuildOption, OptionParser.BuildTarget\r
2558 ThreadNumber = BuildOption.ThreadNumber\r
2559 GlobalData.gCmdConfDir = BuildOption.ConfDirectory\r
2560 if ThreadNumber is None:\r
2561 TargetObj = TargetTxtDict()\r
2562 ThreadNumber = TargetObj.Target.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r
2563 if ThreadNumber == '':\r
2564 ThreadNumber = 0\r
2565 else:\r
2566 ThreadNumber = int(ThreadNumber, 0)\r
2567\r
2568 if ThreadNumber == 0:\r
2569 try:\r
2570 ThreadNumber = multiprocessing.cpu_count()\r
2571 except (ImportError, NotImplementedError):\r
2572 ThreadNumber = 1\r
2573 return ThreadNumber\r
2574## Tool entrance method\r
2575#\r
2576# This method mainly dispatch specific methods per the command line options.\r
2577# If no error found, return zero value so the caller of this tool can know\r
2578# if it's executed successfully or not.\r
2579#\r
2580# @retval 0 Tool was successful\r
2581# @retval 1 Tool failed\r
2582#\r
2583LogQMaxSize = ThreadNum() * 10\r
2584def Main():\r
2585 StartTime = time.time()\r
2586\r
2587 #\r
2588 # Create a log Queue\r
2589 #\r
2590 LogQ = mp.Queue(LogQMaxSize)\r
2591 # Initialize log system\r
2592 EdkLogger.LogClientInitialize(LogQ)\r
2593 GlobalData.gCommand = sys.argv[1:]\r
2594 #\r
2595 # Parse the options and args\r
2596 #\r
2597 OptionParser = MyOptionParser()\r
2598 if not OptionParser.BuildOption and not OptionParser.BuildTarget:\r
2599 OptionParser.GetOption()\r
2600 Option, Target = OptionParser.BuildOption, OptionParser.BuildTarget\r
2601 GlobalData.gOptions = Option\r
2602 GlobalData.gCaseInsensitive = Option.CaseInsensitive\r
2603\r
2604 # Set log level\r
2605 LogLevel = EdkLogger.INFO\r
2606 if Option.verbose is not None:\r
2607 EdkLogger.SetLevel(EdkLogger.VERBOSE)\r
2608 LogLevel = EdkLogger.VERBOSE\r
2609 elif Option.quiet is not None:\r
2610 EdkLogger.SetLevel(EdkLogger.QUIET)\r
2611 LogLevel = EdkLogger.QUIET\r
2612 elif Option.debug is not None:\r
2613 EdkLogger.SetLevel(Option.debug + 1)\r
2614 LogLevel = Option.debug + 1\r
2615 else:\r
2616 EdkLogger.SetLevel(EdkLogger.INFO)\r
2617\r
2618 if Option.WarningAsError == True:\r
2619 EdkLogger.SetWarningAsError()\r
2620 Log_Agent = LogAgent(LogQ,LogLevel,Option.LogFile)\r
2621 Log_Agent.start()\r
2622\r
2623 if platform.platform().find("Windows") >= 0:\r
2624 GlobalData.gIsWindows = True\r
2625 else:\r
2626 GlobalData.gIsWindows = False\r
2627\r
2628 EdkLogger.quiet("Build environment: %s" % platform.platform())\r
2629 EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime()));\r
2630 ReturnCode = 0\r
2631 MyBuild = None\r
2632 BuildError = True\r
2633 try:\r
2634 if len(Target) == 0:\r
2635 Target = "all"\r
2636 elif len(Target) >= 2:\r
2637 EdkLogger.error("build", OPTION_NOT_SUPPORTED, "More than one targets are not supported.",\r
2638 ExtraData="Please select one of: %s" % (' '.join(gSupportedTarget)))\r
2639 else:\r
2640 Target = Target[0].lower()\r
2641\r
2642 if Target not in gSupportedTarget:\r
2643 EdkLogger.error("build", OPTION_NOT_SUPPORTED, "Not supported target [%s]." % Target,\r
2644 ExtraData="Please select one of: %s" % (' '.join(gSupportedTarget)))\r
2645\r
2646 #\r
2647 # Check environment variable: EDK_TOOLS_PATH, WORKSPACE, PATH\r
2648 #\r
2649 CheckEnvVariable()\r
2650 GlobalData.gCommandLineDefines.update(ParseDefines(Option.Macros))\r
2651\r
2652 Workspace = os.getenv("WORKSPACE")\r
2653 #\r
2654 # Get files real name in workspace dir\r
2655 #\r
2656 GlobalData.gAllFiles = Utils.DirCache(Workspace)\r
2657\r
2658 WorkingDirectory = os.getcwd()\r
2659 if not Option.ModuleFile:\r
2660 FileList = glob.glob(os.path.normpath(os.path.join(WorkingDirectory, '*.inf')))\r
2661 FileNum = len(FileList)\r
2662 if FileNum >= 2:\r
2663 EdkLogger.error("build", OPTION_NOT_SUPPORTED, "There are %d INF files in %s." % (FileNum, WorkingDirectory),\r
2664 ExtraData="Please use '-m <INF_FILE_PATH>' switch to choose one.")\r
2665 elif FileNum == 1:\r
2666 Option.ModuleFile = NormFile(FileList[0], Workspace)\r
2667\r
2668 if Option.ModuleFile:\r
2669 if os.path.isabs (Option.ModuleFile):\r
2670 if os.path.normcase (os.path.normpath(Option.ModuleFile)).find (Workspace) == 0:\r
2671 Option.ModuleFile = NormFile(os.path.normpath(Option.ModuleFile), Workspace)\r
2672 Option.ModuleFile = PathClass(Option.ModuleFile, Workspace)\r
2673 ErrorCode, ErrorInfo = Option.ModuleFile.Validate(".inf", False)\r
2674 if ErrorCode != 0:\r
2675 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)\r
2676\r
2677 if Option.PlatformFile is not None:\r
2678 if os.path.isabs (Option.PlatformFile):\r
2679 if os.path.normcase (os.path.normpath(Option.PlatformFile)).find (Workspace) == 0:\r
2680 Option.PlatformFile = NormFile(os.path.normpath(Option.PlatformFile), Workspace)\r
2681 Option.PlatformFile = PathClass(Option.PlatformFile, Workspace)\r
2682\r
2683 if Option.FdfFile is not None:\r
2684 if os.path.isabs (Option.FdfFile):\r
2685 if os.path.normcase (os.path.normpath(Option.FdfFile)).find (Workspace) == 0:\r
2686 Option.FdfFile = NormFile(os.path.normpath(Option.FdfFile), Workspace)\r
2687 Option.FdfFile = PathClass(Option.FdfFile, Workspace)\r
2688 ErrorCode, ErrorInfo = Option.FdfFile.Validate(".fdf", False)\r
2689 if ErrorCode != 0:\r
2690 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)\r
2691\r
2692 if Option.Flag is not None and Option.Flag not in ['-c', '-s']:\r
2693 EdkLogger.error("build", OPTION_VALUE_INVALID, "UNI flag must be one of -c or -s")\r
2694\r
2695 MyBuild = Build(Target, Workspace, Option,LogQ)\r
2696 GlobalData.gCommandLineDefines['ARCH'] = ' '.join(MyBuild.ArchList)\r
2697 if not (MyBuild.LaunchPrebuildFlag and os.path.exists(MyBuild.PlatformBuildPath)):\r
2698 MyBuild.Launch()\r
2699\r
2700 #\r
2701 # All job done, no error found and no exception raised\r
2702 #\r
2703 BuildError = False\r
2704 except FatalError as X:\r
2705 if MyBuild is not None:\r
2706 # for multi-thread build exits safely\r
2707 MyBuild.Relinquish()\r
2708 if Option is not None and Option.debug is not None:\r
2709 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
2710 ReturnCode = X.args[0]\r
2711 except Warning as X:\r
2712 # error from Fdf parser\r
2713 if MyBuild is not None:\r
2714 # for multi-thread build exits safely\r
2715 MyBuild.Relinquish()\r
2716 if Option is not None and Option.debug is not None:\r
2717 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
2718 else:\r
2719 EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError=False)\r
2720 ReturnCode = FORMAT_INVALID\r
2721 except KeyboardInterrupt:\r
2722 if MyBuild is not None:\r
2723\r
2724 # for multi-thread build exits safely\r
2725 MyBuild.Relinquish()\r
2726 ReturnCode = ABORT_ERROR\r
2727 if Option is not None and Option.debug is not None:\r
2728 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
2729 except:\r
2730 if MyBuild is not None:\r
2731 # for multi-thread build exits safely\r
2732 MyBuild.Relinquish()\r
2733\r
2734 # try to get the meta-file from the object causing exception\r
2735 Tb = sys.exc_info()[-1]\r
2736 MetaFile = GlobalData.gProcessingFile\r
2737 while Tb is not None:\r
2738 if 'self' in Tb.tb_frame.f_locals and hasattr(Tb.tb_frame.f_locals['self'], 'MetaFile'):\r
2739 MetaFile = Tb.tb_frame.f_locals['self'].MetaFile\r
2740 Tb = Tb.tb_next\r
2741 EdkLogger.error(\r
2742 "\nbuild",\r
2743 CODE_ERROR,\r
2744 "Unknown fatal error when processing [%s]" % MetaFile,\r
2745 ExtraData="\n(Please send email to %s for help, attaching following call stack trace!)\n" % MSG_EDKII_MAIL_ADDR,\r
2746 RaiseError=False\r
2747 )\r
2748 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r
2749 ReturnCode = CODE_ERROR\r
2750 finally:\r
2751 Utils.Progressor.Abort()\r
2752 Utils.ClearDuplicatedInf()\r
2753\r
2754 if ReturnCode == 0:\r
2755 try:\r
2756 MyBuild.LaunchPostbuild()\r
2757 Conclusion = "Done"\r
2758 except:\r
2759 Conclusion = "Failed"\r
2760 ReturnCode = POSTBUILD_ERROR\r
2761 elif ReturnCode == ABORT_ERROR:\r
2762 Conclusion = "Aborted"\r
2763 else:\r
2764 Conclusion = "Failed"\r
2765 FinishTime = time.time()\r
2766 BuildDuration = time.gmtime(int(round(FinishTime - StartTime)))\r
2767 BuildDurationStr = ""\r
2768 if BuildDuration.tm_yday > 1:\r
2769 BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration) + ", %d day(s)" % (BuildDuration.tm_yday - 1)\r
2770 else:\r
2771 BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration)\r
2772 if MyBuild is not None:\r
2773 if not BuildError:\r
2774 MyBuild.BuildReport.GenerateReport(BuildDurationStr, LogBuildTime(MyBuild.AutoGenTime), LogBuildTime(MyBuild.MakeTime), LogBuildTime(MyBuild.GenFdsTime))\r
2775\r
2776 EdkLogger.SetLevel(EdkLogger.QUIET)\r
2777 EdkLogger.quiet("\n- %s -" % Conclusion)\r
2778 EdkLogger.quiet(time.strftime("Build end time: %H:%M:%S, %b.%d %Y", time.localtime()))\r
2779 EdkLogger.quiet("Build total time: %s\n" % BuildDurationStr)\r
2780 Log_Agent.kill()\r
2781 Log_Agent.join()\r
2782 return ReturnCode\r
2783\r
2784if __name__ == '__main__':\r
2785 try:\r
2786 mp.set_start_method('spawn')\r
2787 except:\r
2788 pass\r
2789 r = Main()\r
2790 ## 0-127 is a safe return range, and 1 is a standard default error\r
2791 if r < 0 or r > 127: r = 1\r
2792 sys.exit(r)\r