]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/BuildEngine.py
BaseTools: Append FILE_GUID to BaseName.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / BuildEngine.py
CommitLineData
f51461c8
LG
1## @file\r
2# The engine for building files\r
3#\r
1be2ed90 4# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
f51461c8
LG
5# This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
1be2ed90 17import Common.LongFilePathOs as os\r
f51461c8
LG
18import re\r
19import copy\r
20import string\r
1be2ed90 21from Common.LongFilePathSupport import OpenLongFilePath as open\r
f51461c8
LG
22\r
23from Common.GlobalData import *\r
24from Common.BuildToolError import *\r
25from Common.Misc import tdict, PathClass\r
26from Common.String import NormPath\r
27from Common.DataType import *\r
28\r
29import Common.EdkLogger as EdkLogger\r
30\r
31## Convert file type to file list macro name\r
32#\r
33# @param FileType The name of file type\r
34#\r
35# @retval string The name of macro\r
36#\r
37def FileListMacro(FileType):\r
38 return "%sS" % FileType.replace("-", "_").upper()\r
39\r
40## Convert file type to list file macro name\r
41#\r
42# @param FileType The name of file type\r
43#\r
44# @retval string The name of macro\r
45#\r
46def ListFileMacro(FileType):\r
47 return "%s_LIST" % FileListMacro(FileType)\r
48\r
49class TargetDescBlock(object):\r
50 _Cache_ = {} # {TargetFile : TargetDescBlock object}\r
51\r
52 # Factory method\r
53 def __new__(Class, Inputs, Outputs, Commands, Dependencies):\r
54 if Outputs[0] in Class._Cache_:\r
55 Tdb = Class._Cache_[Outputs[0]]\r
56 for File in Inputs:\r
57 Tdb.AddInput(File)\r
58 else:\r
59 Tdb = super(TargetDescBlock, Class).__new__(Class)\r
60 Tdb._Init(Inputs, Outputs, Commands, Dependencies)\r
61 #Class._Cache_[Outputs[0]] = Tdb\r
62 return Tdb\r
63\r
64 def _Init(self, Inputs, Outputs, Commands, Dependencies):\r
65 self.Inputs = Inputs\r
66 self.Outputs = Outputs\r
67 self.Commands = Commands\r
68 self.Dependencies = Dependencies\r
69 if self.Outputs:\r
70 self.Target = self.Outputs[0]\r
71 else:\r
72 self.Target = None\r
73\r
74 def __str__(self):\r
75 return self.Target.Path\r
76\r
77 def __hash__(self):\r
78 return hash(self.Target.Path)\r
79\r
80 def __eq__(self, Other):\r
81 if type(Other) == type(self):\r
82 return Other.Target.Path == self.Target.Path\r
83 else:\r
84 return str(Other) == self.Target.Path\r
85\r
86 def AddInput(self, Input):\r
87 if Input not in self.Inputs:\r
88 self.Inputs.append(Input)\r
89\r
90 def IsMultipleInput(self):\r
91 return len(self.Inputs) > 1\r
92\r
93 @staticmethod\r
94 def Renew():\r
95 TargetDescBlock._Cache_ = {}\r
96\r
97## Class for one build rule\r
98#\r
99# This represents a build rule which can give out corresponding command list for\r
100# building the given source file(s). The result can be used for generating the\r
101# target for makefile.\r
102#\r
103class FileBuildRule:\r
104 INC_LIST_MACRO = "INC_LIST"\r
105 INC_MACRO = "INC"\r
106\r
107 ## constructor\r
108 #\r
109 # @param Input The dictionary represeting input file(s) for a rule\r
110 # @param Output The list represeting output file(s) for a rule\r
111 # @param Command The list containing commands to generate the output from input\r
112 #\r
113 def __init__(self, Type, Input, Output, Command, ExtraDependency=None):\r
114 # The Input should not be empty\r
115 if not Input:\r
116 Input = []\r
117 if not Output:\r
118 Output = []\r
119 if not Command:\r
120 Command = []\r
121\r
122 self.FileListMacro = FileListMacro(Type)\r
123 self.ListFileMacro = ListFileMacro(Type)\r
124 self.IncListFileMacro = self.INC_LIST_MACRO\r
125\r
126 self.SourceFileType = Type\r
127 # source files listed not in "*" or "?" pattern format\r
128 if not ExtraDependency:\r
129 self.ExtraSourceFileList = []\r
130 else:\r
131 self.ExtraSourceFileList = ExtraDependency\r
132\r
133 #\r
134 # Search macros used in command lines for <FILE_TYPE>_LIST and INC_LIST.\r
135 # If found, generate a file to keep the input files used to get over the\r
136 # limitation of command line length\r
137 #\r
138 self.MacroList = []\r
139 self.CommandList = []\r
140 for CmdLine in Command:\r
141 self.MacroList.extend(gMacroRefPattern.findall(CmdLine))\r
142 # replace path separator with native one\r
143 self.CommandList.append(CmdLine)\r
144\r
145 # Indicate what should be generated\r
146 if self.FileListMacro in self.MacroList:\r
147 self.GenFileListMacro = True\r
148 else:\r
149 self.GenFileListMacro = False\r
150\r
151 if self.ListFileMacro in self.MacroList:\r
152 self.GenListFile = True\r
153 self.GenFileListMacro = True\r
154 else:\r
155 self.GenListFile = False\r
156\r
157 if self.INC_LIST_MACRO in self.MacroList:\r
158 self.GenIncListFile = True\r
159 else:\r
160 self.GenIncListFile = False\r
161\r
162 # Check input files\r
163 self.IsMultipleInput = False\r
164 self.SourceFileExtList = []\r
165 for File in Input:\r
166 Base, Ext = os.path.splitext(File)\r
167 if Base.find("*") >= 0:\r
168 # There's "*" in the file name\r
169 self.IsMultipleInput = True\r
170 self.GenFileListMacro = True\r
171 elif Base.find("?") < 0:\r
172 # There's no "*" and "?" in file name\r
173 self.ExtraSourceFileList.append(File)\r
174 continue\r
175 if Ext not in self.SourceFileExtList:\r
176 self.SourceFileExtList.append(Ext)\r
177\r
178 # Check output files\r
179 self.DestFileList = []\r
180 for File in Output:\r
181 self.DestFileList.append(File)\r
182\r
183 # All build targets generated by this rule for a module\r
184 self.BuildTargets = {}\r
185\r
186 ## str() function support\r
187 #\r
188 # @retval string\r
189 #\r
190 def __str__(self):\r
191 SourceString = ""\r
192 SourceString += " %s %s %s" % (self.SourceFileType, " ".join(self.SourceFileExtList), self.ExtraSourceFileList)\r
193 DestString = ", ".join(self.DestFileList)\r
194 CommandString = "\n\t".join(self.CommandList)\r
195 return "%s : %s\n\t%s" % (DestString, SourceString, CommandString)\r
196\r
197 ## Check if given file extension is supported by this rule\r
198 #\r
199 # @param FileExt The extension of a file\r
200 #\r
201 # @retval True If the extension is supported\r
202 # @retval False If the extension is not supported\r
203 #\r
204 def IsSupported(self, FileExt):\r
205 return FileExt in self.SourceFileExtList\r
206\r
207 def Instantiate(self, Macros={}):\r
208 NewRuleObject = copy.copy(self)\r
209 NewRuleObject.BuildTargets = {}\r
210 NewRuleObject.DestFileList = []\r
211 for File in self.DestFileList:\r
212 NewRuleObject.DestFileList.append(PathClass(NormPath(File, Macros)))\r
213 return NewRuleObject\r
214\r
215 ## Apply the rule to given source file(s)\r
216 #\r
217 # @param SourceFile One file or a list of files to be built\r
218 # @param RelativeToDir The relative path of the source file\r
219 # @param PathSeparator Path separator\r
220 #\r
221 # @retval tuple (Source file in full path, List of individual sourcefiles, Destionation file, List of build commands)\r
222 #\r
fe4bf2f9 223 def Apply(self, SourceFile, BuildRuleOrder=None):\r
f51461c8
LG
224 if not self.CommandList or not self.DestFileList:\r
225 return None\r
226\r
227 # source file\r
228 if self.IsMultipleInput:\r
229 SrcFileName = ""\r
230 SrcFileBase = ""\r
231 SrcFileExt = ""\r
232 SrcFileDir = ""\r
233 SrcPath = ""\r
234 # SourceFile must be a list\r
235 SrcFile = "$(%s)" % self.FileListMacro\r
236 else:\r
237 SrcFileName, SrcFileBase, SrcFileExt = SourceFile.Name, SourceFile.BaseName, SourceFile.Ext\r
238 if SourceFile.Root:\r
239 SrcFileDir = SourceFile.SubDir\r
240 if SrcFileDir == "":\r
241 SrcFileDir = "."\r
242 else:\r
243 SrcFileDir = "."\r
244 SrcFile = SourceFile.Path\r
245 SrcPath = SourceFile.Dir\r
246\r
247 # destination file (the first one)\r
248 if self.DestFileList:\r
249 DestFile = self.DestFileList[0].Path\r
250 DestPath = self.DestFileList[0].Dir\r
251 DestFileName = self.DestFileList[0].Name\r
252 DestFileBase, DestFileExt = self.DestFileList[0].BaseName, self.DestFileList[0].Ext\r
253 else:\r
254 DestFile = ""\r
255 DestPath = ""\r
256 DestFileName = ""\r
257 DestFileBase = ""\r
258 DestFileExt = ""\r
259\r
260 BuildRulePlaceholderDict = {\r
261 # source file\r
262 "src" : SrcFile,\r
263 "s_path" : SrcPath,\r
264 "s_dir" : SrcFileDir,\r
265 "s_name" : SrcFileName,\r
266 "s_base" : SrcFileBase,\r
267 "s_ext" : SrcFileExt,\r
268 # destination file\r
269 "dst" : DestFile,\r
270 "d_path" : DestPath,\r
271 "d_name" : DestFileName,\r
272 "d_base" : DestFileBase,\r
273 "d_ext" : DestFileExt,\r
274 }\r
275\r
276 DstFile = []\r
277 for File in self.DestFileList:\r
278 File = string.Template(str(File)).safe_substitute(BuildRulePlaceholderDict)\r
279 File = string.Template(str(File)).safe_substitute(BuildRulePlaceholderDict)\r
280 DstFile.append(PathClass(File, IsBinary=True))\r
281\r
282 if DstFile[0] in self.BuildTargets:\r
283 TargetDesc = self.BuildTargets[DstFile[0]]\r
fe4bf2f9
YL
284 if BuildRuleOrder and SourceFile.Ext in BuildRuleOrder:\r
285 Index = BuildRuleOrder.index(SourceFile.Ext)\r
286 for Input in TargetDesc.Inputs:\r
287 if Input.Ext not in BuildRuleOrder or BuildRuleOrder.index(Input.Ext) > Index:\r
288 #\r
289 # Command line should be regenerated since some macros are different\r
290 #\r
291 CommandList = self._BuildCommand(BuildRulePlaceholderDict)\r
292 TargetDesc._Init([SourceFile], DstFile, CommandList, self.ExtraSourceFileList)\r
293 break\r
294 else:\r
295 TargetDesc.AddInput(SourceFile)\r
f51461c8 296 else:\r
fe4bf2f9 297 CommandList = self._BuildCommand(BuildRulePlaceholderDict)\r
f51461c8
LG
298 TargetDesc = TargetDescBlock([SourceFile], DstFile, CommandList, self.ExtraSourceFileList)\r
299 TargetDesc.ListFileMacro = self.ListFileMacro\r
300 TargetDesc.FileListMacro = self.FileListMacro\r
301 TargetDesc.IncListFileMacro = self.IncListFileMacro\r
302 TargetDesc.GenFileListMacro = self.GenFileListMacro\r
303 TargetDesc.GenListFile = self.GenListFile\r
304 TargetDesc.GenIncListFile = self.GenIncListFile\r
305 self.BuildTargets[DstFile[0]] = TargetDesc\r
306 return TargetDesc\r
307\r
fe4bf2f9
YL
308 def _BuildCommand(self, Macros):\r
309 CommandList = []\r
310 for CommandString in self.CommandList:\r
311 CommandString = string.Template(CommandString).safe_substitute(Macros)\r
312 CommandString = string.Template(CommandString).safe_substitute(Macros)\r
313 CommandList.append(CommandString)\r
314 return CommandList\r
315\r
f51461c8
LG
316## Class for build rules\r
317#\r
318# BuildRule class parses rules defined in a file or passed by caller, and converts\r
319# the rule into FileBuildRule object.\r
320#\r
321class BuildRule:\r
322 _SectionHeader = "SECTIONHEADER"\r
323 _Section = "SECTION"\r
324 _SubSectionHeader = "SUBSECTIONHEADER"\r
325 _SubSection = "SUBSECTION"\r
326 _InputFile = "INPUTFILE"\r
327 _OutputFile = "OUTPUTFILE"\r
328 _ExtraDependency = "EXTRADEPENDENCY"\r
329 _Command = "COMMAND"\r
330 _UnknownSection = "UNKNOWNSECTION"\r
331\r
332 _SubSectionList = [_InputFile, _OutputFile, _Command]\r
333\r
334 _PATH_SEP = "(+)"\r
335 _FileTypePattern = re.compile("^[_a-zA-Z][_\-0-9a-zA-Z]*$")\r
336 _BinaryFileRule = FileBuildRule(TAB_DEFAULT_BINARY_FILE, [], [os.path.join("$(OUTPUT_DIR)", "${s_name}")],\r
337 ["$(CP) ${src} ${dst}"], [])\r
338\r
339 ## Constructor\r
340 #\r
341 # @param File The file containing build rules in a well defined format\r
342 # @param Content The string list of build rules in a well defined format\r
343 # @param LineIndex The line number from which the parsing will begin\r
344 # @param SupportedFamily The list of supported tool chain families\r
345 #\r
346 def __init__(self, File=None, Content=None, LineIndex=0, SupportedFamily=["MSFT", "INTEL", "GCC", "RVCT"]):\r
347 self.RuleFile = File\r
348 # Read build rules from file if it's not none\r
349 if File != None:\r
350 try:\r
351 self.RuleContent = open(File, 'r').readlines()\r
352 except:\r
353 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r
354 elif Content != None:\r
355 self.RuleContent = Content\r
356 else:\r
357 EdkLogger.error("build", PARAMETER_MISSING, ExtraData="No rule file or string given")\r
358\r
359 self.SupportedToolChainFamilyList = SupportedFamily\r
360 self.RuleDatabase = tdict(True, 4) # {FileExt, ModuleType, Arch, Family : FileBuildRule object}\r
361 self.Ext2FileType = {} # {ext : file-type}\r
362 self.FileTypeList = set()\r
363\r
364 self._LineIndex = LineIndex\r
365 self._State = ""\r
366 self._RuleInfo = tdict(True, 2) # {toolchain family : {"InputFile": {}, "OutputFile" : [], "Command" : []}}\r
367 self._FileType = ''\r
368 self._BuildTypeList = []\r
369 self._ArchList = []\r
370 self._FamilyList = []\r
371 self._TotalToolChainFamilySet = set()\r
372 self._RuleObjectList = [] # FileBuildRule object list\r
373 self._FileVersion = ""\r
374\r
375 self.Parse()\r
376\r
377 # some intrinsic rules\r
378 self.RuleDatabase[TAB_DEFAULT_BINARY_FILE, "COMMON", "COMMON", "COMMON"] = self._BinaryFileRule\r
379 self.FileTypeList.add(TAB_DEFAULT_BINARY_FILE)\r
380\r
381 ## Parse the build rule strings\r
382 def Parse(self):\r
383 self._State = self._Section\r
384 for Index in range(self._LineIndex, len(self.RuleContent)):\r
385 # Clean up the line and replace path separator with native one\r
386 Line = self.RuleContent[Index].strip().replace(self._PATH_SEP, os.path.sep)\r
387 self.RuleContent[Index] = Line\r
388 \r
389 # find the build_rule_version\r
390 if Line and Line[0] == "#" and Line.find(TAB_BUILD_RULE_VERSION) <> -1:\r
391 if Line.find("=") <> -1 and Line.find("=") < (len(Line)-1) and (Line[(Line.find("=") + 1):]).split():\r
392 self._FileVersion = (Line[(Line.find("=") + 1):]).split()[0]\r
393 # skip empty or comment line\r
394 if Line == "" or Line[0] == "#":\r
395 continue\r
396\r
397 # find out section header, enclosed by []\r
398 if Line[0] == '[' and Line[-1] == ']':\r
399 # merge last section information into rule database\r
400 self.EndOfSection()\r
401 self._State = self._SectionHeader\r
402 # find out sub-section header, enclosed by <>\r
403 elif Line[0] == '<' and Line[-1] == '>':\r
404 if self._State != self._UnknownSection:\r
405 self._State = self._SubSectionHeader\r
406\r
407 # call section handler to parse each (sub)section\r
408 self._StateHandler[self._State](self, Index)\r
409 # merge last section information into rule database\r
410 self.EndOfSection()\r
411\r
412 ## Parse definitions under a section\r
413 #\r
414 # @param LineIndex The line index of build rule text\r
415 #\r
416 def ParseSection(self, LineIndex):\r
417 pass\r
418\r
419 ## Parse definitions under a subsection\r
420 #\r
421 # @param LineIndex The line index of build rule text\r
422 #\r
423 def ParseSubSection(self, LineIndex):\r
424 # currenly nothing here\r
425 pass\r
426\r
427 ## Placeholder for not supported sections\r
428 #\r
429 # @param LineIndex The line index of build rule text\r
430 #\r
431 def SkipSection(self, LineIndex):\r
432 pass\r
433\r
434 ## Merge section information just got into rule database\r
435 def EndOfSection(self):\r
436 Database = self.RuleDatabase\r
437 # if there's specific toochain family, 'COMMON' doesn't make sense any more\r
438 if len(self._TotalToolChainFamilySet) > 1 and 'COMMON' in self._TotalToolChainFamilySet:\r
439 self._TotalToolChainFamilySet.remove('COMMON')\r
440 for Family in self._TotalToolChainFamilySet:\r
441 Input = self._RuleInfo[Family, self._InputFile]\r
442 Output = self._RuleInfo[Family, self._OutputFile]\r
443 Command = self._RuleInfo[Family, self._Command]\r
444 ExtraDependency = self._RuleInfo[Family, self._ExtraDependency]\r
445\r
446 BuildRule = FileBuildRule(self._FileType, Input, Output, Command, ExtraDependency)\r
447 for BuildType in self._BuildTypeList:\r
448 for Arch in self._ArchList:\r
449 Database[self._FileType, BuildType, Arch, Family] = BuildRule\r
450 for FileExt in BuildRule.SourceFileExtList:\r
451 self.Ext2FileType[FileExt] = self._FileType\r
452\r
453 ## Parse section header\r
454 #\r
455 # @param LineIndex The line index of build rule text\r
456 #\r
457 def ParseSectionHeader(self, LineIndex):\r
458 self._RuleInfo = tdict(True, 2)\r
459 self._BuildTypeList = []\r
460 self._ArchList = []\r
461 self._FamilyList = []\r
462 self._TotalToolChainFamilySet = set()\r
463 FileType = ''\r
464 RuleNameList = self.RuleContent[LineIndex][1:-1].split(',')\r
465 for RuleName in RuleNameList:\r
466 Arch = 'COMMON'\r
467 BuildType = 'COMMON'\r
468 TokenList = [Token.strip().upper() for Token in RuleName.split('.')]\r
469 # old format: Build.File-Type\r
470 if TokenList[0] == "BUILD":\r
471 if len(TokenList) == 1:\r
472 EdkLogger.error("build", FORMAT_INVALID, "Invalid rule section",\r
473 File=self.RuleFile, Line=LineIndex+1,\r
474 ExtraData=self.RuleContent[LineIndex])\r
475\r
476 FileType = TokenList[1]\r
477 if FileType == '':\r
478 EdkLogger.error("build", FORMAT_INVALID, "No file type given",\r
479 File=self.RuleFile, Line=LineIndex+1,\r
480 ExtraData=self.RuleContent[LineIndex])\r
481 if self._FileTypePattern.match(FileType) == None:\r
482 EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1,\r
483 ExtraData="Only character, number (non-first character), '_' and '-' are allowed in file type")\r
484 # new format: File-Type.Build-Type.Arch\r
485 else:\r
486 if FileType == '':\r
487 FileType = TokenList[0]\r
488 elif FileType != TokenList[0]:\r
489 EdkLogger.error("build", FORMAT_INVALID,\r
490 "Different file types are not allowed in the same rule section",\r
491 File=self.RuleFile, Line=LineIndex+1,\r
492 ExtraData=self.RuleContent[LineIndex])\r
493 if len(TokenList) > 1:\r
494 BuildType = TokenList[1]\r
495 if len(TokenList) > 2:\r
496 Arch = TokenList[2]\r
497 if BuildType not in self._BuildTypeList:\r
498 self._BuildTypeList.append(BuildType)\r
499 if Arch not in self._ArchList:\r
500 self._ArchList.append(Arch)\r
501\r
502 if 'COMMON' in self._BuildTypeList and len(self._BuildTypeList) > 1:\r
503 EdkLogger.error("build", FORMAT_INVALID,\r
504 "Specific build types must not be mixed with common one",\r
505 File=self.RuleFile, Line=LineIndex+1,\r
506 ExtraData=self.RuleContent[LineIndex])\r
507 if 'COMMON' in self._ArchList and len(self._ArchList) > 1:\r
508 EdkLogger.error("build", FORMAT_INVALID,\r
509 "Specific ARCH must not be mixed with common one",\r
510 File=self.RuleFile, Line=LineIndex+1,\r
511 ExtraData=self.RuleContent[LineIndex])\r
512\r
513 self._FileType = FileType\r
514 self._State = self._Section\r
515 self.FileTypeList.add(FileType)\r
516\r
517 ## Parse sub-section header\r
518 #\r
519 # @param LineIndex The line index of build rule text\r
520 #\r
521 def ParseSubSectionHeader(self, LineIndex):\r
522 SectionType = ""\r
523 List = self.RuleContent[LineIndex][1:-1].split(',')\r
524 FamilyList = []\r
525 for Section in List:\r
526 TokenList = Section.split('.')\r
527 Type = TokenList[0].strip().upper()\r
528\r
529 if SectionType == "":\r
530 SectionType = Type\r
531 elif SectionType != Type:\r
532 EdkLogger.error("build", FORMAT_INVALID,\r
533 "Two different section types are not allowed in the same sub-section",\r
534 File=self.RuleFile, Line=LineIndex+1,\r
535 ExtraData=self.RuleContent[LineIndex])\r
536\r
537 if len(TokenList) > 1:\r
538 Family = TokenList[1].strip().upper()\r
539 else:\r
540 Family = "COMMON"\r
541\r
542 if Family not in FamilyList:\r
543 FamilyList.append(Family)\r
544\r
545 self._FamilyList = FamilyList\r
546 self._TotalToolChainFamilySet.update(FamilyList)\r
547 self._State = SectionType.upper()\r
548 if 'COMMON' in FamilyList and len(FamilyList) > 1:\r
549 EdkLogger.error("build", FORMAT_INVALID,\r
550 "Specific tool chain family should not be mixed with general one",\r
551 File=self.RuleFile, Line=LineIndex+1,\r
552 ExtraData=self.RuleContent[LineIndex])\r
553 if self._State not in self._StateHandler:\r
554 EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1,\r
555 ExtraData="Unknown subsection: %s" % self.RuleContent[LineIndex])\r
556 ## Parse <InputFile> sub-section\r
557 #\r
558 # @param LineIndex The line index of build rule text\r
559 #\r
560 def ParseInputFile(self, LineIndex):\r
561 FileList = [File.strip() for File in self.RuleContent[LineIndex].split(",")]\r
562 for ToolChainFamily in self._FamilyList:\r
563 InputFiles = self._RuleInfo[ToolChainFamily, self._State]\r
564 if InputFiles == None:\r
565 InputFiles = []\r
566 self._RuleInfo[ToolChainFamily, self._State] = InputFiles\r
567 InputFiles.extend(FileList)\r
568\r
569 ## Parse <ExtraDependency> sub-section\r
570 #\r
571 # @param LineIndex The line index of build rule text\r
572 #\r
573 def ParseCommon(self, LineIndex):\r
574 for ToolChainFamily in self._FamilyList:\r
575 Items = self._RuleInfo[ToolChainFamily, self._State]\r
576 if Items == None:\r
577 Items = []\r
578 self._RuleInfo[ToolChainFamily, self._State] = Items\r
579 Items.append(self.RuleContent[LineIndex])\r
580\r
581 ## Get a build rule via [] operator\r
582 #\r
583 # @param FileExt The extension of a file\r
584 # @param ToolChainFamily The tool chain family name\r
585 # @param BuildVersion The build version number. "*" means any rule\r
586 # is applicalbe.\r
587 #\r
588 # @retval FileType The file type string\r
589 # @retval FileBuildRule The object of FileBuildRule\r
590 #\r
591 # Key = (FileExt, ModuleType, Arch, ToolChainFamily)\r
592 def __getitem__(self, Key):\r
593 if not Key:\r
594 return None\r
595\r
596 if Key[0] in self.Ext2FileType:\r
597 Type = self.Ext2FileType[Key[0]]\r
598 elif Key[0].upper() in self.FileTypeList:\r
599 Type = Key[0].upper()\r
600 else:\r
601 return None\r
602\r
603 if len(Key) > 1:\r
604 Key = (Type,) + Key[1:]\r
605 else:\r
606 Key = (Type,)\r
607 return self.RuleDatabase[Key]\r
608\r
609 _StateHandler = {\r
610 _SectionHeader : ParseSectionHeader,\r
611 _Section : ParseSection,\r
612 _SubSectionHeader : ParseSubSectionHeader,\r
613 _SubSection : ParseSubSection,\r
614 _InputFile : ParseInputFile,\r
615 _OutputFile : ParseCommon,\r
616 _ExtraDependency : ParseCommon,\r
617 _Command : ParseCommon,\r
618 _UnknownSection : SkipSection,\r
619 }\r
620\r
621# This acts like the main() function for the script, unless it is 'import'ed into another\r
622# script.\r
623if __name__ == '__main__':\r
624 import sys\r
625 EdkLogger.Initialize()\r
626 if len(sys.argv) > 1:\r
627 Br = BuildRule(sys.argv[1])\r
628 print str(Br[".c", "DXE_DRIVER", "IA32", "MSFT"][1])\r
629 print\r
630 print str(Br[".c", "DXE_DRIVER", "IA32", "INTEL"][1])\r
631 print\r
632 print str(Br[".c", "DXE_DRIVER", "IA32", "GCC"][1])\r
633 print\r
634 print str(Br[".ac", "ACPI_TABLE", "IA32", "MSFT"][1])\r
635 print\r
636 print str(Br[".h", "ACPI_TABLE", "IA32", "INTEL"][1])\r
637 print\r
638 print str(Br[".ac", "ACPI_TABLE", "IA32", "MSFT"][1])\r
639 print\r
640 print str(Br[".s", "SEC", "IPF", "COMMON"][1])\r
641 print\r
642 print str(Br[".s", "SEC"][1])\r
643\r