12 from EdkIIWorkspaceBuild import *
13 from EdkIIWorkspace import *
14 from DataType import *
15 from BuildInfo import *
16 from StrGather import *
17 from BuildToolError import *
20 # generate AutoGen.c, AutoGen.h
21 # parse unicode file and generate XXXXString.h, XXXXString.c
25 gPlatformDatabase = {} # {arch : {dsc file path : PlatformBuildClassObject}}
26 gModuleDatabase = {} # {arch : {inf file path : ModuleBuildClassObject}}
27 gPackageDatabase = {} # {arch : {dec file path : PackageBuildClassObject}}
28 gAutoGenDatabase = {} # (module/package/platform obj, BuildTarget, ToolChain, Arch) : build info
31 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
32 gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}
34 def FindModuleOwnerPackage(module, pkgdb):
36 pkgDir = path.dirname(pkg)
37 if module.DescFilePath.find(pkgDir) == 0:
41 class AutoGen(object):
43 def __init__(self, moduleFile, platformFile, workspace, target, toolchain, arch):
44 global gModuleDatabase, gPackageDatabase, gPlatformDatabase, gAutoGenDatabase, gWorkspace, gWorkspaceDir
46 if gWorkspace == None:
47 gWorkspace = workspace
48 if gWorkspaceDir == "":
49 gWorkspaceDir = workspace.Workspace.WorkspaceDir
51 if gModuleDatabase == {}:
52 for a in workspace.Build:
53 gModuleDatabase[a] = gWorkspace.Build[a].ModuleDatabase
54 if gPackageDatabase == {}:
55 for a in workspace.Build:
56 gPackageDatabase[a] = gWorkspace.Build[a].PackageDatabase
57 if gPlatformDatabase == {}:
58 for a in workspace.Build:
59 gPlatformDatabase[a] = gWorkspace.Build[a].PlatformDatabase
61 self.ToolChain = toolchain
62 self.BuildTarget = target
63 self.IsMakefileCreated = False
64 self.IsAutoGenCodeCreated = False
66 key = (self.BuildTarget, self.ToolChain, str(platformFile))
67 if moduleFile == None:
69 # autogen for platform
71 self.PlatformBuildInfo = {} # arch : PlatformBuildInfo Object
73 self.IsPlatformAutoGen = True
74 if type(arch) == type([]):
82 if a not in gPlatformDatabase or str(platformFile) not in gPlatformDatabase[a]:
83 raise AutoGenError(msg="[%s] is not active platform, or %s is not supported!" % (platformFile, a))
84 p = gPlatformDatabase[a][str(platformFile)]
86 self.BuildInfo[a] = self.GetPlatformBuildInfo(p, self.BuildTarget, self.ToolChain, a)
87 gAutoGenDatabase[key] = self
89 elif key not in gAutoGenDatabase:
90 gAutoGenDatabase[key] = AutoGen(None, platformFile, workspace, target, toolchain, arch)
92 #print "-------------",moduleFile,"----------------"
96 self.IsPlatformAutoGen = False
97 if type(arch) == type([]):
99 raise AutoGenError(msg="Cannot AutoGen a module for more than one platform objects at the same time!")
104 if self.Arch not in gPlatformDatabase or str(platformFile) not in gPlatformDatabase[arch]:
105 raise AutoGenError(msg="[%s] is not active platform, or %s is not supported!" % (platformFile, self.Arch))
106 if self.Arch not in gModuleDatabase or str(moduleFile) not in gModuleDatabase[self.Arch]:
107 raise AutoGenError(msg="[%s] for %s is not found in active platform [%s]!" % (moduleFile, self.Arch, platformFile))
108 self.Module = gModuleDatabase[self.Arch][str(moduleFile)]
109 self.Platform = gPlatformDatabase[arch][str(platformFile)]
111 self.Package = FindModuleOwnerPackage(self.Module, gPackageDatabase[arch])
112 if self.Package == None:
113 raise AutoGenError(msg="Cannot find owner package for [%s]!" % (moduleFile))
115 self.AutoGenC = GenC.AutoGenString()
116 self.AutoGenH = GenC.AutoGenString()
118 self.BuildInfo = None
119 self.GetModuleBuildInfo()
120 gAutoGenDatabase[self.BuildTarget, self.ToolChain, self.Arch, self.Module] = self
122 def GetModuleBuildInfo(self):
123 key = (self.BuildTarget, self.ToolChain, self.Arch, self.Module)
124 if key in gAutoGenDatabase:
125 self.BuildInfo = gAutoGenDatabase[key].BuildInfo
126 self.IsAutoGenCodeCreated = gAutoGenDatabase[key].IsAutoGenCodeCreated
127 self.IsMakefileCreated = gAutoGenDatabase[key].IsMakefileCreated
128 return gAutoGenDatabase[key].BuildInfo
130 info = ModuleBuildInfo(self.Module)
131 self.BuildInfo = info
132 info.PlatformInfo = self.GetPlatformBuildInfo(self.Platform, self.BuildTarget, self.ToolChain, self.Arch)
134 key = (self.Package, self.BuildTarget, self.ToolChain, self.Arch)
135 if key in gAutoGenDatabase:
136 info.PackageInfo = gAutoGenDatabase[key]
138 info.PackageInfo = PackageBuildInfo(self.Package)
139 self.InitPackageBuildInfo(info.PackageInfo)
140 gAutoGenDatabase[key] = info.PackageInfo
143 info.WorkspaceDir = gWorkspaceDir
144 info.BuildTarget = self.BuildTarget
145 info.ToolChain = self.ToolChain
146 info.Arch = self.Arch
147 info.IsBinary = False
148 info.BaseName = self.Module.BaseName
149 info.FileBase, info.FileExt = path.splitext(path.basename(self.Module.DescFilePath))
150 info.SourceDir = path.dirname(self.Module.DescFilePath)
151 info.BuildDir = os.path.join(info.PlatformInfo.BuildDir,
155 info.OutputDir = os.path.join(info.BuildDir, "OUTPUT")
156 info.DebugDir = os.path.join(info.BuildDir, "DEBUG")
157 info.MakefileDir = info.BuildDir
158 if os.path.isabs(info.BuildDir):
159 CreateDirectory(info.OutputDir)
160 CreateDirectory(info.DebugDir)
162 CreateDirectory(os.path.join(gWorkspaceDir, info.OutputDir))
163 CreateDirectory(os.path.join(gWorkspaceDir, info.DebugDir))
165 for type in self.Module.CustomMakefile:
166 makeType = gMakeTypeMap[type]
167 info.CustomMakefile[makeType] = os.path.join(info.SourceDir, self.Module.CustomMakefile[type])
169 if self.Module.LibraryClass != None and self.Module.LibraryClass != "":
170 info.IsLibrary = True
171 info.DependentLibraryList = []
173 info.IsLibrary = False
174 info.DependentLibraryList = self.GetSortedLibraryList()
176 info.DependentPackageList = self.GetDependentPackageList()
178 info.BuildOption = self.GetModuleBuildOption(info.PlatformInfo)
180 info.PcdIsDriver = self.Module.PcdIsDriver
181 info.PcdList = self.GetPcdList(info.DependentLibraryList)
182 info.GuidList = self.GetGuidList()
183 info.ProtocolList = self.GetProtocolGuidList()
184 info.PpiList = self.GetPpiGuidList()
185 info.MacroList = self.GetMacroList()
186 info.DepexList = self.GetDepexTokenList(info)
188 info.IncludePathList = [info.SourceDir, info.DebugDir]
189 info.IncludePathList.extend(self.GetIncludePathList(info.DependentPackageList))
191 info.SourceFileList = self.GetBuildFileList(info.PlatformInfo)
192 info.AutoGenFileList = self.GetAutoGenFileList(info)
196 def InitPackageBuildInfo(self, info):
197 info.SourceDir = path.dirname(info.Package.DescFilePath)
198 info.IncludePathList.append(info.SourceDir)
199 for inc in info.Package.Includes:
200 info.IncludePathList.append(os.path.join(info.SourceDir, inc))
202 def GetPlatformBuildInfo(self, platform, target, toolchain, arch):
203 key = target, toolchain, platform
204 platformAutoGen = None
205 if key in gAutoGenDatabase:
206 platformAutoGen = gAutoGenDatabase[key]
207 if arch in platformAutoGen.BuildInfo:
208 return platformAutoGen.BuildInfo[arch]
210 info = PlatformBuildInfo(platform)
212 ruleFile = gWorkspace.Workspace.WorkspaceFile(r'Conf\build_rule.txt')
213 info.BuildRule = imp.load_source("BuildRule", ruleFile)
216 info.ToolChain = self.ToolChain
217 info.BuildTarget = self.BuildTarget
219 info.WorkspaceDir = gWorkspace.Workspace.WorkspaceDir
220 info.SourceDir = path.dirname(platform.DescFilePath)
221 info.OutputDir = platform.OutputDirectory
222 info.BuildDir = path.join(info.OutputDir, self.BuildTarget + "_" + self.ToolChain)
223 info.MakefileDir = info.BuildDir
224 if platform.FlashDefinition != "":
225 info.FdfFileList.append(path.join(gWorkspaceDir, platform.FlashDefinition))
227 info.DynamicPcdList = self.GetDynamicPcdList(platform, arch)
228 info.PcdTokenNumber = self.GeneratePcdTokenNumber(platform, info.DynamicPcdList)
229 info.PackageList = gPackageDatabase[arch].values()
231 self.ProcessToolDefinition(info)
233 if platformAutoGen != None:
234 platformAutoGen.BuildInfo = info
237 def GetDepexTokenList(self, info):
238 dxs = self.Module.Depex
240 # Append depex from dependent libraries
242 for lib in info.DependentLibraryList:
244 dxs += " AND " + lib.Depex
248 tokenList = gDepexTokenPattern.findall(self.Module.Depex)
249 for i in range(0, len(tokenList)):
250 token = tokenList[i].strip()
251 if token.endswith(".inf"): # module file name
252 moduleFile = os.path.normpath(token)
253 token = gModuleDatabase[moduleFile].Guid
254 elif token.upper() in GenDepex.DependencyExpression.SupportedOpcode: # Opcode name
255 token = token.upper()
258 for p in info.DependentPackageList:
259 if guidCName in p.Protocols:
260 token = p.Protocols[guidCName]
262 elif guidCName in p.Ppis:
263 token = p.Ppis[guidCName]
265 elif guidCName in p.Guids:
266 token = p.Guids[guidCName]
269 raise AutoGenError(msg="%s used in module %s cannot be found in any package!" % (guidCName, info.Name))
273 def GetMacroList(self):
274 return ["%s %s" % (name, self.Module.Specification[name]) for name in self.Module.Specification]
276 def ProcessToolDefinition(self, info):
277 toolDefinition = gWorkspace.ToolDef.ToolsDefTxtDictionary
278 toolCodeList = gWorkspace.ToolDef.ToolsDefTxtDatabase["COMMAND_TYPE"]
279 for tool in toolCodeList:
280 keyBaseString = "%s_%s_%s_%s" % (info.BuildTarget, info.ToolChain, info.Arch, tool)
281 key = "%s_NAME" % keyBaseString
282 if key not in toolDefinition:
284 name = toolDefinition[key]
286 key = "%s_PATH" % keyBaseString
287 if key in toolDefinition:
288 path = toolDefinition[key]
292 key = "%s_FAMILY" % keyBaseString
293 if key in toolDefinition:
294 family = toolDefinition[key]
298 key = "%s_FLAGS" % keyBaseString
299 if key in toolDefinition:
300 option = toolDefinition[key]
304 key = "%s_DPATH" % keyBaseString
305 if key in toolDefinition:
306 dll = toolDefinition[key]
310 key = "%s_SPATH" % keyBaseString
311 if key in toolDefinition:
312 lib = toolDefinition[key]
316 info.ToolPath[tool] = os.path.join(path, name)
317 info.ToolDynamicLib[tool] = dll
318 info.ToolStaticLib[tool] = lib
319 info.ToolChainFamily[tool] = family
320 info.DefaultToolOption[tool] = option
322 if self.IsPlatformAutoGen:
323 buildOptions = self.Platform[info.Arch].BuildOptions
325 buildOptions = self.Platform.BuildOptions
327 for key in buildOptions:
329 target, tag, arch, tool, attr = key[1].split("_")
330 if tool not in info.ToolPath:
332 if family != None and family != "" and family != info.ToolChainFamily[tool]:
334 if target == "*" or target == info.BuildTarget:
335 if tag == "*" or tag == info.ToolChain:
336 if arch == "*" or arch == info.Arch:
337 info.BuildOption[tool] = buildOptions[key]
338 for tool in info.DefaultToolOption:
339 if tool not in info.BuildOption:
340 info.BuildOption[tool] = ""
342 def GetModuleBuildOption(self, platformInfo):
343 buildOption = self.Module.BuildOptions
345 for key in buildOption:
347 target, tag, arch, tool, attr = key[1].split("_")
348 if tool not in platformInfo.ToolPath:
350 if family != None and family != "" and family != platformInfo.ToolChainFamily[tool]:
352 if target == "*" or target == self.BuildTarget:
353 if tag == "*" or tag == self.ToolChain:
354 if arch == "*" or arch == self.Arch:
355 optionList[tool] = buildOption[key]
356 for tool in platformInfo.DefaultToolOption:
357 if tool not in optionList:
358 optionList[tool] = ""
361 def GetBuildFileList(self, platformInfo):
362 buildRule = platformInfo.BuildRule
364 fileList = self.Module.Sources
366 if f.TagName != "" and f.TagName != self.ToolChain:
368 if f.ToolCode != "" and f.ToolCode not in platformInfo.ToolPath:
371 dir = path.dirname(f.SourceFile)
373 dir = path.join(self.BuildInfo.SourceDir, dir)
374 if dir not in self.BuildInfo.IncludePathList:
375 self.BuildInfo.IncludePathList.insert(0, dir)
378 base, ext = path.splitext(f.SourceFile)
379 if ext not in buildRule.FileTypeMapping:
380 EdkLogger.verbose("Don't know how to process file %s (%s)" % (f.SourceFile, ext))
383 # skip file which needs a tool having no matching toolchain family
384 fileType = buildRule.FileTypeMapping[ext]
386 toolCode = f.ToolCode
388 toolCode = buildRule.ToolCodeMapping[fileType]
389 # get the toolchain family from tools definition
390 if f.ToolChainFamily != "" and f.ToolChainFamily != platformInfo.ToolChainFamily[toolCode]:
391 EdkLogger.verbose("File %s for toolchain family %s is not supported" % (f.SourceFile, f.ToolChainFamily))
393 if fileType == "Unicode-Text":
394 self.BuildInfo.UnicodeFileList.append(os.path.join(gWorkspaceDir, self.BuildInfo.SourceDir, f.SourceFile))
395 buildFileList.append(f.SourceFile)
398 def GetDependentPackageList(self):
399 if self.Package not in self.Module.Packages:
400 self.Module.Packages.insert(0, str(self.Package))
402 if self.Arch not in gPackageDatabase:
403 raise AutoGenError(msg="[%s] is not supported!")
404 packageDatabase = gPackageDatabase[self.Arch]
407 for pf in self.Module.Packages:
408 if pf in packageList:
410 if pf not in packageDatabase:
411 raise AutoGenError(FILE_NOT_FOUND, name=pf)
412 packageList.append(packageDatabase[pf])
415 def GetAutoGenFileList(self, buildInfo):
416 GenC.CreateCode(buildInfo, self.AutoGenC, self.AutoGenH)
418 if self.AutoGenC.String != "":
419 fileList.append("AutoGen.c")
420 if self.AutoGenH.String != "":
421 fileList.append("AutoGen.h")
422 #print self.AutoGenH.String
425 def GetSortedLibraryList(self):
426 moduleType = self.Module.ModuleType
427 libraryConsumerList = [self.Module]
432 libraryClassList = []
434 EdkLogger.verbose("")
435 EdkLogger.verbose("Library instances of module [%s]:" % str(self.Module))
436 while len(libraryConsumerList) > 0:
437 module = libraryConsumerList.pop()
438 for libc, libf in module.LibraryClasses.iteritems():
439 if moduleType not in libc:
440 EdkLogger.debug(EdkLogger.DEBUG_5, "\t%s for module type %s is not supported" % libc)
442 if libf == None or libf == "":
443 EdkLogger.info("\tLibrary instance of library class %s is not found" % libc[0])
446 libm = gModuleDatabase[self.Arch][libf]
447 if libm not in libraryList and libc not in libraryClassList:
448 libraryConsumerList.append(libm)
449 libraryList.append(libm)
450 libraryClassList.append(libc)
451 EdkLogger.verbose("\t" + libc[0] + " : " + str(libm))
453 if libm.ConstructorList != [] and libm not in constructor:
454 constructor.append(libm)
456 if libm not in consumedByList:
457 consumedByList[libm] = []
458 if module != self.Module:
459 if module in consumedByList[libm]:
461 consumedByList[libm].append(module)
463 # Initialize the sorted output list to the empty set
465 SortedLibraryList = []
467 # Q <- Set of all nodes with no incoming edges
470 for m in libraryList:
471 if consumedByList[m] == []:
474 # while Q is not empty do
478 # remove node n from Q
484 SortedLibraryList.append(n)
486 # for each node m with an edge e from n to m do
488 for m in libraryList:
489 if n not in consumedByList[m]:
492 # remove edge e from the graph
494 consumedByList[m].remove(n)
496 # If m has no other incoming edges then
498 if consumedByList[m] == []:
505 while Q == [] and EdgeRemoved:
508 # for each node m with a constructor
510 for m in libraryList:
513 # for each node n without a constructor with an edge e from m to n
515 for n in consumedByList[m]:
516 if n not in constructor:
518 # remove edge e from the graph
520 consumedByList[m].remove(n)
522 if consumedByList[m] == []:
532 # if any remaining node m in the graph has a constructor and an incoming edge, then the graph has a cycle
534 for m in libraryList:
535 if consumedByList[m] != [] and m in constructor:
536 errorMessage = 'Module library [%s] with constructors have a cycle:\n\t' % str(m)
537 errorMessage += "\n\tconsumed by ".join([str(l) for l in consumedByList[m]])
538 raise AutoGenError(msg=errorMessage)
539 if m not in SortedLibraryList:
540 SortedLibraryList.append(m)
543 # Build the list of constructor and destructir names
544 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
546 SortedLibraryList.reverse()
547 return SortedLibraryList
549 def GetDynamicPcdList(self, platform, arch):
551 for f in gModuleDatabase[arch]:
552 m = gModuleDatabase[arch][f]
554 if key not in platform.Pcds:
555 raise AutoGenError(msg="PCD [%s %s] not found in platform" % key)
557 pPcd = platform.Pcds[key]
558 if pPcd.Type in GenC.gDynamicPcd + GenC.gDynamicExPcd:
559 if m.ModuleType in ["PEIM", "PEI_CORE"]:
561 if pPcd not in pcdList:
562 pPcd.DatumType = mPcd.DatumType
566 def GeneratePcdTokenNumber(self, platform, dynamicPcdList):
569 for pcd in dynamicPcdList:
570 #print "@@@",tokenNumber,"=",pcd.TokenCName, pcd.TokenSpaceGuidCName, pcd.DatumType
571 pcdTokenNumber[pcd.TokenCName, pcd.TokenSpaceGuidCName] = tokenNumber
574 platformPcds = platform.Pcds
575 for key in platformPcds:
576 pcd = platformPcds[key]
578 if key not in pcdTokenNumber:
579 pcdTokenNumber[key] = tokenNumber
581 return pcdTokenNumber
583 def GetPcdList(self, dependentLibraryList):
584 platformPcds = self.Platform.Pcds
587 for m in dependentLibraryList + [self.Module]:
588 for pcdKey in m.Pcds:
590 if (pcd.Type in GenC.gDynamicPcd + GenC.gDynamicExPcd) and self.Module.ModuleType in ["PEIM", "PEI_CORE"]:
591 #platformPcds[pcdKey].Phase = "PEI"
593 if pcd not in pcdList:
597 def GetGuidList(self):
598 packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
601 for Key in self.Module.Guids:
602 for p in self.BuildInfo.DependentPackageList:
604 guid[Key] = p.Guids[Key]
606 if Key in p.Protocols:
607 guid[Key] = p.Protocols[Key]
610 guid[Key] = p.Ppis[Key]
613 raise AutoGenError(msg='GUID [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.BuildInfo.Name, packageListString))
615 for lib in self.BuildInfo.DependentLibraryList:
619 for Key in lib.Guids:
620 for p in lib.Packages:
621 # print gPackageDatabase
622 p = gPackageDatabase[self.Arch][p]
624 guid[Key] = p.Guids[Key]
626 if Key in p.Protocols:
627 guid[Key] = p.Protocols[Key]
630 guid[Key] = p.Ppis[Key]
633 raise AutoGenError(msg='GUID [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, lib.BaseName, packageListString))
636 def GetProtocolGuidList(self):
637 packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
640 for Key in self.Module.Protocols:
641 for p in self.BuildInfo.DependentPackageList:
643 guid[Key] = p.Guids[Key]
645 if Key in p.Protocols:
646 guid[Key] = p.Protocols[Key]
649 guid[Key] = p.Ppis[Key]
652 raise AutoGenError(msg='Protocol [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.BuildInfo.Name, packageListString))
654 for lib in self.BuildInfo.DependentLibraryList:
655 if lib.Protocols == []:
657 for Key in lib.Protocols:
658 for p in lib.Packages:
659 p = gPackageDatabase[self.Arch][p]
661 guid[Key] = p.Guids[Key]
663 if Key in p.Protocols:
664 guid[Key] = p.Protocols[Key]
667 guid[Key] = p.Ppis[Key]
670 raise AutoGenError(msg='Protocol [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, lib.BaseName, packageListString))
674 def GetPpiGuidList(self):
675 packageListString = "\n\t".join([p.PackageName for p in self.BuildInfo.DependentPackageList])
678 for Key in self.Module.Ppis:
679 for p in self.BuildInfo.DependentPackageList:
681 guid[Key] = p.Guids[Key]
683 if Key in p.Protocols:
684 guid[Key] = p.Protocols[Key]
687 guid[Key] = p.Ppis[Key]
690 raise AutoGenError(msg='PPI [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, self.BuildInfo.Name, packageListString))
692 for lib in self.BuildInfo.DependentLibraryList:
696 for p in lib.Packages:
697 p = gPackageDatabase[self.Arch][p]
699 guid[Key] = p.Guids[Key]
701 if Key in p.Protocols:
702 guid[Key] = p.Protocols[Key]
705 guid[Key] = p.Ppis[Key]
708 raise AutoGenError(msg='PPI [%s] used by [%s] cannot be found in dependent packages:\n\t%s' % (Key, lib.BaseName, packageListString))
711 def GetIncludePathList(self, dependentPackageList):
713 for inc in self.Module.Includes:
714 includePathList.append(inc)
716 for package in dependentPackageList:
717 packageDir = path.dirname(package.DescFilePath)
718 includePathList.append(packageDir)
719 for inc in package.Includes:
720 inc = os.path.join(packageDir, inc)
721 if inc not in includePathList:
722 includePathList.append(inc)
723 return includePathList
725 def CreateMakefile(self, filePath=None):
727 "ENABLE_PCH" : False,
728 "ENABLE_LOCAL_LIB" : True,
730 if self.IsMakefileCreated:
733 if self.IsPlatformAutoGen:
734 for arch in self.BuildInfo:
735 info = self.BuildInfo[arch]
736 for moduleFile in info.Platform.Modules:
737 key = (info.BuildTarget, info.ToolChain, arch, moduleFile)
739 if key not in gAutoGenDatabase:
740 moduleAutoGen = AutoGen(moduleFile, info.Platform, gWorkspace,
741 info.BuildTarget, info.ToolChain, info.Arch)
743 moduleAutoGen = gAutoGenDatabase[key]
744 moduleAutoGen.CreateMakefile()
746 platformInfo = self.BuildInfo.PlatformInfo
747 if not self.BuildInfo.IsLibrary:
748 if self not in platformInfo.ModuleAutoGenList:
749 platformInfo.ModuleAutoGenList.append(self)
750 elif self not in platformInfo.LibraryAutoGenList:
751 platformInfo.LibraryAutoGenList.append(self)
753 for lib in self.BuildInfo.DependentLibraryList:
754 EdkLogger.debug(EdkLogger.DEBUG_2, "###" + str(lib))
755 key = (self.BuildTarget, self.ToolChain, self.Arch, lib)
756 libraryAutoGen = None
757 if key not in gAutoGenDatabase:
758 libraryAutoGen = AutoGen(lib, self.Platform, gWorkspace,
759 self.BuildTarget, self.ToolChain, self.Arch)
761 libraryAutoGen = gAutoGenDatabase[key]
762 if libraryAutoGen not in self.BuildInfo.LibraryAutoGenList:
763 self.BuildInfo.LibraryAutoGenList.append(libraryAutoGen)
764 libraryAutoGen.CreateMakefile()
766 makefile = GenMake.Makefile(self.BuildInfo, myBuildOption)
767 f = makefile.Generate()
768 self.IsMakefileCreated = True
769 EdkLogger.info("Generated [%s] for module %s" % (path.basename(f), self.BuildInfo.Name))
772 makefile = GenMake.Makefile(self.BuildInfo, myBuildOption)
773 f = makefile.Generate()
774 self.IsMakefileCreated = True
775 EdkLogger.info("Generated [%s] for platform %s" % (path.basename(f), self.BuildInfo[self.Arch[0]].Name))
779 def CreateAutoGenFile(self, filePath=None):
780 if self.IsAutoGenCodeCreated:
783 if self.IsPlatformAutoGen:
784 for arch in self.BuildInfo:
785 info = self.BuildInfo[arch]
786 for moduleFile in info.Platform.Modules:
787 key = (info.BuildTarget, info.ToolChain, arch, moduleFile)
789 if key not in gAutoGenDatabase:
790 moduleAutoGen = AutoGen(moduleFile, info.Platform, gWorkspace,
791 info.BuildTarget, info.ToolChain, info.Arch)
793 moduleAutoGen = gAutoGenDatabase[key]
794 moduleAutoGen.CreateAutoGenFile()
797 platformInfo = self.BuildInfo.PlatformInfo
798 if not self.BuildInfo.IsLibrary and self not in platformInfo.ModuleAutoGenList:
799 platformInfo.ModuleAutoGenList.append(self)
800 elif self.BuildInfo.IsLibrary and self not in platformInfo.LibraryAutoGenList:
801 platformInfo.LibraryAutoGenList.append(self)
803 for lib in self.BuildInfo.DependentLibraryList:
804 key = (self.BuildTarget, self.ToolChain, self.Arch, lib)
805 libraryAutoGen = None
806 if key not in gAutoGenDatabase:
807 libraryAutoGen = AutoGen(lib, self.Platform, gWorkspace,
808 self.BuildTarget, self.ToolChain, self.Arch)
810 libraryAutoGen = gAutoGenDatabase[key]
811 if libraryAutoGen not in self.BuildInfo.LibraryAutoGenList:
812 self.BuildInfo.LibraryAutoGenList.append(libraryAutoGen)
813 libraryAutoGen.CreateAutoGenFile()
815 autoGenList = GenC.Generate(os.path.join(self.BuildInfo.WorkspaceDir, self.BuildInfo.DebugDir),
816 self.AutoGenC, self.AutoGenH)
818 if self.BuildInfo.DepexList != []:
819 dpx = GenDepex.DependencyExpression(self.BuildInfo.DepexList, self.BuildInfo.ModuleType)
820 dpxFile = dpx.Generate(os.path.join(gWorkspaceDir, self.BuildInfo.OutputDir, self.BuildInfo.Name + ".depex"))
821 autoGenList.append(dpxFile)
823 self.IsAutoGenCodeCreated = True
824 EdkLogger.info("Generated [%s] files for module %s" % (" ".join([path.basename(f) for f in autoGenList]), self.BuildInfo.Name))
828 # This acts like the main() function for the script, unless it is 'import'ed into another
830 if __name__ == '__main__':
831 print "Running Operating System =", sys.platform
832 ewb = WorkspaceBuild()
833 #print ewb.Build.keys()
835 myArch = ewb.Build["IA32"].Arch
838 myBuild = ewb.Build["IA32"]
841 apf = os.path.normpath(ewb.TargetTxt.TargetTxtDictionary["ACTIVE_PLATFORM"][0])
842 myPlatform = myBuild.PlatformDatabase[os.path.normpath(apf)]
844 #LoadBuildRule(myWorkspace.Workspace.WorkspaceFile('Tools/Conf/build.rule'))
846 myToolchain = ewb.TargetTxt.TargetTxtDictionary["TOOL_CHAIN_TAG"][0]
849 myBuildTarget = ewb.TargetTxt.TargetTxtDictionary["TARGET"][0]
853 "ENABLE_PCH" : False,
854 "ENABLE_LOCAL_LIB" : True,
857 def PrintAutoGen(ag):
858 bi = ag.ModuleBuildInfo
860 print " WorkSpaceDir =",bi.WorkspaceDir
861 print " SourceDir =",bi.SourceDir
862 print " Is Library =",bi.IsLibrary
863 print " BaseName =",bi.BaseName
864 print " FileBase =",bi.FileBase
865 print " FileExt =",bi.FileExt
866 print " BuildDir =",bi.BuildDir
867 print " OutputDir =",bi.OutputDir
868 print " DebugDir =",bi.DebugDir
869 print " MakefileDir =",bi.MakefileDir
871 print " Include Path:","\n ","\n ".join(bi.InclduePathList)
872 print " SourceFileList:","\n ","\n ".join(bi.SourceFileList)
874 print " BuildOption:","\n ","\n ".join(["%s = %s" % (tool,bi.BuildOption[tool]) for tool in bi.BuildOption])
875 print " PcdList:","\n ","\n ".join([pcd.TokenCName for pcd in bi.PcdList])
876 print " GuidList:","\n ","\n ".join(bi.GuidList)
877 print " ProtocolList:","\n ","\n ".join(bi.ProtocolList)
878 print " PpiList:","\n ","\n ".join(bi.PpiList)
879 print " LibraryList:","\n ","\n ".join([str(l) for l in bi.DependentLibraryList])
883 ## for key in gAutoGenDatabase:
884 ## if str(myPlatform) == str(key[0]):
885 ## pi = gAutoGenDatabase[key]
886 ## print " BuildDir =",pi.BuildDir
887 ## print " OutputDir =",pi.OutputDir
888 ## print " DebugDir =",pi.DebugDir
889 ## print " LibraryDir =",pi.LibraryDir
890 ## print " FvDir =",pi.FvDir
891 ## print " MakefileDir =",pi.MakefileDir
892 ## print " PcdTokenNumber:","\n ","\n ".join(["%s = %s" % (pcd,pi.PcdTokenNumber[pcd]) for pcd in pi.PcdTokenNumber])
893 ## print " DynamicPcdList:","\n ","\n ".join([str(pcd) for pcd in pi.DynamicPcdList])
895 ## print " ToolPath:","\n ","\n ".join(["%s = %s" % (tool,pi.ToolPath[tool]) for tool in pi.ToolPath])
896 ## print " ToolDynamicLib:","\n ","\n ".join(["%s = %s" % (tool,pi.ToolDynamicLib[tool]) for tool in pi.ToolDynamicLib])
897 ## print " ToolStaticLib:","\n ","\n ".join(["%s = %s" % (tool,pi.ToolStaticLib[tool]) for tool in pi.ToolStaticLib])
898 ## print " ToolChainFamily:","\n ","\n ".join(["%s = %s" % (tool,pi.ToolChainFamily[tool]) for tool in pi.ToolChainFamily])
899 ## print " BuildOption:","\n ","\n ".join(["%s = %s" % (tool,pi.BuildOption[tool]) for tool in pi.BuildOption])
900 ## print " DefaultToolOption:","\n ","\n ".join(["%s = %s" % (tool,pi.DefaultToolOption[tool]) for tool in pi.DefaultToolOption])
902 for mf in myBuild.ModuleDatabase:
903 #mf = "MdePkg\\Library\\BaseLib\\BaseLib.inf"
904 #if mf in myPlatform.Modules and mf in myBuild.ModuleDatabase:
906 myModule = myBuild.ModuleDatabase[mf]
907 ag = AutoGen(myModule, myPlatform, myWorkspace, myBuildTarget, myToolchain, myArch)
908 ag.CreateAutoGenFile()
912 ## for lib in ag.ModuleBuildInfo.DependentLibraryList:
913 ## ag = AutoGen(lib, myPlatform, myWorkspace, myArch, myToolchain, myBuildTarget)
914 ## ag.CreateAutoGenFile()
915 ## ag.CreateMakefile()
917 platformAutoGen = AutoGen(None, apf, myWorkspace, myBuildTarget, myToolchain, myWorkspace.SupArchList)
918 platformAutoGen.CreateAutoGenFile()
919 platformAutoGen.CreateMakefile()