]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/build/build.py
BaseTools: Fix a cleanall issue.
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
1 ## @file
2 # build a platform or a module
3 #
4 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Common.LongFilePathOs as os
19 import re
20 import StringIO
21 import sys
22 import glob
23 import time
24 import platform
25 import traceback
26 import encodings.ascii
27
28 from struct import *
29 from threading import *
30 from optparse import OptionParser
31 from subprocess import *
32 from Common import Misc as Utils
33
34 from Common.LongFilePathSupport import OpenLongFilePath as open
35 from Common.LongFilePathSupport import LongFilePath
36 from Common.TargetTxtClassObject import *
37 from Common.ToolDefClassObject import *
38 from Common.DataType import *
39 from Common.BuildVersion import gBUILD_VERSION
40 from AutoGen.AutoGen import *
41 from Common.BuildToolError import *
42 from Workspace.WorkspaceDatabase import *
43
44 from BuildReport import BuildReport
45 from GenPatchPcdTable.GenPatchPcdTable import *
46 from PatchPcdValue.PatchPcdValue import *
47
48 import Common.EdkLogger
49 import Common.GlobalData as GlobalData
50
51 # Version and Copyright
52 VersionNumber = "0.60" + ' ' + gBUILD_VERSION
53 __version__ = "%prog Version " + VersionNumber
54 __copyright__ = "Copyright (c) 2007 - 2014, Intel Corporation All rights reserved."
55
56 ## standard targets of build command
57 gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']
58
59 ## build configuration file
60 gBuildConfiguration = "target.txt"
61 gToolsDefinition = "tools_def.txt"
62
63 TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$')
64 TmpTableDict = {}
65
66 ## Check environment PATH variable to make sure the specified tool is found
67 #
68 # If the tool is found in the PATH, then True is returned
69 # Otherwise, False is returned
70 #
71 def IsToolInPath(tool):
72 if os.environ.has_key('PATHEXT'):
73 extns = os.environ['PATHEXT'].split(os.path.pathsep)
74 else:
75 extns = ('',)
76 for pathDir in os.environ['PATH'].split(os.path.pathsep):
77 for ext in extns:
78 if os.path.exists(os.path.join(pathDir, tool + ext)):
79 return True
80 return False
81
82 ## Check environment variables
83 #
84 # Check environment variables that must be set for build. Currently they are
85 #
86 # WORKSPACE The directory all packages/platforms start from
87 # EDK_TOOLS_PATH The directory contains all tools needed by the build
88 # PATH $(EDK_TOOLS_PATH)/Bin/<sys> must be set in PATH
89 #
90 # If any of above environment variable is not set or has error, the build
91 # will be broken.
92 #
93 def CheckEnvVariable():
94 # check WORKSPACE
95 if "WORKSPACE" not in os.environ:
96 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",
97 ExtraData="WORKSPACE")
98
99 WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"]))
100 if not os.path.exists(WorkspaceDir):
101 EdkLogger.error("build", FILE_NOT_FOUND, "WORKSPACE doesn't exist", ExtraData="%s" % WorkspaceDir)
102 elif ' ' in WorkspaceDir:
103 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in WORKSPACE path",
104 ExtraData=WorkspaceDir)
105 os.environ["WORKSPACE"] = WorkspaceDir
106
107 #
108 # Check EFI_SOURCE (Edk build convention). EDK_SOURCE will always point to ECP
109 #
110 if "ECP_SOURCE" not in os.environ:
111 os.environ["ECP_SOURCE"] = os.path.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg)
112 if "EFI_SOURCE" not in os.environ:
113 os.environ["EFI_SOURCE"] = os.environ["ECP_SOURCE"]
114 if "EDK_SOURCE" not in os.environ:
115 os.environ["EDK_SOURCE"] = os.environ["ECP_SOURCE"]
116
117 #
118 # Unify case of characters on case-insensitive systems
119 #
120 EfiSourceDir = os.path.normcase(os.path.normpath(os.environ["EFI_SOURCE"]))
121 EdkSourceDir = os.path.normcase(os.path.normpath(os.environ["EDK_SOURCE"]))
122 EcpSourceDir = os.path.normcase(os.path.normpath(os.environ["ECP_SOURCE"]))
123
124 os.environ["EFI_SOURCE"] = EfiSourceDir
125 os.environ["EDK_SOURCE"] = EdkSourceDir
126 os.environ["ECP_SOURCE"] = EcpSourceDir
127 os.environ["EDK_TOOLS_PATH"] = os.path.normcase(os.environ["EDK_TOOLS_PATH"])
128
129 if not os.path.exists(EcpSourceDir):
130 EdkLogger.verbose("ECP_SOURCE = %s doesn't exist. Edk modules could not be built." % EcpSourceDir)
131 elif ' ' in EcpSourceDir:
132 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in ECP_SOURCE path",
133 ExtraData=EcpSourceDir)
134 if not os.path.exists(EdkSourceDir):
135 if EdkSourceDir == EcpSourceDir:
136 EdkLogger.verbose("EDK_SOURCE = %s doesn't exist. Edk modules could not be built." % EdkSourceDir)
137 else:
138 EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE does not exist",
139 ExtraData=EdkSourceDir)
140 elif ' ' in EdkSourceDir:
141 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in EDK_SOURCE path",
142 ExtraData=EdkSourceDir)
143 if not os.path.exists(EfiSourceDir):
144 if EfiSourceDir == EcpSourceDir:
145 EdkLogger.verbose("EFI_SOURCE = %s doesn't exist. Edk modules could not be built." % EfiSourceDir)
146 else:
147 EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE does not exist",
148 ExtraData=EfiSourceDir)
149 elif ' ' in EfiSourceDir:
150 EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in EFI_SOURCE path",
151 ExtraData=EfiSourceDir)
152
153 # change absolute path to relative path to WORKSPACE
154 if EfiSourceDir.upper().find(WorkspaceDir.upper()) != 0:
155 EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE is not under WORKSPACE",
156 ExtraData="WORKSPACE = %s\n EFI_SOURCE = %s" % (WorkspaceDir, EfiSourceDir))
157 if EdkSourceDir.upper().find(WorkspaceDir.upper()) != 0:
158 EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE is not under WORKSPACE",
159 ExtraData="WORKSPACE = %s\n EDK_SOURCE = %s" % (WorkspaceDir, EdkSourceDir))
160 if EcpSourceDir.upper().find(WorkspaceDir.upper()) != 0:
161 EdkLogger.error("build", PARAMETER_INVALID, "ECP_SOURCE is not under WORKSPACE",
162 ExtraData="WORKSPACE = %s\n ECP_SOURCE = %s" % (WorkspaceDir, EcpSourceDir))
163
164 # check EDK_TOOLS_PATH
165 if "EDK_TOOLS_PATH" not in os.environ:
166 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",
167 ExtraData="EDK_TOOLS_PATH")
168
169 # check PATH
170 if "PATH" not in os.environ:
171 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",
172 ExtraData="PATH")
173
174 GlobalData.gWorkspace = WorkspaceDir
175 GlobalData.gEfiSource = EfiSourceDir
176 GlobalData.gEdkSource = EdkSourceDir
177 GlobalData.gEcpSource = EcpSourceDir
178
179 GlobalData.gGlobalDefines["WORKSPACE"] = WorkspaceDir
180 GlobalData.gGlobalDefines["EFI_SOURCE"] = EfiSourceDir
181 GlobalData.gGlobalDefines["EDK_SOURCE"] = EdkSourceDir
182 GlobalData.gGlobalDefines["ECP_SOURCE"] = EcpSourceDir
183 GlobalData.gGlobalDefines["EDK_TOOLS_PATH"] = os.environ["EDK_TOOLS_PATH"]
184
185 ## Get normalized file path
186 #
187 # Convert the path to be local format, and remove the WORKSPACE path at the
188 # beginning if the file path is given in full path.
189 #
190 # @param FilePath File path to be normalized
191 # @param Workspace Workspace path which the FilePath will be checked against
192 #
193 # @retval string The normalized file path
194 #
195 def NormFile(FilePath, Workspace):
196 # check if the path is absolute or relative
197 if os.path.isabs(FilePath):
198 FileFullPath = os.path.normpath(FilePath)
199 else:
200 FileFullPath = os.path.normpath(os.path.join(Workspace, FilePath))
201
202 # check if the file path exists or not
203 if not os.path.isfile(FileFullPath):
204 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData="\t%s (Please give file in absolute path or relative to WORKSPACE)" % FileFullPath)
205
206 # remove workspace directory from the beginning part of the file path
207 if Workspace[-1] in ["\\", "/"]:
208 return FileFullPath[len(Workspace):]
209 else:
210 return FileFullPath[(len(Workspace) + 1):]
211
212 ## Get the output of an external program
213 #
214 # This is the entrance method of thread reading output of an external program and
215 # putting them in STDOUT/STDERR of current program.
216 #
217 # @param From The stream message read from
218 # @param To The stream message put on
219 # @param ExitFlag The flag used to indicate stopping reading
220 #
221 def ReadMessage(From, To, ExitFlag):
222 while True:
223 # read one line a time
224 Line = From.readline()
225 # empty string means "end"
226 if Line != None and Line != "":
227 To(Line.rstrip())
228 else:
229 break
230 if ExitFlag.isSet():
231 break
232
233 ## Launch an external program
234 #
235 # This method will call subprocess.Popen to execute an external program with
236 # given options in specified directory. Because of the dead-lock issue during
237 # redirecting output of the external program, threads are used to to do the
238 # redirection work.
239 #
240 # @param Command A list or string containing the call of the program
241 # @param WorkingDir The directory in which the program will be running
242 #
243 def LaunchCommand(Command, WorkingDir):
244 # if working directory doesn't exist, Popen() will raise an exception
245 if not os.path.isdir(WorkingDir):
246 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=WorkingDir)
247
248 # Command is used as the first Argument in following Popen().
249 # It could be a string or sequence. We find that if command is a string in following Popen(),
250 # ubuntu may fail with an error message that the command is not found.
251 # So here we may need convert command from string to list instance.
252 if not isinstance(Command, list):
253 if platform.system() != 'Windows':
254 Command = Command.split()
255
256 Proc = None
257 EndOfProcedure = None
258 try:
259 # launch the command
260 Proc = Popen(Command, stdout=PIPE, stderr=PIPE, env=os.environ, cwd=WorkingDir, bufsize=-1)
261
262 # launch two threads to read the STDOUT and STDERR
263 EndOfProcedure = Event()
264 EndOfProcedure.clear()
265 if Proc.stdout:
266 StdOutThread = Thread(target=ReadMessage, args=(Proc.stdout, EdkLogger.info, EndOfProcedure))
267 StdOutThread.setName("STDOUT-Redirector")
268 StdOutThread.setDaemon(False)
269 StdOutThread.start()
270
271 if Proc.stderr:
272 StdErrThread = Thread(target=ReadMessage, args=(Proc.stderr, EdkLogger.quiet, EndOfProcedure))
273 StdErrThread.setName("STDERR-Redirector")
274 StdErrThread.setDaemon(False)
275 StdErrThread.start()
276
277 # waiting for program exit
278 Proc.wait()
279 except: # in case of aborting
280 # terminate the threads redirecting the program output
281 if EndOfProcedure != None:
282 EndOfProcedure.set()
283 if Proc == None:
284 if type(Command) != type(""):
285 Command = " ".join(Command)
286 EdkLogger.error("build", COMMAND_FAILURE, "Failed to start command", ExtraData="%s [%s]" % (Command, WorkingDir))
287
288 if Proc.stdout:
289 StdOutThread.join()
290 if Proc.stderr:
291 StdErrThread.join()
292
293 # check the return code of the program
294 if Proc.returncode != 0:
295 if type(Command) != type(""):
296 Command = " ".join(Command)
297 EdkLogger.error("build", COMMAND_FAILURE, ExtraData="%s [%s]" % (Command, WorkingDir))
298
299 ## The smallest unit that can be built in multi-thread build mode
300 #
301 # This is the base class of build unit. The "Obj" parameter must provide
302 # __str__(), __eq__() and __hash__() methods. Otherwise there could be build units
303 # missing build.
304 #
305 # Currently the "Obj" should be only ModuleAutoGen or PlatformAutoGen objects.
306 #
307 class BuildUnit:
308 ## The constructor
309 #
310 # @param self The object pointer
311 # @param Obj The object the build is working on
312 # @param Target The build target name, one of gSupportedTarget
313 # @param Dependency The BuildUnit(s) which must be completed in advance
314 # @param WorkingDir The directory build command starts in
315 #
316 def __init__(self, Obj, BuildCommand, Target, Dependency, WorkingDir="."):
317 self.BuildObject = Obj
318 self.Dependency = Dependency
319 self.WorkingDir = WorkingDir
320 self.Target = Target
321 self.BuildCommand = BuildCommand
322 if not BuildCommand:
323 EdkLogger.error("build", OPTION_MISSING,
324 "No build command found for this module. "
325 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %
326 (Obj.BuildTarget, Obj.ToolChain, Obj.Arch),
327 ExtraData=str(Obj))
328
329
330 ## str() method
331 #
332 # It just returns the string representation of self.BuildObject
333 #
334 # @param self The object pointer
335 #
336 def __str__(self):
337 return str(self.BuildObject)
338
339 ## "==" operator method
340 #
341 # It just compares self.BuildObject with "Other". So self.BuildObject must
342 # provide its own __eq__() method.
343 #
344 # @param self The object pointer
345 # @param Other The other BuildUnit object compared to
346 #
347 def __eq__(self, Other):
348 return Other != None and self.BuildObject == Other.BuildObject \
349 and self.BuildObject.Arch == Other.BuildObject.Arch
350
351 ## hash() method
352 #
353 # It just returns the hash value of self.BuildObject which must be hashable.
354 #
355 # @param self The object pointer
356 #
357 def __hash__(self):
358 return hash(self.BuildObject) + hash(self.BuildObject.Arch)
359
360 def __repr__(self):
361 return repr(self.BuildObject)
362
363 ## The smallest module unit that can be built by nmake/make command in multi-thread build mode
364 #
365 # This class is for module build by nmake/make build system. The "Obj" parameter
366 # must provide __str__(), __eq__() and __hash__() methods. Otherwise there could
367 # be make units missing build.
368 #
369 # Currently the "Obj" should be only ModuleAutoGen object.
370 #
371 class ModuleMakeUnit(BuildUnit):
372 ## The constructor
373 #
374 # @param self The object pointer
375 # @param Obj The ModuleAutoGen object the build is working on
376 # @param Target The build target name, one of gSupportedTarget
377 #
378 def __init__(self, Obj, Target):
379 Dependency = [ModuleMakeUnit(La, Target) for La in Obj.LibraryAutoGenList]
380 BuildUnit.__init__(self, Obj, Obj.BuildCommand, Target, Dependency, Obj.MakeFileDir)
381 if Target in [None, "", "all"]:
382 self.Target = "tbuild"
383
384 ## The smallest platform unit that can be built by nmake/make command in multi-thread build mode
385 #
386 # This class is for platform build by nmake/make build system. The "Obj" parameter
387 # must provide __str__(), __eq__() and __hash__() methods. Otherwise there could
388 # be make units missing build.
389 #
390 # Currently the "Obj" should be only PlatformAutoGen object.
391 #
392 class PlatformMakeUnit(BuildUnit):
393 ## The constructor
394 #
395 # @param self The object pointer
396 # @param Obj The PlatformAutoGen object the build is working on
397 # @param Target The build target name, one of gSupportedTarget
398 #
399 def __init__(self, Obj, Target):
400 Dependency = [ModuleMakeUnit(Lib, Target) for Lib in self.BuildObject.LibraryAutoGenList]
401 Dependency.extend([ModuleMakeUnit(Mod, Target) for Mod in self.BuildObject.ModuleAutoGenList])
402 BuildUnit.__init__(self, Obj, Obj.BuildCommand, Target, Dependency, Obj.MakeFileDir)
403
404 ## The class representing the task of a module build or platform build
405 #
406 # This class manages the build tasks in multi-thread build mode. Its jobs include
407 # scheduling thread running, catching thread error, monitor the thread status, etc.
408 #
409 class BuildTask:
410 # queue for tasks waiting for schedule
411 _PendingQueue = sdict()
412 _PendingQueueLock = threading.Lock()
413
414 # queue for tasks ready for running
415 _ReadyQueue = sdict()
416 _ReadyQueueLock = threading.Lock()
417
418 # queue for run tasks
419 _RunningQueue = sdict()
420 _RunningQueueLock = threading.Lock()
421
422 # queue containing all build tasks, in case duplicate build
423 _TaskQueue = sdict()
424
425 # flag indicating error occurs in a running thread
426 _ErrorFlag = threading.Event()
427 _ErrorFlag.clear()
428 _ErrorMessage = ""
429
430 # BoundedSemaphore object used to control the number of running threads
431 _Thread = None
432
433 # flag indicating if the scheduler is started or not
434 _SchedulerStopped = threading.Event()
435 _SchedulerStopped.set()
436
437 ## Start the task scheduler thread
438 #
439 # @param MaxThreadNumber The maximum thread number
440 # @param ExitFlag Flag used to end the scheduler
441 #
442 @staticmethod
443 def StartScheduler(MaxThreadNumber, ExitFlag):
444 SchedulerThread = Thread(target=BuildTask.Scheduler, args=(MaxThreadNumber, ExitFlag))
445 SchedulerThread.setName("Build-Task-Scheduler")
446 SchedulerThread.setDaemon(False)
447 SchedulerThread.start()
448 # wait for the scheduler to be started, especially useful in Linux
449 while not BuildTask.IsOnGoing():
450 time.sleep(0.01)
451
452 ## Scheduler method
453 #
454 # @param MaxThreadNumber The maximum thread number
455 # @param ExitFlag Flag used to end the scheduler
456 #
457 @staticmethod
458 def Scheduler(MaxThreadNumber, ExitFlag):
459 BuildTask._SchedulerStopped.clear()
460 try:
461 # use BoundedSemaphore to control the maximum running threads
462 BuildTask._Thread = BoundedSemaphore(MaxThreadNumber)
463 #
464 # scheduling loop, which will exits when no pending/ready task and
465 # indicated to do so, or there's error in running thread
466 #
467 while (len(BuildTask._PendingQueue) > 0 or len(BuildTask._ReadyQueue) > 0 \
468 or not ExitFlag.isSet()) and not BuildTask._ErrorFlag.isSet():
469 EdkLogger.debug(EdkLogger.DEBUG_8, "Pending Queue (%d), Ready Queue (%d)"
470 % (len(BuildTask._PendingQueue), len(BuildTask._ReadyQueue)))
471
472 # get all pending tasks
473 BuildTask._PendingQueueLock.acquire()
474 BuildObjectList = BuildTask._PendingQueue.keys()
475 #
476 # check if their dependency is resolved, and if true, move them
477 # into ready queue
478 #
479 for BuildObject in BuildObjectList:
480 Bt = BuildTask._PendingQueue[BuildObject]
481 if Bt.IsReady():
482 BuildTask._ReadyQueue[BuildObject] = BuildTask._PendingQueue.pop(BuildObject)
483 BuildTask._PendingQueueLock.release()
484
485 # launch build thread until the maximum number of threads is reached
486 while not BuildTask._ErrorFlag.isSet():
487 # empty ready queue, do nothing further
488 if len(BuildTask._ReadyQueue) == 0:
489 break
490
491 # wait for active thread(s) exit
492 BuildTask._Thread.acquire(True)
493
494 # start a new build thread
495 Bo = BuildTask._ReadyQueue.keys()[0]
496 Bt = BuildTask._ReadyQueue.pop(Bo)
497
498 # move into running queue
499 BuildTask._RunningQueueLock.acquire()
500 BuildTask._RunningQueue[Bo] = Bt
501 BuildTask._RunningQueueLock.release()
502
503 Bt.Start()
504 # avoid tense loop
505 time.sleep(0.01)
506
507 # avoid tense loop
508 time.sleep(0.01)
509
510 # wait for all running threads exit
511 if BuildTask._ErrorFlag.isSet():
512 EdkLogger.quiet("\nWaiting for all build threads exit...")
513 # while not BuildTask._ErrorFlag.isSet() and \
514 while len(BuildTask._RunningQueue) > 0:
515 EdkLogger.verbose("Waiting for thread ending...(%d)" % len(BuildTask._RunningQueue))
516 EdkLogger.debug(EdkLogger.DEBUG_8, "Threads [%s]" % ", ".join([Th.getName() for Th in threading.enumerate()]))
517 # avoid tense loop
518 time.sleep(0.1)
519 except BaseException, X:
520 #
521 # TRICK: hide the output of threads left runing, so that the user can
522 # catch the error message easily
523 #
524 EdkLogger.SetLevel(EdkLogger.ERROR)
525 BuildTask._ErrorFlag.set()
526 BuildTask._ErrorMessage = "build thread scheduler error\n\t%s" % str(X)
527
528 BuildTask._PendingQueue.clear()
529 BuildTask._ReadyQueue.clear()
530 BuildTask._RunningQueue.clear()
531 BuildTask._TaskQueue.clear()
532 BuildTask._SchedulerStopped.set()
533
534 ## Wait for all running method exit
535 #
536 @staticmethod
537 def WaitForComplete():
538 BuildTask._SchedulerStopped.wait()
539
540 ## Check if the scheduler is running or not
541 #
542 @staticmethod
543 def IsOnGoing():
544 return not BuildTask._SchedulerStopped.isSet()
545
546 ## Abort the build
547 @staticmethod
548 def Abort():
549 if BuildTask.IsOnGoing():
550 BuildTask._ErrorFlag.set()
551 BuildTask.WaitForComplete()
552
553 ## Check if there's error in running thread
554 #
555 # Since the main thread cannot catch exceptions in other thread, we have to
556 # use threading.Event to communicate this formation to main thread.
557 #
558 @staticmethod
559 def HasError():
560 return BuildTask._ErrorFlag.isSet()
561
562 ## Get error message in running thread
563 #
564 # Since the main thread cannot catch exceptions in other thread, we have to
565 # use a static variable to communicate this message to main thread.
566 #
567 @staticmethod
568 def GetErrorMessage():
569 return BuildTask._ErrorMessage
570
571 ## Factory method to create a BuildTask object
572 #
573 # This method will check if a module is building or has been built. And if
574 # true, just return the associated BuildTask object in the _TaskQueue. If
575 # not, create and return a new BuildTask object. The new BuildTask object
576 # will be appended to the _PendingQueue for scheduling later.
577 #
578 # @param BuildItem A BuildUnit object representing a build object
579 # @param Dependency The dependent build object of BuildItem
580 #
581 @staticmethod
582 def New(BuildItem, Dependency=None):
583 if BuildItem in BuildTask._TaskQueue:
584 Bt = BuildTask._TaskQueue[BuildItem]
585 return Bt
586
587 Bt = BuildTask()
588 Bt._Init(BuildItem, Dependency)
589 BuildTask._TaskQueue[BuildItem] = Bt
590
591 BuildTask._PendingQueueLock.acquire()
592 BuildTask._PendingQueue[BuildItem] = Bt
593 BuildTask._PendingQueueLock.release()
594
595 return Bt
596
597 ## The real constructor of BuildTask
598 #
599 # @param BuildItem A BuildUnit object representing a build object
600 # @param Dependency The dependent build object of BuildItem
601 #
602 def _Init(self, BuildItem, Dependency=None):
603 self.BuildItem = BuildItem
604
605 self.DependencyList = []
606 if Dependency == None:
607 Dependency = BuildItem.Dependency
608 else:
609 Dependency.extend(BuildItem.Dependency)
610 self.AddDependency(Dependency)
611 # flag indicating build completes, used to avoid unnecessary re-build
612 self.CompleteFlag = False
613
614 ## Check if all dependent build tasks are completed or not
615 #
616 def IsReady(self):
617 ReadyFlag = True
618 for Dep in self.DependencyList:
619 if Dep.CompleteFlag == True:
620 continue
621 ReadyFlag = False
622 break
623
624 return ReadyFlag
625
626 ## Add dependent build task
627 #
628 # @param Dependency The list of dependent build objects
629 #
630 def AddDependency(self, Dependency):
631 for Dep in Dependency:
632 if not Dep.BuildObject.IsBinaryModule:
633 self.DependencyList.append(BuildTask.New(Dep)) # BuildTask list
634
635 ## The thread wrapper of LaunchCommand function
636 #
637 # @param Command A list or string contains the call of the command
638 # @param WorkingDir The directory in which the program will be running
639 #
640 def _CommandThread(self, Command, WorkingDir):
641 try:
642 LaunchCommand(Command, WorkingDir)
643 self.CompleteFlag = True
644 except:
645 #
646 # TRICK: hide the output of threads left runing, so that the user can
647 # catch the error message easily
648 #
649 if not BuildTask._ErrorFlag.isSet():
650 GlobalData.gBuildingModule = "%s [%s, %s, %s]" % (str(self.BuildItem.BuildObject),
651 self.BuildItem.BuildObject.Arch,
652 self.BuildItem.BuildObject.ToolChain,
653 self.BuildItem.BuildObject.BuildTarget
654 )
655 EdkLogger.SetLevel(EdkLogger.ERROR)
656 BuildTask._ErrorFlag.set()
657 BuildTask._ErrorMessage = "%s broken\n %s [%s]" % \
658 (threading.currentThread().getName(), Command, WorkingDir)
659 # indicate there's a thread is available for another build task
660 BuildTask._RunningQueueLock.acquire()
661 BuildTask._RunningQueue.pop(self.BuildItem)
662 BuildTask._RunningQueueLock.release()
663 BuildTask._Thread.release()
664
665 ## Start build task thread
666 #
667 def Start(self):
668 EdkLogger.quiet("Building ... %s" % repr(self.BuildItem))
669 Command = self.BuildItem.BuildCommand + [self.BuildItem.Target]
670 self.BuildTread = Thread(target=self._CommandThread, args=(Command, self.BuildItem.WorkingDir))
671 self.BuildTread.setName("build thread")
672 self.BuildTread.setDaemon(False)
673 self.BuildTread.start()
674
675 ## The class contains the information related to EFI image
676 #
677 class PeImageInfo():
678 ## Constructor
679 #
680 # Constructor will load all required image information.
681 #
682 # @param BaseName The full file path of image.
683 # @param Guid The GUID for image.
684 # @param Arch Arch of this image.
685 # @param OutputDir The output directory for image.
686 # @param DebugDir The debug directory for image.
687 # @param ImageClass PeImage Information
688 #
689 def __init__(self, BaseName, Guid, Arch, OutputDir, DebugDir, ImageClass):
690 self.BaseName = BaseName
691 self.Guid = Guid
692 self.Arch = Arch
693 self.OutputDir = OutputDir
694 self.DebugDir = DebugDir
695 self.Image = ImageClass
696 self.Image.Size = (self.Image.Size / 0x1000 + 1) * 0x1000
697
698 ## The class implementing the EDK2 build process
699 #
700 # The build process includes:
701 # 1. Load configuration from target.txt and tools_def.txt in $(WORKSPACE)/Conf
702 # 2. Parse DSC file of active platform
703 # 3. Parse FDF file if any
704 # 4. Establish build database, including parse all other files (module, package)
705 # 5. Create AutoGen files (C code file, depex file, makefile) if necessary
706 # 6. Call build command
707 #
708 class Build():
709 ## Constructor
710 #
711 # Constructor will load all necessary configurations, parse platform, modules
712 # and packages and the establish a database for AutoGen.
713 #
714 # @param Target The build command target, one of gSupportedTarget
715 # @param WorkspaceDir The directory of workspace
716 # @param BuildOptions Build options passed from command line
717 #
718 def __init__(self, Target, WorkspaceDir, BuildOptions):
719 self.WorkspaceDir = WorkspaceDir
720 self.Target = Target
721 self.PlatformFile = BuildOptions.PlatformFile
722 self.ModuleFile = BuildOptions.ModuleFile
723 self.ArchList = BuildOptions.TargetArch
724 self.ToolChainList = BuildOptions.ToolChain
725 self.BuildTargetList= BuildOptions.BuildTarget
726 self.Fdf = BuildOptions.FdfFile
727 self.FdList = BuildOptions.RomImage
728 self.FvList = BuildOptions.FvImage
729 self.CapList = BuildOptions.CapName
730 self.SilentMode = BuildOptions.SilentMode
731 self.ThreadNumber = BuildOptions.ThreadNumber
732 self.SkipAutoGen = BuildOptions.SkipAutoGen
733 self.Reparse = BuildOptions.Reparse
734 self.SkuId = BuildOptions.SkuId
735 self.ConfDirectory = BuildOptions.ConfDirectory
736 self.SpawnMode = True
737 self.BuildReport = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)
738 self.TargetTxt = TargetTxtClassObject()
739 self.ToolDef = ToolDefClassObject()
740 #Set global flag for build mode
741 GlobalData.gIgnoreSource = BuildOptions.IgnoreSources
742
743 if self.ConfDirectory:
744 # Get alternate Conf location, if it is absolute, then just use the absolute directory name
745 ConfDirectoryPath = os.path.normpath(self.ConfDirectory)
746
747 if not os.path.isabs(ConfDirectoryPath):
748 # Since alternate directory name is not absolute, the alternate directory is located within the WORKSPACE
749 # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf
750 ConfDirectoryPath = os.path.join(self.WorkspaceDir, ConfDirectoryPath)
751 else:
752 # Get standard WORKSPACE/Conf use the absolute path to the WORKSPACE/Conf
753 ConfDirectoryPath = os.path.join(self.WorkspaceDir, 'Conf')
754 GlobalData.gConfDirectory = ConfDirectoryPath
755 GlobalData.gDatabasePath = os.path.normpath(os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath))
756
757 if BuildOptions.DisableCache:
758 self.Db = WorkspaceDatabase(":memory:")
759 else:
760 self.Db = WorkspaceDatabase(GlobalData.gDatabasePath, self.Reparse)
761 self.BuildDatabase = self.Db.BuildObject
762 self.Platform = None
763 self.LoadFixAddress = 0
764 self.UniFlag = BuildOptions.Flag
765 self.BuildModules = []
766
767 # print dot character during doing some time-consuming work
768 self.Progress = Utils.Progressor()
769
770 self.InitBuild()
771
772 # print current build environment and configuration
773 EdkLogger.quiet("%-16s = %s" % ("WORKSPACE", os.environ["WORKSPACE"]))
774 EdkLogger.quiet("%-16s = %s" % ("ECP_SOURCE", os.environ["ECP_SOURCE"]))
775 EdkLogger.quiet("%-16s = %s" % ("EDK_SOURCE", os.environ["EDK_SOURCE"]))
776 EdkLogger.quiet("%-16s = %s" % ("EFI_SOURCE", os.environ["EFI_SOURCE"]))
777 EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"]))
778
779 EdkLogger.info("")
780
781 os.chdir(self.WorkspaceDir)
782
783 ## Load configuration
784 #
785 # This method will parse target.txt and get the build configurations.
786 #
787 def LoadConfiguration(self):
788 #
789 # Check target.txt and tools_def.txt and Init them
790 #
791 BuildConfigurationFile = os.path.normpath(os.path.join(GlobalData.gConfDirectory, gBuildConfiguration))
792 if os.path.isfile(BuildConfigurationFile) == True:
793 StatusCode = self.TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
794
795 ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
796 if ToolDefinitionFile == '':
797 ToolDefinitionFile = gToolsDefinition
798 ToolDefinitionFile = os.path.normpath(os.path.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))
799 if os.path.isfile(ToolDefinitionFile) == True:
800 StatusCode = self.ToolDef.LoadToolDefFile(ToolDefinitionFile)
801 else:
802 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=ToolDefinitionFile)
803 else:
804 EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=BuildConfigurationFile)
805
806 # if no ARCH given in command line, get it from target.txt
807 if not self.ArchList:
808 self.ArchList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET_ARCH]
809 self.ArchList = tuple(self.ArchList)
810
811 # if no build target given in command line, get it from target.txt
812 if not self.BuildTargetList:
813 self.BuildTargetList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]
814
815 # if no tool chain given in command line, get it from target.txt
816 if not self.ToolChainList:
817 self.ToolChainList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]
818 if self.ToolChainList == None or len(self.ToolChainList) == 0:
819 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.\n")
820
821 # check if the tool chains are defined or not
822 NewToolChainList = []
823 for ToolChain in self.ToolChainList:
824 if ToolChain not in self.ToolDef.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]:
825 EdkLogger.warn("build", "Tool chain [%s] is not defined" % ToolChain)
826 else:
827 NewToolChainList.append(ToolChain)
828 # if no tool chain available, break the build
829 if len(NewToolChainList) == 0:
830 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,
831 ExtraData="[%s] not defined. No toolchain available for build!\n" % ", ".join(self.ToolChainList))
832 else:
833 self.ToolChainList = NewToolChainList
834
835 if self.ThreadNumber == None:
836 self.ThreadNumber = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]
837 if self.ThreadNumber == '':
838 self.ThreadNumber = 0
839 else:
840 self.ThreadNumber = int(self.ThreadNumber, 0)
841
842 if self.ThreadNumber == 0:
843 self.ThreadNumber = 1
844
845 if not self.PlatformFile:
846 PlatformFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM]
847 if not PlatformFile:
848 # Try to find one in current directory
849 WorkingDirectory = os.getcwd()
850 FileList = glob.glob(os.path.normpath(os.path.join(WorkingDirectory, '*.dsc')))
851 FileNum = len(FileList)
852 if FileNum >= 2:
853 EdkLogger.error("build", OPTION_MISSING,
854 ExtraData="There are %d DSC files in %s. Use '-p' to specify one.\n" % (FileNum, WorkingDirectory))
855 elif FileNum == 1:
856 PlatformFile = FileList[0]
857 else:
858 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,
859 ExtraData="No active platform specified in target.txt or command line! Nothing can be built.\n")
860
861 self.PlatformFile = PathClass(NormFile(PlatformFile, self.WorkspaceDir), self.WorkspaceDir)
862
863 ## Initialize build configuration
864 #
865 # This method will parse DSC file and merge the configurations from
866 # command line and target.txt, then get the final build configurations.
867 #
868 def InitBuild(self):
869 # parse target.txt, tools_def.txt, and platform file
870 self.LoadConfiguration()
871
872 # Allow case-insensitive for those from command line or configuration file
873 ErrorCode, ErrorInfo = self.PlatformFile.Validate(".dsc", False)
874 if ErrorCode != 0:
875 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)
876
877 # create metafile database
878 self.Db.InitDatabase()
879
880 ## Build a module or platform
881 #
882 # Create autogen code and makefile for a module or platform, and the launch
883 # "make" command to build it
884 #
885 # @param Target The target of build command
886 # @param Platform The platform file
887 # @param Module The module file
888 # @param BuildTarget The name of build target, one of "DEBUG", "RELEASE"
889 # @param ToolChain The name of toolchain to build
890 # @param Arch The arch of the module/platform
891 # @param CreateDepModuleCodeFile Flag used to indicate creating code
892 # for dependent modules/Libraries
893 # @param CreateDepModuleMakeFile Flag used to indicate creating makefile
894 # for dependent modules/Libraries
895 #
896 def _BuildPa(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeFile=True, BuildModule=False):
897 if AutoGenObject == None:
898 return False
899
900 # skip file generation for cleanxxx targets, run and fds target
901 if Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:
902 # for target which must generate AutoGen code and makefile
903 if not self.SkipAutoGen or Target == 'genc':
904 self.Progress.Start("Generating code")
905 AutoGenObject.CreateCodeFile(CreateDepsCodeFile)
906 self.Progress.Stop("done!")
907 if Target == "genc":
908 return True
909
910 if not self.SkipAutoGen or Target == 'genmake':
911 self.Progress.Start("Generating makefile")
912 AutoGenObject.CreateMakeFile(CreateDepsMakeFile)
913 self.Progress.Stop("done!")
914 if Target == "genmake":
915 return True
916 else:
917 # always recreate top/platform makefile when clean, just in case of inconsistency
918 AutoGenObject.CreateCodeFile(False)
919 AutoGenObject.CreateMakeFile(False)
920
921 if EdkLogger.GetLevel() == EdkLogger.QUIET:
922 EdkLogger.quiet("Building ... %s" % repr(AutoGenObject))
923
924 BuildCommand = AutoGenObject.BuildCommand
925 if BuildCommand == None or len(BuildCommand) == 0:
926 EdkLogger.error("build", OPTION_MISSING,
927 "No build command found for this module. "
928 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %
929 (AutoGenObject.BuildTarget, AutoGenObject.ToolChain, AutoGenObject.Arch),
930 ExtraData=str(AutoGenObject))
931
932 makefile = GenMake.BuildFile(AutoGenObject)._FILE_NAME_[GenMake.gMakeType]
933
934 # genfds
935 if Target == 'fds':
936 LaunchCommand(AutoGenObject.GenFdsCommand, AutoGenObject.MakeFileDir)
937 return True
938
939 # run
940 if Target == 'run':
941 RunDir = os.path.normpath(os.path.join(AutoGenObject.BuildDir, 'IA32'))
942 Command = '.\SecMain'
943 os.chdir(RunDir)
944 LaunchCommand(Command, RunDir)
945 return True
946
947 # build modules
948 if BuildModule:
949 BuildCommand = BuildCommand + [Target]
950 LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)
951 self.CreateAsBuiltInf()
952 return True
953
954 # build library
955 if Target == 'libraries':
956 for Lib in AutoGenObject.LibraryBuildDirectoryList:
957 NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Lib, makefile)), 'pbuild']
958 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
959 return True
960
961 # build module
962 if Target == 'modules':
963 for Lib in AutoGenObject.LibraryBuildDirectoryList:
964 NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Lib, makefile)), 'pbuild']
965 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
966 for Mod in AutoGenObject.ModuleBuildDirectoryList:
967 NewBuildCommand = BuildCommand + ['-f', os.path.normpath(os.path.join(Mod, makefile)), 'pbuild']
968 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
969 self.CreateAsBuiltInf()
970 return True
971
972 # cleanlib
973 if Target == 'cleanlib':
974 for Lib in AutoGenObject.LibraryBuildDirectoryList:
975 LibMakefile = os.path.normpath(os.path.join(Lib, makefile))
976 if os.path.exists(LibMakefile):
977 NewBuildCommand = BuildCommand + ['-f', LibMakefile, 'cleanall']
978 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
979 return True
980
981 # clean
982 if Target == 'clean':
983 for Mod in AutoGenObject.ModuleBuildDirectoryList:
984 ModMakefile = os.path.normpath(os.path.join(Mod, makefile))
985 if os.path.exists(ModMakefile):
986 NewBuildCommand = BuildCommand + ['-f', ModMakefile, 'cleanall']
987 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
988 for Lib in AutoGenObject.LibraryBuildDirectoryList:
989 LibMakefile = os.path.normpath(os.path.join(Lib, makefile))
990 if os.path.exists(LibMakefile):
991 NewBuildCommand = BuildCommand + ['-f', LibMakefile, 'cleanall']
992 LaunchCommand(NewBuildCommand, AutoGenObject.MakeFileDir)
993 return True
994
995 # cleanall
996 if Target == 'cleanall':
997 try:
998 #os.rmdir(AutoGenObject.BuildDir)
999 RemoveDirectory(AutoGenObject.BuildDir, True)
1000 except WindowsError, X:
1001 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))
1002 return True
1003
1004 ## Build a module or platform
1005 #
1006 # Create autogen code and makefile for a module or platform, and the launch
1007 # "make" command to build it
1008 #
1009 # @param Target The target of build command
1010 # @param Platform The platform file
1011 # @param Module The module file
1012 # @param BuildTarget The name of build target, one of "DEBUG", "RELEASE"
1013 # @param ToolChain The name of toolchain to build
1014 # @param Arch The arch of the module/platform
1015 # @param CreateDepModuleCodeFile Flag used to indicate creating code
1016 # for dependent modules/Libraries
1017 # @param CreateDepModuleMakeFile Flag used to indicate creating makefile
1018 # for dependent modules/Libraries
1019 #
1020 def _Build(self, Target, AutoGenObject, CreateDepsCodeFile=True, CreateDepsMakeFile=True, BuildModule=False):
1021 if AutoGenObject == None:
1022 return False
1023
1024 # skip file generation for cleanxxx targets, run and fds target
1025 if Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:
1026 # for target which must generate AutoGen code and makefile
1027 if not self.SkipAutoGen or Target == 'genc':
1028 self.Progress.Start("Generating code")
1029 AutoGenObject.CreateCodeFile(CreateDepsCodeFile)
1030 self.Progress.Stop("done!")
1031 if Target == "genc":
1032 return True
1033
1034 if not self.SkipAutoGen or Target == 'genmake':
1035 self.Progress.Start("Generating makefile")
1036 AutoGenObject.CreateMakeFile(CreateDepsMakeFile)
1037 #AutoGenObject.CreateAsBuiltInf()
1038 self.Progress.Stop("done!")
1039 if Target == "genmake":
1040 return True
1041 else:
1042 # always recreate top/platform makefile when clean, just in case of inconsistency
1043 AutoGenObject.CreateCodeFile(False)
1044 AutoGenObject.CreateMakeFile(False)
1045
1046 if EdkLogger.GetLevel() == EdkLogger.QUIET:
1047 EdkLogger.quiet("Building ... %s" % repr(AutoGenObject))
1048
1049 BuildCommand = AutoGenObject.BuildCommand
1050 if BuildCommand == None or len(BuildCommand) == 0:
1051 EdkLogger.error("build", OPTION_MISSING,
1052 "No build command found for this module. "
1053 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %
1054 (AutoGenObject.BuildTarget, AutoGenObject.ToolChain, AutoGenObject.Arch),
1055 ExtraData=str(AutoGenObject))
1056
1057 # genfds
1058 if Target == 'fds':
1059 LaunchCommand(AutoGenObject.GenFdsCommand, AutoGenObject.MakeFileDir)
1060 return True
1061
1062 # run
1063 if Target == 'run':
1064 RunDir = os.path.normpath(os.path.join(AutoGenObject.BuildDir, 'IA32'))
1065 Command = '.\SecMain'
1066 os.chdir(RunDir)
1067 LaunchCommand(Command, RunDir)
1068 return True
1069
1070 # build modules
1071 BuildCommand = BuildCommand + [Target]
1072 if BuildModule:
1073 LaunchCommand(BuildCommand, AutoGenObject.MakeFileDir)
1074 self.CreateAsBuiltInf()
1075 return True
1076
1077 # build library
1078 if Target == 'libraries':
1079 pass
1080
1081 # not build modules
1082
1083
1084 # cleanall
1085 if Target == 'cleanall':
1086 try:
1087 #os.rmdir(AutoGenObject.BuildDir)
1088 RemoveDirectory(AutoGenObject.BuildDir, True)
1089 except WindowsError, X:
1090 EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X))
1091 return True
1092
1093 ## Rebase module image and Get function address for the input module list.
1094 #
1095 def _RebaseModule (self, MapBuffer, BaseAddress, ModuleList, AddrIsOffset = True, ModeIsSmm = False):
1096 if ModeIsSmm:
1097 AddrIsOffset = False
1098 InfFileNameList = ModuleList.keys()
1099 #InfFileNameList.sort()
1100 for InfFile in InfFileNameList:
1101 sys.stdout.write (".")
1102 sys.stdout.flush()
1103 ModuleInfo = ModuleList[InfFile]
1104 ModuleName = ModuleInfo.BaseName
1105 ModuleOutputImage = ModuleInfo.Image.FileName
1106 ModuleDebugImage = os.path.join(ModuleInfo.DebugDir, ModuleInfo.BaseName + '.efi')
1107 ## for SMM module in SMRAM, the SMRAM will be allocated from base to top.
1108 if not ModeIsSmm:
1109 BaseAddress = BaseAddress - ModuleInfo.Image.Size
1110 #
1111 # Update Image to new BaseAddress by GenFw tool
1112 #
1113 LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)
1114 LaunchCommand(["GenFw", "--rebase", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)
1115 else:
1116 #
1117 # Set new address to the section header only for SMM driver.
1118 #
1119 LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleOutputImage], ModuleInfo.OutputDir)
1120 LaunchCommand(["GenFw", "--address", str(BaseAddress), "-r", ModuleDebugImage], ModuleInfo.DebugDir)
1121 #
1122 # Collect funtion address from Map file
1123 #
1124 ImageMapTable = ModuleOutputImage.replace('.efi', '.map')
1125 FunctionList = []
1126 if os.path.exists(ImageMapTable):
1127 OrigImageBaseAddress = 0
1128 ImageMap = open (ImageMapTable, 'r')
1129 for LinStr in ImageMap:
1130 if len (LinStr.strip()) == 0:
1131 continue
1132 #
1133 # Get the preferred address set on link time.
1134 #
1135 if LinStr.find ('Preferred load address is') != -1:
1136 StrList = LinStr.split()
1137 OrigImageBaseAddress = int (StrList[len(StrList) - 1], 16)
1138
1139 StrList = LinStr.split()
1140 if len (StrList) > 4:
1141 if StrList[3] == 'f' or StrList[3] =='F':
1142 Name = StrList[1]
1143 RelativeAddress = int (StrList[2], 16) - OrigImageBaseAddress
1144 FunctionList.append ((Name, RelativeAddress))
1145 if ModuleInfo.Arch == 'IPF' and Name.endswith('_ModuleEntryPoint'):
1146 #
1147 # Get the real entry point address for IPF image.
1148 #
1149 ModuleInfo.Image.EntryPoint = RelativeAddress
1150 ImageMap.close()
1151 #
1152 # Add general information.
1153 #
1154 if ModeIsSmm:
1155 MapBuffer.write('\n\n%s (Fixed SMRAM Offset, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))
1156 elif AddrIsOffset:
1157 MapBuffer.write('\n\n%s (Fixed Memory Offset, BaseAddress=-0x%010X, EntryPoint=-0x%010X)\n' % (ModuleName, 0 - BaseAddress, 0 - (BaseAddress + ModuleInfo.Image.EntryPoint)))
1158 else:
1159 MapBuffer.write('\n\n%s (Fixed Memory Address, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName, BaseAddress, BaseAddress + ModuleInfo.Image.EntryPoint))
1160 #
1161 # Add guid and general seciton section.
1162 #
1163 TextSectionAddress = 0
1164 DataSectionAddress = 0
1165 for SectionHeader in ModuleInfo.Image.SectionHeaderList:
1166 if SectionHeader[0] == '.text':
1167 TextSectionAddress = SectionHeader[1]
1168 elif SectionHeader[0] in ['.data', '.sdata']:
1169 DataSectionAddress = SectionHeader[1]
1170 if AddrIsOffset:
1171 MapBuffer.write('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n' % (ModuleInfo.Guid, 0 - (BaseAddress + TextSectionAddress), 0 - (BaseAddress + DataSectionAddress)))
1172 else:
1173 MapBuffer.write('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n' % (ModuleInfo.Guid, BaseAddress + TextSectionAddress, BaseAddress + DataSectionAddress))
1174 #
1175 # Add debug image full path.
1176 #
1177 MapBuffer.write('(IMAGE=%s)\n\n' % (ModuleDebugImage))
1178 #
1179 # Add funtion address
1180 #
1181 for Function in FunctionList:
1182 if AddrIsOffset:
1183 MapBuffer.write(' -0x%010X %s\n' % (0 - (BaseAddress + Function[1]), Function[0]))
1184 else:
1185 MapBuffer.write(' 0x%010X %s\n' % (BaseAddress + Function[1], Function[0]))
1186 ImageMap.close()
1187
1188 #
1189 # for SMM module in SMRAM, the SMRAM will be allocated from base to top.
1190 #
1191 if ModeIsSmm:
1192 BaseAddress = BaseAddress + ModuleInfo.Image.Size
1193
1194 ## Collect MAP information of all FVs
1195 #
1196 def _CollectFvMapBuffer (self, MapBuffer, Wa, ModuleList):
1197 if self.Fdf:
1198 # First get the XIP base address for FV map file.
1199 GuidPattern = re.compile("[-a-fA-F0-9]+")
1200 GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
1201 for FvName in Wa.FdfProfile.FvDict.keys():
1202 FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')
1203 if not os.path.exists(FvMapBuffer):
1204 continue
1205 FvMap = open(FvMapBuffer, 'r')
1206 #skip FV size information
1207 FvMap.readline()
1208 FvMap.readline()
1209 FvMap.readline()
1210 FvMap.readline()
1211 for Line in FvMap:
1212 MatchGuid = GuidPattern.match(Line)
1213 if MatchGuid != None:
1214 #
1215 # Replace GUID with module name
1216 #
1217 GuidString = MatchGuid.group()
1218 if GuidString.upper() in ModuleList:
1219 Line = Line.replace(GuidString, ModuleList[GuidString.upper()].Name)
1220 MapBuffer.write('%s' % (Line))
1221 #
1222 # Add the debug image full path.
1223 #
1224 MatchGuid = GuidName.match(Line)
1225 if MatchGuid != None:
1226 GuidString = MatchGuid.group().split("=")[1]
1227 if GuidString.upper() in ModuleList:
1228 MapBuffer.write('(IMAGE=%s)\n' % (os.path.join(ModuleList[GuidString.upper()].DebugDir, ModuleList[GuidString.upper()].Name + '.efi')))
1229
1230 FvMap.close()
1231
1232 ## Collect MAP information of all modules
1233 #
1234 def _CollectModuleMapBuffer (self, MapBuffer, ModuleList):
1235 sys.stdout.write ("Generate Load Module At Fix Address Map")
1236 sys.stdout.flush()
1237 PatchEfiImageList = []
1238 PeiModuleList = {}
1239 BtModuleList = {}
1240 RtModuleList = {}
1241 SmmModuleList = {}
1242 PeiSize = 0
1243 BtSize = 0
1244 RtSize = 0
1245 # reserve 4K size in SMRAM to make SMM module address not from 0.
1246 SmmSize = 0x1000
1247 IsIpfPlatform = False
1248 if 'IPF' in self.ArchList:
1249 IsIpfPlatform = True
1250 for ModuleGuid in ModuleList:
1251 Module = ModuleList[ModuleGuid]
1252 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (Module.MetaFile, Module.Arch, Module.ToolChain, Module.BuildTarget)
1253
1254 OutputImageFile = ''
1255 for ResultFile in Module.CodaTargetList:
1256 if str(ResultFile.Target).endswith('.efi'):
1257 #
1258 # module list for PEI, DXE, RUNTIME and SMM
1259 #
1260 OutputImageFile = os.path.join(Module.OutputDir, Module.Name + '.efi')
1261 ImageClass = PeImageClass (OutputImageFile)
1262 if not ImageClass.IsValid:
1263 EdkLogger.error("build", FILE_PARSE_FAILURE, ExtraData=ImageClass.ErrorInfo)
1264 ImageInfo = PeImageInfo(Module.Name, Module.Guid, Module.Arch, Module.OutputDir, Module.DebugDir, ImageClass)
1265 if Module.ModuleType in ['PEI_CORE', 'PEIM', 'COMBINED_PEIM_DRIVER','PIC_PEIM', 'RELOCATABLE_PEIM', 'DXE_CORE']:
1266 PeiModuleList[Module.MetaFile] = ImageInfo
1267 PeiSize += ImageInfo.Image.Size
1268 elif Module.ModuleType in ['BS_DRIVER', 'DXE_DRIVER', 'UEFI_DRIVER']:
1269 BtModuleList[Module.MetaFile] = ImageInfo
1270 BtSize += ImageInfo.Image.Size
1271 elif Module.ModuleType in ['DXE_RUNTIME_DRIVER', 'RT_DRIVER', 'DXE_SAL_DRIVER', 'SAL_RT_DRIVER']:
1272 RtModuleList[Module.MetaFile] = ImageInfo
1273 #IPF runtime driver needs to be at 2 page alignment.
1274 if IsIpfPlatform and ImageInfo.Image.Size % 0x2000 != 0:
1275 ImageInfo.Image.Size = (ImageInfo.Image.Size / 0x2000 + 1) * 0x2000
1276 RtSize += ImageInfo.Image.Size
1277 elif Module.ModuleType in ['SMM_CORE', 'DXE_SMM_DRIVER']:
1278 SmmModuleList[Module.MetaFile] = ImageInfo
1279 SmmSize += ImageInfo.Image.Size
1280 if Module.ModuleType == 'DXE_SMM_DRIVER':
1281 PiSpecVersion = '0x00000000'
1282 if 'PI_SPECIFICATION_VERSION' in Module.Module.Specification:
1283 PiSpecVersion = Module.Module.Specification['PI_SPECIFICATION_VERSION']
1284 # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver.
1285 if int(PiSpecVersion, 16) < 0x0001000A:
1286 BtModuleList[Module.MetaFile] = ImageInfo
1287 BtSize += ImageInfo.Image.Size
1288 break
1289 #
1290 # EFI image is final target.
1291 # Check EFI image contains patchable FixAddress related PCDs.
1292 #
1293 if OutputImageFile != '':
1294 ModuleIsPatch = False
1295 for Pcd in Module.ModulePcdList:
1296 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_LIST:
1297 ModuleIsPatch = True
1298 break
1299 if not ModuleIsPatch:
1300 for Pcd in Module.LibraryPcdList:
1301 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_LIST:
1302 ModuleIsPatch = True
1303 break
1304
1305 if not ModuleIsPatch:
1306 continue
1307 #
1308 # Module includes the patchable load fix address PCDs.
1309 # It will be fixed up later.
1310 #
1311 PatchEfiImageList.append (OutputImageFile)
1312
1313 #
1314 # Get Top Memory address
1315 #
1316 ReservedRuntimeMemorySize = 0
1317 TopMemoryAddress = 0
1318 if self.LoadFixAddress == 0xFFFFFFFFFFFFFFFF:
1319 TopMemoryAddress = 0
1320 else:
1321 TopMemoryAddress = self.LoadFixAddress
1322 if TopMemoryAddress < RtSize + BtSize + PeiSize:
1323 EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is too low to load driver")
1324 # Make IPF runtime driver at 2 page alignment.
1325 if IsIpfPlatform:
1326 ReservedRuntimeMemorySize = TopMemoryAddress % 0x2000
1327 RtSize = RtSize + ReservedRuntimeMemorySize
1328
1329 #
1330 # Patch FixAddress related PCDs into EFI image
1331 #
1332 for EfiImage in PatchEfiImageList:
1333 EfiImageMap = EfiImage.replace('.efi', '.map')
1334 if not os.path.exists(EfiImageMap):
1335 continue
1336 #
1337 # Get PCD offset in EFI image by GenPatchPcdTable function
1338 #
1339 PcdTable = parsePcdInfoFromMapFile(EfiImageMap, EfiImage)
1340 #
1341 # Patch real PCD value by PatchPcdValue tool
1342 #
1343 for PcdInfo in PcdTable:
1344 ReturnValue = 0
1345 if PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE:
1346 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize/0x1000))
1347 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE:
1348 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize/0x1000))
1349 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE:
1350 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize/0x1000))
1351 elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0:
1352 ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize/0x1000))
1353 if ReturnValue != 0:
1354 EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD value failed", ExtraData=ErrorInfo)
1355
1356 MapBuffer.write('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize/0x1000))
1357 MapBuffer.write('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize/0x1000))
1358 MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize/0x1000))
1359 if len (SmmModuleList) > 0:
1360 MapBuffer.write('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize/0x1000))
1361
1362 PeiBaseAddr = TopMemoryAddress - RtSize - BtSize
1363 BtBaseAddr = TopMemoryAddress - RtSize
1364 RtBaseAddr = TopMemoryAddress - ReservedRuntimeMemorySize
1365
1366 self._RebaseModule (MapBuffer, PeiBaseAddr, PeiModuleList, TopMemoryAddress == 0)
1367 self._RebaseModule (MapBuffer, BtBaseAddr, BtModuleList, TopMemoryAddress == 0)
1368 self._RebaseModule (MapBuffer, RtBaseAddr, RtModuleList, TopMemoryAddress == 0)
1369 self._RebaseModule (MapBuffer, 0x1000, SmmModuleList, AddrIsOffset = False, ModeIsSmm = True)
1370 MapBuffer.write('\n\n')
1371 sys.stdout.write ("\n")
1372 sys.stdout.flush()
1373
1374 ## Save platform Map file
1375 #
1376 def _SaveMapFile (self, MapBuffer, Wa):
1377 #
1378 # Map file path is got.
1379 #
1380 MapFilePath = os.path.join(Wa.BuildDir, Wa.Name + '.map')
1381 #
1382 # Save address map into MAP file.
1383 #
1384 SaveFileOnChange(MapFilePath, MapBuffer.getvalue(), False)
1385 MapBuffer.close()
1386 if self.LoadFixAddress != 0:
1387 sys.stdout.write ("\nLoad Module At Fix Address Map file can be found at %s\n" %(MapFilePath))
1388 sys.stdout.flush()
1389
1390 ## Build active platform for different build targets and different tool chains
1391 #
1392 def _BuildPlatform(self):
1393 for BuildTarget in self.BuildTargetList:
1394 GlobalData.gGlobalDefines['TARGET'] = BuildTarget
1395 for ToolChain in self.ToolChainList:
1396 GlobalData.gGlobalDefines['TOOLCHAIN'] = ToolChain
1397 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = ToolChain
1398 Wa = WorkspaceAutoGen(
1399 self.WorkspaceDir,
1400 self.PlatformFile,
1401 BuildTarget,
1402 ToolChain,
1403 self.ArchList,
1404 self.BuildDatabase,
1405 self.TargetTxt,
1406 self.ToolDef,
1407 self.Fdf,
1408 self.FdList,
1409 self.FvList,
1410 self.CapList,
1411 self.SkuId,
1412 self.UniFlag,
1413 self.Progress
1414 )
1415 self.Fdf = Wa.FdfFile
1416 self.LoadFixAddress = Wa.Platform.LoadFixAddress
1417 self.BuildReport.AddPlatformReport(Wa)
1418 self.Progress.Stop("done!")
1419 for Arch in Wa.ArchList:
1420 GlobalData.gGlobalDefines['ARCH'] = Arch
1421 Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)
1422 for Module in Pa.Platform.Modules:
1423 # Get ModuleAutoGen object to generate C code file and makefile
1424 Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile)
1425 if Ma == None:
1426 continue
1427 self.BuildModules.append(Ma)
1428 self._BuildPa(self.Target, Pa)
1429
1430 # Create MAP file when Load Fix Address is enabled.
1431 if self.Target in ["", "all", "fds"]:
1432 for Arch in Wa.ArchList:
1433 GlobalData.gGlobalDefines['ARCH'] = Arch
1434 #
1435 # Check whether the set fix address is above 4G for 32bit image.
1436 #
1437 if (Arch == 'IA32' or Arch == 'ARM') and self.LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self.LoadFixAddress >= 0x100000000:
1438 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")
1439 #
1440 # Get Module List
1441 #
1442 ModuleList = {}
1443 for Pa in Wa.AutoGenObjectList:
1444 for Ma in Pa.ModuleAutoGenList:
1445 if Ma == None:
1446 continue
1447 if not Ma.IsLibrary:
1448 ModuleList[Ma.Guid.upper()] = Ma
1449
1450 MapBuffer = StringIO('')
1451 if self.LoadFixAddress != 0:
1452 #
1453 # Rebase module to the preferred memory address before GenFds
1454 #
1455 self._CollectModuleMapBuffer(MapBuffer, ModuleList)
1456 if self.Fdf:
1457 #
1458 # create FDS again for the updated EFI image
1459 #
1460 self._Build("fds", Wa)
1461 if self.Fdf:
1462 #
1463 # Create MAP file for all platform FVs after GenFds.
1464 #
1465 self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)
1466 #
1467 # Save MAP buffer into MAP file.
1468 #
1469 self._SaveMapFile (MapBuffer, Wa)
1470
1471 ## Build active module for different build targets, different tool chains and different archs
1472 #
1473 def _BuildModule(self):
1474 for BuildTarget in self.BuildTargetList:
1475 GlobalData.gGlobalDefines['TARGET'] = BuildTarget
1476 for ToolChain in self.ToolChainList:
1477 GlobalData.gGlobalDefines['TOOLCHAIN'] = ToolChain
1478 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = ToolChain
1479 #
1480 # module build needs platform build information, so get platform
1481 # AutoGen first
1482 #
1483 Wa = WorkspaceAutoGen(
1484 self.WorkspaceDir,
1485 self.PlatformFile,
1486 BuildTarget,
1487 ToolChain,
1488 self.ArchList,
1489 self.BuildDatabase,
1490 self.TargetTxt,
1491 self.ToolDef,
1492 self.Fdf,
1493 self.FdList,
1494 self.FvList,
1495 self.CapList,
1496 self.SkuId,
1497 self.UniFlag,
1498 self.Progress,
1499 self.ModuleFile
1500 )
1501 self.Fdf = Wa.FdfFile
1502 self.LoadFixAddress = Wa.Platform.LoadFixAddress
1503 Wa.CreateMakeFile(False)
1504 self.Progress.Stop("done!")
1505 MaList = []
1506 for Arch in Wa.ArchList:
1507 GlobalData.gGlobalDefines['ARCH'] = Arch
1508 Ma = ModuleAutoGen(Wa, self.ModuleFile, BuildTarget, ToolChain, Arch, self.PlatformFile)
1509 if Ma == None: continue
1510 MaList.append(Ma)
1511 self.BuildModules.append(Ma)
1512 if not Ma.IsBinaryModule:
1513 self._Build(self.Target, Ma, BuildModule=True)
1514
1515 self.BuildReport.AddPlatformReport(Wa, MaList)
1516 if MaList == []:
1517 EdkLogger.error(
1518 'build',
1519 BUILD_ERROR,
1520 "Module for [%s] is not a component of active platform."\
1521 " Please make sure that the ARCH and inf file path are"\
1522 " given in the same as in [%s]" %\
1523 (', '.join(Wa.ArchList), self.PlatformFile),
1524 ExtraData=self.ModuleFile
1525 )
1526 # Create MAP file when Load Fix Address is enabled.
1527 if self.Target == "fds" and self.Fdf:
1528 for Arch in Wa.ArchList:
1529 #
1530 # Check whether the set fix address is above 4G for 32bit image.
1531 #
1532 if (Arch == 'IA32' or Arch == 'ARM') and self.LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self.LoadFixAddress >= 0x100000000:
1533 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")
1534 #
1535 # Get Module List
1536 #
1537 ModuleList = {}
1538 for Pa in Wa.AutoGenObjectList:
1539 for Ma in Pa.ModuleAutoGenList:
1540 if Ma == None:
1541 continue
1542 if not Ma.IsLibrary:
1543 ModuleList[Ma.Guid.upper()] = Ma
1544
1545 MapBuffer = StringIO('')
1546 if self.LoadFixAddress != 0:
1547 #
1548 # Rebase module to the preferred memory address before GenFds
1549 #
1550 self._CollectModuleMapBuffer(MapBuffer, ModuleList)
1551 #
1552 # create FDS again for the updated EFI image
1553 #
1554 self._Build("fds", Wa)
1555 #
1556 # Create MAP file for all platform FVs after GenFds.
1557 #
1558 self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)
1559 #
1560 # Save MAP buffer into MAP file.
1561 #
1562 self._SaveMapFile (MapBuffer, Wa)
1563
1564 ## Build a platform in multi-thread mode
1565 #
1566 def _MultiThreadBuildPlatform(self):
1567 for BuildTarget in self.BuildTargetList:
1568 GlobalData.gGlobalDefines['TARGET'] = BuildTarget
1569 for ToolChain in self.ToolChainList:
1570 GlobalData.gGlobalDefines['TOOLCHAIN'] = ToolChain
1571 GlobalData.gGlobalDefines['TOOL_CHAIN_TAG'] = ToolChain
1572 Wa = WorkspaceAutoGen(
1573 self.WorkspaceDir,
1574 self.PlatformFile,
1575 BuildTarget,
1576 ToolChain,
1577 self.ArchList,
1578 self.BuildDatabase,
1579 self.TargetTxt,
1580 self.ToolDef,
1581 self.Fdf,
1582 self.FdList,
1583 self.FvList,
1584 self.CapList,
1585 self.SkuId,
1586 self.UniFlag,
1587 self.Progress
1588 )
1589 self.Fdf = Wa.FdfFile
1590 self.LoadFixAddress = Wa.Platform.LoadFixAddress
1591 self.BuildReport.AddPlatformReport(Wa)
1592 Wa.CreateMakeFile(False)
1593
1594 # multi-thread exit flag
1595 ExitFlag = threading.Event()
1596 ExitFlag.clear()
1597 for Arch in Wa.ArchList:
1598 GlobalData.gGlobalDefines['ARCH'] = Arch
1599 Pa = PlatformAutoGen(Wa, self.PlatformFile, BuildTarget, ToolChain, Arch)
1600 if Pa == None:
1601 continue
1602 ModuleList = []
1603 for Inf in Pa.Platform.Modules:
1604 ModuleList.append(Inf)
1605 # Add the INF only list in FDF
1606 if GlobalData.gFdfParser != None:
1607 for InfName in GlobalData.gFdfParser.Profile.InfList:
1608 Inf = PathClass(NormPath(InfName), self.WorkspaceDir, Arch)
1609 if Inf in Pa.Platform.Modules:
1610 continue
1611 ModuleList.append(Inf)
1612 for Module in ModuleList:
1613 # Get ModuleAutoGen object to generate C code file and makefile
1614 Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile)
1615
1616 if Ma == None:
1617 continue
1618 # Not to auto-gen for targets 'clean', 'cleanlib', 'cleanall', 'run', 'fds'
1619 if self.Target not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:
1620 # for target which must generate AutoGen code and makefile
1621 if not self.SkipAutoGen or self.Target == 'genc':
1622 Ma.CreateCodeFile(True)
1623 if self.Target == "genc":
1624 continue
1625
1626 if not self.SkipAutoGen or self.Target == 'genmake':
1627 Ma.CreateMakeFile(True)
1628 if self.Target == "genmake":
1629 continue
1630 self.BuildModules.append(Ma)
1631 self.Progress.Stop("done!")
1632
1633 for Ma in self.BuildModules:
1634 # Generate build task for the module
1635 if not Ma.IsBinaryModule:
1636 Bt = BuildTask.New(ModuleMakeUnit(Ma, self.Target))
1637 # Break build if any build thread has error
1638 if BuildTask.HasError():
1639 # we need a full version of makefile for platform
1640 ExitFlag.set()
1641 BuildTask.WaitForComplete()
1642 Pa.CreateMakeFile(False)
1643 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)
1644 # Start task scheduler
1645 if not BuildTask.IsOnGoing():
1646 BuildTask.StartScheduler(self.ThreadNumber, ExitFlag)
1647
1648 # in case there's an interruption. we need a full version of makefile for platform
1649 Pa.CreateMakeFile(False)
1650 if BuildTask.HasError():
1651 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)
1652
1653 #
1654 # Save temp tables to a TmpTableDict.
1655 #
1656 for Key in Wa.BuildDatabase._CACHE_:
1657 if Wa.BuildDatabase._CACHE_[Key]._RawData and Wa.BuildDatabase._CACHE_[Key]._RawData._Table and Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Table:
1658 if TemporaryTablePattern.match(Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Table):
1659 TmpTableDict[Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Table] = Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Cur
1660 #
1661 #
1662 # All modules have been put in build tasks queue. Tell task scheduler
1663 # to exit if all tasks are completed
1664 #
1665 ExitFlag.set()
1666 BuildTask.WaitForComplete()
1667 self.CreateAsBuiltInf()
1668
1669 #
1670 # Check for build error, and raise exception if one
1671 # has been signaled.
1672 #
1673 if BuildTask.HasError():
1674 EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)
1675
1676 # Create MAP file when Load Fix Address is enabled.
1677 if self.Target in ["", "all", "fds"]:
1678 for Arch in Wa.ArchList:
1679 #
1680 # Check whether the set fix address is above 4G for 32bit image.
1681 #
1682 if (Arch == 'IA32' or Arch == 'ARM') and self.LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self.LoadFixAddress >= 0x100000000:
1683 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")
1684 #
1685 # Get Module List
1686 #
1687 ModuleList = {}
1688 for Pa in Wa.AutoGenObjectList:
1689 for Ma in Pa.ModuleAutoGenList:
1690 if Ma == None:
1691 continue
1692 if not Ma.IsLibrary:
1693 ModuleList[Ma.Guid.upper()] = Ma
1694 #
1695 # Rebase module to the preferred memory address before GenFds
1696 #
1697 MapBuffer = StringIO('')
1698 if self.LoadFixAddress != 0:
1699 self._CollectModuleMapBuffer(MapBuffer, ModuleList)
1700
1701 if self.Fdf:
1702 #
1703 # Generate FD image if there's a FDF file found
1704 #
1705 LaunchCommand(Wa.GenFdsCommand, os.getcwd())
1706
1707 #
1708 # Create MAP file for all platform FVs after GenFds.
1709 #
1710 self._CollectFvMapBuffer(MapBuffer, Wa, ModuleList)
1711 #
1712 # Save MAP buffer into MAP file.
1713 #
1714 self._SaveMapFile(MapBuffer, Wa)
1715
1716 ## Generate GuidedSectionTools.txt in the FV directories.
1717 #
1718 def CreateGuidedSectionToolsFile(self):
1719 for BuildTarget in self.BuildTargetList:
1720 for ToolChain in self.ToolChainList:
1721 Wa = WorkspaceAutoGen(
1722 self.WorkspaceDir,
1723 self.PlatformFile,
1724 BuildTarget,
1725 ToolChain,
1726 self.ArchList,
1727 self.BuildDatabase,
1728 self.TargetTxt,
1729 self.ToolDef,
1730 self.Fdf,
1731 self.FdList,
1732 self.FvList,
1733 self.CapList,
1734 self.SkuId,
1735 self.UniFlag
1736 )
1737 FvDir = Wa.FvDir
1738 if not os.path.exists(FvDir):
1739 continue
1740
1741 for Arch in self.ArchList:
1742 # Build up the list of supported architectures for this build
1743 prefix = '%s_%s_%s_' % (BuildTarget, ToolChain, Arch)
1744
1745 # Look through the tool definitions for GUIDed tools
1746 guidAttribs = []
1747 for (attrib, value) in self.ToolDef.ToolsDefTxtDictionary.iteritems():
1748 if attrib.upper().endswith('_GUID'):
1749 split = attrib.split('_')
1750 thisPrefix = '_'.join(split[0:3]) + '_'
1751 if thisPrefix == prefix:
1752 guid = self.ToolDef.ToolsDefTxtDictionary[attrib]
1753 guid = guid.lower()
1754 toolName = split[3]
1755 path = '_'.join(split[0:4]) + '_PATH'
1756 path = self.ToolDef.ToolsDefTxtDictionary[path]
1757 path = self.GetFullPathOfTool(path)
1758 guidAttribs.append((guid, toolName, path))
1759
1760 # Write out GuidedSecTools.txt
1761 toolsFile = os.path.join(FvDir, 'GuidedSectionTools.txt')
1762 toolsFile = open(toolsFile, 'wt')
1763 for guidedSectionTool in guidAttribs:
1764 print >> toolsFile, ' '.join(guidedSectionTool)
1765 toolsFile.close()
1766
1767 ## Returns the full path of the tool.
1768 #
1769 def GetFullPathOfTool (self, tool):
1770 if os.path.exists(tool):
1771 return os.path.realpath(tool)
1772 else:
1773 # We need to search for the tool using the
1774 # PATH environment variable.
1775 for dirInPath in os.environ['PATH'].split(os.pathsep):
1776 foundPath = os.path.join(dirInPath, tool)
1777 if os.path.exists(foundPath):
1778 return os.path.realpath(foundPath)
1779
1780 # If the tool was not found in the path then we just return
1781 # the input tool.
1782 return tool
1783
1784 ## Launch the module or platform build
1785 #
1786 def Launch(self):
1787 if not self.ModuleFile:
1788 if not self.SpawnMode or self.Target not in ["", "all"]:
1789 self.SpawnMode = False
1790 self._BuildPlatform()
1791 else:
1792 self._MultiThreadBuildPlatform()
1793 self.CreateGuidedSectionToolsFile()
1794 else:
1795 self.SpawnMode = False
1796 self._BuildModule()
1797
1798 if self.Target == 'cleanall':
1799 self.Db.Close()
1800 RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True)
1801
1802 def CreateAsBuiltInf(self):
1803 for Module in self.BuildModules:
1804 Module.CreateAsBuiltInf()
1805 self.BuildModules = []
1806 ## Do some clean-up works when error occurred
1807 def Relinquish(self):
1808 OldLogLevel = EdkLogger.GetLevel()
1809 EdkLogger.SetLevel(EdkLogger.ERROR)
1810 #self.DumpBuildData()
1811 Utils.Progressor.Abort()
1812 if self.SpawnMode == True:
1813 BuildTask.Abort()
1814 EdkLogger.SetLevel(OldLogLevel)
1815
1816 def DumpBuildData(self):
1817 CacheDirectory = os.path.dirname(GlobalData.gDatabasePath)
1818 Utils.CreateDirectory(CacheDirectory)
1819 Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache"))
1820 Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase"))
1821
1822 def RestoreBuildData(self):
1823 FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gFileTimeStampCache")
1824 if Utils.gFileTimeStampCache == {} and os.path.isfile(FilePath):
1825 Utils.gFileTimeStampCache = Utils.DataRestore(FilePath)
1826 if Utils.gFileTimeStampCache == None:
1827 Utils.gFileTimeStampCache = {}
1828
1829 FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gDependencyDatabase")
1830 if Utils.gDependencyDatabase == {} and os.path.isfile(FilePath):
1831 Utils.gDependencyDatabase = Utils.DataRestore(FilePath)
1832 if Utils.gDependencyDatabase == None:
1833 Utils.gDependencyDatabase = {}
1834
1835 def ParseDefines(DefineList=[]):
1836 DefineDict = {}
1837 if DefineList != None:
1838 for Define in DefineList:
1839 DefineTokenList = Define.split("=", 1)
1840 if not GlobalData.gMacroNamePattern.match(DefineTokenList[0]):
1841 EdkLogger.error('build', FORMAT_INVALID,
1842 "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
1843 ExtraData=DefineTokenList[0])
1844
1845 if len(DefineTokenList) == 1:
1846 DefineDict[DefineTokenList[0]] = "TRUE"
1847 else:
1848 DefineDict[DefineTokenList[0]] = DefineTokenList[1].strip()
1849 return DefineDict
1850
1851 gParamCheck = []
1852 def SingleCheckCallback(option, opt_str, value, parser):
1853 if option not in gParamCheck:
1854 setattr(parser.values, option.dest, value)
1855 gParamCheck.append(option)
1856 else:
1857 parser.error("Option %s only allows one instance in command line!" % option)
1858
1859 ## Parse command line options
1860 #
1861 # Using standard Python module optparse to parse command line option of this tool.
1862 #
1863 # @retval Opt A optparse.Values object containing the parsed options
1864 # @retval Args Target of build command
1865 #
1866 def MyOptionParser():
1867 Parser = OptionParser(description=__copyright__,version=__version__,prog="build.exe",usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]")
1868 Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32','X64','IPF','EBC','ARM', 'AARCH64'], dest="TargetArch",
1869 help="ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 or EBC, which overrides target.txt's TARGET_ARCH definition. To specify more archs, please repeat this option.")
1870 Parser.add_option("-p", "--platform", action="callback", type="string", dest="PlatformFile", callback=SingleCheckCallback,
1871 help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")
1872 Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback,
1873 help="Build the module specified by the INF file name argument.")
1874 Parser.add_option("-b", "--buildtarget", type="string", dest="BuildTarget", help="Using the TARGET to build the platform, overriding target.txt's TARGET definition.",
1875 action="append")
1876 Parser.add_option("-t", "--tagname", action="append", type="string", dest="ToolChain",
1877 help="Using the Tool Chain Tagname to build the platform, overriding target.txt's TOOL_CHAIN_TAG definition.")
1878 Parser.add_option("-x", "--sku-id", action="callback", type="string", dest="SkuId", callback=SingleCheckCallback,
1879 help="Using this name of SKU ID to build the platform, overriding SKUID_IDENTIFIER in DSC file.")
1880
1881 Parser.add_option("-n", action="callback", type="int", dest="ThreadNumber", callback=SingleCheckCallback,
1882 help="Build the platform using multi-threaded compiler. The value overrides target.txt's MAX_CONCURRENT_THREAD_NUMBER. Less than 2 will disable multi-thread builds.")
1883
1884 Parser.add_option("-f", "--fdf", action="callback", type="string", dest="FdfFile", callback=SingleCheckCallback,
1885 help="The name of the FDF file to use, which overrides the setting in the DSC file.")
1886 Parser.add_option("-r", "--rom-image", action="append", type="string", dest="RomImage", default=[],
1887 help="The name of FD to be generated. The name must be from [FD] section in FDF file.")
1888 Parser.add_option("-i", "--fv-image", action="append", type="string", dest="FvImage", default=[],
1889 help="The name of FV to be generated. The name must be from [FV] section in FDF file.")
1890 Parser.add_option("-C", "--capsule-image", action="append", type="string", dest="CapName", default=[],
1891 help="The name of Capsule to be generated. The name must be from [Capsule] section in FDF file.")
1892 Parser.add_option("-u", "--skip-autogen", action="store_true", dest="SkipAutoGen", help="Skip AutoGen step.")
1893 Parser.add_option("-e", "--re-parse", action="store_true", dest="Reparse", help="Re-parse all meta-data files.")
1894
1895 Parser.add_option("-c", "--case-insensitive", action="store_true", dest="CaseInsensitive", default=False, help="Don't check case of file name.")
1896
1897 Parser.add_option("-w", "--warning-as-error", action="store_true", dest="WarningAsError", help="Treat warning in tools as error.")
1898 Parser.add_option("-j", "--log", action="store", dest="LogFile", help="Put log in specified file as well as on console.")
1899
1900 Parser.add_option("-s", "--silent", action="store_true", type=None, dest="SilentMode",
1901 help="Make use of silent mode of (n)make.")
1902 Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")
1903 Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\
1904 "including library instances selected, final dependency expression, "\
1905 "and warning messages, etc.")
1906 Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")
1907 Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")
1908
1909 Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.")
1910 Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD','LIBRARY','FLASH','DEPEX','BUILD_FLAGS','FIXED_ADDRESS', 'EXECUTION_ORDER'], dest="ReportType", default=[],
1911 help="Flags that control the type of build report to generate. Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, EXECUTION_ORDER]. "\
1912 "To specify more than one flag, repeat this option on the command line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS]")
1913 Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",
1914 help="Specify the specific option to parse EDK UNI file. Must be one of: [-c, -s]. -c is for EDK framework UNI file, and -s is for EDK UEFI UNI file. "\
1915 "This option can also be specified by setting *_*_*_BUILD_FLAGS in [BuildOptions] section of platform DSC. If they are both specified, this value "\
1916 "will override the setting in [BuildOptions] section of platform DSC.")
1917 Parser.add_option("-N", "--no-cache", action="store_true", dest="DisableCache", default=False, help="Disable build cache mechanism")
1918 Parser.add_option("--conf", action="store", type="string", dest="ConfDirectory", help="Specify the customized Conf directory.")
1919 Parser.add_option("--check-usage", action="store_true", dest="CheckUsage", default=False, help="Check usage content of entries listed in INF file.")
1920 Parser.add_option("--ignore-sources", action="store_true", dest="IgnoreSources", default=False, help="Focus to a binary build and ignore all source files")
1921
1922 (Opt, Args)=Parser.parse_args()
1923 return (Opt, Args)
1924
1925 ## Tool entrance method
1926 #
1927 # This method mainly dispatch specific methods per the command line options.
1928 # If no error found, return zero value so the caller of this tool can know
1929 # if it's executed successfully or not.
1930 #
1931 # @retval 0 Tool was successful
1932 # @retval 1 Tool failed
1933 #
1934 def Main():
1935 StartTime = time.time()
1936
1937 # Initialize log system
1938 EdkLogger.Initialize()
1939
1940 #
1941 # Parse the options and args
1942 #
1943 (Option, Target) = MyOptionParser()
1944 GlobalData.gOptions = Option
1945 GlobalData.gCaseInsensitive = Option.CaseInsensitive
1946
1947 # Set log level
1948 if Option.verbose != None:
1949 EdkLogger.SetLevel(EdkLogger.VERBOSE)
1950 elif Option.quiet != None:
1951 EdkLogger.SetLevel(EdkLogger.QUIET)
1952 elif Option.debug != None:
1953 EdkLogger.SetLevel(Option.debug + 1)
1954 else:
1955 EdkLogger.SetLevel(EdkLogger.INFO)
1956
1957 if Option.LogFile != None:
1958 EdkLogger.SetLogFile(Option.LogFile)
1959
1960 if Option.WarningAsError == True:
1961 EdkLogger.SetWarningAsError()
1962
1963 if platform.platform().find("Windows") >= 0:
1964 GlobalData.gIsWindows = True
1965 else:
1966 GlobalData.gIsWindows = False
1967
1968 EdkLogger.quiet("Build environment: %s" % platform.platform())
1969 EdkLogger.quiet(time.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time.localtime()));
1970 ReturnCode = 0
1971 MyBuild = None
1972 try:
1973 if len(Target) == 0:
1974 Target = "all"
1975 elif len(Target) >= 2:
1976 EdkLogger.error("build", OPTION_NOT_SUPPORTED, "More than one targets are not supported.",
1977 ExtraData="Please select one of: %s" %(' '.join(gSupportedTarget)))
1978 else:
1979 Target = Target[0].lower()
1980
1981 if Target not in gSupportedTarget:
1982 EdkLogger.error("build", OPTION_NOT_SUPPORTED, "Not supported target [%s]." % Target,
1983 ExtraData="Please select one of: %s" %(' '.join(gSupportedTarget)))
1984
1985 #
1986 # Check environment variable: EDK_TOOLS_PATH, WORKSPACE, PATH
1987 #
1988 CheckEnvVariable()
1989 GlobalData.gCommandLineDefines.update(ParseDefines(Option.Macros))
1990
1991 Workspace = os.getenv("WORKSPACE")
1992 #
1993 # Get files real name in workspace dir
1994 #
1995 GlobalData.gAllFiles = Utils.DirCache(Workspace)
1996
1997 WorkingDirectory = os.getcwd()
1998 if not Option.ModuleFile:
1999 FileList = glob.glob(os.path.normpath(os.path.join(WorkingDirectory, '*.inf')))
2000 FileNum = len(FileList)
2001 if FileNum >= 2:
2002 EdkLogger.error("build", OPTION_NOT_SUPPORTED, "There are %d INF files in %s." % (FileNum, WorkingDirectory),
2003 ExtraData="Please use '-m <INF_FILE_PATH>' switch to choose one.")
2004 elif FileNum == 1:
2005 Option.ModuleFile = NormFile(FileList[0], Workspace)
2006
2007 if Option.ModuleFile:
2008 if os.path.isabs (Option.ModuleFile):
2009 if os.path.normcase (os.path.normpath(Option.ModuleFile)).find (Workspace) == 0:
2010 Option.ModuleFile = NormFile(os.path.normpath(Option.ModuleFile), Workspace)
2011 Option.ModuleFile = PathClass(Option.ModuleFile, Workspace)
2012 ErrorCode, ErrorInfo = Option.ModuleFile.Validate(".inf", False)
2013 if ErrorCode != 0:
2014 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)
2015
2016 if Option.PlatformFile != None:
2017 if os.path.isabs (Option.PlatformFile):
2018 if os.path.normcase (os.path.normpath(Option.PlatformFile)).find (Workspace) == 0:
2019 Option.PlatformFile = NormFile(os.path.normpath(Option.PlatformFile), Workspace)
2020 Option.PlatformFile = PathClass(Option.PlatformFile, Workspace)
2021
2022 if Option.FdfFile != None:
2023 if os.path.isabs (Option.FdfFile):
2024 if os.path.normcase (os.path.normpath(Option.FdfFile)).find (Workspace) == 0:
2025 Option.FdfFile = NormFile(os.path.normpath(Option.FdfFile), Workspace)
2026 Option.FdfFile = PathClass(Option.FdfFile, Workspace)
2027 ErrorCode, ErrorInfo = Option.FdfFile.Validate(".fdf", False)
2028 if ErrorCode != 0:
2029 EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo)
2030
2031 if Option.Flag != None and Option.Flag not in ['-c', '-s']:
2032 EdkLogger.error("build", OPTION_VALUE_INVALID, "UNI flag must be one of -c or -s")
2033
2034 MyBuild = Build(Target, Workspace, Option)
2035 GlobalData.gCommandLineDefines['ARCH'] = ' '.join(MyBuild.ArchList)
2036 MyBuild.Launch()
2037 # Drop temp tables to avoid database locked.
2038 for TmpTableName in TmpTableDict:
2039 SqlCommand = """drop table IF EXISTS %s""" % TmpTableName
2040 TmpTableDict[TmpTableName].execute(SqlCommand)
2041 #MyBuild.DumpBuildData()
2042 except FatalError, X:
2043 if MyBuild != None:
2044 # for multi-thread build exits safely
2045 MyBuild.Relinquish()
2046 if Option != None and Option.debug != None:
2047 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())
2048 ReturnCode = X.args[0]
2049 except Warning, X:
2050 # error from Fdf parser
2051 if MyBuild != None:
2052 # for multi-thread build exits safely
2053 MyBuild.Relinquish()
2054 if Option != None and Option.debug != None:
2055 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())
2056 else:
2057 EdkLogger.error(X.ToolName, FORMAT_INVALID, File=X.FileName, Line=X.LineNumber, ExtraData=X.Message, RaiseError = False)
2058 ReturnCode = FORMAT_INVALID
2059 except KeyboardInterrupt:
2060 ReturnCode = ABORT_ERROR
2061 if Option != None and Option.debug != None:
2062 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())
2063 except:
2064 if MyBuild != None:
2065 # for multi-thread build exits safely
2066 MyBuild.Relinquish()
2067
2068 # try to get the meta-file from the object causing exception
2069 Tb = sys.exc_info()[-1]
2070 MetaFile = GlobalData.gProcessingFile
2071 while Tb != None:
2072 if 'self' in Tb.tb_frame.f_locals and hasattr(Tb.tb_frame.f_locals['self'], 'MetaFile'):
2073 MetaFile = Tb.tb_frame.f_locals['self'].MetaFile
2074 Tb = Tb.tb_next
2075 EdkLogger.error(
2076 "\nbuild",
2077 CODE_ERROR,
2078 "Unknown fatal error when processing [%s]" % MetaFile,
2079 ExtraData="\n(Please send email to edk2-devel@lists.sourceforge.net for help, attaching following call stack trace!)\n",
2080 RaiseError=False
2081 )
2082 EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())
2083 ReturnCode = CODE_ERROR
2084 finally:
2085 Utils.Progressor.Abort()
2086 Utils.ClearDuplicatedInf()
2087
2088 if ReturnCode == 0:
2089 Conclusion = "Done"
2090 elif ReturnCode == ABORT_ERROR:
2091 Conclusion = "Aborted"
2092 else:
2093 Conclusion = "Failed"
2094 FinishTime = time.time()
2095 BuildDuration = time.gmtime(int(round(FinishTime - StartTime)))
2096 BuildDurationStr = ""
2097 if BuildDuration.tm_yday > 1:
2098 BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration) + ", %d day(s)"%(BuildDuration.tm_yday - 1)
2099 else:
2100 BuildDurationStr = time.strftime("%H:%M:%S", BuildDuration)
2101 if MyBuild != None:
2102 MyBuild.BuildReport.GenerateReport(BuildDurationStr)
2103 MyBuild.Db.Close()
2104 EdkLogger.SetLevel(EdkLogger.QUIET)
2105 EdkLogger.quiet("\n- %s -" % Conclusion)
2106 EdkLogger.quiet(time.strftime("Build end time: %H:%M:%S, %b.%d %Y", time.localtime()))
2107 EdkLogger.quiet("Build total time: %s\n" % BuildDurationStr)
2108 return ReturnCode
2109
2110 if __name__ == '__main__':
2111 r = Main()
2112 ## 0-127 is a safe return range, and 1 is a standard default error
2113 if r < 0 or r > 127: r = 1
2114 sys.exit(r)
2115