2 # This file is used to create a database used by build tool
4 # Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 import Common
.EdkLogger
as EdkLogger
24 import Common
.GlobalData
as GlobalData
26 from Common
.String
import *
27 from Common
.DataType
import *
28 from Common
.Misc
import *
31 from CommonDataClass
.CommonClass
import SkuInfoClass
33 from MetaDataTable
import *
34 from MetaFileTable
import *
35 from MetaFileParser
import *
36 from BuildClassObject
import *
38 ## Platform build information from DSC file
40 # This class is used to retrieve information stored in database and convert them
41 # into PlatformBuildClassObject form for easier use for AutoGen.
43 class DscBuildData(PlatformBuildClassObject
):
44 # dict used to convert PCD type in database to string used by build tool
46 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
47 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
48 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
49 MODEL_PCD_DYNAMIC
: "Dynamic",
50 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
51 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
52 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
53 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
54 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
55 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
56 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
59 # dict used to convert part of [Defines] to members of DscBuildData directly
64 TAB_DSC_DEFINES_PLATFORM_NAME
: "_PlatformName",
65 TAB_DSC_DEFINES_PLATFORM_GUID
: "_Guid",
66 TAB_DSC_DEFINES_PLATFORM_VERSION
: "_Version",
67 TAB_DSC_DEFINES_DSC_SPECIFICATION
: "_DscSpecification",
68 #TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory",
69 #TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList",
70 #TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets",
71 #TAB_DSC_DEFINES_SKUID_IDENTIFIER : "_SkuName",
72 #TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition",
73 TAB_DSC_DEFINES_BUILD_NUMBER
: "_BuildNumber",
74 TAB_DSC_DEFINES_MAKEFILE_NAME
: "_MakefileName",
75 TAB_DSC_DEFINES_BS_BASE_ADDRESS
: "_BsBaseAddress",
76 TAB_DSC_DEFINES_RT_BASE_ADDRESS
: "_RtBaseAddress",
77 #TAB_DSC_DEFINES_RFC_LANGUAGES : "_RFCLanguages",
78 #TAB_DSC_DEFINES_ISO_LANGUAGES : "_ISOLanguages",
81 # used to compose dummy library class name for those forced library instances
82 _NullLibraryNumber
= 0
84 ## Constructor of DscBuildData
86 # Initialize object of DscBuildData
88 # @param FilePath The path of platform description file
89 # @param RawData The raw data of DSC file
90 # @param BuildDataBase Database used to retrieve module/package information
91 # @param Arch The target architecture
92 # @param Platform (not used for DscBuildData)
93 # @param Macros Macros used for replacement in DSC file
95 def __init__(self
, FilePath
, RawData
, BuildDataBase
, Arch
='COMMON', Platform
='DUMMY', Macros
={}):
96 self
.MetaFile
= FilePath
97 self
._RawData
= RawData
98 self
._Bdb
= BuildDataBase
100 self
._Macros
= Macros
102 RecordList
= self
._RawData
[MODEL_META_DATA_DEFINE
, self
._Arch
]
103 for Record
in RecordList
:
104 GlobalData
.gEdkGlobal
[Record
[0]] = Record
[1]
106 RecordList
= self
._RawData
[MODEL_META_DATA_GLOBAL_DEFINE
, self
._Arch
]
107 for Record
in RecordList
:
108 GlobalData
.gGlobalDefines
[Record
[0]] = Record
[1]
111 def __setitem__(self
, key
, value
):
112 self
.__dict
__[self
._PROPERTY
_[key
]] = value
115 def __getitem__(self
, key
):
116 return self
.__dict
__[self
._PROPERTY
_[key
]]
119 def __contains__(self
, key
):
120 return key
in self
._PROPERTY
_
122 ## Set all internal used members of DscBuildData to None
125 self
._PlatformName
= None
128 self
._DscSpecification
= None
129 self
._OutputDirectory
= None
130 self
._SupArchList
= None
131 self
._BuildTargets
= None
133 self
._FlashDefinition
= None
134 self
._BuildNumber
= None
135 self
._MakefileName
= None
136 self
._BsBaseAddress
= None
137 self
._RtBaseAddress
= None
140 self
._LibraryInstances
= None
141 self
._LibraryClasses
= None
143 self
._BuildOptions
= None
144 self
._LoadFixAddress
= None
145 self
._RFCLanguages
= None
146 self
._ISOLanguages
= None
147 self
._VpdToolGuid
= None
155 # Changing the default ARCH to another may affect all other information
156 # because all information in a platform may be ARCH-related. That's
157 # why we need to clear all internal used members, in order to cause all
158 # information to be re-retrieved.
160 # @param Value The value of ARCH
162 def _SetArch(self
, Value
):
163 if self
._Arch
== Value
:
168 ## Retrieve all information in [Defines] section
170 # (Retriving all [Defines] information in one-shot is just to save time.)
172 def _GetHeaderInfo(self
):
173 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
]
174 for Record
in RecordList
:
176 # items defined _PROPERTY_ don't need additional processing
178 self
[Name
] = Record
[1]
179 # some special items in [Defines] section need special treatment
180 elif Name
== TAB_DSC_DEFINES_OUTPUT_DIRECTORY
:
181 self
._OutputDirectory
= NormPath(Record
[1], self
._Macros
)
182 if ' ' in self
._OutputDirectory
:
183 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "No space is allowed in OUTPUT_DIRECTORY",
184 File
=self
.MetaFile
, Line
=Record
[-1],
185 ExtraData
=self
._OutputDirectory
)
186 elif Name
== TAB_DSC_DEFINES_FLASH_DEFINITION
:
187 self
._FlashDefinition
= PathClass(NormPath(Record
[1], self
._Macros
), GlobalData
.gWorkspace
)
188 ErrorCode
, ErrorInfo
= self
._FlashDefinition
.Validate('.fdf')
190 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=Record
[-1],
192 elif Name
== TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES
:
193 self
._SupArchList
= GetSplitValueList(Record
[1], TAB_VALUE_SPLIT
)
194 elif Name
== TAB_DSC_DEFINES_BUILD_TARGETS
:
195 self
._BuildTargets
= GetSplitValueList(Record
[1])
196 elif Name
== TAB_DSC_DEFINES_SKUID_IDENTIFIER
:
197 if self
._SkuName
== None:
198 self
._SkuName
= Record
[1]
199 elif Name
== TAB_FIX_LOAD_TOP_MEMORY_ADDRESS
:
200 self
._LoadFixAddress
= Record
[1]
201 elif Name
== TAB_DSC_DEFINES_RFC_LANGUAGES
:
202 if not Record
[1] or Record
[1][0] != '"' or Record
[1][-1] != '"' or len(Record
[1]) == 1:
203 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',
204 File
=self
.MetaFile
, Line
=Record
[-1])
205 LanguageCodes
= Record
[1][1:-1]
206 if not LanguageCodes
:
207 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
208 File
=self
.MetaFile
, Line
=Record
[-1])
209 LanguageList
= GetSplitValueList(LanguageCodes
, TAB_SEMI_COLON_SPLIT
)
210 # check whether there is empty entries in the list
211 if None in LanguageList
:
212 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more empty language code is in RFC_LANGUAGES statement',
213 File
=self
.MetaFile
, Line
=Record
[-1])
214 self
._RFCLanguages
= LanguageList
215 elif Name
== TAB_DSC_DEFINES_ISO_LANGUAGES
:
216 if not Record
[1] or Record
[1][0] != '"' or Record
[1][-1] != '"' or len(Record
[1]) == 1:
217 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
218 File
=self
.MetaFile
, Line
=Record
[-1])
219 LanguageCodes
= Record
[1][1:-1]
220 if not LanguageCodes
:
221 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
222 File
=self
.MetaFile
, Line
=Record
[-1])
223 if len(LanguageCodes
)%3:
224 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, 'bad ISO639-2 format for ISO_LANGUAGES',
225 File
=self
.MetaFile
, Line
=Record
[-1])
227 for i
in range(0, len(LanguageCodes
), 3):
228 LanguageList
.append(LanguageCodes
[i
:i
+3])
229 self
._ISOLanguages
= LanguageList
230 elif Name
== TAB_DSC_DEFINES_VPD_TOOL_GUID
:
232 # try to convert GUID to a real UUID value to see whether the GUID is format
233 # for VPD_TOOL_GUID is correct.
238 EdkLogger
.error("build", FORMAT_INVALID
, "Invalid GUID format for VPD_TOOL_GUID", File
=self
.MetaFile
)
239 self
._VpdToolGuid
= Record
[1]
240 # set _Header to non-None in order to avoid database re-querying
241 self
._Header
= 'DUMMY'
243 ## Retrieve platform name
244 def _GetPlatformName(self
):
245 if self
._PlatformName
== None:
246 if self
._Header
== None:
247 self
._GetHeaderInfo
()
248 if self
._PlatformName
== None:
249 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No PLATFORM_NAME", File
=self
.MetaFile
)
250 return self
._PlatformName
252 ## Retrieve file guid
253 def _GetFileGuid(self
):
254 if self
._Guid
== None:
255 if self
._Header
== None:
256 self
._GetHeaderInfo
()
257 if self
._Guid
== None:
258 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No FILE_GUID", File
=self
.MetaFile
)
261 ## Retrieve platform version
262 def _GetVersion(self
):
263 if self
._Version
== None:
264 if self
._Header
== None:
265 self
._GetHeaderInfo
()
266 if self
._Version
== None:
270 ## Retrieve platform description file version
271 def _GetDscSpec(self
):
272 if self
._DscSpecification
== None:
273 if self
._Header
== None:
274 self
._GetHeaderInfo
()
275 if self
._DscSpecification
== None:
276 self
._DscSpecification
= ''
277 return self
._DscSpecification
279 ## Retrieve OUTPUT_DIRECTORY
280 def _GetOutpuDir(self
):
281 if self
._OutputDirectory
== None:
282 if self
._Header
== None:
283 self
._GetHeaderInfo
()
284 if self
._OutputDirectory
== None:
285 self
._OutputDirectory
= os
.path
.join("Build", self
._PlatformName
)
286 return self
._OutputDirectory
288 ## Retrieve SUPPORTED_ARCHITECTURES
289 def _GetSupArch(self
):
290 if self
._SupArchList
== None:
291 if self
._Header
== None:
292 self
._GetHeaderInfo
()
293 if self
._SupArchList
== None:
294 self
._SupArchList
= ARCH_LIST
295 return self
._SupArchList
297 ## Retrieve BUILD_TARGETS
298 def _GetBuildTarget(self
):
299 if self
._BuildTargets
== None:
300 if self
._Header
== None:
301 self
._GetHeaderInfo
()
302 if self
._BuildTargets
== None:
303 self
._BuildTargets
= ['DEBUG', 'RELEASE']
304 return self
._BuildTargets
306 ## Retrieve SKUID_IDENTIFIER
307 def _GetSkuName(self
):
308 if self
._SkuName
== None:
309 if self
._Header
== None:
310 self
._GetHeaderInfo
()
311 if self
._SkuName
== None or self
._SkuName
not in self
.SkuIds
:
312 self
._SkuName
= 'DEFAULT'
315 ## Override SKUID_IDENTIFIER
316 def _SetSkuName(self
, Value
):
317 if Value
in self
.SkuIds
:
318 self
._SkuName
= Value
319 # Needs to re-retrieve the PCD information
322 def _GetFdfFile(self
):
323 if self
._FlashDefinition
== None:
324 if self
._Header
== None:
325 self
._GetHeaderInfo
()
326 if self
._FlashDefinition
== None:
327 self
._FlashDefinition
= ''
328 return self
._FlashDefinition
330 ## Retrieve FLASH_DEFINITION
331 def _GetBuildNumber(self
):
332 if self
._BuildNumber
== None:
333 if self
._Header
== None:
334 self
._GetHeaderInfo
()
335 if self
._BuildNumber
== None:
336 self
._BuildNumber
= ''
337 return self
._BuildNumber
339 ## Retrieve MAKEFILE_NAME
340 def _GetMakefileName(self
):
341 if self
._MakefileName
== None:
342 if self
._Header
== None:
343 self
._GetHeaderInfo
()
344 if self
._MakefileName
== None:
345 self
._MakefileName
= ''
346 return self
._MakefileName
348 ## Retrieve BsBaseAddress
349 def _GetBsBaseAddress(self
):
350 if self
._BsBaseAddress
== None:
351 if self
._Header
== None:
352 self
._GetHeaderInfo
()
353 if self
._BsBaseAddress
== None:
354 self
._BsBaseAddress
= ''
355 return self
._BsBaseAddress
357 ## Retrieve RtBaseAddress
358 def _GetRtBaseAddress(self
):
359 if self
._RtBaseAddress
== None:
360 if self
._Header
== None:
361 self
._GetHeaderInfo
()
362 if self
._RtBaseAddress
== None:
363 self
._RtBaseAddress
= ''
364 return self
._RtBaseAddress
366 ## Retrieve the top address for the load fix address
367 def _GetLoadFixAddress(self
):
368 if self
._LoadFixAddress
== None:
369 if self
._Header
== None:
370 self
._GetHeaderInfo
()
371 if self
._LoadFixAddress
== None:
372 self
._LoadFixAddress
= ''
373 return self
._LoadFixAddress
375 ## Retrieve RFCLanguage filter
376 def _GetRFCLanguages(self
):
377 if self
._RFCLanguages
== None:
378 if self
._Header
== None:
379 self
._GetHeaderInfo
()
380 if self
._RFCLanguages
== None:
381 self
._RFCLanguages
= []
382 return self
._RFCLanguages
384 ## Retrieve ISOLanguage filter
385 def _GetISOLanguages(self
):
386 if self
._ISOLanguages
== None:
387 if self
._Header
== None:
388 self
._GetHeaderInfo
()
389 if self
._ISOLanguages
== None:
390 self
._ISOLanguages
= []
391 return self
._ISOLanguages
393 ## Retrieve the GUID string for VPD tool
394 def _GetVpdToolGuid(self
):
395 if self
._VpdToolGuid
== None:
396 if self
._Header
== None:
397 self
._GetHeaderInfo
()
398 if self
._VpdToolGuid
== None:
399 self
._VpdToolGuid
= ''
400 return self
._VpdToolGuid
402 ## Retrieve [SkuIds] section information
403 def _GetSkuIds(self
):
404 if self
._SkuIds
== None:
406 RecordList
= self
._RawData
[MODEL_EFI_SKU_ID
]
407 for Record
in RecordList
:
408 if Record
[0] in [None, '']:
409 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID number',
410 File
=self
.MetaFile
, Line
=Record
[-1])
411 if Record
[1] in [None, '']:
412 EdkLogger
.error('build', FORMAT_INVALID
, 'No Sku ID name',
413 File
=self
.MetaFile
, Line
=Record
[-1])
414 self
._SkuIds
[Record
[1]] = Record
[0]
415 if 'DEFAULT' not in self
._SkuIds
:
416 self
._SkuIds
['DEFAULT'] = 0
419 ## Retrieve [Components] section information
420 def _GetModules(self
):
421 if self
._Modules
!= None:
424 self
._Modules
= sdict()
425 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT
, self
._Arch
]
426 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
}
427 Macros
.update(self
._Macros
)
428 for Record
in RecordList
:
429 ModuleFile
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
433 # check the file validation
434 ErrorCode
, ErrorInfo
= ModuleFile
.Validate('.inf')
436 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
439 if ModuleFile
in self
._Modules
:
440 EdkLogger
.error('build', FILE_DUPLICATED
, File
=self
.MetaFile
, ExtraData
=str(ModuleFile
), Line
=LineNo
)
442 Module
= ModuleBuildClassObject()
443 Module
.MetaFile
= ModuleFile
445 # get module override path
446 RecordList
= self
._RawData
[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
, self
._Arch
, None, ModuleId
]
448 Module
.SourceOverridePath
= os
.path
.join(GlobalData
.gWorkspace
, NormPath(RecordList
[0][0], Macros
))
450 # Check if the source override path exists
451 if not os
.path
.isdir(Module
.SourceOverridePath
):
452 EdkLogger
.error('build', FILE_NOT_FOUND
, Message
= 'Source override path does not exist:', File
=self
.MetaFile
, ExtraData
=Module
.SourceOverridePath
, Line
=LineNo
)
454 #Add to GlobalData Variables
455 GlobalData
.gOverrideDir
[ModuleFile
.Key
] = Module
.SourceOverridePath
457 # get module private library instance
458 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, None, ModuleId
]
459 for Record
in RecordList
:
460 LibraryClass
= Record
[0]
461 LibraryPath
= PathClass(NormPath(Record
[1], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
464 # check the file validation
465 ErrorCode
, ErrorInfo
= LibraryPath
.Validate('.inf')
467 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
470 if LibraryClass
== '' or LibraryClass
== 'NULL':
471 self
._NullLibraryNumber
+= 1
472 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
473 EdkLogger
.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile
, LibraryPath
, LibraryClass
))
474 Module
.LibraryClasses
[LibraryClass
] = LibraryPath
475 if LibraryPath
not in self
.LibraryInstances
:
476 self
.LibraryInstances
.append(LibraryPath
)
478 # get module private PCD setting
479 for Type
in [MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, \
480 MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_DYNAMIC
, MODEL_PCD_DYNAMIC_EX
]:
481 RecordList
= self
._RawData
[Type
, self
._Arch
, None, ModuleId
]
482 for TokenSpaceGuid
, PcdCName
, Setting
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
483 TokenList
= GetSplitValueList(Setting
)
484 DefaultValue
= TokenList
[0]
485 if len(TokenList
) > 1:
486 MaxDatumSize
= TokenList
[1]
489 TypeString
= self
._PCD
_TYPE
_STRING
_[Type
]
490 Pcd
= PcdClassObject(
502 Module
.Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
504 # get module private build options
505 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, None, ModuleId
]
506 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
507 if (ToolChainFamily
, ToolChain
) not in Module
.BuildOptions
:
508 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = Option
510 OptionString
= Module
.BuildOptions
[ToolChainFamily
, ToolChain
]
511 Module
.BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
513 self
._Modules
[ModuleFile
] = Module
516 ## Retrieve all possible library instances used in this platform
517 def _GetLibraryInstances(self
):
518 if self
._LibraryInstances
== None:
519 self
._GetLibraryClasses
()
520 return self
._LibraryInstances
522 ## Retrieve [LibraryClasses] information
523 def _GetLibraryClasses(self
):
524 if self
._LibraryClasses
== None:
525 self
._LibraryInstances
= []
527 # tdict is a special dict kind of type, used for selecting correct
528 # library instance for given library class and module type
530 LibraryClassDict
= tdict(True, 3)
531 # track all library class names
532 LibraryClassSet
= set()
533 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
]
534 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
}
535 Macros
.update(self
._Macros
)
536 for Record
in RecordList
:
537 LibraryClass
, LibraryInstance
, Dummy
, Arch
, ModuleType
, Dummy
, LineNo
= Record
538 if LibraryClass
== '' or LibraryClass
== 'NULL':
539 self
._NullLibraryNumber
+= 1
540 LibraryClass
= 'NULL%d' % self
._NullLibraryNumber
541 EdkLogger
.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch
, LibraryInstance
, LibraryClass
))
542 LibraryClassSet
.add(LibraryClass
)
543 LibraryInstance
= PathClass(NormPath(LibraryInstance
, Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
544 # check the file validation
545 ErrorCode
, ErrorInfo
= LibraryInstance
.Validate('.inf')
547 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
550 if ModuleType
!= 'COMMON' and ModuleType
not in SUP_MODULE_LIST
:
551 EdkLogger
.error('build', OPTION_UNKNOWN
, "Unknown module type [%s]" % ModuleType
,
552 File
=self
.MetaFile
, ExtraData
=LibraryInstance
, Line
=LineNo
)
553 LibraryClassDict
[Arch
, ModuleType
, LibraryClass
] = LibraryInstance
554 if LibraryInstance
not in self
._LibraryInstances
:
555 self
._LibraryInstances
.append(LibraryInstance
)
557 # resolve the specific library instance for each class and each module type
558 self
._LibraryClasses
= tdict(True)
559 for LibraryClass
in LibraryClassSet
:
560 # try all possible module types
561 for ModuleType
in SUP_MODULE_LIST
:
562 LibraryInstance
= LibraryClassDict
[self
._Arch
, ModuleType
, LibraryClass
]
563 if LibraryInstance
== None:
565 self
._LibraryClasses
[LibraryClass
, ModuleType
] = LibraryInstance
567 # for R8 style library instances, which are listed in different section
568 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
]
569 for Record
in RecordList
:
570 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
572 # check the file validation
573 ErrorCode
, ErrorInfo
= File
.Validate('.inf')
575 EdkLogger
.error('build', ErrorCode
, File
=self
.MetaFile
, Line
=LineNo
,
577 if File
not in self
._LibraryInstances
:
578 self
._LibraryInstances
.append(File
)
580 # we need the module name as the library class name, so we have
581 # to parse it here. (self._Bdb[] will trigger a file parse if it
582 # hasn't been parsed)
584 Library
= self
._Bdb
[File
, self
._Arch
]
585 self
._LibraryClasses
[Library
.BaseName
, ':dummy:'] = Library
586 return self
._LibraryClasses
588 ## Retrieve all PCD settings in platform
590 if self
._Pcds
== None:
592 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
593 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
594 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
595 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_DEFAULT
))
596 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_HII
))
597 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_VPD
))
598 self
._Pcds
.update(self
._GetDynamicPcd
(MODEL_PCD_DYNAMIC_EX_DEFAULT
))
599 self
._Pcds
.update(self
._GetDynamicHiiPcd
(MODEL_PCD_DYNAMIC_EX_HII
))
600 self
._Pcds
.update(self
._GetDynamicVpdPcd
(MODEL_PCD_DYNAMIC_EX_VPD
))
603 ## Retrieve [BuildOptions]
604 def _GetBuildOptions(self
):
605 if self
._BuildOptions
== None:
606 self
._BuildOptions
= {}
608 # Retrieve build option for EDKII style module
610 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, 'COMMON', EDKII_NAME
]
611 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
612 self
._BuildOptions
[ToolChainFamily
, ToolChain
, EDKII_NAME
] = Option
614 # Retrieve build option for EDK style module
616 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, 'COMMON', EDK_NAME
]
617 for ToolChainFamily
, ToolChain
, Option
, Dummy1
, Dummy2
, Dummy3
, Dummy4
in RecordList
:
618 self
._BuildOptions
[ToolChainFamily
, ToolChain
, EDK_NAME
] = Option
619 return self
._BuildOptions
621 ## Retrieve non-dynamic PCD settings
623 # @param Type PCD type
625 # @retval a dict object contains settings of given PCD type
627 def _GetPcd(self
, Type
):
630 # tdict is a special dict kind of type, used for selecting correct
631 # PCD settings for certain ARCH
633 PcdDict
= tdict(True, 3)
635 # Find out all possible PCD candidates for self._Arch
636 RecordList
= self
._RawData
[Type
, self
._Arch
]
637 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
638 PcdSet
.add((PcdCName
, TokenSpaceGuid
))
639 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
] = Setting
640 # Remove redundant PCD candidates
641 for PcdCName
, TokenSpaceGuid
in PcdSet
:
642 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
]
645 PcdValue
, DatumType
, MaxDatumSize
= AnalyzePcdData(Setting
)
646 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
649 self
._PCD
_TYPE
_STRING
_[Type
],
660 ## Retrieve dynamic PCD settings
662 # @param Type PCD type
664 # @retval a dict object contains settings of given PCD type
666 def _GetDynamicPcd(self
, Type
):
669 # tdict is a special dict kind of type, used for selecting correct
670 # PCD settings for certain ARCH and SKU
672 PcdDict
= tdict(True, 4)
674 # Find out all possible PCD candidates for self._Arch
675 RecordList
= self
._RawData
[Type
, self
._Arch
]
676 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
677 PcdList
.append((PcdCName
, TokenSpaceGuid
))
678 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
679 # Remove redundant PCD candidates, per the ARCH and SKU
680 for PcdCName
, TokenSpaceGuid
in PcdList
:
681 Setting
= PcdDict
[self
._Arch
, self
.SkuName
, PcdCName
, TokenSpaceGuid
]
685 PcdValue
, DatumType
, MaxDatumSize
= AnalyzePcdData(Setting
)
687 SkuInfo
= SkuInfoClass(self
.SkuName
, self
.SkuIds
[self
.SkuName
], '', '', '', '', '', PcdValue
)
688 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
691 self
._PCD
_TYPE
_STRING
_[Type
],
696 {self
.SkuName
: SkuInfo
},
702 ## Retrieve dynamic HII PCD settings
704 # @param Type PCD type
706 # @retval a dict object contains settings of given PCD type
708 def _GetDynamicHiiPcd(self
, Type
):
711 # tdict is a special dict kind of type, used for selecting correct
712 # PCD settings for certain ARCH and SKU
714 PcdDict
= tdict(True, 4)
716 RecordList
= self
._RawData
[Type
, self
._Arch
]
717 # Find out all possible PCD candidates for self._Arch
718 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
719 PcdSet
.add((PcdCName
, TokenSpaceGuid
))
720 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
721 # Remove redundant PCD candidates, per the ARCH and SKU
722 for PcdCName
, TokenSpaceGuid
in PcdSet
:
723 Setting
= PcdDict
[self
._Arch
, self
.SkuName
, PcdCName
, TokenSpaceGuid
]
726 VariableName
, VariableGuid
, VariableOffset
, DefaultValue
= AnalyzeHiiPcdData(Setting
)
727 SkuInfo
= SkuInfoClass(self
.SkuName
, self
.SkuIds
[self
.SkuName
], VariableName
, VariableGuid
, VariableOffset
, DefaultValue
)
728 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
731 self
._PCD
_TYPE
_STRING
_[Type
],
736 {self
.SkuName
: SkuInfo
},
742 ## Retrieve dynamic VPD PCD settings
744 # @param Type PCD type
746 # @retval a dict object contains settings of given PCD type
748 def _GetDynamicVpdPcd(self
, Type
):
751 # tdict is a special dict kind of type, used for selecting correct
752 # PCD settings for certain ARCH and SKU
754 PcdDict
= tdict(True, 4)
756 # Find out all possible PCD candidates for self._Arch
757 RecordList
= self
._RawData
[Type
, self
._Arch
]
758 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, SkuName
, Dummy3
, Dummy4
in RecordList
:
759 PcdList
.append((PcdCName
, TokenSpaceGuid
))
760 PcdDict
[Arch
, SkuName
, PcdCName
, TokenSpaceGuid
] = Setting
761 # Remove redundant PCD candidates, per the ARCH and SKU
762 for PcdCName
, TokenSpaceGuid
in PcdList
:
763 Setting
= PcdDict
[self
._Arch
, self
.SkuName
, PcdCName
, TokenSpaceGuid
]
767 # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue
768 # For the Integer & Boolean type, the optional data can only be InitialValue.
769 # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
770 # until the DEC parser has been called.
772 VpdOffset
, MaxDatumSize
, InitialValue
= AnalyzeVpdPcdData(Setting
)
774 SkuInfo
= SkuInfoClass(self
.SkuName
, self
.SkuIds
[self
.SkuName
], '', '', '', '', VpdOffset
, InitialValue
)
775 Pcds
[PcdCName
, TokenSpaceGuid
] = PcdClassObject(
778 self
._PCD
_TYPE
_STRING
_[Type
],
783 {self
.SkuName
: SkuInfo
},
789 ## Add external modules
791 # The external modules are mostly those listed in FDF file, which don't
794 # @param FilePath The path of module description file
796 def AddModule(self
, FilePath
):
797 FilePath
= NormPath(FilePath
)
798 if FilePath
not in self
.Modules
:
799 Module
= ModuleBuildClassObject()
800 Module
.MetaFile
= FilePath
801 self
.Modules
.append(Module
)
805 # The external PCDs are mostly those listed in FDF file to specify address
806 # or offset information.
808 # @param Name Name of the PCD
809 # @param Guid Token space guid of the PCD
810 # @param Value Value of the PCD
812 def AddPcd(self
, Name
, Guid
, Value
):
813 if (Name
, Guid
) not in self
.Pcds
:
814 self
.Pcds
[Name
, Guid
] = PcdClassObject(Name
, Guid
, '', '', '', '', '', {}, False, None)
815 self
.Pcds
[Name
, Guid
].DefaultValue
= Value
817 Arch
= property(_GetArch
, _SetArch
)
818 Platform
= property(_GetPlatformName
)
819 PlatformName
= property(_GetPlatformName
)
820 Guid
= property(_GetFileGuid
)
821 Version
= property(_GetVersion
)
822 DscSpecification
= property(_GetDscSpec
)
823 OutputDirectory
= property(_GetOutpuDir
)
824 SupArchList
= property(_GetSupArch
)
825 BuildTargets
= property(_GetBuildTarget
)
826 SkuName
= property(_GetSkuName
, _SetSkuName
)
827 FlashDefinition
= property(_GetFdfFile
)
828 BuildNumber
= property(_GetBuildNumber
)
829 MakefileName
= property(_GetMakefileName
)
830 BsBaseAddress
= property(_GetBsBaseAddress
)
831 RtBaseAddress
= property(_GetRtBaseAddress
)
832 LoadFixAddress
= property(_GetLoadFixAddress
)
833 RFCLanguages
= property(_GetRFCLanguages
)
834 ISOLanguages
= property(_GetISOLanguages
)
835 VpdToolGuid
= property(_GetVpdToolGuid
)
836 SkuIds
= property(_GetSkuIds
)
837 Modules
= property(_GetModules
)
838 LibraryInstances
= property(_GetLibraryInstances
)
839 LibraryClasses
= property(_GetLibraryClasses
)
840 Pcds
= property(_GetPcds
)
841 BuildOptions
= property(_GetBuildOptions
)
843 ## Platform build information from DEC file
845 # This class is used to retrieve information stored in database and convert them
846 # into PackageBuildClassObject form for easier use for AutoGen.
848 class DecBuildData(PackageBuildClassObject
):
849 # dict used to convert PCD type in database to string used by build tool
850 _PCD_TYPE_STRING_
= {
851 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
852 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
853 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
854 MODEL_PCD_DYNAMIC
: "Dynamic",
855 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
856 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
857 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
858 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
859 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
860 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
861 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
864 # dict used to convert part of [Defines] to members of DecBuildData directly
869 TAB_DEC_DEFINES_PACKAGE_NAME
: "_PackageName",
870 TAB_DEC_DEFINES_PACKAGE_GUID
: "_Guid",
871 TAB_DEC_DEFINES_PACKAGE_VERSION
: "_Version",
872 TAB_DEC_DEFINES_PKG_UNI_FILE
: "_PkgUniFile",
876 ## Constructor of DecBuildData
878 # Initialize object of DecBuildData
880 # @param FilePath The path of package description file
881 # @param RawData The raw data of DEC file
882 # @param BuildDataBase Database used to retrieve module information
883 # @param Arch The target architecture
884 # @param Platform (not used for DecBuildData)
885 # @param Macros Macros used for replacement in DSC file
887 def __init__(self
, File
, RawData
, BuildDataBase
, Arch
='COMMON', Platform
='DUMMY', Macros
={}):
889 self
._PackageDir
= File
.Dir
890 self
._RawData
= RawData
891 self
._Bdb
= BuildDataBase
893 self
._Macros
= Macros
897 def __setitem__(self
, key
, value
):
898 self
.__dict
__[self
._PROPERTY
_[key
]] = value
901 def __getitem__(self
, key
):
902 return self
.__dict
__[self
._PROPERTY
_[key
]]
905 def __contains__(self
, key
):
906 return key
in self
._PROPERTY
_
908 ## Set all internal used members of DecBuildData to None
911 self
._PackageName
= None
914 self
._PkgUniFile
= None
915 self
._Protocols
= None
918 self
._Includes
= None
919 self
._LibraryClasses
= None
928 # Changing the default ARCH to another may affect all other information
929 # because all information in a platform may be ARCH-related. That's
930 # why we need to clear all internal used members, in order to cause all
931 # information to be re-retrieved.
933 # @param Value The value of ARCH
935 def _SetArch(self
, Value
):
936 if self
._Arch
== Value
:
941 ## Retrieve all information in [Defines] section
943 # (Retriving all [Defines] information in one-shot is just to save time.)
945 def _GetHeaderInfo(self
):
946 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
]
947 for Record
in RecordList
:
950 self
[Name
] = Record
[1]
951 self
._Header
= 'DUMMY'
953 ## Retrieve package name
954 def _GetPackageName(self
):
955 if self
._PackageName
== None:
956 if self
._Header
== None:
957 self
._GetHeaderInfo
()
958 if self
._PackageName
== None:
959 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "No PACKAGE_NAME", File
=self
.MetaFile
)
960 return self
._PackageName
962 ## Retrieve file guid
963 def _GetFileGuid(self
):
964 if self
._Guid
== None:
965 if self
._Header
== None:
966 self
._GetHeaderInfo
()
967 if self
._Guid
== None:
968 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
, "No PACKAGE_GUID", File
=self
.MetaFile
)
971 ## Retrieve package version
972 def _GetVersion(self
):
973 if self
._Version
== None:
974 if self
._Header
== None:
975 self
._GetHeaderInfo
()
976 if self
._Version
== None:
980 ## Retrieve protocol definitions (name/value pairs)
981 def _GetProtocol(self
):
982 if self
._Protocols
== None:
984 # tdict is a special kind of dict, used for selecting correct
985 # protocol defition for given ARCH
987 ProtocolDict
= tdict(True)
989 # find out all protocol definitions for specific and 'common' arch
990 RecordList
= self
._RawData
[MODEL_EFI_PROTOCOL
, self
._Arch
]
991 for Name
, Guid
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
992 if Name
not in NameList
:
993 NameList
.append(Name
)
994 ProtocolDict
[Arch
, Name
] = Guid
995 # use sdict to keep the order
996 self
._Protocols
= sdict()
997 for Name
in NameList
:
999 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1000 # will automatically turn to 'common' ARCH for trying
1002 self
._Protocols
[Name
] = ProtocolDict
[self
._Arch
, Name
]
1003 return self
._Protocols
1005 ## Retrieve PPI definitions (name/value pairs)
1007 if self
._Ppis
== None:
1009 # tdict is a special kind of dict, used for selecting correct
1010 # PPI defition for given ARCH
1012 PpiDict
= tdict(True)
1014 # find out all PPI definitions for specific arch and 'common' arch
1015 RecordList
= self
._RawData
[MODEL_EFI_PPI
, self
._Arch
]
1016 for Name
, Guid
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1017 if Name
not in NameList
:
1018 NameList
.append(Name
)
1019 PpiDict
[Arch
, Name
] = Guid
1020 # use sdict to keep the order
1021 self
._Ppis
= sdict()
1022 for Name
in NameList
:
1024 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1025 # will automatically turn to 'common' ARCH for trying
1027 self
._Ppis
[Name
] = PpiDict
[self
._Arch
, Name
]
1030 ## Retrieve GUID definitions (name/value pairs)
1032 if self
._Guids
== None:
1034 # tdict is a special kind of dict, used for selecting correct
1035 # GUID defition for given ARCH
1037 GuidDict
= tdict(True)
1039 # find out all protocol definitions for specific and 'common' arch
1040 RecordList
= self
._RawData
[MODEL_EFI_GUID
, self
._Arch
]
1041 for Name
, Guid
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1042 if Name
not in NameList
:
1043 NameList
.append(Name
)
1044 GuidDict
[Arch
, Name
] = Guid
1045 # use sdict to keep the order
1046 self
._Guids
= sdict()
1047 for Name
in NameList
:
1049 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1050 # will automatically turn to 'common' ARCH for trying
1052 self
._Guids
[Name
] = GuidDict
[self
._Arch
, Name
]
1055 ## Retrieve public include paths declared in this package
1056 def _GetInclude(self
):
1057 if self
._Includes
== None:
1059 RecordList
= self
._RawData
[MODEL_EFI_INCLUDE
, self
._Arch
]
1060 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
}
1061 Macros
.update(self
._Macros
)
1062 for Record
in RecordList
:
1063 File
= PathClass(NormPath(Record
[0], Macros
), self
._PackageDir
, Arch
=self
._Arch
)
1066 ErrorCode
, ErrorInfo
= File
.Validate()
1068 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1070 # avoid duplicate include path
1071 if File
not in self
._Includes
:
1072 self
._Includes
.append(File
)
1073 return self
._Includes
1075 ## Retrieve library class declarations (not used in build at present)
1076 def _GetLibraryClass(self
):
1077 if self
._LibraryClasses
== None:
1079 # tdict is a special kind of dict, used for selecting correct
1080 # library class declaration for given ARCH
1082 LibraryClassDict
= tdict(True)
1083 LibraryClassSet
= set()
1084 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
]
1085 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
}
1086 Macros
.update(self
._Macros
)
1087 for LibraryClass
, File
, Dummy
, Arch
, ID
, LineNo
in RecordList
:
1088 File
= PathClass(NormPath(File
, Macros
), self
._PackageDir
, Arch
=self
._Arch
)
1089 # check the file validation
1090 ErrorCode
, ErrorInfo
= File
.Validate()
1092 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1093 LibraryClassSet
.add(LibraryClass
)
1094 LibraryClassDict
[Arch
, LibraryClass
] = File
1095 self
._LibraryClasses
= sdict()
1096 for LibraryClass
in LibraryClassSet
:
1097 self
._LibraryClasses
[LibraryClass
] = LibraryClassDict
[self
._Arch
, LibraryClass
]
1098 return self
._LibraryClasses
1100 ## Retrieve PCD declarations
1102 if self
._Pcds
== None:
1104 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1105 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1106 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1107 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC
))
1108 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC_EX
))
1111 ## Retrieve PCD declarations for given type
1112 def _GetPcd(self
, Type
):
1115 # tdict is a special kind of dict, used for selecting correct
1116 # PCD declaration for given ARCH
1118 PcdDict
= tdict(True, 3)
1119 # for summarizing PCD
1121 # find out all PCDs of the 'type'
1122 RecordList
= self
._RawData
[Type
, self
._Arch
]
1123 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, Dummy1
, Dummy2
in RecordList
:
1124 PcdDict
[Arch
, PcdCName
, TokenSpaceGuid
] = Setting
1125 PcdSet
.add((PcdCName
, TokenSpaceGuid
))
1127 for PcdCName
, TokenSpaceGuid
in PcdSet
:
1129 # limit the ARCH to self._Arch, if no self._Arch found, tdict
1130 # will automatically turn to 'common' ARCH and try again
1132 Setting
= PcdDict
[self
._Arch
, PcdCName
, TokenSpaceGuid
]
1136 DefaultValue
, DatumType
, TokenNumber
= AnalyzePcdData(Setting
)
1138 Pcds
[PcdCName
, TokenSpaceGuid
, self
._PCD
_TYPE
_STRING
_[Type
]] = PcdClassObject(
1141 self
._PCD
_TYPE
_STRING
_[Type
],
1153 Arch
= property(_GetArch
, _SetArch
)
1154 PackageName
= property(_GetPackageName
)
1155 Guid
= property(_GetFileGuid
)
1156 Version
= property(_GetVersion
)
1158 Protocols
= property(_GetProtocol
)
1159 Ppis
= property(_GetPpi
)
1160 Guids
= property(_GetGuid
)
1161 Includes
= property(_GetInclude
)
1162 LibraryClasses
= property(_GetLibraryClass
)
1163 Pcds
= property(_GetPcds
)
1165 ## Module build information from INF file
1167 # This class is used to retrieve information stored in database and convert them
1168 # into ModuleBuildClassObject form for easier use for AutoGen.
1170 class InfBuildData(ModuleBuildClassObject
):
1171 # dict used to convert PCD type in database to string used by build tool
1172 _PCD_TYPE_STRING_
= {
1173 MODEL_PCD_FIXED_AT_BUILD
: "FixedAtBuild",
1174 MODEL_PCD_PATCHABLE_IN_MODULE
: "PatchableInModule",
1175 MODEL_PCD_FEATURE_FLAG
: "FeatureFlag",
1176 MODEL_PCD_DYNAMIC
: "Dynamic",
1177 MODEL_PCD_DYNAMIC_DEFAULT
: "Dynamic",
1178 MODEL_PCD_DYNAMIC_HII
: "DynamicHii",
1179 MODEL_PCD_DYNAMIC_VPD
: "DynamicVpd",
1180 MODEL_PCD_DYNAMIC_EX
: "DynamicEx",
1181 MODEL_PCD_DYNAMIC_EX_DEFAULT
: "DynamicEx",
1182 MODEL_PCD_DYNAMIC_EX_HII
: "DynamicExHii",
1183 MODEL_PCD_DYNAMIC_EX_VPD
: "DynamicExVpd",
1186 # dict used to convert part of [Defines] to members of InfBuildData directly
1191 TAB_INF_DEFINES_BASE_NAME
: "_BaseName",
1192 TAB_INF_DEFINES_FILE_GUID
: "_Guid",
1193 TAB_INF_DEFINES_MODULE_TYPE
: "_ModuleType",
1197 TAB_INF_DEFINES_INF_VERSION
: "_AutoGenVersion",
1198 TAB_INF_DEFINES_COMPONENT_TYPE
: "_ComponentType",
1199 TAB_INF_DEFINES_MAKEFILE_NAME
: "_MakefileName",
1200 #TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
1201 TAB_INF_DEFINES_VERSION_NUMBER
: "_Version",
1202 TAB_INF_DEFINES_VERSION_STRING
: "_Version",
1203 TAB_INF_DEFINES_VERSION
: "_Version",
1204 TAB_INF_DEFINES_PCD_IS_DRIVER
: "_PcdIsDriver",
1205 TAB_INF_DEFINES_SHADOW
: "_Shadow",
1207 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH
: "_SourceOverridePath",
1210 # dict used to convert Component type to Module type
1213 "SECURITY_CORE" : "SEC",
1214 "PEI_CORE" : "PEI_CORE",
1215 "COMBINED_PEIM_DRIVER" : "PEIM",
1216 "PIC_PEIM" : "PEIM",
1217 "RELOCATABLE_PEIM" : "PEIM",
1218 "PE32_PEIM" : "PEIM",
1219 "BS_DRIVER" : "DXE_DRIVER",
1220 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",
1221 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",
1222 "DXE_SMM_DRIVER" : "DXE_SMM_DRIVER",
1223 # "SMM_DRIVER" : "DXE_SMM_DRIVER",
1224 # "BS_DRIVER" : "DXE_SMM_DRIVER",
1225 # "BS_DRIVER" : "UEFI_DRIVER",
1226 "APPLICATION" : "UEFI_APPLICATION",
1230 # regular expression for converting XXX_FLAGS in [nmake] section to new type
1231 _NMAKE_FLAG_PATTERN_
= re
.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re
.UNICODE
)
1232 # dict used to convert old tool name used in [nmake] section to new ones
1240 ## Constructor of DscBuildData
1242 # Initialize object of DscBuildData
1244 # @param FilePath The path of platform description file
1245 # @param RawData The raw data of DSC file
1246 # @param BuildDataBase Database used to retrieve module/package information
1247 # @param Arch The target architecture
1248 # @param Platform The name of platform employing this module
1249 # @param Macros Macros used for replacement in DSC file
1251 def __init__(self
, FilePath
, RawData
, BuildDatabase
, Arch
='COMMON', Platform
='COMMON', Macros
={}):
1252 self
.MetaFile
= FilePath
1253 self
._ModuleDir
= FilePath
.Dir
1254 self
._RawData
= RawData
1255 self
._Bdb
= BuildDatabase
1257 self
._Platform
= 'COMMON'
1258 self
._Macros
= Macros
1259 self
._SourceOverridePath
= None
1260 if FilePath
.Key
in GlobalData
.gOverrideDir
:
1261 self
._SourceOverridePath
= GlobalData
.gOverrideDir
[FilePath
.Key
]
1265 def __setitem__(self
, key
, value
):
1266 self
.__dict
__[self
._PROPERTY
_[key
]] = value
1269 def __getitem__(self
, key
):
1270 return self
.__dict
__[self
._PROPERTY
_[key
]]
1272 ## "in" test support
1273 def __contains__(self
, key
):
1274 return key
in self
._PROPERTY
_
1276 ## Set all internal used members of InfBuildData to None
1278 self
._Header
_ = None
1279 self
._AutoGenVersion
= None
1280 self
._BaseName
= None
1281 self
._ModuleType
= None
1282 self
._ComponentType
= None
1283 self
._BuildType
= None
1285 self
._Version
= None
1286 self
._PcdIsDriver
= None
1287 self
._BinaryModule
= None
1289 self
._MakefileName
= None
1290 self
._CustomMakefile
= None
1291 self
._Specification
= None
1292 self
._LibraryClass
= None
1293 self
._ModuleEntryPointList
= None
1294 self
._ModuleUnloadImageList
= None
1295 self
._ConstructorList
= None
1296 self
._DestructorList
= None
1298 self
._Binaries
= None
1299 self
._Sources
= None
1300 self
._LibraryClasses
= None
1301 self
._Libraries
= None
1302 self
._Protocols
= None
1305 self
._Includes
= None
1306 self
._Packages
= None
1308 self
._BuildOptions
= None
1310 self
._DepexExpression
= None
1311 #self._SourceOverridePath = None
1319 # Changing the default ARCH to another may affect all other information
1320 # because all information in a platform may be ARCH-related. That's
1321 # why we need to clear all internal used members, in order to cause all
1322 # information to be re-retrieved.
1324 # @param Value The value of ARCH
1326 def _SetArch(self
, Value
):
1327 if self
._Arch
== Value
:
1332 ## Return the name of platform employing this module
1333 def _GetPlatform(self
):
1334 return self
._Platform
1336 ## Change the name of platform employing this module
1338 # Changing the default name of platform to another may affect some information
1339 # because they may be PLATFORM-related. That's why we need to clear all internal
1340 # used members, in order to cause all information to be re-retrieved.
1342 def _SetPlatform(self
, Value
):
1343 if self
._Platform
== Value
:
1345 self
._Platform
= Value
1348 ## Retrieve all information in [Defines] section
1350 # (Retriving all [Defines] information in one-shot is just to save time.)
1352 def _GetHeaderInfo(self
):
1353 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
1354 for Record
in RecordList
:
1355 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1357 # items defined _PROPERTY_ don't need additional processing
1359 self
[Name
] = Record
[1]
1360 # some special items in [Defines] section need special treatment
1361 elif Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
1362 if Name
in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
1363 Name
= 'UEFI_SPECIFICATION_VERSION'
1364 if self
._Specification
== None:
1365 self
._Specification
= sdict()
1366 self
._Specification
[Name
] = GetHexVerValue(Record
[1])
1367 if self
._Specification
[Name
] == None:
1368 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
1369 "'%s' format is not supported for %s" % (Record
[1], Name
),
1370 File
=self
.MetaFile
, Line
=Record
[-1])
1371 elif Name
== 'LIBRARY_CLASS':
1372 if self
._LibraryClass
== None:
1373 self
._LibraryClass
= []
1374 ValueList
= GetSplitValueList(Record
[1])
1375 LibraryClass
= ValueList
[0]
1376 if len(ValueList
) > 1:
1377 SupModuleList
= GetSplitValueList(ValueList
[1], ' ')
1379 SupModuleList
= SUP_MODULE_LIST
1380 self
._LibraryClass
.append(LibraryClassObject(LibraryClass
, SupModuleList
))
1381 elif Name
== 'ENTRY_POINT':
1382 if self
._ModuleEntryPointList
== None:
1383 self
._ModuleEntryPointList
= []
1384 self
._ModuleEntryPointList
.append(Record
[1])
1385 elif Name
== 'UNLOAD_IMAGE':
1386 if self
._ModuleUnloadImageList
== None:
1387 self
._ModuleUnloadImageList
= []
1390 self
._ModuleUnloadImageList
.append(Record
[1])
1391 elif Name
== 'CONSTRUCTOR':
1392 if self
._ConstructorList
== None:
1393 self
._ConstructorList
= []
1396 self
._ConstructorList
.append(Record
[1])
1397 elif Name
== 'DESTRUCTOR':
1398 if self
._DestructorList
== None:
1399 self
._DestructorList
= []
1402 self
._DestructorList
.append(Record
[1])
1403 elif Name
== TAB_INF_DEFINES_CUSTOM_MAKEFILE
:
1404 TokenList
= GetSplitValueList(Record
[1])
1405 if self
._CustomMakefile
== None:
1406 self
._CustomMakefile
= {}
1407 if len(TokenList
) < 2:
1408 self
._CustomMakefile
['MSFT'] = TokenList
[0]
1409 self
._CustomMakefile
['GCC'] = TokenList
[0]
1411 if TokenList
[0] not in ['MSFT', 'GCC']:
1412 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
1413 "No supported family [%s]" % TokenList
[0],
1414 File
=self
.MetaFile
, Line
=Record
[-1])
1415 self
._CustomMakefile
[TokenList
[0]] = TokenList
[1]
1417 if self
._Defs
== None:
1418 self
._Defs
= sdict()
1419 self
._Defs
[Name
] = Record
[1]
1422 # Retrieve information in sections specific to R8.x modules
1424 if self
._AutoGenVersion
>= 0x00010005: # _AutoGenVersion may be None, which is less than anything
1425 if not self
._ModuleType
:
1426 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1427 "MODULE_TYPE is not given", File
=self
.MetaFile
)
1428 if self
._ModuleType
not in SUP_MODULE_LIST
:
1429 RecordList
= self
._RawData
[MODEL_META_DATA_HEADER
, self
._Arch
, self
._Platform
]
1430 for Record
in RecordList
:
1432 if Name
== "MODULE_TYPE":
1435 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
,
1436 "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self
._ModuleType
,' '.join(l
for l
in SUP_MODULE_LIST
)),
1437 File
=self
.MetaFile
, Line
=LineNo
)
1438 if (self
._Specification
== None) or (not 'PI_SPECIFICATION_VERSION' in self
._Specification
) or (int(self
._Specification
['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
1439 if self
._ModuleType
== SUP_MODULE_SMM_CORE
:
1440 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File
=self
.MetaFile
)
1441 if self
._Defs
and 'PCI_DEVICE_ID' in self
._Defs
and 'PCI_VENDOR_ID' in self
._Defs \
1442 and 'PCI_CLASS_CODE' in self
._Defs
:
1443 self
._BuildType
= 'UEFI_OPTIONROM'
1444 elif self
._Defs
and 'UEFI_HII_RESOURCE_SECTION' in self
._Defs \
1445 and self
._Defs
['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':
1446 self
._BuildType
= 'UEFI_HII'
1448 self
._BuildType
= self
._ModuleType
.upper()
1450 self
._BuildType
= self
._ComponentType
.upper()
1451 if not self
._ComponentType
:
1452 EdkLogger
.error("build", ATTRIBUTE_NOT_AVAILABLE
,
1453 "COMPONENT_TYPE is not given", File
=self
.MetaFile
)
1454 if self
._ComponentType
in self
._MODULE
_TYPE
_:
1455 self
._ModuleType
= self
._MODULE
_TYPE
_[self
._ComponentType
]
1456 if self
._ComponentType
== 'LIBRARY':
1457 self
._LibraryClass
= [LibraryClassObject(self
._BaseName
, SUP_MODULE_LIST
)]
1458 # make use some [nmake] section macros
1459 RecordList
= self
._RawData
[MODEL_META_DATA_NMAKE
, self
._Arch
, self
._Platform
]
1460 for Name
,Value
,Dummy
,Arch
,Platform
,ID
,LineNo
in RecordList
:
1461 Value
= Value
.replace('$(PROCESSOR)', self
._Arch
)
1462 Name
= Name
.replace('$(PROCESSOR)', self
._Arch
)
1463 Name
, Value
= ReplaceMacros((Name
, Value
), GlobalData
.gEdkGlobal
, True)
1464 if Name
== "IMAGE_ENTRY_POINT":
1465 if self
._ModuleEntryPointList
== None:
1466 self
._ModuleEntryPointList
= []
1467 self
._ModuleEntryPointList
.append(Value
)
1468 elif Name
== "DPX_SOURCE":
1469 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
}
1470 Macros
.update(self
._Macros
)
1471 File
= PathClass(NormPath(Value
, Macros
), self
._ModuleDir
, Arch
=self
._Arch
)
1472 # check the file validation
1473 ErrorCode
, ErrorInfo
= File
.Validate(".dxs", CaseSensitive
=False)
1475 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
,
1476 File
=self
.MetaFile
, Line
=LineNo
)
1477 if self
.Sources
== None:
1479 self
._Sources
.append(File
)
1481 ToolList
= self
._NMAKE
_FLAG
_PATTERN
_.findall(Name
)
1482 if len(ToolList
) == 0 or len(ToolList
) != 1:
1484 # EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name,
1485 # File=self.MetaFile, Line=LineNo)
1487 if self
._BuildOptions
== None:
1488 self
._BuildOptions
= sdict()
1490 if ToolList
[0] in self
._TOOL
_CODE
_:
1491 Tool
= self
._TOOL
_CODE
_[ToolList
[0]]
1494 ToolChain
= "*_*_*_%s_FLAGS" % Tool
1495 ToolChainFamily
= 'MSFT' # R8.x only support MSFT tool chain
1496 #ignore not replaced macros in value
1497 ValueList
= GetSplitValueList(' ' + Value
, '/D')
1498 Dummy
= ValueList
[0]
1499 for Index
in range(1, len(ValueList
)):
1500 if ValueList
[Index
][-1] == '=' or ValueList
[Index
] == '':
1502 Dummy
= Dummy
+ ' /D ' + ValueList
[Index
]
1503 Value
= Dummy
.strip()
1504 if (ToolChainFamily
, ToolChain
) not in self
._BuildOptions
:
1505 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = Value
1507 OptionString
= self
._BuildOptions
[ToolChainFamily
, ToolChain
]
1508 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Value
1509 # set _Header to non-None in order to avoid database re-querying
1510 self
._Header
_ = 'DUMMY'
1512 ## Retrieve file version
1513 def _GetInfVersion(self
):
1514 if self
._AutoGenVersion
== None:
1515 if self
._Header
_ == None:
1516 self
._GetHeaderInfo
()
1517 if self
._AutoGenVersion
== None:
1518 self
._AutoGenVersion
= 0x00010000
1519 return self
._AutoGenVersion
1521 ## Retrieve BASE_NAME
1522 def _GetBaseName(self
):
1523 if self
._BaseName
== None:
1524 if self
._Header
_ == None:
1525 self
._GetHeaderInfo
()
1526 if self
._BaseName
== None:
1527 EdkLogger
.error('build', ATTRIBUTE_NOT_AVAILABLE
, "No BASE_NAME name", File
=self
.MetaFile
)
1528 return self
._BaseName
1530 ## Retrieve MODULE_TYPE
1531 def _GetModuleType(self
):
1532 if self
._ModuleType
== None:
1533 if self
._Header
_ == None:
1534 self
._GetHeaderInfo
()
1535 if self
._ModuleType
== None:
1536 self
._ModuleType
= 'BASE'
1537 if self
._ModuleType
not in SUP_MODULE_LIST
:
1538 self
._ModuleType
= "USER_DEFINED"
1539 return self
._ModuleType
1541 ## Retrieve COMPONENT_TYPE
1542 def _GetComponentType(self
):
1543 if self
._ComponentType
== None:
1544 if self
._Header
_ == None:
1545 self
._GetHeaderInfo
()
1546 if self
._ComponentType
== None:
1547 self
._ComponentType
= 'USER_DEFINED'
1548 return self
._ComponentType
1550 ## Retrieve "BUILD_TYPE"
1551 def _GetBuildType(self
):
1552 if self
._BuildType
== None:
1553 if self
._Header
_ == None:
1554 self
._GetHeaderInfo
()
1555 if not self
._BuildType
:
1556 self
._BuildType
= "BASE"
1557 return self
._BuildType
1559 ## Retrieve file guid
1560 def _GetFileGuid(self
):
1561 if self
._Guid
== None:
1562 if self
._Header
_ == None:
1563 self
._GetHeaderInfo
()
1564 if self
._Guid
== None:
1565 self
._Guid
= '00000000-0000-0000-000000000000'
1568 ## Retrieve module version
1569 def _GetVersion(self
):
1570 if self
._Version
== None:
1571 if self
._Header
_ == None:
1572 self
._GetHeaderInfo
()
1573 if self
._Version
== None:
1574 self
._Version
= '0.0'
1575 return self
._Version
1577 ## Retrieve PCD_IS_DRIVER
1578 def _GetPcdIsDriver(self
):
1579 if self
._PcdIsDriver
== None:
1580 if self
._Header
_ == None:
1581 self
._GetHeaderInfo
()
1582 if self
._PcdIsDriver
== None:
1583 self
._PcdIsDriver
= ''
1584 return self
._PcdIsDriver
1587 def _GetShadow(self
):
1588 if self
._Shadow
== None:
1589 if self
._Header
_ == None:
1590 self
._GetHeaderInfo
()
1591 if self
._Shadow
!= None and self
._Shadow
.upper() == 'TRUE':
1594 self
._Shadow
= False
1597 ## Retrieve CUSTOM_MAKEFILE
1598 def _GetMakefile(self
):
1599 if self
._CustomMakefile
== None:
1600 if self
._Header
_ == None:
1601 self
._GetHeaderInfo
()
1602 if self
._CustomMakefile
== None:
1603 self
._CustomMakefile
= {}
1604 return self
._CustomMakefile
1606 ## Retrieve EFI_SPECIFICATION_VERSION
1608 if self
._Specification
== None:
1609 if self
._Header
_ == None:
1610 self
._GetHeaderInfo
()
1611 if self
._Specification
== None:
1612 self
._Specification
= {}
1613 return self
._Specification
1615 ## Retrieve LIBRARY_CLASS
1616 def _GetLibraryClass(self
):
1617 if self
._LibraryClass
== None:
1618 if self
._Header
_ == None:
1619 self
._GetHeaderInfo
()
1620 if self
._LibraryClass
== None:
1621 self
._LibraryClass
= []
1622 return self
._LibraryClass
1624 ## Retrieve ENTRY_POINT
1625 def _GetEntryPoint(self
):
1626 if self
._ModuleEntryPointList
== None:
1627 if self
._Header
_ == None:
1628 self
._GetHeaderInfo
()
1629 if self
._ModuleEntryPointList
== None:
1630 self
._ModuleEntryPointList
= []
1631 return self
._ModuleEntryPointList
1633 ## Retrieve UNLOAD_IMAGE
1634 def _GetUnloadImage(self
):
1635 if self
._ModuleUnloadImageList
== None:
1636 if self
._Header
_ == None:
1637 self
._GetHeaderInfo
()
1638 if self
._ModuleUnloadImageList
== None:
1639 self
._ModuleUnloadImageList
= []
1640 return self
._ModuleUnloadImageList
1642 ## Retrieve CONSTRUCTOR
1643 def _GetConstructor(self
):
1644 if self
._ConstructorList
== None:
1645 if self
._Header
_ == None:
1646 self
._GetHeaderInfo
()
1647 if self
._ConstructorList
== None:
1648 self
._ConstructorList
= []
1649 return self
._ConstructorList
1651 ## Retrieve DESTRUCTOR
1652 def _GetDestructor(self
):
1653 if self
._DestructorList
== None:
1654 if self
._Header
_ == None:
1655 self
._GetHeaderInfo
()
1656 if self
._DestructorList
== None:
1657 self
._DestructorList
= []
1658 return self
._DestructorList
1660 ## Retrieve definies other than above ones
1661 def _GetDefines(self
):
1662 if self
._Defs
== None:
1663 if self
._Header
_ == None:
1664 self
._GetHeaderInfo
()
1665 if self
._Defs
== None:
1666 self
._Defs
= sdict()
1669 ## Retrieve binary files
1670 def _GetBinaryFiles(self
):
1671 if self
._Binaries
== None:
1673 RecordList
= self
._RawData
[MODEL_EFI_BINARY_FILE
, self
._Arch
, self
._Platform
]
1674 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
, 'PROCESSOR':self
._Arch
}
1675 Macros
.update(self
._Macros
)
1676 for Record
in RecordList
:
1677 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1678 FileType
= Record
[0]
1683 TokenList
= GetSplitValueList(Record
[2], TAB_VALUE_SPLIT
)
1685 Target
= TokenList
[0]
1686 if len(TokenList
) > 1:
1687 FeatureFlag
= Record
[1:]
1689 File
= PathClass(NormPath(Record
[1], Macros
), self
._ModuleDir
, '', FileType
, True, self
._Arch
, '', Target
)
1690 # check the file validation
1691 ErrorCode
, ErrorInfo
= File
.Validate()
1693 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1694 self
._Binaries
.append(File
)
1695 return self
._Binaries
1697 ## Retrieve source files
1698 def _GetSourceFiles(self
):
1699 if self
._Sources
== None:
1701 RecordList
= self
._RawData
[MODEL_EFI_SOURCE_FILE
, self
._Arch
, self
._Platform
]
1702 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
, 'PROCESSOR':self
._Arch
}
1703 Macros
.update(self
._Macros
)
1704 for Record
in RecordList
:
1705 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1707 ToolChainFamily
= Record
[1]
1709 ToolCode
= Record
[3]
1710 FeatureFlag
= Record
[4]
1711 if self
._AutoGenVersion
< 0x00010005:
1712 # old module source files (R8)
1713 File
= PathClass(NormPath(Record
[0], Macros
), self
._ModuleDir
, self
._SourceOverridePath
,
1714 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
1715 # check the file validation
1716 ErrorCode
, ErrorInfo
= File
.Validate(CaseSensitive
=False)
1718 if File
.Ext
.lower() == '.h':
1719 EdkLogger
.warn('build', 'Include file not found', ExtraData
=ErrorInfo
,
1720 File
=self
.MetaFile
, Line
=LineNo
)
1723 EdkLogger
.error('build', ErrorCode
, ExtraData
=File
, File
=self
.MetaFile
, Line
=LineNo
)
1725 File
= PathClass(NormPath(Record
[0], Macros
), self
._ModuleDir
, '',
1726 '', False, self
._Arch
, ToolChainFamily
, '', TagName
, ToolCode
)
1727 # check the file validation
1728 ErrorCode
, ErrorInfo
= File
.Validate()
1730 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1732 self
._Sources
.append(File
)
1733 return self
._Sources
1735 ## Retrieve library classes employed by this module
1736 def _GetLibraryClassUses(self
):
1737 if self
._LibraryClasses
== None:
1738 self
._LibraryClasses
= sdict()
1739 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_CLASS
, self
._Arch
, self
._Platform
]
1740 for Record
in RecordList
:
1741 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1743 Instance
= Record
[1]
1744 if Instance
!= None and Instance
!= '':
1745 Instance
= NormPath(Instance
, self
._Macros
)
1746 self
._LibraryClasses
[Lib
] = Instance
1747 return self
._LibraryClasses
1749 ## Retrieve library names (for R8.x style of modules)
1750 def _GetLibraryNames(self
):
1751 if self
._Libraries
== None:
1752 self
._Libraries
= []
1753 RecordList
= self
._RawData
[MODEL_EFI_LIBRARY_INSTANCE
, self
._Arch
, self
._Platform
]
1754 for Record
in RecordList
:
1755 # in case of name with '.lib' extension, which is unusual in R8.x inf
1756 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1757 LibraryName
= os
.path
.splitext(Record
[0])[0]
1758 if LibraryName
not in self
._Libraries
:
1759 self
._Libraries
.append(LibraryName
)
1760 return self
._Libraries
1762 ## Retrieve protocols consumed/produced by this module
1763 def _GetProtocols(self
):
1764 if self
._Protocols
== None:
1765 self
._Protocols
= sdict()
1766 RecordList
= self
._RawData
[MODEL_EFI_PROTOCOL
, self
._Arch
, self
._Platform
]
1767 for Record
in RecordList
:
1769 Value
= ProtocolValue(CName
, self
.Packages
)
1771 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
1772 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
1773 "Value of Protocol [%s] is not found under [Protocols] section in" % CName
,
1774 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
1775 self
._Protocols
[CName
] = Value
1776 return self
._Protocols
1778 ## Retrieve PPIs consumed/produced by this module
1780 if self
._Ppis
== None:
1781 self
._Ppis
= sdict()
1782 RecordList
= self
._RawData
[MODEL_EFI_PPI
, self
._Arch
, self
._Platform
]
1783 for Record
in RecordList
:
1785 Value
= PpiValue(CName
, self
.Packages
)
1787 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
1788 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
1789 "Value of PPI [%s] is not found under [Ppis] section in " % CName
,
1790 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
1791 self
._Ppis
[CName
] = Value
1794 ## Retrieve GUIDs consumed/produced by this module
1795 def _GetGuids(self
):
1796 if self
._Guids
== None:
1797 self
._Guids
= sdict()
1798 RecordList
= self
._RawData
[MODEL_EFI_GUID
, self
._Arch
, self
._Platform
]
1799 for Record
in RecordList
:
1801 Value
= GuidValue(CName
, self
.Packages
)
1803 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
1804 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
1805 "Value of Guid [%s] is not found under [Guids] section in" % CName
,
1806 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
1807 self
._Guids
[CName
] = Value
1810 ## Retrieve include paths necessary for this module (for R8.x style of modules)
1811 def _GetIncludes(self
):
1812 if self
._Includes
== None:
1814 if self
._SourceOverridePath
:
1815 self
._Includes
.append(self
._SourceOverridePath
)
1816 RecordList
= self
._RawData
[MODEL_EFI_INCLUDE
, self
._Arch
, self
._Platform
]
1817 # [includes] section must be used only in old (R8.x) inf file
1818 if self
.AutoGenVersion
>= 0x00010005 and len(RecordList
) > 0:
1819 EdkLogger
.error('build', FORMAT_NOT_SUPPORTED
, "No [include] section allowed",
1820 File
=self
.MetaFile
, Line
=RecordList
[0][-1]-1)
1821 for Record
in RecordList
:
1822 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1823 Record
[0] = Record
[0].replace('$(PROCESSOR)', self
._Arch
)
1824 Record
[0] = ReplaceMacro(Record
[0], {'EFI_SOURCE' : GlobalData
.gEfiSource
}, False)
1825 if Record
[0].find('EDK_SOURCE') > -1:
1826 File
= NormPath(ReplaceMacro(Record
[0], {'EDK_SOURCE' : GlobalData
.gEcpSource
}, False), self
._Macros
)
1828 File
= os
.path
.join(self
._ModuleDir
, File
)
1830 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
1831 File
= RealPath(os
.path
.normpath(File
))
1833 self
._Includes
.append(File
)
1835 #TRICK: let compiler to choose correct header file
1836 File
= NormPath(ReplaceMacro(Record
[0], {'EDK_SOURCE' : GlobalData
.gEdkSource
}, False), self
._Macros
)
1838 File
= os
.path
.join(self
._ModuleDir
, File
)
1840 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
1841 File
= RealPath(os
.path
.normpath(File
))
1843 self
._Includes
.append(File
)
1845 File
= NormPath(Record
[0], self
._Macros
)
1847 File
= os
.path
.join(self
._ModuleDir
, File
)
1849 File
= os
.path
.join(GlobalData
.gWorkspace
, File
)
1850 File
= RealPath(os
.path
.normpath(File
))
1852 self
._Includes
.append(File
)
1853 return self
._Includes
1855 ## Retrieve packages this module depends on
1856 def _GetPackages(self
):
1857 if self
._Packages
== None:
1859 RecordList
= self
._RawData
[MODEL_META_DATA_PACKAGE
, self
._Arch
, self
._Platform
]
1860 Macros
= {"EDK_SOURCE":GlobalData
.gEcpSource
, "EFI_SOURCE":GlobalData
.gEfiSource
}
1861 Macros
.update(self
._Macros
)
1862 for Record
in RecordList
:
1863 File
= PathClass(NormPath(Record
[0], Macros
), GlobalData
.gWorkspace
, Arch
=self
._Arch
)
1865 # check the file validation
1866 ErrorCode
, ErrorInfo
= File
.Validate('.dec')
1868 EdkLogger
.error('build', ErrorCode
, ExtraData
=ErrorInfo
, File
=self
.MetaFile
, Line
=LineNo
)
1869 # parse this package now. we need it to get protocol/ppi/guid value
1870 Package
= self
._Bdb
[File
, self
._Arch
]
1871 self
._Packages
.append(Package
)
1872 return self
._Packages
1874 ## Retrieve PCDs used in this module
1876 if self
._Pcds
== None:
1878 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FIXED_AT_BUILD
))
1879 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_PATCHABLE_IN_MODULE
))
1880 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_FEATURE_FLAG
))
1881 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC
))
1882 self
._Pcds
.update(self
._GetPcd
(MODEL_PCD_DYNAMIC_EX
))
1885 ## Retrieve build options specific to this module
1886 def _GetBuildOptions(self
):
1887 if self
._BuildOptions
== None:
1888 self
._BuildOptions
= sdict()
1889 RecordList
= self
._RawData
[MODEL_META_DATA_BUILD_OPTION
, self
._Arch
, self
._Platform
]
1890 for Record
in RecordList
:
1891 ToolChainFamily
= Record
[0]
1892 ToolChain
= Record
[1]
1894 if (ToolChainFamily
, ToolChain
) not in self
._BuildOptions
:
1895 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = Option
1897 # concatenate the option string if they're for the same tool
1898 OptionString
= self
._BuildOptions
[ToolChainFamily
, ToolChain
]
1899 self
._BuildOptions
[ToolChainFamily
, ToolChain
] = OptionString
+ " " + Option
1900 return self
._BuildOptions
1902 ## Retrieve depedency expression
1903 def _GetDepex(self
):
1904 if self
._Depex
== None:
1905 self
._Depex
= tdict(False, 2)
1906 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
1908 # If the module has only Binaries and no Sources, then ignore [Depex]
1909 if self
.Sources
== None or self
.Sources
== []:
1910 if self
.Binaries
<> None and self
.Binaries
<> []:
1913 # PEIM and DXE drivers must have a valid [Depex] section
1914 if len(self
.LibraryClass
) == 0 and len(RecordList
) == 0:
1915 if self
.ModuleType
== 'DXE_DRIVER' or self
.ModuleType
== 'PEIM' or self
.ModuleType
== 'DXE_SMM_DRIVER' or \
1916 self
.ModuleType
== 'DXE_SAL_DRIVER' or self
.ModuleType
== 'DXE_RUNTIME_DRIVER':
1917 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
1918 % self
.ModuleType
, File
=self
.MetaFile
)
1921 for Record
in RecordList
:
1922 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1924 ModuleType
= Record
[4]
1925 TokenList
= Record
[0].split()
1926 if (Arch
, ModuleType
) not in Depex
:
1927 Depex
[Arch
, ModuleType
] = []
1928 DepexList
= Depex
[Arch
, ModuleType
]
1929 for Token
in TokenList
:
1930 if Token
in DEPEX_SUPPORTED_OPCODE
:
1931 DepexList
.append(Token
)
1932 elif Token
.endswith(".inf"): # module file name
1933 ModuleFile
= os
.path
.normpath(Token
)
1934 Module
= self
.BuildDatabase
[ModuleFile
]
1936 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
, "Module is not found in active platform",
1937 ExtraData
=Token
, File
=self
.MetaFile
, Line
=Record
[-1])
1938 DepexList
.append(Module
.Guid
)
1940 # get the GUID value now
1941 Value
= ProtocolValue(Token
, self
.Packages
)
1943 Value
= PpiValue(Token
, self
.Packages
)
1945 Value
= GuidValue(Token
, self
.Packages
)
1947 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
1948 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
1949 "Value of [%s] is not found in" % Token
,
1950 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=Record
[-1])
1951 DepexList
.append(Value
)
1952 for Arch
, ModuleType
in Depex
:
1953 self
._Depex
[Arch
, ModuleType
] = Depex
[Arch
, ModuleType
]
1956 ## Retrieve depedency expression
1957 def _GetDepexExpression(self
):
1958 if self
._DepexExpression
== None:
1959 self
._DepexExpression
= tdict(False, 2)
1960 RecordList
= self
._RawData
[MODEL_EFI_DEPEX
, self
._Arch
]
1961 DepexExpression
= {}
1962 for Record
in RecordList
:
1963 Record
= ReplaceMacros(Record
, GlobalData
.gEdkGlobal
, False)
1965 ModuleType
= Record
[4]
1966 TokenList
= Record
[0].split()
1967 if (Arch
, ModuleType
) not in DepexExpression
:
1968 DepexExpression
[Arch
, ModuleType
] = ''
1969 for Token
in TokenList
:
1970 DepexExpression
[Arch
, ModuleType
] = DepexExpression
[Arch
, ModuleType
] + Token
.strip() + ' '
1971 for Arch
, ModuleType
in DepexExpression
:
1972 self
._DepexExpression
[Arch
, ModuleType
] = DepexExpression
[Arch
, ModuleType
]
1973 return self
._DepexExpression
1975 ## Retrieve PCD for given type
1976 def _GetPcd(self
, Type
):
1978 PcdDict
= tdict(True, 4)
1980 RecordList
= self
._RawData
[Type
, self
._Arch
, self
._Platform
]
1981 for TokenSpaceGuid
, PcdCName
, Setting
, Arch
, Platform
, Dummy1
, LineNo
in RecordList
:
1982 PcdDict
[Arch
, Platform
, PcdCName
, TokenSpaceGuid
] = (Setting
, LineNo
)
1983 PcdList
.append((PcdCName
, TokenSpaceGuid
))
1984 # get the guid value
1985 if TokenSpaceGuid
not in self
.Guids
:
1986 Value
= GuidValue(TokenSpaceGuid
, self
.Packages
)
1988 PackageList
= "\n\t".join([str(P
) for P
in self
.Packages
])
1989 EdkLogger
.error('build', RESOURCE_NOT_AVAILABLE
,
1990 "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid
,
1991 ExtraData
=PackageList
, File
=self
.MetaFile
, Line
=LineNo
)
1992 self
.Guids
[TokenSpaceGuid
] = Value
1994 # resolve PCD type, value, datum info, etc. by getting its definition from package
1995 for PcdCName
, TokenSpaceGuid
in PcdList
:
1996 Setting
, LineNo
= PcdDict
[self
._Arch
, self
.Platform
, PcdCName
, TokenSpaceGuid
]
1999 ValueList
= AnalyzePcdData(Setting
)
2000 DefaultValue
= ValueList
[0]
2001 Pcd
= PcdClassObject(
2011 self
.Guids
[TokenSpaceGuid
]
2014 # get necessary info from package declaring this PCD
2015 for Package
in self
.Packages
:
2017 # 'dynamic' in INF means its type is determined by platform;
2018 # if platform doesn't give its type, use 'lowest' one in the
2019 # following order, if any
2021 # "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"
2023 PcdType
= self
._PCD
_TYPE
_STRING
_[Type
]
2024 if Type
== MODEL_PCD_DYNAMIC
:
2026 for T
in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:
2027 if (PcdCName
, TokenSpaceGuid
, T
) in Package
.Pcds
:
2033 if (PcdCName
, TokenSpaceGuid
, PcdType
) in Package
.Pcds
:
2034 PcdInPackage
= Package
.Pcds
[PcdCName
, TokenSpaceGuid
, PcdType
]
2036 Pcd
.TokenValue
= PcdInPackage
.TokenValue
2039 # Check whether the token value exist or not.
2041 if Pcd
.TokenValue
== None or Pcd
.TokenValue
== "":
2045 "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid
, PcdCName
, str(Package
)),
2046 File
=self
.MetaFile
, Line
=LineNo
,
2050 # Check hexadecimal token value length and format.
2052 if Pcd
.TokenValue
.startswith("0x") or Pcd
.TokenValue
.startswith("0X"):
2053 if len(Pcd
.TokenValue
) < 3 or len(Pcd
.TokenValue
) > 10:
2057 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2058 File
=self
.MetaFile
, Line
=LineNo
,
2062 int (Pcd
.TokenValue
, 16)
2067 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2068 File
=self
.MetaFile
, Line
=LineNo
,
2073 # Check decimal token value length and format.
2077 TokenValueInt
= int (Pcd
.TokenValue
, 10)
2078 if (TokenValueInt
< 0 or TokenValueInt
> 4294967295):
2082 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!"% (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2083 File
=self
.MetaFile
, Line
=LineNo
,
2090 "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!"% (Pcd
.TokenValue
, TokenSpaceGuid
, PcdCName
, str(Package
)),
2091 File
=self
.MetaFile
, Line
=LineNo
,
2095 Pcd
.DatumType
= PcdInPackage
.DatumType
2096 Pcd
.MaxDatumSize
= PcdInPackage
.MaxDatumSize
2097 Pcd
.InfDefaultValue
= Pcd
.DefaultValue
2098 if Pcd
.DefaultValue
in [None, '']:
2099 Pcd
.DefaultValue
= PcdInPackage
.DefaultValue
2105 "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid
, PcdCName
, self
.MetaFile
),
2106 File
=self
.MetaFile
, Line
=LineNo
,
2107 ExtraData
="\t%s" % '\n\t'.join([str(P
) for P
in self
.Packages
])
2109 Pcds
[PcdCName
, TokenSpaceGuid
] = Pcd
2113 Arch
= property(_GetArch
, _SetArch
)
2114 Platform
= property(_GetPlatform
, _SetPlatform
)
2116 AutoGenVersion
= property(_GetInfVersion
)
2117 BaseName
= property(_GetBaseName
)
2118 ModuleType
= property(_GetModuleType
)
2119 ComponentType
= property(_GetComponentType
)
2120 BuildType
= property(_GetBuildType
)
2121 Guid
= property(_GetFileGuid
)
2122 Version
= property(_GetVersion
)
2123 PcdIsDriver
= property(_GetPcdIsDriver
)
2124 Shadow
= property(_GetShadow
)
2125 CustomMakefile
= property(_GetMakefile
)
2126 Specification
= property(_GetSpec
)
2127 LibraryClass
= property(_GetLibraryClass
)
2128 ModuleEntryPointList
= property(_GetEntryPoint
)
2129 ModuleUnloadImageList
= property(_GetUnloadImage
)
2130 ConstructorList
= property(_GetConstructor
)
2131 DestructorList
= property(_GetDestructor
)
2132 Defines
= property(_GetDefines
)
2134 Binaries
= property(_GetBinaryFiles
)
2135 Sources
= property(_GetSourceFiles
)
2136 LibraryClasses
= property(_GetLibraryClassUses
)
2137 Libraries
= property(_GetLibraryNames
)
2138 Protocols
= property(_GetProtocols
)
2139 Ppis
= property(_GetPpis
)
2140 Guids
= property(_GetGuids
)
2141 Includes
= property(_GetIncludes
)
2142 Packages
= property(_GetPackages
)
2143 Pcds
= property(_GetPcds
)
2144 BuildOptions
= property(_GetBuildOptions
)
2145 Depex
= property(_GetDepex
)
2146 DepexExpression
= property(_GetDepexExpression
)
2150 # This class defined the build database for all modules, packages and platform.
2151 # It will call corresponding parser for the given file if it cannot find it in
2154 # @param DbPath Path of database file
2155 # @param GlobalMacros Global macros used for replacement during file parsing
2156 # @prarm RenewDb=False Create new database file if it's already there
2158 class WorkspaceDatabase(object):
2161 MODEL_FILE_INF
: InfParser
,
2162 MODEL_FILE_DEC
: DecParser
,
2163 MODEL_FILE_DSC
: DscParser
,
2164 MODEL_FILE_FDF
: None, #FdfParser,
2165 MODEL_FILE_CIF
: None
2170 MODEL_FILE_INF
: ModuleTable
,
2171 MODEL_FILE_DEC
: PackageTable
,
2172 MODEL_FILE_DSC
: PlatformTable
,
2175 # default database file path
2176 _DB_PATH_
= "Conf/.cache/build.db"
2179 # internal class used for call corresponding file parser and caching the result
2180 # to avoid unnecessary re-parsing
2182 class BuildObjectFactory(object):
2184 ".inf" : MODEL_FILE_INF
,
2185 ".dec" : MODEL_FILE_DEC
,
2186 ".dsc" : MODEL_FILE_DSC
,
2187 ".fdf" : MODEL_FILE_FDF
,
2190 # convert to xxxBuildData object
2192 MODEL_FILE_INF
: InfBuildData
,
2193 MODEL_FILE_DEC
: DecBuildData
,
2194 MODEL_FILE_DSC
: DscBuildData
,
2195 MODEL_FILE_FDF
: None #FlashDefTable,
2198 _CACHE_
= {} # (FilePath, Arch) : <object>
2201 def __init__(self
, WorkspaceDb
):
2202 self
.WorkspaceDb
= WorkspaceDb
2204 # key = (FilePath, Arch='COMMON')
2205 def __contains__(self
, Key
):
2210 return (FilePath
, Arch
) in self
._CACHE
_
2212 # key = (FilePath, Arch='COMMON')
2213 def __getitem__(self
, Key
):
2222 # if it's generated before, just return the cached one
2223 Key
= (FilePath
, Arch
)
2224 if Key
in self
._CACHE
_:
2225 return self
._CACHE
_[Key
]
2228 Ext
= FilePath
.Ext
.lower()
2229 if Ext
not in self
._FILE
_TYPE
_:
2231 FileType
= self
._FILE
_TYPE
_[Ext
]
2232 if FileType
not in self
._GENERATOR
_:
2235 # get table for current file
2236 MetaFile
= self
.WorkspaceDb
[FilePath
, FileType
, self
.WorkspaceDb
._GlobalMacros
]
2237 BuildObject
= self
._GENERATOR
_[FileType
](
2243 self
.WorkspaceDb
._GlobalMacros
,
2245 self
._CACHE
_[Key
] = BuildObject
2248 # placeholder for file format conversion
2249 class TransformObjectFactory
:
2250 def __init__(self
, WorkspaceDb
):
2251 self
.WorkspaceDb
= WorkspaceDb
2253 # key = FilePath, Arch
2254 def __getitem__(self
, Key
):
2257 ## Constructor of WorkspaceDatabase
2259 # @param DbPath Path of database file
2260 # @param GlobalMacros Global macros used for replacement during file parsing
2261 # @prarm RenewDb=False Create new database file if it's already there
2263 def __init__(self
, DbPath
, GlobalMacros
={}, RenewDb
=False):
2264 self
._GlobalMacros
= GlobalMacros
2266 if DbPath
== None or DbPath
== '':
2267 DbPath
= os
.path
.normpath(os
.path
.join(GlobalData
.gWorkspace
, self
._DB
_PATH
_))
2269 # don't create necessary path for db in memory
2270 if DbPath
!= ':memory:':
2271 DbDir
= os
.path
.split(DbPath
)[0]
2272 if not os
.path
.exists(DbDir
):
2275 # remove db file in case inconsistency between db and file in file system
2276 if self
._CheckWhetherDbNeedRenew
(RenewDb
, DbPath
):
2279 # create db with optimized parameters
2280 self
.Conn
= sqlite3
.connect(DbPath
, isolation_level
='DEFERRED')
2281 self
.Conn
.execute("PRAGMA synchronous=OFF")
2282 self
.Conn
.execute("PRAGMA temp_store=MEMORY")
2283 self
.Conn
.execute("PRAGMA count_changes=OFF")
2284 self
.Conn
.execute("PRAGMA cache_size=8192")
2285 #self.Conn.execute("PRAGMA page_size=8192")
2287 # to avoid non-ascii character conversion issue
2288 self
.Conn
.text_factory
= str
2289 self
.Cur
= self
.Conn
.cursor()
2291 # create table for internal uses
2292 self
.TblDataModel
= TableDataModel(self
.Cur
)
2293 self
.TblFile
= TableFile(self
.Cur
)
2295 # conversion object for build or file format conversion purpose
2296 self
.BuildObject
= WorkspaceDatabase
.BuildObjectFactory(self
)
2297 self
.TransformObject
= WorkspaceDatabase
.TransformObjectFactory(self
)
2299 ## Check whether workspace database need to be renew.
2300 # The renew reason maybe:
2301 # 1) If user force to renew;
2302 # 2) If user do not force renew, and
2303 # a) If the time of last modified python source is newer than database file;
2304 # b) If the time of last modified frozen executable file is newer than database file;
2306 # @param force User force renew database
2307 # @param DbPath The absolute path of workspace database file
2309 # @return Bool value for whether need renew workspace databse
2311 def _CheckWhetherDbNeedRenew (self
, force
, DbPath
):
2312 DbDir
= os
.path
.split(DbPath
)[0]
2313 MacroFilePath
= os
.path
.normpath(os
.path
.join(DbDir
, "build.mac"))
2315 if os
.path
.exists(MacroFilePath
) and os
.path
.isfile(MacroFilePath
):
2318 f
= open(MacroFilePath
,'r')
2319 LastMacros
= pickle
.load(f
)
2326 if LastMacros
!= None and type(LastMacros
) is DictType
:
2327 if LastMacros
== self
._GlobalMacros
:
2329 for Macro
in LastMacros
.keys():
2330 if not (Macro
in self
._GlobalMacros
and LastMacros
[Macro
] == self
._GlobalMacros
[Macro
]):
2335 # save command line macros to file
2337 f
= open(MacroFilePath
,'w')
2338 pickle
.dump(self
._GlobalMacros
, f
, 2)
2347 # if database does not exist, we need do nothing
2348 if not os
.path
.exists(DbPath
): return False
2350 # if user force to renew database, then not check whether database is out of date
2351 if force
: return True
2354 # Check the time of last modified source file or build.exe
2355 # if is newer than time of database, then database need to be re-created.
2357 timeOfToolModified
= 0
2358 if hasattr(sys
, "frozen"):
2359 exePath
= os
.path
.abspath(sys
.executable
)
2360 timeOfToolModified
= os
.stat(exePath
).st_mtime
2362 curPath
= os
.path
.dirname(__file__
) # curPath is the path of WorkspaceDatabase.py
2363 rootPath
= os
.path
.split(curPath
)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python
2364 if rootPath
== "" or rootPath
== None:
2365 EdkLogger
.verbose("\nFail to find the root path of build.exe or python sources, so can not \
2366 determine whether database file is out of date!\n")
2368 # walk the root path of source or build's binary to get the time last modified.
2370 for root
, dirs
, files
in os
.walk (rootPath
):
2372 # bypass source control folder
2373 if dir.lower() in [".svn", "_svn", "cvs"]:
2377 ext
= os
.path
.splitext(file)[1]
2378 if ext
.lower() == ".py": # only check .py files
2379 fd
= os
.stat(os
.path
.join(root
, file))
2380 if timeOfToolModified
< fd
.st_mtime
:
2381 timeOfToolModified
= fd
.st_mtime
2382 if timeOfToolModified
> os
.stat(DbPath
).st_mtime
:
2383 EdkLogger
.verbose("\nWorkspace database is out of data!")
2388 ## Initialize build database
2389 def InitDatabase(self
):
2390 EdkLogger
.verbose("\nInitialize build database started ...")
2395 self
.TblDataModel
.Create(False)
2396 self
.TblFile
.Create(False)
2399 # Initialize table DataModel
2401 self
.TblDataModel
.InitTable()
2402 EdkLogger
.verbose("Initialize build database ... DONE!")
2406 # @param Table: The instance of the table to be queried
2408 def QueryTable(self
, Table
):
2411 ## Close entire database
2414 # Close the connection and cursor
2421 ## Get unique file ID for the gvien file
2422 def GetFileId(self
, FilePath
):
2423 return self
.TblFile
.GetFileId(FilePath
)
2425 ## Get file type value for the gvien file ID
2426 def GetFileType(self
, FileId
):
2427 return self
.TblFile
.GetFileType(FileId
)
2429 ## Get time stamp stored in file table
2430 def GetTimeStamp(self
, FileId
):
2431 return self
.TblFile
.GetFileTimeStamp(FileId
)
2433 ## Update time stamp in file table
2434 def SetTimeStamp(self
, FileId
, TimeStamp
):
2435 return self
.TblFile
.SetFileTimeStamp(FileId
, TimeStamp
)
2437 ## Check if a table integrity flag exists or not
2438 def CheckIntegrity(self
, TableName
):
2440 Result
= self
.Cur
.execute("select min(ID) from %s" % (TableName
)).fetchall()
2441 if Result
[0][0] != -1:
2444 # Check whether the meta data file has external dependency by comparing the time stamp
2446 Sql
= "select Value1, Value2 from %s where Model=%d" % (TableName
, MODEL_EXTERNAL_DEPENDENCY
)
2447 for Dependency
in self
.Cur
.execute(Sql
).fetchall():
2448 if str(os
.stat(Dependency
[0])[8]) != Dependency
[1]:
2454 ## Compose table name for given file type and file ID
2455 def GetTableName(self
, FileType
, FileId
):
2456 return "_%s_%s" % (FileType
, FileId
)
2458 ## Return a temp table containing all content of the given file
2460 # @param FileInfo The tuple containing path and type of a file
2462 def __getitem__(self
, FileInfo
):
2463 FilePath
, FileType
, Macros
= FileInfo
2464 if FileType
not in self
._FILE
_TABLE
_:
2467 # flag used to indicate if it's parsed or not
2468 FilePath
= str(FilePath
)
2470 FileId
= self
.GetFileId(FilePath
)
2472 TimeStamp
= os
.stat(FilePath
)[8]
2473 TableName
= self
.GetTableName(FileType
, FileId
)
2474 if TimeStamp
!= self
.GetTimeStamp(FileId
):
2475 # update the timestamp in database
2476 self
.SetTimeStamp(FileId
, TimeStamp
)
2478 # if the table exists and is integrity, don't parse it
2479 Parsed
= self
.CheckIntegrity(TableName
)
2481 FileId
= self
.TblFile
.InsertFile(FilePath
, FileType
)
2482 TableName
= self
.GetTableName(FileType
, FileId
)
2484 FileTable
= self
._FILE
_TABLE
_[FileType
](self
.Cur
, TableName
, FileId
)
2485 FileTable
.Create(not Parsed
)
2486 Parser
= self
._FILE
_PARSER
_[FileType
](FilePath
, FileType
, FileTable
, Macros
)
2487 # set the "Finished" flag in parser in order to avoid re-parsing (if parsed)
2488 Parser
.Finished
= Parsed
2491 ## Summarize all packages in the database
2492 def _GetPackageList(self
):
2494 for Module
in self
.ModuleList
:
2495 for Package
in Module
.Packages
:
2496 if Package
not in PackageList
:
2497 PackageList
.append(Package
)
2500 ## Summarize all platforms in the database
2501 def _GetPlatformList(self
):
2503 for PlatformFile
in self
.TblFile
.GetFileList(MODEL_FILE_DSC
):
2505 Platform
= self
.BuildObject
[PathClass(PlatformFile
), 'COMMON']
2508 if Platform
!= None:
2509 PlatformList
.append(Platform
)
2512 ## Summarize all modules in the database
2513 def _GetModuleList(self
):
2515 for ModuleFile
in self
.TblFile
.GetFileList(MODEL_FILE_INF
):
2517 Module
= self
.BuildObject
[PathClass(ModuleFile
), 'COMMON']
2521 ModuleList
.append(Module
)
2524 PlatformList
= property(_GetPlatformList
)
2525 PackageList
= property(_GetPackageList
)
2526 ModuleList
= property(_GetModuleList
)
2530 # This acts like the main() function for the script, unless it is 'import'ed into another
2533 if __name__
== '__main__':