2 # build a platform or a module
4 # Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
5 # Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR>
6 # Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>
7 # Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.<BR>
9 # SPDX-License-Identifier: BSD-2-Clause-Patent
15 from __future__
import print_function
16 from __future__
import absolute_import
17 import os
.path
as path
25 import multiprocessing
26 from threading
import Thread
,Event
,BoundedSemaphore
28 from linecache
import getlines
29 from subprocess
import Popen
,PIPE
, STDOUT
30 from collections
import OrderedDict
, defaultdict
32 from AutoGen
.PlatformAutoGen
import PlatformAutoGen
33 from AutoGen
.ModuleAutoGen
import ModuleAutoGen
34 from AutoGen
.WorkspaceAutoGen
import WorkspaceAutoGen
35 from AutoGen
.AutoGenWorker
import AutoGenWorkerInProcess
,AutoGenManager
,\
37 from AutoGen
import GenMake
38 from Common
import Misc
as Utils
40 from Common
.TargetTxtClassObject
import TargetTxtDict
41 from Common
.ToolDefClassObject
import ToolDefDict
42 from buildoptions
import MyOptionParser
43 from Common
.Misc
import PathClass
,SaveFileOnChange
,RemoveDirectory
44 from Common
.StringUtils
import NormPath
45 from Common
.MultipleWorkspace
import MultipleWorkspace
as mws
46 from Common
.BuildToolError
import *
47 from Common
.DataType
import *
48 import Common
.EdkLogger
as EdkLogger
50 from Workspace
.WorkspaceDatabase
import BuildDB
52 from BuildReport
import BuildReport
53 from GenPatchPcdTable
.GenPatchPcdTable
import PeImageClass
,parsePcdInfoFromMapFile
54 from PatchPcdValue
.PatchPcdValue
import PatchBinaryFile
56 import Common
.GlobalData
as GlobalData
57 from GenFds
.GenFds
import GenFds
, GenFdsApi
58 import multiprocessing
as mp
59 from multiprocessing
import Manager
60 from AutoGen
.DataPipe
import MemoryDataPipe
61 from AutoGen
.ModuleAutoGenHelper
import WorkSpaceInfo
, PlatformInfo
62 from GenFds
.FdfParser
import FdfParser
63 from AutoGen
.IncludesAutoGen
import IncludesAutoGen
64 from GenFds
.GenFds
import resetFdsGlobalVariable
65 from AutoGen
.AutoGen
import CalculatePriorityValue
67 ## standard targets of build command
68 gSupportedTarget
= ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']
70 ## build configuration file
71 gBuildConfiguration
= "target.txt"
72 gToolsDefinition
= "tools_def.txt"
74 TemporaryTablePattern
= re
.compile(r
'^_\d+_\d+_[a-fA-F0-9]+$')
77 ## Check environment PATH variable to make sure the specified tool is found
79 # If the tool is found in the PATH, then True is returned
80 # Otherwise, False is returned
82 def IsToolInPath(tool
):
83 if 'PATHEXT' in os
.environ
:
84 extns
= os
.environ
['PATHEXT'].split(os
.path
.pathsep
)
87 for pathDir
in os
.environ
['PATH'].split(os
.path
.pathsep
):
89 if os
.path
.exists(os
.path
.join(pathDir
, tool
+ ext
)):
93 ## Check environment variables
95 # Check environment variables that must be set for build. Currently they are
97 # WORKSPACE The directory all packages/platforms start from
98 # EDK_TOOLS_PATH The directory contains all tools needed by the build
99 # PATH $(EDK_TOOLS_PATH)/Bin/<sys> must be set in PATH
101 # If any of above environment variable is not set or has error, the build
104 def CheckEnvVariable():
106 if "WORKSPACE" not in os
.environ
:
107 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "Environment variable not found",
108 ExtraData
="WORKSPACE")
110 WorkspaceDir
= os
.path
.normcase(os
.path
.normpath(os
.environ
["WORKSPACE"]))
111 if not os
.path
.exists(WorkspaceDir
):
112 EdkLogger
.error("build", FILE_NOT_FOUND
, "WORKSPACE doesn't exist", ExtraData
=WorkspaceDir
)
113 elif ' ' in WorkspaceDir
:
114 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in WORKSPACE path",
115 ExtraData
=WorkspaceDir
)
116 os
.environ
["WORKSPACE"] = WorkspaceDir
118 # set multiple workspace
119 PackagesPath
= os
.getenv("PACKAGES_PATH")
120 mws
.setWs(WorkspaceDir
, PackagesPath
)
121 if mws
.PACKAGES_PATH
:
122 for Path
in mws
.PACKAGES_PATH
:
123 if not os
.path
.exists(Path
):
124 EdkLogger
.error("build", FILE_NOT_FOUND
, "One Path in PACKAGES_PATH doesn't exist", ExtraData
=Path
)
126 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in PACKAGES_PATH", ExtraData
=Path
)
129 os
.environ
["EDK_TOOLS_PATH"] = os
.path
.normcase(os
.environ
["EDK_TOOLS_PATH"])
131 # check EDK_TOOLS_PATH
132 if "EDK_TOOLS_PATH" not in os
.environ
:
133 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "Environment variable not found",
134 ExtraData
="EDK_TOOLS_PATH")
137 if "PATH" not in os
.environ
:
138 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "Environment variable not found",
141 GlobalData
.gWorkspace
= WorkspaceDir
143 GlobalData
.gGlobalDefines
["WORKSPACE"] = WorkspaceDir
144 GlobalData
.gGlobalDefines
["EDK_TOOLS_PATH"] = os
.environ
["EDK_TOOLS_PATH"]
146 ## Get normalized file path
148 # Convert the path to be local format, and remove the WORKSPACE path at the
149 # beginning if the file path is given in full path.
151 # @param FilePath File path to be normalized
152 # @param Workspace Workspace path which the FilePath will be checked against
154 # @retval string The normalized file path
156 def NormFile(FilePath
, Workspace
):
157 # check if the path is absolute or relative
158 if os
.path
.isabs(FilePath
):
159 FileFullPath
= os
.path
.normpath(FilePath
)
161 FileFullPath
= os
.path
.normpath(mws
.join(Workspace
, FilePath
))
162 Workspace
= mws
.getWs(Workspace
, FilePath
)
164 # check if the file path exists or not
165 if not os
.path
.isfile(FileFullPath
):
166 EdkLogger
.error("build", FILE_NOT_FOUND
, ExtraData
="\t%s (Please give file in absolute path or relative to WORKSPACE)" % FileFullPath
)
168 # remove workspace directory from the beginning part of the file path
169 if Workspace
[-1] in ["\\", "/"]:
170 return FileFullPath
[len(Workspace
):]
172 return FileFullPath
[(len(Workspace
) + 1):]
174 ## Get the output of an external program
176 # This is the entrance method of thread reading output of an external program and
177 # putting them in STDOUT/STDERR of current program.
179 # @param From The stream message read from
180 # @param To The stream message put on
181 # @param ExitFlag The flag used to indicate stopping reading
183 def ReadMessage(From
, To
, ExitFlag
,MemTo
=None):
185 # read one line a time
186 Line
= From
.readline()
187 # empty string means "end"
188 if Line
is not None and Line
!= b
"":
189 LineStr
= Line
.rstrip().decode(encoding
='utf-8', errors
='ignore')
190 if MemTo
is not None:
191 if "Note: including file:" == LineStr
.lstrip()[:21]:
192 MemTo
.append(LineStr
)
195 MemTo
.append(LineStr
)
200 if ExitFlag
.is_set():
203 class MakeSubProc(Popen
):
204 def __init__(self
,*args
, **argv
):
205 super(MakeSubProc
,self
).__init
__(*args
, **argv
)
208 ## Launch an external program
210 # This method will call subprocess.Popen to execute an external program with
211 # given options in specified directory. Because of the dead-lock issue during
212 # redirecting output of the external program, threads are used to to do the
215 # @param Command A list or string containing the call of the program
216 # @param WorkingDir The directory in which the program will be running
218 def LaunchCommand(Command
, WorkingDir
,ModuleAuto
= None):
219 BeginTime
= time
.time()
220 # if working directory doesn't exist, Popen() will raise an exception
221 if not os
.path
.isdir(WorkingDir
):
222 EdkLogger
.error("build", FILE_NOT_FOUND
, ExtraData
=WorkingDir
)
224 # Command is used as the first Argument in following Popen().
225 # It could be a string or sequence. We find that if command is a string in following Popen(),
226 # ubuntu may fail with an error message that the command is not found.
227 # So here we may need convert command from string to list instance.
228 if platform
.system() != 'Windows':
229 if not isinstance(Command
, list):
230 Command
= Command
.split()
231 Command
= ' '.join(Command
)
234 EndOfProcedure
= None
237 Proc
= MakeSubProc(Command
, stdout
=PIPE
, stderr
=STDOUT
, env
=os
.environ
, cwd
=WorkingDir
, bufsize
=-1, shell
=True)
239 # launch two threads to read the STDOUT and STDERR
240 EndOfProcedure
= Event()
241 EndOfProcedure
.clear()
243 StdOutThread
= Thread(target
=ReadMessage
, args
=(Proc
.stdout
, EdkLogger
.info
, EndOfProcedure
,Proc
.ProcOut
))
244 StdOutThread
.name
= "STDOUT-Redirector"
245 StdOutThread
.daemon
= False
249 # waiting for program exit
251 except: # in case of aborting
252 # terminate the threads redirecting the program output
253 EdkLogger
.quiet("(Python %s on %s) " % (platform
.python_version(), sys
.platform
) + traceback
.format_exc())
254 if EndOfProcedure
is not None:
257 if not isinstance(Command
, type("")):
258 Command
= " ".join(Command
)
259 EdkLogger
.error("build", COMMAND_FAILURE
, "Failed to start command", ExtraData
="%s [%s]" % (Command
, WorkingDir
))
264 # check the return code of the program
265 if Proc
.returncode
!= 0:
266 if not isinstance(Command
, type("")):
267 Command
= " ".join(Command
)
268 # print out the Response file and its content when make failure
269 RespFile
= os
.path
.join(WorkingDir
, 'OUTPUT', 'respfilelist.txt')
270 if os
.path
.isfile(RespFile
):
272 RespContent
= f
.read()
274 EdkLogger
.info(RespContent
)
276 EdkLogger
.error("build", COMMAND_FAILURE
, ExtraData
="%s [%s]" % (Command
, WorkingDir
))
278 iau
= IncludesAutoGen(WorkingDir
,ModuleAuto
)
279 if ModuleAuto
.ToolChainFamily
== TAB_COMPILER_MSFT
:
280 iau
.CreateDepsFileForMsvc(Proc
.ProcOut
)
282 iau
.UpdateDepsFileforNonMsvc()
283 iau
.UpdateDepsFileforTrim()
284 iau
.CreateModuleDeps()
285 iau
.CreateDepsInclude()
286 iau
.CreateDepsTarget()
287 return "%dms" % (int(round((time
.time() - BeginTime
) * 1000)))
289 ## The smallest unit that can be built in multi-thread build mode
291 # This is the base class of build unit. The "Obj" parameter must provide
292 # __str__(), __eq__() and __hash__() methods. Otherwise there could be build units
295 # Currently the "Obj" should be only ModuleAutoGen or PlatformAutoGen objects.
300 # @param self The object pointer
301 # @param Obj The object the build is working on
302 # @param Target The build target name, one of gSupportedTarget
303 # @param Dependency The BuildUnit(s) which must be completed in advance
304 # @param WorkingDir The directory build command starts in
306 def __init__(self
, Obj
, BuildCommand
, Target
, Dependency
, WorkingDir
="."):
307 self
.BuildObject
= Obj
308 self
.Dependency
= Dependency
309 self
.WorkingDir
= WorkingDir
311 self
.BuildCommand
= BuildCommand
313 EdkLogger
.error("build", OPTION_MISSING
,
314 "No build command found for this module. "
315 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %
316 (Obj
.BuildTarget
, Obj
.ToolChain
, Obj
.Arch
),
322 # It just returns the string representation of self.BuildObject
324 # @param self The object pointer
327 return str(self
.BuildObject
)
329 ## "==" operator method
331 # It just compares self.BuildObject with "Other". So self.BuildObject must
332 # provide its own __eq__() method.
334 # @param self The object pointer
335 # @param Other The other BuildUnit object compared to
337 def __eq__(self
, Other
):
338 return Other
and self
.BuildObject
== Other
.BuildObject \
339 and Other
.BuildObject \
340 and self
.BuildObject
.Arch
== Other
.BuildObject
.Arch
344 # It just returns the hash value of self.BuildObject which must be hashable.
346 # @param self The object pointer
349 return hash(self
.BuildObject
) + hash(self
.BuildObject
.Arch
)
352 return repr(self
.BuildObject
)
354 ## The smallest module unit that can be built by nmake/make command in multi-thread build mode
356 # This class is for module build by nmake/make build system. The "Obj" parameter
357 # must provide __str__(), __eq__() and __hash__() methods. Otherwise there could
358 # be make units missing build.
360 # Currently the "Obj" should be only ModuleAutoGen object.
362 class ModuleMakeUnit(BuildUnit
):
365 # @param self The object pointer
366 # @param Obj The ModuleAutoGen object the build is working on
367 # @param Target The build target name, one of gSupportedTarget
369 def __init__(self
, Obj
, BuildCommand
,Target
):
370 Dependency
= [ModuleMakeUnit(La
, BuildCommand
,Target
) for La
in Obj
.LibraryAutoGenList
]
371 BuildUnit
.__init
__(self
, Obj
, BuildCommand
, Target
, Dependency
, Obj
.MakeFileDir
)
372 if Target
in [None, "", "all"]:
373 self
.Target
= "tbuild"
375 ## The smallest platform unit that can be built by nmake/make command in multi-thread build mode
377 # This class is for platform build by nmake/make build system. The "Obj" parameter
378 # must provide __str__(), __eq__() and __hash__() methods. Otherwise there could
379 # be make units missing build.
381 # Currently the "Obj" should be only PlatformAutoGen object.
383 class PlatformMakeUnit(BuildUnit
):
386 # @param self The object pointer
387 # @param Obj The PlatformAutoGen object the build is working on
388 # @param Target The build target name, one of gSupportedTarget
390 def __init__(self
, Obj
, BuildCommand
, Target
):
391 Dependency
= [ModuleMakeUnit(Lib
, BuildCommand
, Target
) for Lib
in self
.BuildObject
.LibraryAutoGenList
]
392 Dependency
.extend([ModuleMakeUnit(Mod
, BuildCommand
,Target
) for Mod
in self
.BuildObject
.ModuleAutoGenList
])
393 BuildUnit
.__init
__(self
, Obj
, BuildCommand
, Target
, Dependency
, Obj
.MakeFileDir
)
395 ## The class representing the task of a module build or platform build
397 # This class manages the build tasks in multi-thread build mode. Its jobs include
398 # scheduling thread running, catching thread error, monitor the thread status, etc.
401 # queue for tasks waiting for schedule
402 _PendingQueue
= OrderedDict()
403 _PendingQueueLock
= threading
.Lock()
405 # queue for tasks ready for running
406 _ReadyQueue
= OrderedDict()
407 _ReadyQueueLock
= threading
.Lock()
409 # queue for run tasks
410 _RunningQueue
= OrderedDict()
411 _RunningQueueLock
= threading
.Lock()
413 # queue containing all build tasks, in case duplicate build
414 _TaskQueue
= OrderedDict()
416 # flag indicating error occurs in a running thread
417 _ErrorFlag
= threading
.Event()
421 # BoundedSemaphore object used to control the number of running threads
424 # flag indicating if the scheduler is started or not
425 _SchedulerStopped
= threading
.Event()
426 _SchedulerStopped
.set()
428 ## Start the task scheduler thread
430 # @param MaxThreadNumber The maximum thread number
431 # @param ExitFlag Flag used to end the scheduler
434 def StartScheduler(MaxThreadNumber
, ExitFlag
):
435 SchedulerThread
= Thread(target
=BuildTask
.Scheduler
, args
=(MaxThreadNumber
, ExitFlag
))
436 SchedulerThread
.name
= "Build-Task-Scheduler"
437 SchedulerThread
.daemon
= False
438 SchedulerThread
.start()
439 # wait for the scheduler to be started, especially useful in Linux
440 while not BuildTask
.IsOnGoing():
445 # @param MaxThreadNumber The maximum thread number
446 # @param ExitFlag Flag used to end the scheduler
449 def Scheduler(MaxThreadNumber
, ExitFlag
):
450 BuildTask
._SchedulerStopped
.clear()
452 # use BoundedSemaphore to control the maximum running threads
453 BuildTask
._Thread
= BoundedSemaphore(MaxThreadNumber
)
455 # scheduling loop, which will exits when no pending/ready task and
456 # indicated to do so, or there's error in running thread
458 while (len(BuildTask
._PendingQueue
) > 0 or len(BuildTask
._ReadyQueue
) > 0 \
459 or not ExitFlag
.is_set()) and not BuildTask
._ErrorFlag
.is_set():
460 EdkLogger
.debug(EdkLogger
.DEBUG_8
, "Pending Queue (%d), Ready Queue (%d)"
461 % (len(BuildTask
._PendingQueue
), len(BuildTask
._ReadyQueue
)))
463 # get all pending tasks
464 BuildTask
._PendingQueueLock
.acquire()
465 BuildObjectList
= list(BuildTask
._PendingQueue
.keys())
467 # check if their dependency is resolved, and if true, move them
470 for BuildObject
in BuildObjectList
:
471 Bt
= BuildTask
._PendingQueue
[BuildObject
]
473 BuildTask
._ReadyQueue
[BuildObject
] = BuildTask
._PendingQueue
.pop(BuildObject
)
474 BuildTask
._PendingQueueLock
.release()
476 # launch build thread until the maximum number of threads is reached
477 while not BuildTask
._ErrorFlag
.is_set():
478 # empty ready queue, do nothing further
479 if len(BuildTask
._ReadyQueue
) == 0:
482 # wait for active thread(s) exit
483 BuildTask
._Thread
.acquire(True)
485 # start a new build thread
486 Bo
, Bt
= BuildTask
._ReadyQueue
.popitem()
488 # move into running queue
489 BuildTask
._RunningQueueLock
.acquire()
490 BuildTask
._RunningQueue
[Bo
] = Bt
491 BuildTask
._RunningQueueLock
.release()
500 # wait for all running threads exit
501 if BuildTask
._ErrorFlag
.is_set():
502 EdkLogger
.quiet("\nWaiting for all build threads exit...")
503 # while not BuildTask._ErrorFlag.is_set() and \
504 while len(BuildTask
._RunningQueue
) > 0:
505 EdkLogger
.verbose("Waiting for thread ending...(%d)" % len(BuildTask
._RunningQueue
))
506 EdkLogger
.debug(EdkLogger
.DEBUG_8
, "Threads [%s]" % ", ".join(Th
.name
for Th
in threading
.enumerate()))
509 except BaseException
as X
:
511 # TRICK: hide the output of threads left running, so that the user can
512 # catch the error message easily
514 EdkLogger
.SetLevel(EdkLogger
.ERROR
)
515 BuildTask
._ErrorFlag
.set()
516 BuildTask
._ErrorMessage
= "build thread scheduler error\n\t%s" % str(X
)
518 BuildTask
._PendingQueue
.clear()
519 BuildTask
._ReadyQueue
.clear()
520 BuildTask
._RunningQueue
.clear()
521 BuildTask
._TaskQueue
.clear()
522 BuildTask
._SchedulerStopped
.set()
524 ## Wait for all running method exit
527 def WaitForComplete():
528 BuildTask
._SchedulerStopped
.wait()
530 ## Check if the scheduler is running or not
534 return not BuildTask
._SchedulerStopped
.is_set()
539 if BuildTask
.IsOnGoing():
540 BuildTask
._ErrorFlag
.set()
541 BuildTask
.WaitForComplete()
543 ## Check if there's error in running thread
545 # Since the main thread cannot catch exceptions in other thread, we have to
546 # use threading.Event to communicate this formation to main thread.
550 return BuildTask
._ErrorFlag
.is_set()
552 ## Get error message in running thread
554 # Since the main thread cannot catch exceptions in other thread, we have to
555 # use a static variable to communicate this message to main thread.
558 def GetErrorMessage():
559 return BuildTask
._ErrorMessage
561 ## Factory method to create a BuildTask object
563 # This method will check if a module is building or has been built. And if
564 # true, just return the associated BuildTask object in the _TaskQueue. If
565 # not, create and return a new BuildTask object. The new BuildTask object
566 # will be appended to the _PendingQueue for scheduling later.
568 # @param BuildItem A BuildUnit object representing a build object
569 # @param Dependency The dependent build object of BuildItem
572 def New(BuildItem
, Dependency
=None):
573 if BuildItem
in BuildTask
._TaskQueue
:
574 Bt
= BuildTask
._TaskQueue
[BuildItem
]
578 Bt
._Init
(BuildItem
, Dependency
)
579 BuildTask
._TaskQueue
[BuildItem
] = Bt
581 BuildTask
._PendingQueueLock
.acquire()
582 BuildTask
._PendingQueue
[BuildItem
] = Bt
583 BuildTask
._PendingQueueLock
.release()
587 ## The real constructor of BuildTask
589 # @param BuildItem A BuildUnit object representing a build object
590 # @param Dependency The dependent build object of BuildItem
592 def _Init(self
, BuildItem
, Dependency
=None):
593 self
.BuildItem
= BuildItem
595 self
.DependencyList
= []
596 if Dependency
is None:
597 Dependency
= BuildItem
.Dependency
599 Dependency
.extend(BuildItem
.Dependency
)
600 self
.AddDependency(Dependency
)
601 # flag indicating build completes, used to avoid unnecessary re-build
602 self
.CompleteFlag
= False
604 ## Check if all dependent build tasks are completed or not
608 for Dep
in self
.DependencyList
:
609 if Dep
.CompleteFlag
== True:
616 ## Add dependent build task
618 # @param Dependency The list of dependent build objects
620 def AddDependency(self
, Dependency
):
621 for Dep
in Dependency
:
622 if not Dep
.BuildObject
.IsBinaryModule
and not Dep
.BuildObject
.CanSkipbyCache(GlobalData
.gModuleCacheHit
):
623 self
.DependencyList
.append(BuildTask
.New(Dep
)) # BuildTask list
625 ## The thread wrapper of LaunchCommand function
627 # @param Command A list or string contains the call of the command
628 # @param WorkingDir The directory in which the program will be running
630 def _CommandThread(self
, Command
, WorkingDir
):
632 self
.BuildItem
.BuildObject
.BuildTime
= LaunchCommand(Command
, WorkingDir
,self
.BuildItem
.BuildObject
)
633 self
.CompleteFlag
= True
635 # Run hash operation post dependency to account for libs
636 # Run if --hash or --binary-destination
637 if GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheSource
:
638 self
.BuildItem
.BuildObject
.GenModuleHash()
639 if GlobalData
.gBinCacheDest
:
640 self
.BuildItem
.BuildObject
.GenCMakeHash()
644 # TRICK: hide the output of threads left running, so that the user can
645 # catch the error message easily
647 if not BuildTask
._ErrorFlag
.is_set():
648 GlobalData
.gBuildingModule
= "%s [%s, %s, %s]" % (str(self
.BuildItem
.BuildObject
),
649 self
.BuildItem
.BuildObject
.Arch
,
650 self
.BuildItem
.BuildObject
.ToolChain
,
651 self
.BuildItem
.BuildObject
.BuildTarget
653 EdkLogger
.SetLevel(EdkLogger
.ERROR
)
654 BuildTask
._ErrorFlag
.set()
655 BuildTask
._ErrorMessage
= "%s broken\n %s [%s]" % \
656 (threading
.current_thread().name
, Command
, WorkingDir
)
658 # indicate there's a thread is available for another build task
659 BuildTask
._RunningQueueLock
.acquire()
660 BuildTask
._RunningQueue
.pop(self
.BuildItem
)
661 BuildTask
._RunningQueueLock
.release()
662 BuildTask
._Thread
.release()
664 ## Start build task thread
667 EdkLogger
.quiet("Building ... %s" % repr(self
.BuildItem
))
668 Command
= self
.BuildItem
.BuildCommand
+ [self
.BuildItem
.Target
]
669 self
.BuildTread
= Thread(target
=self
._CommandThread
, args
=(Command
, self
.BuildItem
.WorkingDir
))
670 self
.BuildTread
.name
= "build thread"
671 self
.BuildTread
.daemon
= False
672 self
.BuildTread
.start()
674 ## The class contains the information related to EFI image
679 # Constructor will load all required image information.
681 # @param BaseName The full file path of image.
682 # @param Guid The GUID for image.
683 # @param Arch Arch of this image.
684 # @param OutputDir The output directory for image.
685 # @param DebugDir The debug directory for image.
686 # @param ImageClass PeImage Information
688 def __init__(self
, BaseName
, Guid
, Arch
, OutputDir
, DebugDir
, ImageClass
):
689 self
.BaseName
= BaseName
692 self
.OutputDir
= OutputDir
693 self
.DebugDir
= DebugDir
694 self
.Image
= ImageClass
695 self
.Image
.Size
= (self
.Image
.Size
// 0x1000 + 1) * 0x1000
697 ## The class implementing the EDK2 build process
699 # The build process includes:
700 # 1. Load configuration from target.txt and tools_def.txt in $(WORKSPACE)/Conf
701 # 2. Parse DSC file of active platform
702 # 3. Parse FDF file if any
703 # 4. Establish build database, including parse all other files (module, package)
704 # 5. Create AutoGen files (C code file, depex file, makefile) if necessary
705 # 6. Call build command
710 # Constructor will load all necessary configurations, parse platform, modules
711 # and packages and the establish a database for AutoGen.
713 # @param Target The build command target, one of gSupportedTarget
714 # @param WorkspaceDir The directory of workspace
715 # @param BuildOptions Build options passed from command line
717 def __init__(self
, Target
, WorkspaceDir
, BuildOptions
,log_q
):
718 self
.WorkspaceDir
= WorkspaceDir
720 self
.PlatformFile
= BuildOptions
.PlatformFile
721 self
.ModuleFile
= BuildOptions
.ModuleFile
722 self
.ArchList
= BuildOptions
.TargetArch
723 self
.ToolChainList
= BuildOptions
.ToolChain
724 self
.BuildTargetList
= BuildOptions
.BuildTarget
725 self
.Fdf
= BuildOptions
.FdfFile
726 self
.FdList
= BuildOptions
.RomImage
727 self
.FvList
= BuildOptions
.FvImage
728 self
.CapList
= BuildOptions
.CapName
729 self
.SilentMode
= BuildOptions
.SilentMode
730 self
.ThreadNumber
= 1
731 self
.SkipAutoGen
= BuildOptions
.SkipAutoGen
732 self
.Reparse
= BuildOptions
.Reparse
733 self
.SkuId
= BuildOptions
.SkuId
735 GlobalData
.gSKUID_CMD
= self
.SkuId
736 self
.ConfDirectory
= BuildOptions
.ConfDirectory
737 self
.SpawnMode
= True
738 self
.BuildReport
= BuildReport(BuildOptions
.ReportFile
, BuildOptions
.ReportType
)
742 self
.MakeFileName
= ""
743 TargetObj
= TargetTxtDict()
744 ToolDefObj
= ToolDefDict((os
.path
.join(os
.getenv("WORKSPACE"),"Conf")))
745 self
.TargetTxt
= TargetObj
.Target
746 self
.ToolDef
= ToolDefObj
.ToolDef
747 GlobalData
.BuildOptionPcd
= BuildOptions
.OptionPcd
if BuildOptions
.OptionPcd
else []
748 #Set global flag for build mode
749 GlobalData
.gIgnoreSource
= BuildOptions
.IgnoreSources
750 GlobalData
.gUseHashCache
= BuildOptions
.UseHashCache
751 GlobalData
.gBinCacheDest
= BuildOptions
.BinCacheDest
752 GlobalData
.gBinCacheSource
= BuildOptions
.BinCacheSource
753 GlobalData
.gEnableGenfdsMultiThread
= not BuildOptions
.NoGenfdsMultiThread
754 GlobalData
.gDisableIncludePathCheck
= BuildOptions
.DisableIncludePathCheck
756 if GlobalData
.gBinCacheDest
and not GlobalData
.gUseHashCache
:
757 EdkLogger
.error("build", OPTION_NOT_SUPPORTED
, ExtraData
="--binary-destination must be used together with --hash.")
759 if GlobalData
.gBinCacheSource
and not GlobalData
.gUseHashCache
:
760 EdkLogger
.error("build", OPTION_NOT_SUPPORTED
, ExtraData
="--binary-source must be used together with --hash.")
762 if GlobalData
.gBinCacheDest
and GlobalData
.gBinCacheSource
:
763 EdkLogger
.error("build", OPTION_NOT_SUPPORTED
, ExtraData
="--binary-destination can not be used together with --binary-source.")
765 if GlobalData
.gBinCacheSource
:
766 BinCacheSource
= os
.path
.normpath(GlobalData
.gBinCacheSource
)
767 if not os
.path
.isabs(BinCacheSource
):
768 BinCacheSource
= mws
.join(self
.WorkspaceDir
, BinCacheSource
)
769 GlobalData
.gBinCacheSource
= BinCacheSource
771 if GlobalData
.gBinCacheSource
is not None:
772 EdkLogger
.error("build", OPTION_VALUE_INVALID
, ExtraData
="Invalid value of option --binary-source.")
774 if GlobalData
.gBinCacheDest
:
775 BinCacheDest
= os
.path
.normpath(GlobalData
.gBinCacheDest
)
776 if not os
.path
.isabs(BinCacheDest
):
777 BinCacheDest
= mws
.join(self
.WorkspaceDir
, BinCacheDest
)
778 GlobalData
.gBinCacheDest
= BinCacheDest
780 if GlobalData
.gBinCacheDest
is not None:
781 EdkLogger
.error("build", OPTION_VALUE_INVALID
, ExtraData
="Invalid value of option --binary-destination.")
783 GlobalData
.gDatabasePath
= os
.path
.normpath(os
.path
.join(GlobalData
.gConfDirectory
, GlobalData
.gDatabasePath
))
784 if not os
.path
.exists(os
.path
.join(GlobalData
.gConfDirectory
, '.cache')):
785 os
.makedirs(os
.path
.join(GlobalData
.gConfDirectory
, '.cache'))
787 self
.BuildDatabase
= self
.Db
.BuildObject
789 self
.ToolChainFamily
= None
790 self
.LoadFixAddress
= 0
791 self
.UniFlag
= BuildOptions
.Flag
792 self
.BuildModules
= []
793 self
.HashSkipModules
= []
795 self
.LaunchPrebuildFlag
= False
796 self
.PlatformBuildPath
= os
.path
.join(GlobalData
.gConfDirectory
, '.cache', '.PlatformBuild')
797 if BuildOptions
.CommandLength
:
798 GlobalData
.gCommandMaxLength
= BuildOptions
.CommandLength
800 # print dot character during doing some time-consuming work
801 self
.Progress
= Utils
.Progressor()
802 # print current build environment and configuration
803 EdkLogger
.quiet("%-16s = %s" % ("WORKSPACE", os
.environ
["WORKSPACE"]))
804 if "PACKAGES_PATH" in os
.environ
:
805 # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env.
806 EdkLogger
.quiet("%-16s = %s" % ("PACKAGES_PATH", os
.path
.normcase(os
.path
.normpath(os
.environ
["PACKAGES_PATH"]))))
807 EdkLogger
.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os
.environ
["EDK_TOOLS_PATH"]))
808 if "EDK_TOOLS_BIN" in os
.environ
:
809 # Print the same path style with WORKSPACE env.
810 EdkLogger
.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os
.path
.normcase(os
.path
.normpath(os
.environ
["EDK_TOOLS_BIN"]))))
811 EdkLogger
.quiet("%-16s = %s" % ("CONF_PATH", GlobalData
.gConfDirectory
))
812 if "PYTHON3_ENABLE" in os
.environ
:
813 PYTHON3_ENABLE
= os
.environ
["PYTHON3_ENABLE"]
814 if PYTHON3_ENABLE
!= "TRUE":
815 PYTHON3_ENABLE
= "FALSE"
816 EdkLogger
.quiet("%-16s = %s" % ("PYTHON3_ENABLE", PYTHON3_ENABLE
))
817 if "PYTHON_COMMAND" in os
.environ
:
818 EdkLogger
.quiet("%-16s = %s" % ("PYTHON_COMMAND", os
.environ
["PYTHON_COMMAND"]))
822 EdkLogger
.quiet("%-16s = %s" % ("PREBUILD", self
.Prebuild
))
824 EdkLogger
.quiet("%-16s = %s" % ("POSTBUILD", self
.Postbuild
))
826 self
.LaunchPrebuild()
827 TargetObj
= TargetTxtDict()
828 ToolDefObj
= ToolDefDict((os
.path
.join(os
.getenv("WORKSPACE"), "Conf")))
829 self
.TargetTxt
= TargetObj
.Target
830 self
.ToolDef
= ToolDefObj
.ToolDef
831 if not (self
.LaunchPrebuildFlag
and os
.path
.exists(self
.PlatformBuildPath
)):
834 self
.AutoGenMgr
= None
836 os
.chdir(self
.WorkspaceDir
)
838 GlobalData
.file_lock
= mp
.Lock()
839 # Init cache data for local only
840 GlobalData
.gPackageHashFile
= dict()
841 GlobalData
.gModulePreMakeCacheStatus
= dict()
842 GlobalData
.gModuleMakeCacheStatus
= dict()
843 GlobalData
.gHashChainStatus
= dict()
844 GlobalData
.gCMakeHashFile
= dict()
845 GlobalData
.gModuleHashFile
= dict()
846 GlobalData
.gFileHashDict
= dict()
847 GlobalData
.gModuleAllCacheStatus
= set()
848 GlobalData
.gModuleCacheHit
= set()
850 def StartAutoGen(self
,mqueue
, DataPipe
,SkipAutoGen
,PcdMaList
,cqueue
):
854 feedback_q
= mp
.Queue()
855 error_event
= mp
.Event()
856 FfsCmd
= DataPipe
.Get("FfsCommand")
859 GlobalData
.FfsCmd
= FfsCmd
860 auto_workers
= [AutoGenWorkerInProcess(mqueue
,DataPipe
.dump_file
,feedback_q
,GlobalData
.file_lock
,cqueue
,self
.log_q
,error_event
) for _
in range(self
.ThreadNumber
)]
861 self
.AutoGenMgr
= AutoGenManager(auto_workers
,feedback_q
,error_event
)
862 self
.AutoGenMgr
.start()
863 for w
in auto_workers
:
865 if PcdMaList
is not None:
866 for PcdMa
in PcdMaList
:
867 # SourceFileList calling sequence impact the makefile string sequence.
868 # Create cached SourceFileList here to unify its calling sequence for both
869 # CanSkipbyPreMakeCache and CreateCodeFile/CreateMakeFile.
870 RetVal
= PcdMa
.SourceFileList
871 # Force cache miss for PCD driver
872 if GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheDest
and self
.Target
in [None, "", "all"]:
873 cqueue
.put((PcdMa
.MetaFile
.Path
, PcdMa
.Arch
, "PreMakeCache", False))
875 PcdMa
.CreateCodeFile(False)
876 PcdMa
.CreateMakeFile(False,GenFfsList
= DataPipe
.Get("FfsCommand").get((PcdMa
.MetaFile
.Path
, PcdMa
.Arch
),[]))
877 PcdMa
.CreateAsBuiltInf()
878 # Force cache miss for PCD driver
879 if GlobalData
.gBinCacheSource
and self
.Target
in [None, "", "all"]:
880 cqueue
.put((PcdMa
.MetaFile
.Path
, PcdMa
.Arch
, "MakeCache", False))
882 self
.AutoGenMgr
.join()
883 rt
= self
.AutoGenMgr
.Status
888 except FatalError
as e
:
889 return False, e
.args
[0]
891 return False, UNKNOWN_ERROR
893 ## Add TOOLCHAIN and FAMILY declared in DSC [BuildOptions] to ToolsDefTxtDatabase.
895 # Loop through the set of build targets, tool chains, and archs provided on either
896 # the command line or in target.txt to discover FAMILY and TOOLCHAIN delclarations
897 # in [BuildOptions] sections that may be within !if expressions that may use
898 # $(TARGET), $(TOOLCHAIN), $(TOOLCHAIN_TAG), or $(ARCH) operands.
900 def GetToolChainAndFamilyFromDsc (self
, File
):
901 SavedGlobalDefines
= GlobalData
.gGlobalDefines
.copy()
902 for BuildTarget
in self
.BuildTargetList
:
903 GlobalData
.gGlobalDefines
['TARGET'] = BuildTarget
904 for BuildToolChain
in self
.ToolChainList
:
905 GlobalData
.gGlobalDefines
['TOOLCHAIN'] = BuildToolChain
906 GlobalData
.gGlobalDefines
['TOOL_CHAIN_TAG'] = BuildToolChain
907 for BuildArch
in self
.ArchList
:
908 GlobalData
.gGlobalDefines
['ARCH'] = BuildArch
909 dscobj
= self
.BuildDatabase
[File
, BuildArch
]
910 for KeyFamily
, Key
, KeyCodeBase
in dscobj
.BuildOptions
:
912 Target
, ToolChain
, Arch
, Tool
, Attr
= Key
.split('_')
915 if ToolChain
== TAB_STAR
or Attr
!= TAB_TOD_DEFINES_FAMILY
:
918 Family
= dscobj
.BuildOptions
[(KeyFamily
, Key
, KeyCodeBase
)]
919 Family
= Family
.strip().strip('=').strip()
922 if TAB_TOD_DEFINES_FAMILY
not in self
.ToolDef
.ToolsDefTxtDatabase
:
923 self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_FAMILY
] = {}
924 if ToolChain
not in self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_FAMILY
]:
925 self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_FAMILY
][ToolChain
] = Family
926 if TAB_TOD_DEFINES_BUILDRULEFAMILY
not in self
.ToolDef
.ToolsDefTxtDatabase
:
927 self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_BUILDRULEFAMILY
] = {}
928 if ToolChain
not in self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_BUILDRULEFAMILY
]:
929 self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_BUILDRULEFAMILY
][ToolChain
] = Family
930 if TAB_TOD_DEFINES_TOOL_CHAIN_TAG
not in self
.ToolDef
.ToolsDefTxtDatabase
:
931 self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_TOOL_CHAIN_TAG
] = []
932 if ToolChain
not in self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_TOOL_CHAIN_TAG
]:
933 self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_TOOL_CHAIN_TAG
].append(ToolChain
)
934 GlobalData
.gGlobalDefines
= SavedGlobalDefines
936 ## Load configuration
938 # This method will parse target.txt and get the build configurations.
940 def LoadConfiguration(self
):
942 # if no ARCH given in command line, get it from target.txt
943 if not self
.ArchList
:
944 self
.ArchList
= self
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_TARGET_ARCH
]
945 self
.ArchList
= tuple(self
.ArchList
)
947 # if no build target given in command line, get it from target.txt
948 if not self
.BuildTargetList
:
949 self
.BuildTargetList
= self
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_TARGET
]
951 # if no tool chain given in command line, get it from target.txt
952 if not self
.ToolChainList
:
953 self
.ToolChainList
= self
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_TOOL_CHAIN_TAG
]
954 if self
.ToolChainList
is None or len(self
.ToolChainList
) == 0:
955 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
, ExtraData
="No toolchain given. Don't know how to build.\n")
957 if not self
.PlatformFile
:
958 PlatformFile
= self
.TargetTxt
.TargetTxtDictionary
[TAB_TAT_DEFINES_ACTIVE_PLATFORM
]
960 # Try to find one in current directory
961 WorkingDirectory
= os
.getcwd()
962 FileList
= glob
.glob(os
.path
.normpath(os
.path
.join(WorkingDirectory
, '*.dsc')))
963 FileNum
= len(FileList
)
965 EdkLogger
.error("build", OPTION_MISSING
,
966 ExtraData
="There are %d DSC files in %s. Use '-p' to specify one.\n" % (FileNum
, WorkingDirectory
))
968 PlatformFile
= FileList
[0]
970 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
971 ExtraData
="No active platform specified in target.txt or command line! Nothing can be built.\n")
973 self
.PlatformFile
= PathClass(NormFile(PlatformFile
, self
.WorkspaceDir
), self
.WorkspaceDir
)
975 self
.GetToolChainAndFamilyFromDsc (self
.PlatformFile
)
977 # check if the tool chains are defined or not
978 NewToolChainList
= []
979 for ToolChain
in self
.ToolChainList
:
980 if ToolChain
not in self
.ToolDef
.ToolsDefTxtDatabase
[TAB_TOD_DEFINES_TOOL_CHAIN_TAG
]:
981 EdkLogger
.warn("build", "Tool chain [%s] is not defined" % ToolChain
)
983 NewToolChainList
.append(ToolChain
)
984 # if no tool chain available, break the build
985 if len(NewToolChainList
) == 0:
986 EdkLogger
.error("build", RESOURCE_NOT_AVAILABLE
,
987 ExtraData
="[%s] not defined. No toolchain available for build!\n" % ", ".join(self
.ToolChainList
))
989 self
.ToolChainList
= NewToolChainList
992 ToolDefinition
= self
.ToolDef
.ToolsDefTxtDatabase
993 for Tool
in self
.ToolChainList
:
994 if TAB_TOD_DEFINES_FAMILY
not in ToolDefinition
or Tool
not in ToolDefinition
[TAB_TOD_DEFINES_FAMILY
] \
995 or not ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][Tool
]:
996 EdkLogger
.warn("build", "No tool chain family found in configuration for %s. Default to MSFT." % Tool
)
997 ToolChainFamily
.append(TAB_COMPILER_MSFT
)
999 ToolChainFamily
.append(ToolDefinition
[TAB_TOD_DEFINES_FAMILY
][Tool
])
1000 self
.ToolChainFamily
= ToolChainFamily
1002 self
.ThreadNumber
= ThreadNum()
1003 ## Initialize build configuration
1005 # This method will parse DSC file and merge the configurations from
1006 # command line and target.txt, then get the final build configurations.
1008 def InitBuild(self
):
1009 # parse target.txt, tools_def.txt, and platform file
1010 self
.LoadConfiguration()
1012 # Allow case-insensitive for those from command line or configuration file
1013 ErrorCode
, ErrorInfo
= self
.PlatformFile
.Validate(".dsc", False)
1015 EdkLogger
.error("build", ErrorCode
, ExtraData
=ErrorInfo
)
1018 def InitPreBuild(self
):
1019 self
.LoadConfiguration()
1020 ErrorCode
, ErrorInfo
= self
.PlatformFile
.Validate(".dsc", False)
1022 EdkLogger
.error("build", ErrorCode
, ExtraData
=ErrorInfo
)
1023 if self
.BuildTargetList
:
1024 GlobalData
.gGlobalDefines
['TARGET'] = self
.BuildTargetList
[0]
1026 GlobalData
.gGlobalDefines
['ARCH'] = self
.ArchList
[0]
1027 if self
.ToolChainList
:
1028 GlobalData
.gGlobalDefines
['TOOLCHAIN'] = self
.ToolChainList
[0]
1029 GlobalData
.gGlobalDefines
['TOOL_CHAIN_TAG'] = self
.ToolChainList
[0]
1030 if self
.ToolChainFamily
:
1031 GlobalData
.gGlobalDefines
['FAMILY'] = self
.ToolChainFamily
[0]
1032 if 'PREBUILD' in GlobalData
.gCommandLineDefines
:
1033 self
.Prebuild
= GlobalData
.gCommandLineDefines
.get('PREBUILD')
1036 Platform
= self
.Db
.MapPlatform(str(self
.PlatformFile
))
1037 self
.Prebuild
= str(Platform
.Prebuild
)
1041 # Evaluate all arguments and convert arguments that are WORKSPACE
1042 # relative paths to absolute paths. Filter arguments that look like
1043 # flags or do not follow the file/dir naming rules to avoid false
1044 # positives on this conversion.
1046 for Arg
in self
.Prebuild
.split():
1048 # Do not modify Arg if it looks like a flag or an absolute file path
1050 if Arg
.startswith('-') or os
.path
.isabs(Arg
):
1051 PrebuildList
.append(Arg
)
1054 # Do not modify Arg if it does not look like a Workspace relative
1055 # path that starts with a valid package directory name
1057 if not Arg
[0].isalpha() or os
.path
.dirname(Arg
) == '':
1058 PrebuildList
.append(Arg
)
1061 # If Arg looks like a WORKSPACE relative path, then convert to an
1062 # absolute path and check to see if the file exists.
1064 Temp
= mws
.join(self
.WorkspaceDir
, Arg
)
1065 if os
.path
.isfile(Temp
):
1067 PrebuildList
.append(Arg
)
1068 self
.Prebuild
= ' '.join(PrebuildList
)
1069 self
.Prebuild
+= self
.PassCommandOption(self
.BuildTargetList
, self
.ArchList
, self
.ToolChainList
, self
.PlatformFile
, self
.Target
)
1071 def InitPostBuild(self
):
1072 if 'POSTBUILD' in GlobalData
.gCommandLineDefines
:
1073 self
.Postbuild
= GlobalData
.gCommandLineDefines
.get('POSTBUILD')
1075 Platform
= self
.Db
.MapPlatform(str(self
.PlatformFile
))
1076 self
.Postbuild
= str(Platform
.Postbuild
)
1080 # Evaluate all arguments and convert arguments that are WORKSPACE
1081 # relative paths to absolute paths. Filter arguments that look like
1082 # flags or do not follow the file/dir naming rules to avoid false
1083 # positives on this conversion.
1085 for Arg
in self
.Postbuild
.split():
1087 # Do not modify Arg if it looks like a flag or an absolute file path
1089 if Arg
.startswith('-') or os
.path
.isabs(Arg
):
1090 PostbuildList
.append(Arg
)
1093 # Do not modify Arg if it does not look like a Workspace relative
1094 # path that starts with a valid package directory name
1096 if not Arg
[0].isalpha() or os
.path
.dirname(Arg
) == '':
1097 PostbuildList
.append(Arg
)
1100 # If Arg looks like a WORKSPACE relative path, then convert to an
1101 # absolute path and check to see if the file exists.
1103 Temp
= mws
.join(self
.WorkspaceDir
, Arg
)
1104 if os
.path
.isfile(Temp
):
1106 PostbuildList
.append(Arg
)
1107 self
.Postbuild
= ' '.join(PostbuildList
)
1108 self
.Postbuild
+= self
.PassCommandOption(self
.BuildTargetList
, self
.ArchList
, self
.ToolChainList
, self
.PlatformFile
, self
.Target
)
1110 def PassCommandOption(self
, BuildTarget
, TargetArch
, ToolChain
, PlatformFile
, Target
):
1112 if GlobalData
.gCommand
and isinstance(GlobalData
.gCommand
, list):
1113 BuildStr
+= ' ' + ' '.join(GlobalData
.gCommand
)
1116 ToolChainFlag
= False
1117 PlatformFileFlag
= False
1119 if GlobalData
.gOptions
and not GlobalData
.gOptions
.BuildTarget
:
1121 if GlobalData
.gOptions
and not GlobalData
.gOptions
.TargetArch
:
1123 if GlobalData
.gOptions
and not GlobalData
.gOptions
.ToolChain
:
1124 ToolChainFlag
= True
1125 if GlobalData
.gOptions
and not GlobalData
.gOptions
.PlatformFile
:
1126 PlatformFileFlag
= True
1128 if TargetFlag
and BuildTarget
:
1129 if isinstance(BuildTarget
, list) or isinstance(BuildTarget
, tuple):
1130 BuildStr
+= ' -b ' + ' -b '.join(BuildTarget
)
1131 elif isinstance(BuildTarget
, str):
1132 BuildStr
+= ' -b ' + BuildTarget
1133 if ArchFlag
and TargetArch
:
1134 if isinstance(TargetArch
, list) or isinstance(TargetArch
, tuple):
1135 BuildStr
+= ' -a ' + ' -a '.join(TargetArch
)
1136 elif isinstance(TargetArch
, str):
1137 BuildStr
+= ' -a ' + TargetArch
1138 if ToolChainFlag
and ToolChain
:
1139 if isinstance(ToolChain
, list) or isinstance(ToolChain
, tuple):
1140 BuildStr
+= ' -t ' + ' -t '.join(ToolChain
)
1141 elif isinstance(ToolChain
, str):
1142 BuildStr
+= ' -t ' + ToolChain
1143 if PlatformFileFlag
and PlatformFile
:
1144 if isinstance(PlatformFile
, list) or isinstance(PlatformFile
, tuple):
1145 BuildStr
+= ' -p ' + ' -p '.join(PlatformFile
)
1146 elif isinstance(PlatformFile
, str):
1147 BuildStr
+= ' -p' + PlatformFile
1148 BuildStr
+= ' --conf=' + GlobalData
.gConfDirectory
1150 BuildStr
+= ' ' + Target
1154 def LaunchPrebuild(self
):
1156 EdkLogger
.info("\n- Prebuild Start -\n")
1157 self
.LaunchPrebuildFlag
= True
1159 # The purpose of .PrebuildEnv file is capture environment variable settings set by the prebuild script
1160 # and preserve them for the rest of the main build step, because the child process environment will
1161 # evaporate as soon as it exits, we cannot get it in build step.
1163 PrebuildEnvFile
= os
.path
.join(GlobalData
.gConfDirectory
, '.cache', '.PrebuildEnv')
1164 if os
.path
.isfile(PrebuildEnvFile
):
1165 os
.remove(PrebuildEnvFile
)
1166 if os
.path
.isfile(self
.PlatformBuildPath
):
1167 os
.remove(self
.PlatformBuildPath
)
1168 if sys
.platform
== "win32":
1169 args
= ' && '.join((self
.Prebuild
, 'set > ' + PrebuildEnvFile
))
1170 Process
= Popen(args
, stdout
=PIPE
, stderr
=PIPE
, shell
=True)
1172 args
= ' && '.join((self
.Prebuild
, 'env > ' + PrebuildEnvFile
))
1173 Process
= Popen(args
, stdout
=PIPE
, stderr
=PIPE
, shell
=True)
1175 # launch two threads to read the STDOUT and STDERR
1176 EndOfProcedure
= Event()
1177 EndOfProcedure
.clear()
1179 StdOutThread
= Thread(target
=ReadMessage
, args
=(Process
.stdout
, EdkLogger
.info
, EndOfProcedure
))
1180 StdOutThread
.name
= "STDOUT-Redirector"
1181 StdOutThread
.daemon
= False
1182 StdOutThread
.start()
1185 StdErrThread
= Thread(target
=ReadMessage
, args
=(Process
.stderr
, EdkLogger
.quiet
, EndOfProcedure
))
1186 StdErrThread
.name
= "STDERR-Redirector"
1187 StdErrThread
.daemon
= False
1188 StdErrThread
.start()
1189 # waiting for program exit
1196 if Process
.returncode
!= 0 :
1197 EdkLogger
.error("Prebuild", PREBUILD_ERROR
, 'Prebuild process is not success!')
1199 if os
.path
.exists(PrebuildEnvFile
):
1200 f
= open(PrebuildEnvFile
)
1201 envs
= f
.readlines()
1203 envs
= [l
.split("=", 1) for l
in envs
]
1204 envs
= [[I
.strip() for I
in item
] for item
in envs
if len(item
) == 2]
1205 os
.environ
.update(dict(envs
))
1206 EdkLogger
.info("\n- Prebuild Done -\n")
1208 def LaunchPostbuild(self
):
1210 EdkLogger
.info("\n- Postbuild Start -\n")
1211 if sys
.platform
== "win32":
1212 Process
= Popen(self
.Postbuild
, stdout
=PIPE
, stderr
=PIPE
, shell
=True)
1214 Process
= Popen(self
.Postbuild
, stdout
=PIPE
, stderr
=PIPE
, shell
=True)
1215 # launch two threads to read the STDOUT and STDERR
1216 EndOfProcedure
= Event()
1217 EndOfProcedure
.clear()
1219 StdOutThread
= Thread(target
=ReadMessage
, args
=(Process
.stdout
, EdkLogger
.info
, EndOfProcedure
))
1220 StdOutThread
.name
= "STDOUT-Redirector"
1221 StdOutThread
.daemon
= False
1222 StdOutThread
.start()
1225 StdErrThread
= Thread(target
=ReadMessage
, args
=(Process
.stderr
, EdkLogger
.quiet
, EndOfProcedure
))
1226 StdErrThread
.name
= "STDERR-Redirector"
1227 StdErrThread
.daemon
= False
1228 StdErrThread
.start()
1229 # waiting for program exit
1236 if Process
.returncode
!= 0 :
1237 EdkLogger
.error("Postbuild", POSTBUILD_ERROR
, 'Postbuild process is not success!')
1238 EdkLogger
.info("\n- Postbuild Done -\n")
1240 ## Build a module or platform
1242 # Create autogen code and makefile for a module or platform, and the launch
1243 # "make" command to build it
1245 # @param Target The target of build command
1246 # @param Platform The platform file
1247 # @param Module The module file
1248 # @param BuildTarget The name of build target, one of "DEBUG", "RELEASE"
1249 # @param ToolChain The name of toolchain to build
1250 # @param Arch The arch of the module/platform
1251 # @param CreateDepModuleCodeFile Flag used to indicate creating code
1252 # for dependent modules/Libraries
1253 # @param CreateDepModuleMakeFile Flag used to indicate creating makefile
1254 # for dependent modules/Libraries
1256 def _BuildPa(self
, Target
, AutoGenObject
, CreateDepsCodeFile
=True, CreateDepsMakeFile
=True, BuildModule
=False, FfsCommand
=None, PcdMaList
=None):
1257 if AutoGenObject
is None:
1259 if FfsCommand
is None:
1261 # skip file generation for cleanxxx targets, run and fds target
1262 if Target
not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:
1263 # for target which must generate AutoGen code and makefile
1265 for m
in AutoGenObject
.GetAllModuleInfo
:
1267 mqueue
.put((None,None,None,None,None,None,None))
1268 AutoGenObject
.DataPipe
.DataContainer
= {"CommandTarget": self
.Target
}
1269 AutoGenObject
.DataPipe
.DataContainer
= {"Workspace_timestamp": AutoGenObject
.Workspace
._SrcTimeStamp
}
1270 AutoGenObject
.CreateLibModuelDirs()
1271 AutoGenObject
.DataPipe
.DataContainer
= {"LibraryBuildDirectoryList":AutoGenObject
.LibraryBuildDirectoryList
}
1272 AutoGenObject
.DataPipe
.DataContainer
= {"ModuleBuildDirectoryList":AutoGenObject
.ModuleBuildDirectoryList
}
1273 AutoGenObject
.DataPipe
.DataContainer
= {"FdsCommandDict": AutoGenObject
.Workspace
.GenFdsCommandDict
}
1274 self
.Progress
.Start("Generating makefile and code")
1275 data_pipe_file
= os
.path
.join(AutoGenObject
.BuildDir
, "GlobalVar_%s_%s.bin" % (str(AutoGenObject
.Guid
),AutoGenObject
.Arch
))
1276 AutoGenObject
.DataPipe
.dump(data_pipe_file
)
1278 autogen_rt
,errorcode
= self
.StartAutoGen(mqueue
, AutoGenObject
.DataPipe
, self
.SkipAutoGen
, PcdMaList
, cqueue
)
1279 AutoGenIdFile
= os
.path
.join(GlobalData
.gConfDirectory
,".AutoGenIdFile.txt")
1280 with
open(AutoGenIdFile
,"w") as fw
:
1281 fw
.write("Arch=%s\n" % "|".join((AutoGenObject
.Workspace
.ArchList
)))
1282 fw
.write("BuildDir=%s\n" % AutoGenObject
.Workspace
.BuildDir
)
1283 fw
.write("PlatformGuid=%s\n" % str(AutoGenObject
.Guid
))
1284 self
.Progress
.Stop("done!")
1286 self
.AutoGenMgr
.TerminateWorkers()
1287 self
.AutoGenMgr
.join(1)
1288 raise FatalError(errorcode
)
1289 AutoGenObject
.CreateCodeFile(False)
1290 AutoGenObject
.CreateMakeFile(False)
1292 # always recreate top/platform makefile when clean, just in case of inconsistency
1293 AutoGenObject
.CreateCodeFile(True)
1294 AutoGenObject
.CreateMakeFile(True)
1296 if EdkLogger
.GetLevel() == EdkLogger
.QUIET
:
1297 EdkLogger
.quiet("Building ... %s" % repr(AutoGenObject
))
1299 BuildCommand
= AutoGenObject
.BuildCommand
1300 if BuildCommand
is None or len(BuildCommand
) == 0:
1301 EdkLogger
.error("build", OPTION_MISSING
,
1302 "No build command found for this module. "
1303 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %
1304 (AutoGenObject
.BuildTarget
, AutoGenObject
.ToolChain
, AutoGenObject
.Arch
),
1305 ExtraData
=str(AutoGenObject
))
1311 # Fetch the MakeFileName.
1312 self
.MakeFileName
= AutoGenObject
.MakeFileName
1316 BuildCommand
= BuildCommand
+ [Target
]
1317 LaunchCommand(BuildCommand
, AutoGenObject
.MakeFileDir
)
1318 if GlobalData
.gBinCacheDest
:
1320 elif GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheSource
:
1322 # Update PreMakeCacheChain files
1323 self
.GenLocalPreMakeCache()
1324 self
.BuildModules
= []
1328 if Target
== 'libraries':
1330 for Lib
in AutoGenObject
.LibraryAutoGenList
:
1331 if not Lib
.IsBinaryModule
:
1332 DirList
.append((os
.path
.join(AutoGenObject
.BuildDir
, Lib
.BuildDir
),Lib
))
1333 for Lib
, LibAutoGen
in DirList
:
1334 NewBuildCommand
= BuildCommand
+ ['-f', os
.path
.normpath(os
.path
.join(Lib
, self
.MakeFileName
)), 'pbuild']
1335 LaunchCommand(NewBuildCommand
, AutoGenObject
.MakeFileDir
,LibAutoGen
)
1339 if Target
== 'modules':
1341 for Lib
in AutoGenObject
.LibraryAutoGenList
:
1342 if not Lib
.IsBinaryModule
:
1343 DirList
.append((os
.path
.join(AutoGenObject
.BuildDir
, Lib
.BuildDir
),Lib
))
1344 for Lib
, LibAutoGen
in DirList
:
1345 NewBuildCommand
= BuildCommand
+ ['-f', os
.path
.normpath(os
.path
.join(Lib
, self
.MakeFileName
)), 'pbuild']
1346 LaunchCommand(NewBuildCommand
, AutoGenObject
.MakeFileDir
,LibAutoGen
)
1349 for ModuleAutoGen
in AutoGenObject
.ModuleAutoGenList
:
1350 if not ModuleAutoGen
.IsBinaryModule
:
1351 DirList
.append((os
.path
.join(AutoGenObject
.BuildDir
, ModuleAutoGen
.BuildDir
),ModuleAutoGen
))
1352 for Mod
,ModAutoGen
in DirList
:
1353 NewBuildCommand
= BuildCommand
+ ['-f', os
.path
.normpath(os
.path
.join(Mod
, self
.MakeFileName
)), 'pbuild']
1354 LaunchCommand(NewBuildCommand
, AutoGenObject
.MakeFileDir
,ModAutoGen
)
1355 self
.CreateAsBuiltInf()
1356 if GlobalData
.gBinCacheDest
:
1358 elif GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheSource
:
1360 # Update PreMakeCacheChain files
1361 self
.GenLocalPreMakeCache()
1362 self
.BuildModules
= []
1366 if Target
== 'cleanlib':
1367 for Lib
in AutoGenObject
.LibraryBuildDirectoryList
:
1368 LibMakefile
= os
.path
.normpath(os
.path
.join(Lib
, self
.MakeFileName
))
1369 if os
.path
.exists(LibMakefile
):
1370 NewBuildCommand
= BuildCommand
+ ['-f', LibMakefile
, 'cleanall']
1371 LaunchCommand(NewBuildCommand
, AutoGenObject
.MakeFileDir
)
1375 if Target
== 'clean':
1376 for Mod
in AutoGenObject
.ModuleBuildDirectoryList
:
1377 ModMakefile
= os
.path
.normpath(os
.path
.join(Mod
, self
.MakeFileName
))
1378 if os
.path
.exists(ModMakefile
):
1379 NewBuildCommand
= BuildCommand
+ ['-f', ModMakefile
, 'cleanall']
1380 LaunchCommand(NewBuildCommand
, AutoGenObject
.MakeFileDir
)
1381 for Lib
in AutoGenObject
.LibraryBuildDirectoryList
:
1382 LibMakefile
= os
.path
.normpath(os
.path
.join(Lib
, self
.MakeFileName
))
1383 if os
.path
.exists(LibMakefile
):
1384 NewBuildCommand
= BuildCommand
+ ['-f', LibMakefile
, 'cleanall']
1385 LaunchCommand(NewBuildCommand
, AutoGenObject
.MakeFileDir
)
1389 if Target
== 'cleanall':
1391 #os.rmdir(AutoGenObject.BuildDir)
1392 RemoveDirectory(AutoGenObject
.BuildDir
, True)
1393 except WindowsError as X
:
1394 EdkLogger
.error("build", FILE_DELETE_FAILURE
, ExtraData
=str(X
))
1397 ## Build a module or platform
1399 # Create autogen code and makefile for a module or platform, and the launch
1400 # "make" command to build it
1402 # @param Target The target of build command
1403 # @param Platform The platform file
1404 # @param Module The module file
1405 # @param BuildTarget The name of build target, one of "DEBUG", "RELEASE"
1406 # @param ToolChain The name of toolchain to build
1407 # @param Arch The arch of the module/platform
1408 # @param CreateDepModuleCodeFile Flag used to indicate creating code
1409 # for dependent modules/Libraries
1410 # @param CreateDepModuleMakeFile Flag used to indicate creating makefile
1411 # for dependent modules/Libraries
1413 def _Build(self
, Target
, AutoGenObject
, CreateDepsCodeFile
=True, CreateDepsMakeFile
=True, BuildModule
=False):
1414 if AutoGenObject
is None:
1417 # skip file generation for cleanxxx targets, run and fds target
1418 if Target
not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:
1419 # for target which must generate AutoGen code and makefile
1420 if not self
.SkipAutoGen
or Target
== 'genc':
1421 self
.Progress
.Start("Generating code")
1422 AutoGenObject
.CreateCodeFile(CreateDepsCodeFile
)
1423 self
.Progress
.Stop("done!")
1424 if Target
== "genc":
1427 if not self
.SkipAutoGen
or Target
== 'genmake':
1428 self
.Progress
.Start("Generating makefile")
1429 AutoGenObject
.CreateMakeFile(CreateDepsMakeFile
)
1430 #AutoGenObject.CreateAsBuiltInf()
1431 self
.Progress
.Stop("done!")
1432 if Target
== "genmake":
1435 # always recreate top/platform makefile when clean, just in case of inconsistency
1436 AutoGenObject
.CreateCodeFile(True)
1437 AutoGenObject
.CreateMakeFile(True)
1439 if EdkLogger
.GetLevel() == EdkLogger
.QUIET
:
1440 EdkLogger
.quiet("Building ... %s" % repr(AutoGenObject
))
1442 BuildCommand
= AutoGenObject
.BuildCommand
1443 if BuildCommand
is None or len(BuildCommand
) == 0:
1444 EdkLogger
.error("build", OPTION_MISSING
,
1445 "No build command found for this module. "
1446 "Please check your setting of %s_%s_%s_MAKE_PATH in Conf/tools_def.txt file." %
1447 (AutoGenObject
.BuildTarget
, AutoGenObject
.ToolChain
, AutoGenObject
.Arch
),
1448 ExtraData
=str(AutoGenObject
))
1453 BuildCommand
= BuildCommand
+ [Target
]
1454 AutoGenObject
.BuildTime
= LaunchCommand(BuildCommand
, AutoGenObject
.MakeFileDir
)
1455 self
.CreateAsBuiltInf()
1456 if GlobalData
.gBinCacheDest
:
1458 elif GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheSource
:
1460 # Update PreMakeCacheChain files
1461 self
.GenLocalPreMakeCache()
1462 self
.BuildModules
= []
1467 if GenFdsApi(AutoGenObject
.GenFdsCommandDict
, self
.Db
):
1468 EdkLogger
.error("build", COMMAND_FAILURE
)
1469 Threshold
= self
.GetFreeSizeThreshold()
1471 self
.CheckFreeSizeThreshold(Threshold
, AutoGenObject
.FvDir
)
1479 if Target
== 'libraries':
1486 if Target
== 'cleanall':
1488 #os.rmdir(AutoGenObject.BuildDir)
1489 RemoveDirectory(AutoGenObject
.BuildDir
, True)
1490 except WindowsError as X
:
1491 EdkLogger
.error("build", FILE_DELETE_FAILURE
, ExtraData
=str(X
))
1494 ## Rebase module image and Get function address for the input module list.
1496 def _RebaseModule (self
, MapBuffer
, BaseAddress
, ModuleList
, AddrIsOffset
= True, ModeIsSmm
= False):
1498 AddrIsOffset
= False
1499 for InfFile
in ModuleList
:
1500 sys
.stdout
.write (".")
1502 ModuleInfo
= ModuleList
[InfFile
]
1503 ModuleName
= ModuleInfo
.BaseName
1504 ModuleOutputImage
= ModuleInfo
.Image
.FileName
1505 ModuleDebugImage
= os
.path
.join(ModuleInfo
.DebugDir
, ModuleInfo
.BaseName
+ '.efi')
1506 ## for SMM module in SMRAM, the SMRAM will be allocated from base to top.
1508 BaseAddress
= BaseAddress
- ModuleInfo
.Image
.Size
1510 # Update Image to new BaseAddress by GenFw tool
1512 LaunchCommand(["GenFw", "--rebase", str(BaseAddress
), "-r", ModuleOutputImage
], ModuleInfo
.OutputDir
)
1513 LaunchCommand(["GenFw", "--rebase", str(BaseAddress
), "-r", ModuleDebugImage
], ModuleInfo
.DebugDir
)
1516 # Set new address to the section header only for SMM driver.
1518 LaunchCommand(["GenFw", "--address", str(BaseAddress
), "-r", ModuleOutputImage
], ModuleInfo
.OutputDir
)
1519 LaunchCommand(["GenFw", "--address", str(BaseAddress
), "-r", ModuleDebugImage
], ModuleInfo
.DebugDir
)
1521 # Collect function address from Map file
1523 ImageMapTable
= ModuleOutputImage
.replace('.efi', '.map')
1525 if os
.path
.exists(ImageMapTable
):
1526 OrigImageBaseAddress
= 0
1527 ImageMap
= open(ImageMapTable
, 'r')
1528 for LinStr
in ImageMap
:
1529 if len (LinStr
.strip()) == 0:
1532 # Get the preferred address set on link time.
1534 if LinStr
.find ('Preferred load address is') != -1:
1535 StrList
= LinStr
.split()
1536 OrigImageBaseAddress
= int (StrList
[len(StrList
) - 1], 16)
1538 StrList
= LinStr
.split()
1539 if len (StrList
) > 4:
1540 if StrList
[3] == 'f' or StrList
[3] == 'F':
1542 RelativeAddress
= int (StrList
[2], 16) - OrigImageBaseAddress
1543 FunctionList
.append ((Name
, RelativeAddress
))
1547 # Add general information.
1550 MapBuffer
.append('\n\n%s (Fixed SMRAM Offset, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName
, BaseAddress
, BaseAddress
+ ModuleInfo
.Image
.EntryPoint
))
1552 MapBuffer
.append('\n\n%s (Fixed Memory Offset, BaseAddress=-0x%010X, EntryPoint=-0x%010X)\n' % (ModuleName
, 0 - BaseAddress
, 0 - (BaseAddress
+ ModuleInfo
.Image
.EntryPoint
)))
1554 MapBuffer
.append('\n\n%s (Fixed Memory Address, BaseAddress=0x%010X, EntryPoint=0x%010X)\n' % (ModuleName
, BaseAddress
, BaseAddress
+ ModuleInfo
.Image
.EntryPoint
))
1556 # Add guid and general seciton section.
1558 TextSectionAddress
= 0
1559 DataSectionAddress
= 0
1560 for SectionHeader
in ModuleInfo
.Image
.SectionHeaderList
:
1561 if SectionHeader
[0] == '.text':
1562 TextSectionAddress
= SectionHeader
[1]
1563 elif SectionHeader
[0] in ['.data', '.sdata']:
1564 DataSectionAddress
= SectionHeader
[1]
1566 MapBuffer
.append('(GUID=%s, .textbaseaddress=-0x%010X, .databaseaddress=-0x%010X)\n' % (ModuleInfo
.Guid
, 0 - (BaseAddress
+ TextSectionAddress
), 0 - (BaseAddress
+ DataSectionAddress
)))
1568 MapBuffer
.append('(GUID=%s, .textbaseaddress=0x%010X, .databaseaddress=0x%010X)\n' % (ModuleInfo
.Guid
, BaseAddress
+ TextSectionAddress
, BaseAddress
+ DataSectionAddress
))
1570 # Add debug image full path.
1572 MapBuffer
.append('(IMAGE=%s)\n\n' % (ModuleDebugImage
))
1574 # Add function address
1576 for Function
in FunctionList
:
1578 MapBuffer
.append(' -0x%010X %s\n' % (0 - (BaseAddress
+ Function
[1]), Function
[0]))
1580 MapBuffer
.append(' 0x%010X %s\n' % (BaseAddress
+ Function
[1], Function
[0]))
1584 # for SMM module in SMRAM, the SMRAM will be allocated from base to top.
1587 BaseAddress
= BaseAddress
+ ModuleInfo
.Image
.Size
1589 ## Collect MAP information of all FVs
1591 def _CollectFvMapBuffer (self
, MapBuffer
, Wa
, ModuleList
):
1593 # First get the XIP base address for FV map file.
1594 GuidPattern
= re
.compile("[-a-fA-F0-9]+")
1595 GuidName
= re
.compile(r
"\(GUID=[-a-fA-F0-9]+")
1596 for FvName
in Wa
.FdfProfile
.FvDict
:
1597 FvMapBuffer
= os
.path
.join(Wa
.FvDir
, FvName
+ '.Fv.map')
1598 if not os
.path
.exists(FvMapBuffer
):
1600 FvMap
= open(FvMapBuffer
, 'r')
1601 #skip FV size information
1607 MatchGuid
= GuidPattern
.match(Line
)
1608 if MatchGuid
is not None:
1610 # Replace GUID with module name
1612 GuidString
= MatchGuid
.group()
1613 if GuidString
.upper() in ModuleList
:
1614 Line
= Line
.replace(GuidString
, ModuleList
[GuidString
.upper()].Name
)
1615 MapBuffer
.append(Line
)
1617 # Add the debug image full path.
1619 MatchGuid
= GuidName
.match(Line
)
1620 if MatchGuid
is not None:
1621 GuidString
= MatchGuid
.group().split("=")[1]
1622 if GuidString
.upper() in ModuleList
:
1623 MapBuffer
.append('(IMAGE=%s)\n' % (os
.path
.join(ModuleList
[GuidString
.upper()].DebugDir
, ModuleList
[GuidString
.upper()].Name
+ '.efi')))
1627 ## Collect MAP information of all modules
1629 def _CollectModuleMapBuffer (self
, MapBuffer
, ModuleList
):
1630 sys
.stdout
.write ("Generate Load Module At Fix Address Map")
1632 PatchEfiImageList
= []
1640 # reserve 4K size in SMRAM to make SMM module address not from 0.
1642 for ModuleGuid
in ModuleList
:
1643 Module
= ModuleList
[ModuleGuid
]
1644 GlobalData
.gProcessingFile
= "%s [%s, %s, %s]" % (Module
.MetaFile
, Module
.Arch
, Module
.ToolChain
, Module
.BuildTarget
)
1646 OutputImageFile
= ''
1647 for ResultFile
in Module
.CodaTargetList
:
1648 if str(ResultFile
.Target
).endswith('.efi'):
1650 # module list for PEI, DXE, RUNTIME and SMM
1652 OutputImageFile
= os
.path
.join(Module
.OutputDir
, Module
.Name
+ '.efi')
1653 ImageClass
= PeImageClass (OutputImageFile
)
1654 if not ImageClass
.IsValid
:
1655 EdkLogger
.error("build", FILE_PARSE_FAILURE
, ExtraData
=ImageClass
.ErrorInfo
)
1656 ImageInfo
= PeImageInfo(Module
.Name
, Module
.Guid
, Module
.Arch
, Module
.OutputDir
, Module
.DebugDir
, ImageClass
)
1657 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
]:
1658 PeiModuleList
[Module
.MetaFile
] = ImageInfo
1659 PeiSize
+= ImageInfo
.Image
.Size
1660 elif Module
.ModuleType
in [EDK_COMPONENT_TYPE_BS_DRIVER
, SUP_MODULE_DXE_DRIVER
, SUP_MODULE_UEFI_DRIVER
]:
1661 BtModuleList
[Module
.MetaFile
] = ImageInfo
1662 BtSize
+= ImageInfo
.Image
.Size
1663 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
]:
1664 RtModuleList
[Module
.MetaFile
] = ImageInfo
1665 RtSize
+= ImageInfo
.Image
.Size
1666 elif Module
.ModuleType
in [SUP_MODULE_SMM_CORE
, SUP_MODULE_DXE_SMM_DRIVER
, SUP_MODULE_MM_STANDALONE
, SUP_MODULE_MM_CORE_STANDALONE
]:
1667 SmmModuleList
[Module
.MetaFile
] = ImageInfo
1668 SmmSize
+= ImageInfo
.Image
.Size
1669 if Module
.ModuleType
== SUP_MODULE_DXE_SMM_DRIVER
:
1670 PiSpecVersion
= Module
.Module
.Specification
.get('PI_SPECIFICATION_VERSION', '0x00000000')
1671 # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver.
1672 if int(PiSpecVersion
, 16) < 0x0001000A:
1673 BtModuleList
[Module
.MetaFile
] = ImageInfo
1674 BtSize
+= ImageInfo
.Image
.Size
1677 # EFI image is final target.
1678 # Check EFI image contains patchable FixAddress related PCDs.
1680 if OutputImageFile
!= '':
1681 ModuleIsPatch
= False
1682 for Pcd
in Module
.ModulePcdList
:
1683 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
and Pcd
.TokenCName
in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET
:
1684 ModuleIsPatch
= True
1686 if not ModuleIsPatch
:
1687 for Pcd
in Module
.LibraryPcdList
:
1688 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
and Pcd
.TokenCName
in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET
:
1689 ModuleIsPatch
= True
1692 if not ModuleIsPatch
:
1695 # Module includes the patchable load fix address PCDs.
1696 # It will be fixed up later.
1698 PatchEfiImageList
.append (OutputImageFile
)
1701 # Get Top Memory address
1703 ReservedRuntimeMemorySize
= 0
1704 TopMemoryAddress
= 0
1705 if self
.LoadFixAddress
== 0xFFFFFFFFFFFFFFFF:
1706 TopMemoryAddress
= 0
1708 TopMemoryAddress
= self
.LoadFixAddress
1709 if TopMemoryAddress
< RtSize
+ BtSize
+ PeiSize
:
1710 EdkLogger
.error("build", PARAMETER_INVALID
, "FIX_LOAD_TOP_MEMORY_ADDRESS is too low to load driver")
1713 # Patch FixAddress related PCDs into EFI image
1715 for EfiImage
in PatchEfiImageList
:
1716 EfiImageMap
= EfiImage
.replace('.efi', '.map')
1717 if not os
.path
.exists(EfiImageMap
):
1720 # Get PCD offset in EFI image by GenPatchPcdTable function
1722 PcdTable
= parsePcdInfoFromMapFile(EfiImageMap
, EfiImage
)
1724 # Patch real PCD value by PatchPcdValue tool
1726 for PcdInfo
in PcdTable
:
1728 if PcdInfo
[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE
:
1729 ReturnValue
, ErrorInfo
= PatchBinaryFile (EfiImage
, PcdInfo
[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE
, str (PeiSize
// 0x1000))
1730 elif PcdInfo
[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE
:
1731 ReturnValue
, ErrorInfo
= PatchBinaryFile (EfiImage
, PcdInfo
[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE
, str (BtSize
// 0x1000))
1732 elif PcdInfo
[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE
:
1733 ReturnValue
, ErrorInfo
= PatchBinaryFile (EfiImage
, PcdInfo
[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE
, str (RtSize
// 0x1000))
1734 elif PcdInfo
[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE
and len (SmmModuleList
) > 0:
1735 ReturnValue
, ErrorInfo
= PatchBinaryFile (EfiImage
, PcdInfo
[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE
, str (SmmSize
// 0x1000))
1736 if ReturnValue
!= 0:
1737 EdkLogger
.error("build", PARAMETER_INVALID
, "Patch PCD value failed", ExtraData
=ErrorInfo
)
1739 MapBuffer
.append('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize
// 0x1000))
1740 MapBuffer
.append('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize
// 0x1000))
1741 MapBuffer
.append('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize
// 0x1000))
1742 if len (SmmModuleList
) > 0:
1743 MapBuffer
.append('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize
// 0x1000))
1745 PeiBaseAddr
= TopMemoryAddress
- RtSize
- BtSize
1746 BtBaseAddr
= TopMemoryAddress
- RtSize
1747 RtBaseAddr
= TopMemoryAddress
- ReservedRuntimeMemorySize
1749 self
._RebaseModule
(MapBuffer
, PeiBaseAddr
, PeiModuleList
, TopMemoryAddress
== 0)
1750 self
._RebaseModule
(MapBuffer
, BtBaseAddr
, BtModuleList
, TopMemoryAddress
== 0)
1751 self
._RebaseModule
(MapBuffer
, RtBaseAddr
, RtModuleList
, TopMemoryAddress
== 0)
1752 self
._RebaseModule
(MapBuffer
, 0x1000, SmmModuleList
, AddrIsOffset
=False, ModeIsSmm
=True)
1753 MapBuffer
.append('\n\n')
1754 sys
.stdout
.write ("\n")
1757 ## Save platform Map file
1759 def _SaveMapFile (self
, MapBuffer
, Wa
):
1761 # Map file path is got.
1763 MapFilePath
= os
.path
.join(Wa
.BuildDir
, Wa
.Name
+ '.map')
1765 # Save address map into MAP file.
1767 SaveFileOnChange(MapFilePath
, ''.join(MapBuffer
), False)
1768 if self
.LoadFixAddress
!= 0:
1769 sys
.stdout
.write ("\nLoad Module At Fix Address Map file can be found at %s\n" % (MapFilePath
))
1772 ## Build active platform for different build targets and different tool chains
1774 def _BuildPlatform(self
):
1775 SaveFileOnChange(self
.PlatformBuildPath
, '# DO NOT EDIT \n# FILE auto-generated\n', False)
1776 for BuildTarget
in self
.BuildTargetList
:
1777 GlobalData
.gGlobalDefines
['TARGET'] = BuildTarget
1779 for ToolChain
in self
.ToolChainList
:
1780 GlobalData
.gGlobalDefines
['TOOLCHAIN'] = ToolChain
1781 GlobalData
.gGlobalDefines
['TOOL_CHAIN_TAG'] = ToolChain
1782 GlobalData
.gGlobalDefines
['FAMILY'] = self
.ToolChainFamily
[index
]
1784 Wa
= WorkspaceAutoGen(
1801 self
.Fdf
= Wa
.FdfFile
1802 self
.LoadFixAddress
= Wa
.Platform
.LoadFixAddress
1803 self
.BuildReport
.AddPlatformReport(Wa
)
1804 self
.Progress
.Stop("done!")
1806 # Add ffs build to makefile
1808 if GlobalData
.gEnableGenfdsMultiThread
and self
.Fdf
:
1809 CmdListDict
= self
._GenFfsCmd
(Wa
.ArchList
)
1811 for Arch
in Wa
.ArchList
:
1813 GlobalData
.gGlobalDefines
['ARCH'] = Arch
1814 Pa
= PlatformAutoGen(Wa
, self
.PlatformFile
, BuildTarget
, ToolChain
, Arch
)
1815 for Module
in Pa
.Platform
.Modules
:
1816 # Get ModuleAutoGen object to generate C code file and makefile
1817 Ma
= ModuleAutoGen(Wa
, Module
, BuildTarget
, ToolChain
, Arch
, self
.PlatformFile
,Pa
.DataPipe
)
1821 Ma
.PlatformInfo
= Pa
1823 PcdMaList
.append(Ma
)
1824 self
.BuildModules
.append(Ma
)
1825 Pa
.DataPipe
.DataContainer
= {"FfsCommand":CmdListDict
}
1826 Pa
.DataPipe
.DataContainer
= {"Workspace_timestamp": Wa
._SrcTimeStamp
}
1827 self
._BuildPa
(self
.Target
, Pa
, FfsCommand
=CmdListDict
,PcdMaList
=PcdMaList
)
1829 # Create MAP file when Load Fix Address is enabled.
1830 if self
.Target
in ["", "all", "fds"]:
1831 for Arch
in Wa
.ArchList
:
1832 GlobalData
.gGlobalDefines
['ARCH'] = Arch
1834 # Check whether the set fix address is above 4G for 32bit image.
1836 if (Arch
== 'IA32' or Arch
== 'ARM') and self
.LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
.LoadFixAddress
>= 0x100000000:
1837 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")
1842 for Pa
in Wa
.AutoGenObjectList
:
1843 for Ma
in Pa
.ModuleAutoGenList
:
1846 if not Ma
.IsLibrary
:
1847 ModuleList
[Ma
.Guid
.upper()] = Ma
1850 if self
.LoadFixAddress
!= 0:
1852 # Rebase module to the preferred memory address before GenFds
1854 self
._CollectModuleMapBuffer
(MapBuffer
, ModuleList
)
1857 # create FDS again for the updated EFI image
1859 self
._Build
("fds", Wa
)
1861 # Create MAP file for all platform FVs after GenFds.
1863 self
._CollectFvMapBuffer
(MapBuffer
, Wa
, ModuleList
)
1865 # Save MAP buffer into MAP file.
1867 self
._SaveMapFile
(MapBuffer
, Wa
)
1868 self
.CreateGuidedSectionToolsFile(Wa
)
1870 ## Build active module for different build targets, different tool chains and different archs
1872 def _BuildModule(self
):
1873 for BuildTarget
in self
.BuildTargetList
:
1874 GlobalData
.gGlobalDefines
['TARGET'] = BuildTarget
1876 for ToolChain
in self
.ToolChainList
:
1877 WorkspaceAutoGenTime
= time
.time()
1878 GlobalData
.gGlobalDefines
['TOOLCHAIN'] = ToolChain
1879 GlobalData
.gGlobalDefines
['TOOL_CHAIN_TAG'] = ToolChain
1880 GlobalData
.gGlobalDefines
['FAMILY'] = self
.ToolChainFamily
[index
]
1883 # module build needs platform build information, so get platform
1886 Wa
= WorkspaceAutoGen(
1904 self
.Fdf
= Wa
.FdfFile
1905 self
.LoadFixAddress
= Wa
.Platform
.LoadFixAddress
1906 Wa
.CreateMakeFile(False)
1907 # Add ffs build to makefile
1909 if GlobalData
.gEnableGenfdsMultiThread
and self
.Fdf
:
1910 CmdListDict
= self
._GenFfsCmd
(Wa
.ArchList
)
1912 GlobalData
.file_lock
= mp
.Lock()
1913 GlobalData
.FfsCmd
= CmdListDict
1915 self
.Progress
.Stop("done!")
1917 ExitFlag
= threading
.Event()
1919 self
.AutoGenTime
+= int(round((time
.time() - WorkspaceAutoGenTime
)))
1920 for Arch
in Wa
.ArchList
:
1921 AutoGenStart
= time
.time()
1922 GlobalData
.gGlobalDefines
['ARCH'] = Arch
1923 Pa
= PlatformAutoGen(Wa
, self
.PlatformFile
, BuildTarget
, ToolChain
, Arch
)
1924 for Module
in Pa
.Platform
.Modules
:
1925 if self
.ModuleFile
.Dir
== Module
.Dir
and self
.ModuleFile
.Name
== Module
.Name
:
1926 Ma
= ModuleAutoGen(Wa
, Module
, BuildTarget
, ToolChain
, Arch
, self
.PlatformFile
,Pa
.DataPipe
)
1930 Ma
.PlatformInfo
= Pa
1934 if GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheDest
and self
.Target
in [None, "", "all"]:
1935 if Ma
.CanSkipbyPreMakeCache():
1938 self
.PreMakeCacheMiss
.add(Ma
)
1940 # Not to auto-gen for targets 'clean', 'cleanlib', 'cleanall', 'run', 'fds'
1941 if self
.Target
not in ['clean', 'cleanlib', 'cleanall', 'run', 'fds']:
1942 # for target which must generate AutoGen code and makefile
1943 if not self
.SkipAutoGen
or self
.Target
== 'genc':
1944 self
.Progress
.Start("Generating code")
1945 Ma
.CreateCodeFile(True)
1946 self
.Progress
.Stop("done!")
1947 if self
.Target
== "genc":
1949 if not self
.SkipAutoGen
or self
.Target
== 'genmake':
1950 self
.Progress
.Start("Generating makefile")
1951 if CmdListDict
and self
.Fdf
and (Module
.Path
, Arch
) in CmdListDict
:
1952 Ma
.CreateMakeFile(True, CmdListDict
[Module
.Path
, Arch
])
1953 del CmdListDict
[Module
.Path
, Arch
]
1955 Ma
.CreateMakeFile(True)
1956 self
.Progress
.Stop("done!")
1957 if self
.Target
== "genmake":
1960 if GlobalData
.gBinCacheSource
and self
.Target
in [None, "", "all"]:
1961 if Ma
.CanSkipbyMakeCache():
1964 self
.MakeCacheMiss
.add(Ma
)
1966 self
.BuildModules
.append(Ma
)
1967 self
.AutoGenTime
+= int(round((time
.time() - AutoGenStart
)))
1968 MakeStart
= time
.time()
1969 for Ma
in self
.BuildModules
:
1970 if not Ma
.IsBinaryModule
:
1971 Bt
= BuildTask
.New(ModuleMakeUnit(Ma
, Pa
.BuildCommand
,self
.Target
))
1972 # Break build if any build thread has error
1973 if BuildTask
.HasError():
1974 # we need a full version of makefile for platform
1976 BuildTask
.WaitForComplete()
1977 Pa
.CreateMakeFile(False)
1978 EdkLogger
.error("build", BUILD_ERROR
, "Failed to build module", ExtraData
=GlobalData
.gBuildingModule
)
1979 # Start task scheduler
1980 if not BuildTask
.IsOnGoing():
1981 BuildTask
.StartScheduler(self
.ThreadNumber
, ExitFlag
)
1983 # in case there's an interruption. we need a full version of makefile for platform
1984 Pa
.CreateMakeFile(False)
1985 if BuildTask
.HasError():
1986 EdkLogger
.error("build", BUILD_ERROR
, "Failed to build module", ExtraData
=GlobalData
.gBuildingModule
)
1987 self
.MakeTime
+= int(round((time
.time() - MakeStart
)))
1989 MakeContiue
= time
.time()
1991 BuildTask
.WaitForComplete()
1992 self
.CreateAsBuiltInf()
1993 if GlobalData
.gBinCacheDest
:
1995 elif GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheSource
:
1997 # Update PreMakeCacheChain files
1998 self
.GenLocalPreMakeCache()
1999 self
.BuildModules
= []
2000 self
.MakeTime
+= int(round((time
.time() - MakeContiue
)))
2001 if BuildTask
.HasError():
2002 EdkLogger
.error("build", BUILD_ERROR
, "Failed to build module", ExtraData
=GlobalData
.gBuildingModule
)
2004 self
.BuildReport
.AddPlatformReport(Wa
, MaList
)
2009 "Module for [%s] is not a component of active platform."\
2010 " Please make sure that the ARCH and inf file path are"\
2011 " given in the same as in [%s]" % \
2012 (', '.join(Wa
.ArchList
), self
.PlatformFile
),
2013 ExtraData
=self
.ModuleFile
2015 # Create MAP file when Load Fix Address is enabled.
2016 if self
.Target
== "fds" and self
.Fdf
:
2017 for Arch
in Wa
.ArchList
:
2019 # Check whether the set fix address is above 4G for 32bit image.
2021 if (Arch
== 'IA32' or Arch
== 'ARM') and self
.LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
.LoadFixAddress
>= 0x100000000:
2022 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")
2027 for Pa
in Wa
.AutoGenObjectList
:
2028 for Ma
in Pa
.ModuleAutoGenList
:
2031 if not Ma
.IsLibrary
:
2032 ModuleList
[Ma
.Guid
.upper()] = Ma
2035 if self
.LoadFixAddress
!= 0:
2037 # Rebase module to the preferred memory address before GenFds
2039 self
._CollectModuleMapBuffer
(MapBuffer
, ModuleList
)
2041 # create FDS again for the updated EFI image
2043 GenFdsStart
= time
.time()
2044 self
._Build
("fds", Wa
)
2045 self
.GenFdsTime
+= int(round((time
.time() - GenFdsStart
)))
2047 # Create MAP file for all platform FVs after GenFds.
2049 self
._CollectFvMapBuffer
(MapBuffer
, Wa
, ModuleList
)
2051 # Save MAP buffer into MAP file.
2053 self
._SaveMapFile
(MapBuffer
, Wa
)
2055 def _GenFfsCmd(self
,ArchList
):
2056 # convert dictionary of Cmd:(Inf,Arch)
2057 # to a new dictionary of (Inf,Arch):Cmd,Cmd,Cmd...
2058 CmdSetDict
= defaultdict(set)
2059 GenFfsDict
= GenFds
.GenFfsMakefile('', GlobalData
.gFdfParser
, self
, ArchList
, GlobalData
)
2060 for Cmd
in GenFfsDict
:
2061 tmpInf
, tmpArch
= GenFfsDict
[Cmd
]
2062 CmdSetDict
[tmpInf
, tmpArch
].add(Cmd
)
2064 def VerifyAutoGenFiles(self
):
2065 AutoGenIdFile
= os
.path
.join(GlobalData
.gConfDirectory
,".AutoGenIdFile.txt")
2067 with
open(AutoGenIdFile
) as fd
:
2068 lines
= fd
.readlines()
2073 ArchList
= line
.strip().split("=")[1].split("|")
2074 if "BuildDir" in line
:
2075 BuildDir
= line
.split("=")[1].strip()
2076 if "PlatformGuid" in line
:
2077 PlatformGuid
= line
.split("=")[1].strip()
2079 for arch
in ArchList
:
2080 global_var
= os
.path
.join(BuildDir
, "GlobalVar_%s_%s.bin" % (str(PlatformGuid
),arch
))
2081 if not os
.path
.exists(global_var
):
2083 GlobalVarList
.append(global_var
)
2084 for global_var
in GlobalVarList
:
2085 data_pipe
= MemoryDataPipe()
2086 data_pipe
.load(global_var
)
2087 target
= data_pipe
.Get("P_Info").get("Target")
2088 toolchain
= data_pipe
.Get("P_Info").get("ToolChain")
2089 archlist
= data_pipe
.Get("P_Info").get("ArchList")
2090 Arch
= data_pipe
.Get("P_Info").get("Arch")
2091 active_p
= data_pipe
.Get("P_Info").get("ActivePlatform")
2092 workspacedir
= data_pipe
.Get("P_Info").get("WorkspaceDir")
2093 PackagesPath
= os
.getenv("PACKAGES_PATH")
2094 mws
.setWs(workspacedir
, PackagesPath
)
2095 LibraryBuildDirectoryList
= data_pipe
.Get("LibraryBuildDirectoryList")
2096 ModuleBuildDirectoryList
= data_pipe
.Get("ModuleBuildDirectoryList")
2098 for m_build_dir
in LibraryBuildDirectoryList
:
2099 if not os
.path
.exists(os
.path
.join(m_build_dir
,self
.MakeFileName
)):
2101 for m_build_dir
in ModuleBuildDirectoryList
:
2102 if not os
.path
.exists(os
.path
.join(m_build_dir
,self
.MakeFileName
)):
2105 workspacedir
,active_p
,target
,toolchain
,archlist
2107 Pa
= PlatformInfo(Wa
, active_p
, target
, toolchain
, Arch
,data_pipe
)
2108 Wa
.AutoGenObjectList
.append(Pa
)
2110 def SetupMakeSetting(self
,Wa
):
2112 for Pa
in Wa
.AutoGenObjectList
:
2113 for m
in Pa
._MbList
:
2114 ma
= ModuleAutoGen(Wa
,m
.MetaFile
, Pa
.BuildTarget
, Wa
.ToolChain
, Pa
.Arch
, Pa
.MetaFile
,Pa
.DataPipe
)
2115 BuildModules
.append(ma
)
2116 fdf_file
= Wa
.FlashDefinition
2118 Fdf
= FdfParser(fdf_file
.Path
)
2120 GlobalData
.gFdfParser
= Fdf
2121 if Fdf
.CurrentFdName
and Fdf
.CurrentFdName
in Fdf
.Profile
.FdDict
:
2122 FdDict
= Fdf
.Profile
.FdDict
[Fdf
.CurrentFdName
]
2123 for FdRegion
in FdDict
.RegionList
:
2124 if str(FdRegion
.RegionType
) == 'FILE' and self
.Platform
.VpdToolGuid
in str(FdRegion
.RegionDataList
):
2125 if int(FdRegion
.Offset
) % 8 != 0:
2126 EdkLogger
.error("build", FORMAT_INVALID
, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion
.Offset
))
2127 Wa
.FdfProfile
= Fdf
.Profile
2133 ## Build a platform in multi-thread mode
2135 def PerformAutoGen(self
,BuildTarget
,ToolChain
):
2136 WorkspaceAutoGenTime
= time
.time()
2137 Wa
= WorkspaceAutoGen(
2154 self
.Fdf
= Wa
.FdfFile
2155 self
.LoadFixAddress
= Wa
.Platform
.LoadFixAddress
2156 self
.BuildReport
.AddPlatformReport(Wa
)
2157 Wa
.CreateMakeFile(False)
2159 # Add ffs build to makefile
2161 if GlobalData
.gEnableGenfdsMultiThread
and self
.Fdf
:
2162 CmdListDict
= self
._GenFfsCmd
(Wa
.ArchList
)
2164 self
.AutoGenTime
+= int(round((time
.time() - WorkspaceAutoGenTime
)))
2166 for Arch
in Wa
.ArchList
:
2168 AutoGenStart
= time
.time()
2169 GlobalData
.gGlobalDefines
['ARCH'] = Arch
2170 Pa
= PlatformAutoGen(Wa
, self
.PlatformFile
, BuildTarget
, ToolChain
, Arch
)
2174 for Inf
in Pa
.Platform
.Modules
:
2175 ModuleList
.append(Inf
)
2176 # Add the INF only list in FDF
2177 if GlobalData
.gFdfParser
is not None:
2178 for InfName
in GlobalData
.gFdfParser
.Profile
.InfList
:
2179 Inf
= PathClass(NormPath(InfName
), self
.WorkspaceDir
, Arch
)
2180 if Inf
in Pa
.Platform
.Modules
:
2182 ModuleList
.append(Inf
)
2183 Pa
.DataPipe
.DataContainer
= {"FfsCommand":CmdListDict
}
2184 Pa
.DataPipe
.DataContainer
= {"Workspace_timestamp": Wa
._SrcTimeStamp
}
2185 Pa
.DataPipe
.DataContainer
= {"CommandTarget": self
.Target
}
2186 Pa
.CreateLibModuelDirs()
2187 # Fetch the MakeFileName.
2188 self
.MakeFileName
= Pa
.MakeFileName
2190 Pa
.DataPipe
.DataContainer
= {"LibraryBuildDirectoryList":Pa
.LibraryBuildDirectoryList
}
2191 Pa
.DataPipe
.DataContainer
= {"ModuleBuildDirectoryList":Pa
.ModuleBuildDirectoryList
}
2192 Pa
.DataPipe
.DataContainer
= {"FdsCommandDict": Wa
.GenFdsCommandDict
}
2193 # Prepare the cache share data for multiprocessing
2194 Pa
.DataPipe
.DataContainer
= {"gPlatformHashFile":GlobalData
.gPlatformHashFile
}
2196 for ma
in Pa
.ModuleAutoGenList
:
2197 ModuleCodaFile
[(ma
.MetaFile
.File
,ma
.MetaFile
.Root
,ma
.Arch
,ma
.MetaFile
.Path
)] = [item
.Target
for item
in ma
.CodaTargetList
]
2198 Pa
.DataPipe
.DataContainer
= {"ModuleCodaFile":ModuleCodaFile
}
2199 # ModuleList contains all driver modules only
2200 for Module
in ModuleList
:
2201 # Get ModuleAutoGen object to generate C code file and makefile
2202 Ma
= ModuleAutoGen(Wa
, Module
, BuildTarget
, ToolChain
, Arch
, self
.PlatformFile
,Pa
.DataPipe
)
2206 Ma
.PlatformInfo
= Pa
2208 PcdMaList
.append(Ma
)
2209 self
.AllDrivers
.add(Ma
)
2210 self
.AllModules
.add(Ma
)
2214 for m
in Pa
.GetAllModuleInfo
:
2216 module_file
,module_root
,module_path
,module_basename
,\
2217 module_originalpath
,module_arch
,IsLib
= m
2218 Ma
= ModuleAutoGen(Wa
, PathClass(module_path
, Wa
), BuildTarget
,\
2219 ToolChain
, Arch
, self
.PlatformFile
,Pa
.DataPipe
)
2220 self
.AllModules
.add(Ma
)
2221 data_pipe_file
= os
.path
.join(Pa
.BuildDir
, "GlobalVar_%s_%s.bin" % (str(Pa
.Guid
),Pa
.Arch
))
2222 Pa
.DataPipe
.dump(data_pipe_file
)
2224 mqueue
.put((None,None,None,None,None,None,None))
2225 autogen_rt
, errorcode
= self
.StartAutoGen(mqueue
, Pa
.DataPipe
, self
.SkipAutoGen
, PcdMaList
, cqueue
)
2228 self
.AutoGenMgr
.TerminateWorkers()
2229 self
.AutoGenMgr
.join(1)
2230 raise FatalError(errorcode
)
2232 if GlobalData
.gUseHashCache
:
2233 for item
in GlobalData
.gModuleAllCacheStatus
:
2234 (MetaFilePath
, Arch
, CacheStr
, Status
) = item
2235 Ma
= ModuleAutoGen(Wa
, PathClass(MetaFilePath
, Wa
), BuildTarget
,\
2236 ToolChain
, Arch
, self
.PlatformFile
,Pa
.DataPipe
)
2237 if CacheStr
== "PreMakeCache" and Status
== False:
2238 self
.PreMakeCacheMiss
.add(Ma
)
2239 if CacheStr
== "PreMakeCache" and Status
== True:
2240 self
.PreMakeCacheHit
.add(Ma
)
2241 GlobalData
.gModuleCacheHit
.add(Ma
)
2242 if CacheStr
== "MakeCache" and Status
== False:
2243 self
.MakeCacheMiss
.add(Ma
)
2244 if CacheStr
== "MakeCache" and Status
== True:
2245 self
.MakeCacheHit
.add(Ma
)
2246 GlobalData
.gModuleCacheHit
.add(Ma
)
2247 self
.AutoGenTime
+= int(round((time
.time() - AutoGenStart
)))
2248 AutoGenIdFile
= os
.path
.join(GlobalData
.gConfDirectory
,".AutoGenIdFile.txt")
2249 with
open(AutoGenIdFile
,"w") as fw
:
2250 fw
.write("Arch=%s\n" % "|".join((Wa
.ArchList
)))
2251 fw
.write("BuildDir=%s\n" % Wa
.BuildDir
)
2252 fw
.write("PlatformGuid=%s\n" % str(Wa
.AutoGenObjectList
[0].Guid
))
2254 if GlobalData
.gBinCacheSource
:
2255 BuildModules
.extend(self
.MakeCacheMiss
)
2256 elif GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheDest
:
2257 BuildModules
.extend(self
.PreMakeCacheMiss
)
2259 BuildModules
.extend(self
.AllDrivers
)
2261 self
.Progress
.Stop("done!")
2262 return Wa
, BuildModules
2264 def _MultiThreadBuildPlatform(self
):
2265 SaveFileOnChange(self
.PlatformBuildPath
, '# DO NOT EDIT \n# FILE auto-generated\n', False)
2266 for BuildTarget
in self
.BuildTargetList
:
2267 GlobalData
.gGlobalDefines
['TARGET'] = BuildTarget
2269 for ToolChain
in self
.ToolChainList
:
2270 resetFdsGlobalVariable()
2271 GlobalData
.gGlobalDefines
['TOOLCHAIN'] = ToolChain
2272 GlobalData
.gGlobalDefines
['TOOL_CHAIN_TAG'] = ToolChain
2273 GlobalData
.gGlobalDefines
['FAMILY'] = self
.ToolChainFamily
[index
]
2275 ExitFlag
= threading
.Event()
2277 if self
.SkipAutoGen
:
2278 Wa
= self
.VerifyAutoGenFiles()
2280 self
.SkipAutoGen
= False
2281 Wa
, self
.BuildModules
= self
.PerformAutoGen(BuildTarget
,ToolChain
)
2283 GlobalData
.gAutoGenPhase
= True
2284 self
.BuildModules
= self
.SetupMakeSetting(Wa
)
2286 Wa
, self
.BuildModules
= self
.PerformAutoGen(BuildTarget
,ToolChain
)
2287 Pa
= Wa
.AutoGenObjectList
[0]
2288 GlobalData
.gAutoGenPhase
= False
2290 if GlobalData
.gBinCacheSource
:
2291 EdkLogger
.quiet("[cache Summary]: Total module num: %s" % len(self
.AllModules
))
2292 EdkLogger
.quiet("[cache Summary]: PreMakecache miss num: %s " % len(self
.PreMakeCacheMiss
))
2293 EdkLogger
.quiet("[cache Summary]: Makecache miss num: %s " % len(self
.MakeCacheMiss
))
2295 for Arch
in Wa
.ArchList
:
2296 MakeStart
= time
.time()
2297 for Ma
in set(self
.BuildModules
):
2298 # Generate build task for the module
2299 if not Ma
.IsBinaryModule
:
2300 Bt
= BuildTask
.New(ModuleMakeUnit(Ma
, Pa
.BuildCommand
,self
.Target
))
2301 # Break build if any build thread has error
2302 if BuildTask
.HasError():
2303 # we need a full version of makefile for platform
2305 BuildTask
.WaitForComplete()
2306 Pa
.CreateMakeFile(False)
2307 EdkLogger
.error("build", BUILD_ERROR
, "Failed to build module", ExtraData
=GlobalData
.gBuildingModule
)
2308 # Start task scheduler
2309 if not BuildTask
.IsOnGoing():
2310 BuildTask
.StartScheduler(self
.ThreadNumber
, ExitFlag
)
2312 # in case there's an interruption. we need a full version of makefile for platform
2314 if BuildTask
.HasError():
2315 EdkLogger
.error("build", BUILD_ERROR
, "Failed to build module", ExtraData
=GlobalData
.gBuildingModule
)
2316 self
.MakeTime
+= int(round((time
.time() - MakeStart
)))
2318 MakeContiue
= time
.time()
2321 # All modules have been put in build tasks queue. Tell task scheduler
2322 # to exit if all tasks are completed
2325 BuildTask
.WaitForComplete()
2326 if GlobalData
.gBinCacheDest
:
2328 elif GlobalData
.gUseHashCache
and not GlobalData
.gBinCacheSource
:
2330 # Update PreMakeCacheChain files
2331 self
.GenLocalPreMakeCache()
2335 ModuleList
= {ma
.Guid
.upper(): ma
for ma
in self
.BuildModules
}
2336 self
.BuildModules
= []
2337 self
.MakeTime
+= int(round((time
.time() - MakeContiue
)))
2339 # Check for build error, and raise exception if one
2340 # has been signaled.
2342 if BuildTask
.HasError():
2343 EdkLogger
.error("build", BUILD_ERROR
, "Failed to build module", ExtraData
=GlobalData
.gBuildingModule
)
2345 # Create MAP file when Load Fix Address is enabled.
2346 if self
.Target
in ["", "all", "fds"]:
2347 for Arch
in Wa
.ArchList
:
2349 # Check whether the set fix address is above 4G for 32bit image.
2351 if (Arch
== 'IA32' or Arch
== 'ARM') and self
.LoadFixAddress
!= 0xFFFFFFFFFFFFFFFF and self
.LoadFixAddress
>= 0x100000000:
2352 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")
2355 # Rebase module to the preferred memory address before GenFds
2358 if self
.LoadFixAddress
!= 0:
2359 self
._CollectModuleMapBuffer
(MapBuffer
, ModuleList
)
2363 # Generate FD image if there's a FDF file found
2365 GenFdsStart
= time
.time()
2366 if GenFdsApi(Wa
.GenFdsCommandDict
, self
.Db
):
2367 EdkLogger
.error("build", COMMAND_FAILURE
)
2368 Threshold
= self
.GetFreeSizeThreshold()
2370 self
.CheckFreeSizeThreshold(Threshold
, Wa
.FvDir
)
2373 # Create MAP file for all platform FVs after GenFds.
2375 self
._CollectFvMapBuffer
(MapBuffer
, Wa
, ModuleList
)
2376 self
.GenFdsTime
+= int(round((time
.time() - GenFdsStart
)))
2378 # Save MAP buffer into MAP file.
2380 self
._SaveMapFile
(MapBuffer
, Wa
)
2381 self
.CreateGuidedSectionToolsFile(Wa
)
2383 ## GetFreeSizeThreshold()
2385 # @retval int Threshold value
2387 def GetFreeSizeThreshold(self
):
2389 Threshold_Str
= GlobalData
.gCommandLineDefines
.get('FV_SPARE_SPACE_THRESHOLD')
2392 if Threshold_Str
.lower().startswith('0x'):
2393 Threshold
= int(Threshold_Str
, 16)
2395 Threshold
= int(Threshold_Str
)
2397 EdkLogger
.warn("build", 'incorrect value for FV_SPARE_SPACE_THRESHOLD %s.Only decimal or hex format is allowed.' % Threshold_Str
)
2400 def CheckFreeSizeThreshold(self
, Threshold
=None, FvDir
=None):
2401 if not isinstance(Threshold
, int):
2403 if not isinstance(FvDir
, str) or not FvDir
:
2405 FdfParserObject
= GlobalData
.gFdfParser
2406 FvRegionNameList
= [FvName
for FvName
in FdfParserObject
.Profile
.FvDict
if FdfParserObject
.Profile
.FvDict
[FvName
].FvRegionInFD
]
2407 for FvName
in FdfParserObject
.Profile
.FvDict
:
2408 if FvName
in FvRegionNameList
:
2409 FvSpaceInfoFileName
= os
.path
.join(FvDir
, FvName
.upper() + '.Fv.map')
2410 if os
.path
.exists(FvSpaceInfoFileName
):
2411 FileLinesList
= getlines(FvSpaceInfoFileName
)
2412 for Line
in FileLinesList
:
2413 NameValue
= Line
.split('=')
2414 if len(NameValue
) == 2 and NameValue
[0].strip() == 'EFI_FV_SPACE_SIZE':
2415 FreeSizeValue
= int(NameValue
[1].strip(), 0)
2416 if FreeSizeValue
< Threshold
:
2417 EdkLogger
.error("build", FV_FREESIZE_ERROR
,
2418 '%s FV free space %d is not enough to meet with the required spare space %d set by -D FV_SPARE_SPACE_THRESHOLD option.' % (
2419 FvName
, FreeSizeValue
, Threshold
))
2422 ## Generate GuidedSectionTools.txt in the FV directories.
2424 def CreateGuidedSectionToolsFile(self
,Wa
):
2425 for BuildTarget
in self
.BuildTargetList
:
2426 for ToolChain
in self
.ToolChainList
:
2428 if not os
.path
.exists(FvDir
):
2430 for Arch
in self
.ArchList
:
2432 tooldefguidList
= []
2434 for Platform
in Wa
.AutoGenObjectList
:
2435 if Platform
.BuildTarget
!= BuildTarget
:
2437 if Platform
.ToolChain
!= ToolChain
:
2439 if Platform
.Arch
!= Arch
:
2441 if hasattr (Platform
, 'BuildOption'):
2442 for Tool
in Platform
.BuildOption
:
2443 if 'GUID' in Platform
.BuildOption
[Tool
]:
2444 if 'PATH' in Platform
.BuildOption
[Tool
]:
2445 value
= Platform
.BuildOption
[Tool
]['GUID']
2446 if value
in guidList
:
2447 EdkLogger
.error("build", FORMAT_INVALID
, "Duplicate GUID value %s used with Tool %s in DSC [BuildOptions]." % (value
, Tool
))
2448 path
= Platform
.BuildOption
[Tool
]['PATH']
2449 guidList
.append(value
)
2450 guidAttribs
.append((value
, Tool
, path
))
2451 for Tool
in Platform
.ToolDefinition
:
2452 if 'GUID' in Platform
.ToolDefinition
[Tool
]:
2453 if 'PATH' in Platform
.ToolDefinition
[Tool
]:
2454 value
= Platform
.ToolDefinition
[Tool
]['GUID']
2455 if value
in tooldefguidList
:
2456 EdkLogger
.error("build", FORMAT_INVALID
, "Duplicate GUID value %s used with Tool %s in tools_def.txt." % (value
, Tool
))
2457 tooldefguidList
.append(value
)
2458 if value
in guidList
:
2459 # Already added by platform
2461 path
= Platform
.ToolDefinition
[Tool
]['PATH']
2462 guidList
.append(value
)
2463 guidAttribs
.append((value
, Tool
, path
))
2464 # Sort by GuidTool name
2465 guidAttribs
= sorted (guidAttribs
, key
=lambda x
: x
[1])
2466 # Write out GuidedSecTools.txt
2467 toolsFile
= os
.path
.join(FvDir
, 'GuidedSectionTools.txt')
2468 toolsFile
= open(toolsFile
, 'wt')
2469 for guidedSectionTool
in guidAttribs
:
2470 print(' '.join(guidedSectionTool
), file=toolsFile
)
2473 ## Returns the real path of the tool.
2475 def GetRealPathOfTool (self
, tool
):
2476 if os
.path
.exists(tool
):
2477 return os
.path
.realpath(tool
)
2480 ## Launch the module or platform build
2483 self
.AllDrivers
= set()
2484 self
.AllModules
= set()
2485 self
.PreMakeCacheMiss
= set()
2486 self
.PreMakeCacheHit
= set()
2487 self
.MakeCacheMiss
= set()
2488 self
.MakeCacheHit
= set()
2489 if not self
.ModuleFile
:
2490 if not self
.SpawnMode
or self
.Target
not in ["", "all"]:
2491 self
.SpawnMode
= False
2492 self
._BuildPlatform
()
2494 self
._MultiThreadBuildPlatform
()
2496 self
.SpawnMode
= False
2499 if self
.Target
== 'cleanall':
2500 RemoveDirectory(os
.path
.dirname(GlobalData
.gDatabasePath
), True)
2502 def CreateAsBuiltInf(self
):
2503 for Module
in self
.BuildModules
:
2504 Module
.CreateAsBuiltInf()
2506 def GenDestCache(self
):
2507 for Module
in self
.AllModules
:
2508 Module
.GenPreMakefileHashList()
2509 Module
.GenMakefileHashList()
2510 Module
.CopyModuleToCache()
2512 def GenLocalPreMakeCache(self
):
2513 for Module
in self
.PreMakeCacheMiss
:
2514 Module
.GenPreMakefileHashList()
2516 ## Do some clean-up works when error occurred
2517 def Relinquish(self
):
2518 OldLogLevel
= EdkLogger
.GetLevel()
2519 EdkLogger
.SetLevel(EdkLogger
.ERROR
)
2520 Utils
.Progressor
.Abort()
2521 if self
.SpawnMode
== True:
2523 EdkLogger
.SetLevel(OldLogLevel
)
2525 def ParseDefines(DefineList
=[]):
2527 if DefineList
is not None:
2528 for Define
in DefineList
:
2529 DefineTokenList
= Define
.split("=", 1)
2530 if not GlobalData
.gMacroNamePattern
.match(DefineTokenList
[0]):
2531 EdkLogger
.error('build', FORMAT_INVALID
,
2532 "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
2533 ExtraData
=DefineTokenList
[0])
2535 if len(DefineTokenList
) == 1:
2536 DefineDict
[DefineTokenList
[0]] = "TRUE"
2538 DefineDict
[DefineTokenList
[0]] = DefineTokenList
[1].strip()
2543 def LogBuildTime(Time
):
2546 TimeDur
= time
.gmtime(Time
)
2547 if TimeDur
.tm_yday
> 1:
2548 TimeDurStr
= time
.strftime("%H:%M:%S", TimeDur
) + ", %d day(s)" % (TimeDur
.tm_yday
- 1)
2550 TimeDurStr
= time
.strftime("%H:%M:%S", TimeDur
)
2555 OptionParser
= MyOptionParser()
2556 if not OptionParser
.BuildOption
and not OptionParser
.BuildTarget
:
2557 OptionParser
.GetOption()
2558 BuildOption
, BuildTarget
= OptionParser
.BuildOption
, OptionParser
.BuildTarget
2559 ThreadNumber
= BuildOption
.ThreadNumber
2560 GlobalData
.gCmdConfDir
= BuildOption
.ConfDirectory
2561 if ThreadNumber
is None:
2562 TargetObj
= TargetTxtDict()
2563 ThreadNumber
= TargetObj
.Target
.TargetTxtDictionary
[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER
]
2564 if ThreadNumber
== '':
2567 ThreadNumber
= int(ThreadNumber
, 0)
2569 if ThreadNumber
== 0:
2571 ThreadNumber
= multiprocessing
.cpu_count()
2572 except (ImportError, NotImplementedError):
2575 ## Tool entrance method
2577 # This method mainly dispatch specific methods per the command line options.
2578 # If no error found, return zero value so the caller of this tool can know
2579 # if it's executed successfully or not.
2581 # @retval 0 Tool was successful
2582 # @retval 1 Tool failed
2584 LogQMaxSize
= ThreadNum() * 10
2586 StartTime
= time
.time()
2589 # Create a log Queue
2591 LogQ
= mp
.Queue(LogQMaxSize
)
2592 # Initialize log system
2593 EdkLogger
.LogClientInitialize(LogQ
)
2594 GlobalData
.gCommand
= sys
.argv
[1:]
2596 # Parse the options and args
2598 OptionParser
= MyOptionParser()
2599 if not OptionParser
.BuildOption
and not OptionParser
.BuildTarget
:
2600 OptionParser
.GetOption()
2601 Option
, Target
= OptionParser
.BuildOption
, OptionParser
.BuildTarget
2602 GlobalData
.gOptions
= Option
2603 GlobalData
.gCaseInsensitive
= Option
.CaseInsensitive
2606 LogLevel
= EdkLogger
.INFO
2607 if Option
.verbose
is not None:
2608 EdkLogger
.SetLevel(EdkLogger
.VERBOSE
)
2609 LogLevel
= EdkLogger
.VERBOSE
2610 elif Option
.quiet
is not None:
2611 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
2612 LogLevel
= EdkLogger
.QUIET
2613 elif Option
.debug
is not None:
2614 EdkLogger
.SetLevel(Option
.debug
+ 1)
2615 LogLevel
= Option
.debug
+ 1
2617 EdkLogger
.SetLevel(EdkLogger
.INFO
)
2619 if Option
.WarningAsError
== True:
2620 EdkLogger
.SetWarningAsError()
2621 Log_Agent
= LogAgent(LogQ
,LogLevel
,Option
.LogFile
)
2624 if platform
.platform().find("Windows") >= 0:
2625 GlobalData
.gIsWindows
= True
2627 GlobalData
.gIsWindows
= False
2629 EdkLogger
.quiet("Build environment: %s" % platform
.platform())
2630 EdkLogger
.quiet(time
.strftime("Build start time: %H:%M:%S, %b.%d %Y\n", time
.localtime()));
2635 if len(Target
) == 0:
2637 elif len(Target
) >= 2:
2638 EdkLogger
.error("build", OPTION_NOT_SUPPORTED
, "More than one targets are not supported.",
2639 ExtraData
="Please select one of: %s" % (' '.join(gSupportedTarget
)))
2641 Target
= Target
[0].lower()
2643 if Target
not in gSupportedTarget
:
2644 EdkLogger
.error("build", OPTION_NOT_SUPPORTED
, "Not supported target [%s]." % Target
,
2645 ExtraData
="Please select one of: %s" % (' '.join(gSupportedTarget
)))
2648 # Check environment variable: EDK_TOOLS_PATH, WORKSPACE, PATH
2651 GlobalData
.gCommandLineDefines
.update(ParseDefines(Option
.Macros
))
2653 Workspace
= os
.getenv("WORKSPACE")
2655 # Get files real name in workspace dir
2657 GlobalData
.gAllFiles
= Utils
.DirCache(Workspace
)
2659 WorkingDirectory
= os
.getcwd()
2660 if not Option
.ModuleFile
:
2661 FileList
= glob
.glob(os
.path
.normpath(os
.path
.join(WorkingDirectory
, '*.inf')))
2662 FileNum
= len(FileList
)
2664 EdkLogger
.error("build", OPTION_NOT_SUPPORTED
, "There are %d INF files in %s." % (FileNum
, WorkingDirectory
),
2665 ExtraData
="Please use '-m <INF_FILE_PATH>' switch to choose one.")
2667 Option
.ModuleFile
= NormFile(FileList
[0], Workspace
)
2669 if Option
.ModuleFile
:
2670 if os
.path
.isabs (Option
.ModuleFile
):
2671 if os
.path
.normcase (os
.path
.normpath(Option
.ModuleFile
)).find (Workspace
) == 0:
2672 Option
.ModuleFile
= NormFile(os
.path
.normpath(Option
.ModuleFile
), Workspace
)
2673 Option
.ModuleFile
= PathClass(Option
.ModuleFile
, Workspace
)
2674 ErrorCode
, ErrorInfo
= Option
.ModuleFile
.Validate(".inf", False)
2676 EdkLogger
.error("build", ErrorCode
, ExtraData
=ErrorInfo
)
2678 if Option
.PlatformFile
is not None:
2679 if os
.path
.isabs (Option
.PlatformFile
):
2680 if os
.path
.normcase (os
.path
.normpath(Option
.PlatformFile
)).find (Workspace
) == 0:
2681 Option
.PlatformFile
= NormFile(os
.path
.normpath(Option
.PlatformFile
), Workspace
)
2682 Option
.PlatformFile
= PathClass(Option
.PlatformFile
, Workspace
)
2684 if Option
.FdfFile
is not None:
2685 if os
.path
.isabs (Option
.FdfFile
):
2686 if os
.path
.normcase (os
.path
.normpath(Option
.FdfFile
)).find (Workspace
) == 0:
2687 Option
.FdfFile
= NormFile(os
.path
.normpath(Option
.FdfFile
), Workspace
)
2688 Option
.FdfFile
= PathClass(Option
.FdfFile
, Workspace
)
2689 ErrorCode
, ErrorInfo
= Option
.FdfFile
.Validate(".fdf", False)
2691 EdkLogger
.error("build", ErrorCode
, ExtraData
=ErrorInfo
)
2693 if Option
.Flag
is not None and Option
.Flag
not in ['-c', '-s']:
2694 EdkLogger
.error("build", OPTION_VALUE_INVALID
, "UNI flag must be one of -c or -s")
2696 MyBuild
= Build(Target
, Workspace
, Option
,LogQ
)
2697 GlobalData
.gCommandLineDefines
['ARCH'] = ' '.join(MyBuild
.ArchList
)
2698 if not (MyBuild
.LaunchPrebuildFlag
and os
.path
.exists(MyBuild
.PlatformBuildPath
)):
2702 # All job done, no error found and no exception raised
2705 except FatalError
as X
:
2706 if MyBuild
is not None:
2707 # for multi-thread build exits safely
2708 MyBuild
.Relinquish()
2709 if Option
is not None and Option
.debug
is not None:
2710 EdkLogger
.quiet("(Python %s on %s) " % (platform
.python_version(), sys
.platform
) + traceback
.format_exc())
2711 ReturnCode
= X
.args
[0]
2712 except Warning as X
:
2713 # error from Fdf parser
2714 if MyBuild
is not None:
2715 # for multi-thread build exits safely
2716 MyBuild
.Relinquish()
2717 if Option
is not None and Option
.debug
is not None:
2718 EdkLogger
.quiet("(Python %s on %s) " % (platform
.python_version(), sys
.platform
) + traceback
.format_exc())
2720 EdkLogger
.error(X
.ToolName
, FORMAT_INVALID
, File
=X
.FileName
, Line
=X
.LineNumber
, ExtraData
=X
.Message
, RaiseError
=False)
2721 ReturnCode
= FORMAT_INVALID
2722 except KeyboardInterrupt:
2723 if MyBuild
is not None:
2725 # for multi-thread build exits safely
2726 MyBuild
.Relinquish()
2727 ReturnCode
= ABORT_ERROR
2728 if Option
is not None and Option
.debug
is not None:
2729 EdkLogger
.quiet("(Python %s on %s) " % (platform
.python_version(), sys
.platform
) + traceback
.format_exc())
2731 if MyBuild
is not None:
2732 # for multi-thread build exits safely
2733 MyBuild
.Relinquish()
2735 # try to get the meta-file from the object causing exception
2736 Tb
= sys
.exc_info()[-1]
2737 MetaFile
= GlobalData
.gProcessingFile
2738 while Tb
is not None:
2739 if 'self' in Tb
.tb_frame
.f_locals
and hasattr(Tb
.tb_frame
.f_locals
['self'], 'MetaFile'):
2740 MetaFile
= Tb
.tb_frame
.f_locals
['self'].MetaFile
2745 "Unknown fatal error when processing [%s]" % MetaFile
,
2746 ExtraData
="\n(Please send email to %s for help, attaching following call stack trace!)\n" % MSG_EDKII_MAIL_ADDR
,
2749 EdkLogger
.quiet("(Python %s on %s) " % (platform
.python_version(), sys
.platform
) + traceback
.format_exc())
2750 ReturnCode
= CODE_ERROR
2752 Utils
.Progressor
.Abort()
2753 Utils
.ClearDuplicatedInf()
2757 MyBuild
.LaunchPostbuild()
2760 Conclusion
= "Failed"
2761 ReturnCode
= POSTBUILD_ERROR
2762 elif ReturnCode
== ABORT_ERROR
:
2763 Conclusion
= "Aborted"
2765 Conclusion
= "Failed"
2766 FinishTime
= time
.time()
2767 BuildDuration
= time
.gmtime(int(round(FinishTime
- StartTime
)))
2768 BuildDurationStr
= ""
2769 if BuildDuration
.tm_yday
> 1:
2770 BuildDurationStr
= time
.strftime("%H:%M:%S", BuildDuration
) + ", %d day(s)" % (BuildDuration
.tm_yday
- 1)
2772 BuildDurationStr
= time
.strftime("%H:%M:%S", BuildDuration
)
2773 if MyBuild
is not None:
2775 MyBuild
.BuildReport
.GenerateReport(BuildDurationStr
, LogBuildTime(MyBuild
.AutoGenTime
), LogBuildTime(MyBuild
.MakeTime
), LogBuildTime(MyBuild
.GenFdsTime
))
2777 EdkLogger
.SetLevel(EdkLogger
.QUIET
)
2778 EdkLogger
.quiet("\n- %s -" % Conclusion
)
2779 EdkLogger
.quiet(time
.strftime("Build end time: %H:%M:%S, %b.%d %Y", time
.localtime()))
2780 EdkLogger
.quiet("Build total time: %s\n" % BuildDurationStr
)
2785 if __name__
== '__main__':
2787 mp
.set_start_method('spawn')
2791 ## 0-127 is a safe return range, and 1 is a standard default error
2792 if r
< 0 or r
> 127: r
= 1