]>
Commit | Line | Data |
---|---|---|
e8449e1d FB |
1 | ## @file\r |
2 | # Create makefile for MS nmake and GNU make\r | |
3 | #\r | |
4 | # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | #\r | |
7 | from __future__ import absolute_import\r | |
8 | from AutoGen.AutoGen import AutoGen\r | |
fc8b8dea | 9 | from Common.LongFilePathSupport import LongFilePath, CopyLongFilePath\r |
e8449e1d FB |
10 | from Common.BuildToolError import *\r |
11 | from Common.DataType import *\r | |
12 | from Common.Misc import *\r | |
13 | from Common.StringUtils import NormPath,GetSplitList\r | |
14 | from collections import defaultdict\r | |
15 | from Workspace.WorkspaceCommon import OrderedListDict\r | |
16 | import os.path as path\r | |
17 | import copy\r | |
18 | import hashlib\r | |
19 | from . import InfSectionParser\r | |
20 | from . import GenC\r | |
21 | from . import GenMake\r | |
22 | from . import GenDepex\r | |
23 | from io import BytesIO\r | |
24 | from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r | |
25 | from Workspace.MetaFileCommentParser import UsageList\r | |
26 | from .GenPcdDb import CreatePcdDatabaseCode\r | |
27 | from Common.caching import cached_class_function\r | |
28 | from AutoGen.ModuleAutoGenHelper import PlatformInfo,WorkSpaceInfo\r | |
0e7e7a26 | 29 | import json\r |
94459080 | 30 | import tempfile\r |
e8449e1d FB |
31 | \r |
32 | ## Mapping Makefile type\r | |
33 | gMakeTypeMap = {TAB_COMPILER_MSFT:"nmake", "GCC":"gmake"}\r | |
34 | #\r | |
708620d2 | 35 | # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC\r |
e8449e1d FB |
36 | # is the former use /I , the Latter used -I to specify include directories\r |
37 | #\r | |
38 | gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r | |
39 | gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r | |
40 | \r | |
41 | ## default file name for AutoGen\r | |
42 | gAutoGenCodeFileName = "AutoGen.c"\r | |
43 | gAutoGenHeaderFileName = "AutoGen.h"\r | |
44 | gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r | |
45 | gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r | |
46 | gAutoGenDepexFileName = "%(module_name)s.depex"\r | |
47 | gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r | |
48 | gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r | |
49 | gInfSpecVersion = "0x00010017"\r | |
50 | \r | |
51 | #\r | |
52 | # Match name = variable\r | |
53 | #\r | |
54 | gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")\r | |
55 | #\r | |
56 | # The format of guid in efivarstore statement likes following and must be correct:\r | |
57 | # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}\r | |
58 | #\r | |
59 | gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r | |
60 | \r | |
61 | #\r | |
62 | # Template string to generic AsBuilt INF\r | |
63 | #\r | |
64 | gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r | |
65 | \r | |
66 | # DO NOT EDIT\r | |
67 | # FILE auto-generated\r | |
68 | \r | |
69 | [Defines]\r | |
70 | INF_VERSION = ${module_inf_version}\r | |
71 | BASE_NAME = ${module_name}\r | |
72 | FILE_GUID = ${module_guid}\r | |
73 | MODULE_TYPE = ${module_module_type}${BEGIN}\r | |
74 | VERSION_STRING = ${module_version_string}${END}${BEGIN}\r | |
75 | PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}\r | |
76 | UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r | |
77 | PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}\r | |
78 | ENTRY_POINT = ${module_entry_point}${END}${BEGIN}\r | |
79 | UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}\r | |
80 | CONSTRUCTOR = ${module_constructor}${END}${BEGIN}\r | |
81 | DESTRUCTOR = ${module_destructor}${END}${BEGIN}\r | |
82 | SHADOW = ${module_shadow}${END}${BEGIN}\r | |
83 | PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}\r | |
84 | PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}\r | |
85 | PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}\r | |
86 | PCI_REVISION = ${module_pci_revision}${END}${BEGIN}\r | |
87 | BUILD_NUMBER = ${module_build_number}${END}${BEGIN}\r | |
88 | SPEC = ${module_spec}${END}${BEGIN}\r | |
89 | UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}\r | |
90 | MODULE_UNI_FILE = ${module_uni_file}${END}\r | |
91 | \r | |
92 | [Packages.${module_arch}]${BEGIN}\r | |
93 | ${package_item}${END}\r | |
94 | \r | |
95 | [Binaries.${module_arch}]${BEGIN}\r | |
96 | ${binary_item}${END}\r | |
97 | \r | |
98 | [PatchPcd.${module_arch}]${BEGIN}\r | |
99 | ${patchablepcd_item}\r | |
100 | ${END}\r | |
101 | \r | |
102 | [Protocols.${module_arch}]${BEGIN}\r | |
103 | ${protocol_item}\r | |
104 | ${END}\r | |
105 | \r | |
106 | [Ppis.${module_arch}]${BEGIN}\r | |
107 | ${ppi_item}\r | |
108 | ${END}\r | |
109 | \r | |
110 | [Guids.${module_arch}]${BEGIN}\r | |
111 | ${guid_item}\r | |
112 | ${END}\r | |
113 | \r | |
114 | [PcdEx.${module_arch}]${BEGIN}\r | |
115 | ${pcd_item}\r | |
116 | ${END}\r | |
117 | \r | |
118 | [LibraryClasses.${module_arch}]\r | |
119 | ## @LIB_INSTANCES${BEGIN}\r | |
120 | # ${libraryclasses_item}${END}\r | |
121 | \r | |
122 | ${depexsection_item}\r | |
123 | \r | |
124 | ${userextension_tianocore_item}\r | |
125 | \r | |
126 | ${tail_comments}\r | |
127 | \r | |
128 | [BuildOptions.${module_arch}]\r | |
129 | ## @AsBuilt${BEGIN}\r | |
130 | ## ${flags_item}${END}\r | |
131 | """)\r | |
132 | #\r | |
133 | # extend lists contained in a dictionary with lists stored in another dictionary\r | |
134 | # if CopyToDict is not derived from DefaultDict(list) then this may raise exception\r | |
135 | #\r | |
136 | def ExtendCopyDictionaryLists(CopyToDict, CopyFromDict):\r | |
137 | for Key in CopyFromDict:\r | |
138 | CopyToDict[Key].extend(CopyFromDict[Key])\r | |
139 | \r | |
140 | # Create a directory specified by a set of path elements and return the full path\r | |
141 | def _MakeDir(PathList):\r | |
142 | RetVal = path.join(*PathList)\r | |
143 | CreateDirectory(RetVal)\r | |
144 | return RetVal\r | |
145 | \r | |
146 | #\r | |
147 | # Convert string to C format array\r | |
148 | #\r | |
149 | def _ConvertStringToByteArray(Value):\r | |
150 | Value = Value.strip()\r | |
151 | if not Value:\r | |
152 | return None\r | |
153 | if Value[0] == '{':\r | |
154 | if not Value.endswith('}'):\r | |
155 | return None\r | |
156 | Value = Value.replace(' ', '').replace('{', '').replace('}', '')\r | |
157 | ValFields = Value.split(',')\r | |
158 | try:\r | |
159 | for Index in range(len(ValFields)):\r | |
160 | ValFields[Index] = str(int(ValFields[Index], 0))\r | |
161 | except ValueError:\r | |
162 | return None\r | |
163 | Value = '{' + ','.join(ValFields) + '}'\r | |
164 | return Value\r | |
165 | \r | |
166 | Unicode = False\r | |
167 | if Value.startswith('L"'):\r | |
168 | if not Value.endswith('"'):\r | |
169 | return None\r | |
170 | Value = Value[1:]\r | |
171 | Unicode = True\r | |
172 | elif not Value.startswith('"') or not Value.endswith('"'):\r | |
173 | return None\r | |
174 | \r | |
175 | Value = eval(Value) # translate escape character\r | |
176 | NewValue = '{'\r | |
177 | for Index in range(0, len(Value)):\r | |
178 | if Unicode:\r | |
179 | NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ','\r | |
180 | else:\r | |
181 | NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ','\r | |
182 | Value = NewValue + '0}'\r | |
183 | return Value\r | |
184 | \r | |
185 | ## ModuleAutoGen class\r | |
186 | #\r | |
187 | # This class encapsules the AutoGen behaviors for the build tools. In addition to\r | |
188 | # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r | |
189 | # to the [depex] section in module's inf file.\r | |
190 | #\r | |
191 | class ModuleAutoGen(AutoGen):\r | |
192 | # call super().__init__ then call the worker function with different parameter count\r | |
193 | def __init__(self, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r | |
194 | if not hasattr(self, "_Init"):\r | |
195 | self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args)\r | |
196 | self._Init = True\r | |
197 | \r | |
198 | ## Cache the timestamps of metafiles of every module in a class attribute\r | |
199 | #\r | |
200 | TimeDict = {}\r | |
201 | \r | |
202 | def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r | |
203 | # check if this module is employed by active platform\r | |
204 | if not PlatformInfo(Workspace, args[0], Target, Toolchain, Arch,args[-1]).ValidModule(MetaFile):\r | |
205 | EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r | |
206 | % (MetaFile, Arch))\r | |
207 | return None\r | |
208 | return super(ModuleAutoGen, cls).__new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r | |
209 | \r | |
210 | ## Initialize ModuleAutoGen\r | |
211 | #\r | |
212 | # @param Workspace EdkIIWorkspaceBuild object\r | |
213 | # @param ModuleFile The path of module file\r | |
214 | # @param Target Build target (DEBUG, RELEASE)\r | |
215 | # @param Toolchain Name of tool chain\r | |
216 | # @param Arch The arch the module supports\r | |
217 | # @param PlatformFile Platform meta-file\r | |
218 | #\r | |
219 | def _InitWorker(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile,DataPipe):\r | |
220 | EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r | |
221 | GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r | |
222 | \r | |
a000d5d1 | 223 | self.Workspace = Workspace\r |
e8449e1d FB |
224 | self.WorkspaceDir = ""\r |
225 | self.PlatformInfo = None\r | |
226 | self.DataPipe = DataPipe\r | |
227 | self.__init_platform_info__()\r | |
228 | self.MetaFile = ModuleFile\r | |
229 | self.SourceDir = self.MetaFile.SubDir\r | |
230 | self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r | |
231 | \r | |
232 | self.ToolChain = Toolchain\r | |
233 | self.BuildTarget = Target\r | |
234 | self.Arch = Arch\r | |
235 | self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r | |
236 | self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r | |
237 | \r | |
238 | self.IsCodeFileCreated = False\r | |
239 | self.IsAsBuiltInfCreated = False\r | |
240 | self.DepexGenerated = False\r | |
241 | \r | |
242 | self.BuildDatabase = self.Workspace.BuildDatabase\r | |
243 | self.BuildRuleOrder = None\r | |
244 | self.BuildTime = 0\r | |
245 | \r | |
246 | self._GuidComments = OrderedListDict()\r | |
247 | self._ProtocolComments = OrderedListDict()\r | |
248 | self._PpiComments = OrderedListDict()\r | |
249 | self._BuildTargets = None\r | |
250 | self._IntroBuildTargetList = None\r | |
251 | self._FinalBuildTargetList = None\r | |
252 | self._FileTypes = None\r | |
253 | \r | |
254 | self.AutoGenDepSet = set()\r | |
255 | self.ReferenceModules = []\r | |
256 | self.ConstPcd = {}\r | |
0e7e7a26 | 257 | self.FileDependCache = {}\r |
e8449e1d FB |
258 | \r |
259 | def __init_platform_info__(self):\r | |
260 | pinfo = self.DataPipe.Get("P_Info")\r | |
e8449e1d FB |
261 | self.WorkspaceDir = pinfo.get("WorkspaceDir")\r |
262 | self.PlatformInfo = PlatformInfo(self.Workspace,pinfo.get("ActivePlatform"),pinfo.get("Target"),pinfo.get("ToolChain"),pinfo.get("Arch"),self.DataPipe)\r | |
263 | ## hash() operator of ModuleAutoGen\r | |
264 | #\r | |
265 | # The module file path and arch string will be used to represent\r | |
266 | # hash value of this object\r | |
267 | #\r | |
268 | # @retval int Hash value of the module file path and arch\r | |
269 | #\r | |
270 | @cached_class_function\r | |
271 | def __hash__(self):\r | |
78fb6b0e | 272 | return hash((self.MetaFile, self.Arch, self.ToolChain,self.BuildTarget))\r |
e8449e1d FB |
273 | def __repr__(self):\r |
274 | return "%s [%s]" % (self.MetaFile, self.Arch)\r | |
275 | \r | |
276 | # Get FixedAtBuild Pcds of this Module\r | |
277 | @cached_property\r | |
278 | def FixedAtBuildPcds(self):\r | |
279 | RetVal = []\r | |
280 | for Pcd in self.ModulePcdList:\r | |
281 | if Pcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r | |
282 | continue\r | |
283 | if Pcd not in RetVal:\r | |
284 | RetVal.append(Pcd)\r | |
285 | return RetVal\r | |
286 | \r | |
287 | @cached_property\r | |
288 | def FixedVoidTypePcds(self):\r | |
289 | RetVal = {}\r | |
290 | for Pcd in self.FixedAtBuildPcds:\r | |
291 | if Pcd.DatumType == TAB_VOID:\r | |
292 | if '.'.join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName)) not in RetVal:\r | |
293 | RetVal['.'.join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))] = Pcd.DefaultValue\r | |
294 | return RetVal\r | |
295 | \r | |
296 | @property\r | |
297 | def UniqueBaseName(self):\r | |
298 | ModuleNames = self.DataPipe.Get("M_Name")\r | |
299 | if not ModuleNames:\r | |
300 | return self.Name\r | |
76e12fa3 | 301 | return ModuleNames.get((self.Name,self.MetaFile),self.Name)\r |
e8449e1d FB |
302 | \r |
303 | # Macros could be used in build_rule.txt (also Makefile)\r | |
304 | @cached_property\r | |
305 | def Macros(self):\r | |
306 | return OrderedDict((\r | |
307 | ("WORKSPACE" ,self.WorkspaceDir),\r | |
308 | ("MODULE_NAME" ,self.Name),\r | |
309 | ("MODULE_NAME_GUID" ,self.UniqueBaseName),\r | |
310 | ("MODULE_GUID" ,self.Guid),\r | |
311 | ("MODULE_VERSION" ,self.Version),\r | |
312 | ("MODULE_TYPE" ,self.ModuleType),\r | |
313 | ("MODULE_FILE" ,str(self.MetaFile)),\r | |
314 | ("MODULE_FILE_BASE_NAME" ,self.MetaFile.BaseName),\r | |
315 | ("MODULE_RELATIVE_DIR" ,self.SourceDir),\r | |
316 | ("MODULE_DIR" ,self.SourceDir),\r | |
317 | ("BASE_NAME" ,self.Name),\r | |
318 | ("ARCH" ,self.Arch),\r | |
319 | ("TOOLCHAIN" ,self.ToolChain),\r | |
320 | ("TOOLCHAIN_TAG" ,self.ToolChain),\r | |
321 | ("TOOL_CHAIN_TAG" ,self.ToolChain),\r | |
322 | ("TARGET" ,self.BuildTarget),\r | |
323 | ("BUILD_DIR" ,self.PlatformInfo.BuildDir),\r | |
324 | ("BIN_DIR" ,os.path.join(self.PlatformInfo.BuildDir, self.Arch)),\r | |
325 | ("LIB_DIR" ,os.path.join(self.PlatformInfo.BuildDir, self.Arch)),\r | |
326 | ("MODULE_BUILD_DIR" ,self.BuildDir),\r | |
327 | ("OUTPUT_DIR" ,self.OutputDir),\r | |
328 | ("DEBUG_DIR" ,self.DebugDir),\r | |
329 | ("DEST_DIR_OUTPUT" ,self.OutputDir),\r | |
330 | ("DEST_DIR_DEBUG" ,self.DebugDir),\r | |
331 | ("PLATFORM_NAME" ,self.PlatformInfo.Name),\r | |
332 | ("PLATFORM_GUID" ,self.PlatformInfo.Guid),\r | |
333 | ("PLATFORM_VERSION" ,self.PlatformInfo.Version),\r | |
334 | ("PLATFORM_RELATIVE_DIR" ,self.PlatformInfo.SourceDir),\r | |
335 | ("PLATFORM_DIR" ,mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)),\r | |
336 | ("PLATFORM_OUTPUT_DIR" ,self.PlatformInfo.OutputDir),\r | |
337 | ("FFS_OUTPUT_DIR" ,self.FfsOutputDir)\r | |
338 | ))\r | |
339 | \r | |
340 | ## Return the module build data object\r | |
341 | @cached_property\r | |
342 | def Module(self):\r | |
343 | return self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r | |
344 | \r | |
345 | ## Return the module name\r | |
346 | @cached_property\r | |
347 | def Name(self):\r | |
348 | return self.Module.BaseName\r | |
349 | \r | |
350 | ## Return the module DxsFile if exist\r | |
351 | @cached_property\r | |
352 | def DxsFile(self):\r | |
353 | return self.Module.DxsFile\r | |
354 | \r | |
355 | ## Return the module meta-file GUID\r | |
356 | @cached_property\r | |
357 | def Guid(self):\r | |
358 | #\r | |
359 | # To build same module more than once, the module path with FILE_GUID overridden has\r | |
360 | # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the real path\r | |
361 | # in DSC. The overridden GUID can be retrieved from file name\r | |
362 | #\r | |
363 | if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r | |
364 | #\r | |
365 | # Length of GUID is 36\r | |
366 | #\r | |
367 | return os.path.basename(self.MetaFile.Path)[:36]\r | |
368 | return self.Module.Guid\r | |
369 | \r | |
370 | ## Return the module version\r | |
371 | @cached_property\r | |
372 | def Version(self):\r | |
373 | return self.Module.Version\r | |
374 | \r | |
375 | ## Return the module type\r | |
376 | @cached_property\r | |
377 | def ModuleType(self):\r | |
378 | return self.Module.ModuleType\r | |
379 | \r | |
380 | ## Return the component type (for Edk.x style of module)\r | |
381 | @cached_property\r | |
382 | def ComponentType(self):\r | |
383 | return self.Module.ComponentType\r | |
384 | \r | |
385 | ## Return the build type\r | |
386 | @cached_property\r | |
387 | def BuildType(self):\r | |
388 | return self.Module.BuildType\r | |
389 | \r | |
390 | ## Return the PCD_IS_DRIVER setting\r | |
391 | @cached_property\r | |
392 | def PcdIsDriver(self):\r | |
393 | return self.Module.PcdIsDriver\r | |
394 | \r | |
395 | ## Return the autogen version, i.e. module meta-file version\r | |
396 | @cached_property\r | |
397 | def AutoGenVersion(self):\r | |
398 | return self.Module.AutoGenVersion\r | |
399 | \r | |
400 | ## Check if the module is library or not\r | |
401 | @cached_property\r | |
402 | def IsLibrary(self):\r | |
403 | return bool(self.Module.LibraryClass)\r | |
404 | \r | |
405 | ## Check if the module is binary module or not\r | |
406 | @cached_property\r | |
407 | def IsBinaryModule(self):\r | |
408 | return self.Module.IsBinaryModule\r | |
409 | \r | |
410 | ## Return the directory to store intermediate files of the module\r | |
411 | @cached_property\r | |
412 | def BuildDir(self):\r | |
413 | return _MakeDir((\r | |
414 | self.PlatformInfo.BuildDir,\r | |
415 | self.Arch,\r | |
416 | self.SourceDir,\r | |
417 | self.MetaFile.BaseName\r | |
418 | ))\r | |
419 | \r | |
420 | ## Return the directory to store the intermediate object files of the module\r | |
421 | @cached_property\r | |
422 | def OutputDir(self):\r | |
423 | return _MakeDir((self.BuildDir, "OUTPUT"))\r | |
424 | \r | |
425 | ## Return the directory path to store ffs file\r | |
426 | @cached_property\r | |
427 | def FfsOutputDir(self):\r | |
428 | if GlobalData.gFdfParser:\r | |
429 | return path.join(self.PlatformInfo.BuildDir, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name)\r | |
430 | return ''\r | |
431 | \r | |
432 | ## Return the directory to store auto-gened source files of the module\r | |
433 | @cached_property\r | |
434 | def DebugDir(self):\r | |
435 | return _MakeDir((self.BuildDir, "DEBUG"))\r | |
436 | \r | |
437 | ## Return the path of custom file\r | |
438 | @cached_property\r | |
439 | def CustomMakefile(self):\r | |
440 | RetVal = {}\r | |
441 | for Type in self.Module.CustomMakefile:\r | |
442 | MakeType = gMakeTypeMap[Type] if Type in gMakeTypeMap else 'nmake'\r | |
443 | File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r | |
444 | RetVal[MakeType] = File\r | |
445 | return RetVal\r | |
446 | \r | |
447 | ## Return the directory of the makefile\r | |
448 | #\r | |
449 | # @retval string The directory string of module's makefile\r | |
450 | #\r | |
451 | @cached_property\r | |
452 | def MakeFileDir(self):\r | |
453 | return self.BuildDir\r | |
454 | \r | |
455 | ## Return build command string\r | |
456 | #\r | |
457 | # @retval string Build command string\r | |
458 | #\r | |
459 | @cached_property\r | |
460 | def BuildCommand(self):\r | |
461 | return self.PlatformInfo.BuildCommand\r | |
462 | \r | |
bf1ea933 FZ |
463 | ## Get Module package and Platform package\r |
464 | #\r | |
465 | # @retval list The list of package object\r | |
466 | #\r | |
467 | @cached_property\r | |
468 | def PackageList(self):\r | |
469 | PkagList = []\r | |
470 | if self.Module.Packages:\r | |
471 | PkagList.extend(self.Module.Packages)\r | |
472 | Platform = self.BuildDatabase[self.PlatformInfo.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r | |
473 | for Package in Platform.Packages:\r | |
474 | if Package in PkagList:\r | |
475 | continue\r | |
476 | PkagList.append(Package)\r | |
477 | return PkagList\r | |
478 | \r | |
479 | ## Get object list of all packages the module and its dependent libraries belong to and the Platform depends on\r | |
e8449e1d FB |
480 | #\r |
481 | # @retval list The list of package object\r | |
482 | #\r | |
483 | @cached_property\r | |
484 | def DerivedPackageList(self):\r | |
485 | PackageList = []\r | |
bf1ea933 FZ |
486 | PackageList.extend(self.PackageList)\r |
487 | for M in self.DependentLibraryList:\r | |
e8449e1d FB |
488 | for Package in M.Packages:\r |
489 | if Package in PackageList:\r | |
490 | continue\r | |
491 | PackageList.append(Package)\r | |
492 | return PackageList\r | |
493 | \r | |
494 | ## Get the depex string\r | |
495 | #\r | |
496 | # @return : a string contain all depex expression.\r | |
497 | def _GetDepexExpresionString(self):\r | |
498 | DepexStr = ''\r | |
499 | DepexList = []\r | |
500 | ## DPX_SOURCE IN Define section.\r | |
501 | if self.Module.DxsFile:\r | |
502 | return DepexStr\r | |
503 | for M in [self.Module] + self.DependentLibraryList:\r | |
504 | Filename = M.MetaFile.Path\r | |
505 | InfObj = InfSectionParser.InfSectionParser(Filename)\r | |
506 | DepexExpressionList = InfObj.GetDepexExpresionList()\r | |
507 | for DepexExpression in DepexExpressionList:\r | |
508 | for key in DepexExpression:\r | |
509 | Arch, ModuleType = key\r | |
510 | DepexExpr = [x for x in DepexExpression[key] if not str(x).startswith('#')]\r | |
511 | # the type of build module is USER_DEFINED.\r | |
512 | # All different DEPEX section tags would be copied into the As Built INF file\r | |
513 | # and there would be separate DEPEX section tags\r | |
514 | if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED or self.ModuleType.upper() == SUP_MODULE_HOST_APPLICATION:\r | |
515 | if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r | |
516 | DepexList.append({(Arch, ModuleType): DepexExpr})\r | |
517 | else:\r | |
518 | if Arch.upper() == TAB_ARCH_COMMON or \\r | |
519 | (Arch.upper() == self.Arch.upper() and \\r | |
520 | ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r | |
521 | DepexList.append({(Arch, ModuleType): DepexExpr})\r | |
522 | \r | |
523 | #the type of build module is USER_DEFINED.\r | |
524 | if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED or self.ModuleType.upper() == SUP_MODULE_HOST_APPLICATION:\r | |
525 | for Depex in DepexList:\r | |
526 | for key in Depex:\r | |
527 | DepexStr += '[Depex.%s.%s]\n' % key\r | |
528 | DepexStr += '\n'.join('# '+ val for val in Depex[key])\r | |
529 | DepexStr += '\n\n'\r | |
530 | if not DepexStr:\r | |
531 | return '[Depex.%s]\n' % self.Arch\r | |
532 | return DepexStr\r | |
533 | \r | |
534 | #the type of build module not is USER_DEFINED.\r | |
535 | Count = 0\r | |
536 | for Depex in DepexList:\r | |
537 | Count += 1\r | |
538 | if DepexStr != '':\r | |
539 | DepexStr += ' AND '\r | |
540 | DepexStr += '('\r | |
541 | for D in Depex.values():\r | |
542 | DepexStr += ' '.join(val for val in D)\r | |
543 | Index = DepexStr.find('END')\r | |
544 | if Index > -1 and Index == len(DepexStr) - 3:\r | |
545 | DepexStr = DepexStr[:-3]\r | |
546 | DepexStr = DepexStr.strip()\r | |
547 | DepexStr += ')'\r | |
548 | if Count == 1:\r | |
549 | DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r | |
550 | if not DepexStr:\r | |
551 | return '[Depex.%s]\n' % self.Arch\r | |
552 | return '[Depex.%s]\n# ' % self.Arch + DepexStr\r | |
553 | \r | |
554 | ## Merge dependency expression\r | |
555 | #\r | |
556 | # @retval list The token list of the dependency expression after parsed\r | |
557 | #\r | |
558 | @cached_property\r | |
559 | def DepexList(self):\r | |
560 | if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r | |
561 | return {}\r | |
562 | \r | |
563 | DepexList = []\r | |
564 | #\r | |
565 | # Append depex from dependent libraries, if not "BEFORE", "AFTER" expression\r | |
566 | #\r | |
567 | FixedVoidTypePcds = {}\r | |
568 | for M in [self] + self.LibraryAutoGenList:\r | |
569 | FixedVoidTypePcds.update(M.FixedVoidTypePcds)\r | |
570 | for M in [self] + self.LibraryAutoGenList:\r | |
571 | Inherited = False\r | |
572 | for D in M.Module.Depex[self.Arch, self.ModuleType]:\r | |
573 | if DepexList != []:\r | |
574 | DepexList.append('AND')\r | |
575 | DepexList.append('(')\r | |
576 | #replace D with value if D is FixedAtBuild PCD\r | |
577 | NewList = []\r | |
578 | for item in D:\r | |
579 | if '.' not in item:\r | |
580 | NewList.append(item)\r | |
581 | else:\r | |
582 | try:\r | |
583 | Value = FixedVoidTypePcds[item]\r | |
584 | if len(Value.split(',')) != 16:\r | |
585 | EdkLogger.error("build", FORMAT_INVALID,\r | |
586 | "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type and 16 bytes in the module.".format(item))\r | |
587 | NewList.append(Value)\r | |
588 | except:\r | |
589 | EdkLogger.error("build", FORMAT_INVALID, "{} used in [Depex] section should be used as FixedAtBuild type and VOID* datum type in the module.".format(item))\r | |
590 | \r | |
591 | DepexList.extend(NewList)\r | |
592 | if DepexList[-1] == 'END': # no need of a END at this time\r | |
593 | DepexList.pop()\r | |
594 | DepexList.append(')')\r | |
595 | Inherited = True\r | |
596 | if Inherited:\r | |
597 | EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.Module.BaseName, DepexList))\r | |
598 | if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r | |
599 | break\r | |
600 | if len(DepexList) > 0:\r | |
601 | EdkLogger.verbose('')\r | |
602 | return {self.ModuleType:DepexList}\r | |
603 | \r | |
604 | ## Merge dependency expression\r | |
605 | #\r | |
606 | # @retval list The token list of the dependency expression after parsed\r | |
607 | #\r | |
608 | @cached_property\r | |
609 | def DepexExpressionDict(self):\r | |
610 | if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r | |
611 | return {}\r | |
612 | \r | |
613 | DepexExpressionString = ''\r | |
614 | #\r | |
615 | # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r | |
616 | #\r | |
617 | for M in [self.Module] + self.DependentLibraryList:\r | |
618 | Inherited = False\r | |
619 | for D in M.DepexExpression[self.Arch, self.ModuleType]:\r | |
620 | if DepexExpressionString != '':\r | |
621 | DepexExpressionString += ' AND '\r | |
622 | DepexExpressionString += '('\r | |
623 | DepexExpressionString += D\r | |
624 | DepexExpressionString = DepexExpressionString.rstrip('END').strip()\r | |
625 | DepexExpressionString += ')'\r | |
626 | Inherited = True\r | |
627 | if Inherited:\r | |
628 | EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionString))\r | |
629 | if 'BEFORE' in DepexExpressionString or 'AFTER' in DepexExpressionString:\r | |
630 | break\r | |
631 | if len(DepexExpressionString) > 0:\r | |
632 | EdkLogger.verbose('')\r | |
633 | \r | |
634 | return {self.ModuleType:DepexExpressionString}\r | |
635 | \r | |
636 | # Get the tiano core user extension, it is contain dependent library.\r | |
637 | # @retval: a list contain tiano core userextension.\r | |
638 | #\r | |
639 | def _GetTianoCoreUserExtensionList(self):\r | |
640 | TianoCoreUserExtentionList = []\r | |
641 | for M in [self.Module] + self.DependentLibraryList:\r | |
642 | Filename = M.MetaFile.Path\r | |
643 | InfObj = InfSectionParser.InfSectionParser(Filename)\r | |
644 | TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore()\r | |
645 | for TianoCoreUserExtent in TianoCoreUserExtenList:\r | |
646 | for Section in TianoCoreUserExtent:\r | |
647 | ItemList = Section.split(TAB_SPLIT)\r | |
648 | Arch = self.Arch\r | |
649 | if len(ItemList) == 4:\r | |
650 | Arch = ItemList[3]\r | |
651 | if Arch.upper() == TAB_ARCH_COMMON or Arch.upper() == self.Arch.upper():\r | |
652 | TianoCoreList = []\r | |
653 | TianoCoreList.extend([TAB_SECTION_START + Section + TAB_SECTION_END])\r | |
654 | TianoCoreList.extend(TianoCoreUserExtent[Section][:])\r | |
655 | TianoCoreList.append('\n')\r | |
656 | TianoCoreUserExtentionList.append(TianoCoreList)\r | |
657 | \r | |
658 | return TianoCoreUserExtentionList\r | |
659 | \r | |
660 | ## Return the list of specification version required for the module\r | |
661 | #\r | |
662 | # @retval list The list of specification defined in module file\r | |
663 | #\r | |
664 | @cached_property\r | |
665 | def Specification(self):\r | |
666 | return self.Module.Specification\r | |
667 | \r | |
668 | ## Tool option for the module build\r | |
669 | #\r | |
670 | # @param PlatformInfo The object of PlatformBuildInfo\r | |
671 | # @retval dict The dict containing valid options\r | |
672 | #\r | |
673 | @cached_property\r | |
674 | def BuildOption(self):\r | |
675 | RetVal, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)\r | |
676 | if self.BuildRuleOrder:\r | |
677 | self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]\r | |
678 | return RetVal\r | |
679 | \r | |
680 | ## Get include path list from tool option for the module build\r | |
681 | #\r | |
682 | # @retval list The include path list\r | |
683 | #\r | |
684 | @cached_property\r | |
685 | def BuildOptionIncPathList(self):\r | |
686 | #\r | |
708620d2 | 687 | # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC\r |
e8449e1d FB |
688 | # is the former use /I , the Latter used -I to specify include directories\r |
689 | #\r | |
690 | if self.PlatformInfo.ToolChainFamily in (TAB_COMPILER_MSFT):\r | |
691 | BuildOptIncludeRegEx = gBuildOptIncludePatternMsft\r | |
708620d2 | 692 | elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC'):\r |
e8449e1d FB |
693 | BuildOptIncludeRegEx = gBuildOptIncludePatternOther\r |
694 | else:\r | |
695 | #\r | |
696 | # New ToolChainFamily, don't known whether there is option to specify include directories\r | |
697 | #\r | |
698 | return []\r | |
699 | \r | |
700 | RetVal = []\r | |
701 | for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r | |
702 | try:\r | |
703 | FlagOption = self.BuildOption[Tool]['FLAGS']\r | |
704 | except KeyError:\r | |
705 | FlagOption = ''\r | |
706 | \r | |
708620d2 | 707 | IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)]\r |
e8449e1d FB |
708 | \r |
709 | #\r | |
710 | # EDK II modules must not reference header files outside of the packages they depend on or\r | |
711 | # within the module's directory tree. Report error if violation.\r | |
712 | #\r | |
713 | if GlobalData.gDisableIncludePathCheck == False:\r | |
714 | for Path in IncPathList:\r | |
715 | if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r | |
716 | ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r | |
717 | EdkLogger.error("build",\r | |
718 | PARAMETER_INVALID,\r | |
719 | ExtraData=ErrMsg,\r | |
720 | File=str(self.MetaFile))\r | |
721 | RetVal += IncPathList\r | |
722 | return RetVal\r | |
723 | \r | |
724 | ## Return a list of files which can be built from source\r | |
725 | #\r | |
726 | # What kind of files can be built is determined by build rules in\r | |
727 | # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.\r | |
728 | #\r | |
729 | @cached_property\r | |
730 | def SourceFileList(self):\r | |
731 | RetVal = []\r | |
732 | ToolChainTagSet = {"", TAB_STAR, self.ToolChain}\r | |
733 | ToolChainFamilySet = {"", TAB_STAR, self.ToolChainFamily, self.BuildRuleFamily}\r | |
734 | for F in self.Module.Sources:\r | |
735 | # match tool chain\r | |
736 | if F.TagName not in ToolChainTagSet:\r | |
737 | EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "\r | |
738 | "but [%s] is currently used" % (F.TagName, str(F), self.ToolChain))\r | |
739 | continue\r | |
740 | # match tool chain family or build rule family\r | |
741 | if F.ToolChainFamily not in ToolChainFamilySet:\r | |
742 | EdkLogger.debug(\r | |
743 | EdkLogger.DEBUG_0,\r | |
744 | "The file [%s] must be built by tools of [%s], " \\r | |
745 | "but current toolchain family is [%s], buildrule family is [%s]" \\r | |
746 | % (str(F), F.ToolChainFamily, self.ToolChainFamily, self.BuildRuleFamily))\r | |
747 | continue\r | |
748 | \r | |
749 | # add the file path into search path list for file including\r | |
750 | if F.Dir not in self.IncludePathList:\r | |
751 | self.IncludePathList.insert(0, F.Dir)\r | |
752 | RetVal.append(F)\r | |
753 | \r | |
754 | self._MatchBuildRuleOrder(RetVal)\r | |
755 | \r | |
756 | for F in RetVal:\r | |
757 | self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)\r | |
758 | return RetVal\r | |
759 | \r | |
760 | def _MatchBuildRuleOrder(self, FileList):\r | |
761 | Order_Dict = {}\r | |
762 | self.BuildOption\r | |
763 | for SingleFile in FileList:\r | |
764 | if self.BuildRuleOrder and SingleFile.Ext in self.BuildRuleOrder and SingleFile.Ext in self.BuildRules:\r | |
765 | key = SingleFile.Path.rsplit(SingleFile.Ext,1)[0]\r | |
766 | if key in Order_Dict:\r | |
767 | Order_Dict[key].append(SingleFile.Ext)\r | |
768 | else:\r | |
769 | Order_Dict[key] = [SingleFile.Ext]\r | |
770 | \r | |
771 | RemoveList = []\r | |
772 | for F in Order_Dict:\r | |
773 | if len(Order_Dict[F]) > 1:\r | |
774 | Order_Dict[F].sort(key=lambda i: self.BuildRuleOrder.index(i))\r | |
775 | for Ext in Order_Dict[F][1:]:\r | |
776 | RemoveList.append(F + Ext)\r | |
777 | \r | |
778 | for item in RemoveList:\r | |
779 | FileList.remove(item)\r | |
780 | \r | |
781 | return FileList\r | |
782 | \r | |
783 | ## Return the list of unicode files\r | |
784 | @cached_property\r | |
785 | def UnicodeFileList(self):\r | |
786 | return self.FileTypes.get(TAB_UNICODE_FILE,[])\r | |
787 | \r | |
788 | ## Return the list of vfr files\r | |
789 | @cached_property\r | |
790 | def VfrFileList(self):\r | |
791 | return self.FileTypes.get(TAB_VFR_FILE, [])\r | |
792 | \r | |
793 | ## Return the list of Image Definition files\r | |
794 | @cached_property\r | |
795 | def IdfFileList(self):\r | |
796 | return self.FileTypes.get(TAB_IMAGE_FILE,[])\r | |
797 | \r | |
798 | ## Return a list of files which can be built from binary\r | |
799 | #\r | |
800 | # "Build" binary files are just to copy them to build directory.\r | |
801 | #\r | |
802 | # @retval list The list of files which can be built later\r | |
803 | #\r | |
804 | @cached_property\r | |
805 | def BinaryFileList(self):\r | |
806 | RetVal = []\r | |
807 | for F in self.Module.Binaries:\r | |
808 | if F.Target not in [TAB_ARCH_COMMON, TAB_STAR] and F.Target != self.BuildTarget:\r | |
809 | continue\r | |
810 | RetVal.append(F)\r | |
811 | self._ApplyBuildRule(F, F.Type, BinaryFileList=RetVal)\r | |
812 | return RetVal\r | |
813 | \r | |
814 | @cached_property\r | |
815 | def BuildRules(self):\r | |
816 | RetVal = {}\r | |
817 | BuildRuleDatabase = self.PlatformInfo.BuildRule\r | |
818 | for Type in BuildRuleDatabase.FileTypeList:\r | |
819 | #first try getting build rule by BuildRuleFamily\r | |
820 | RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]\r | |
821 | if not RuleObject:\r | |
822 | # build type is always module type, but ...\r | |
823 | if self.ModuleType != self.BuildType:\r | |
824 | RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]\r | |
825 | #second try getting build rule by ToolChainFamily\r | |
826 | if not RuleObject:\r | |
827 | RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]\r | |
828 | if not RuleObject:\r | |
829 | # build type is always module type, but ...\r | |
830 | if self.ModuleType != self.BuildType:\r | |
831 | RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]\r | |
832 | if not RuleObject:\r | |
833 | continue\r | |
834 | RuleObject = RuleObject.Instantiate(self.Macros)\r | |
835 | RetVal[Type] = RuleObject\r | |
836 | for Ext in RuleObject.SourceFileExtList:\r | |
837 | RetVal[Ext] = RuleObject\r | |
838 | return RetVal\r | |
839 | \r | |
840 | def _ApplyBuildRule(self, File, FileType, BinaryFileList=None):\r | |
841 | if self._BuildTargets is None:\r | |
842 | self._IntroBuildTargetList = set()\r | |
843 | self._FinalBuildTargetList = set()\r | |
844 | self._BuildTargets = defaultdict(set)\r | |
845 | self._FileTypes = defaultdict(set)\r | |
846 | \r | |
847 | if not BinaryFileList:\r | |
848 | BinaryFileList = self.BinaryFileList\r | |
849 | \r | |
850 | SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r | |
851 | if not os.path.exists(SubDirectory):\r | |
852 | CreateDirectory(SubDirectory)\r | |
65112778 PG |
853 | TargetList = set()\r |
854 | FinalTargetName = set()\r | |
e8449e1d FB |
855 | RuleChain = set()\r |
856 | SourceList = [File]\r | |
857 | Index = 0\r | |
858 | #\r | |
859 | # Make sure to get build rule order value\r | |
860 | #\r | |
861 | self.BuildOption\r | |
862 | \r | |
863 | while Index < len(SourceList):\r | |
65112778 PG |
864 | # Reset the FileType if not the first iteration.\r |
865 | if Index > 0:\r | |
866 | FileType = TAB_UNKNOWN_FILE\r | |
e8449e1d FB |
867 | Source = SourceList[Index]\r |
868 | Index = Index + 1\r | |
869 | \r | |
870 | if Source != File:\r | |
871 | CreateDirectory(Source.Dir)\r | |
872 | \r | |
873 | if File.IsBinary and File == Source and File in BinaryFileList:\r | |
874 | # Skip all files that are not binary libraries\r | |
875 | if not self.IsLibrary:\r | |
876 | continue\r | |
877 | RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r | |
878 | elif FileType in self.BuildRules:\r | |
879 | RuleObject = self.BuildRules[FileType]\r | |
880 | elif Source.Ext in self.BuildRules:\r | |
881 | RuleObject = self.BuildRules[Source.Ext]\r | |
882 | else:\r | |
65112778 PG |
883 | # No more rule to apply: Source is a final target.\r |
884 | FinalTargetName.add(Source)\r | |
885 | continue\r | |
e8449e1d FB |
886 | \r |
887 | FileType = RuleObject.SourceFileType\r | |
888 | self._FileTypes[FileType].add(Source)\r | |
889 | \r | |
890 | # stop at STATIC_LIBRARY for library\r | |
891 | if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:\r | |
65112778 PG |
892 | FinalTargetName.add(Source)\r |
893 | continue\r | |
e8449e1d FB |
894 | \r |
895 | Target = RuleObject.Apply(Source, self.BuildRuleOrder)\r | |
896 | if not Target:\r | |
65112778 PG |
897 | # No Target: Source is a final target.\r |
898 | FinalTargetName.add(Source)\r | |
899 | continue\r | |
e8449e1d | 900 | \r |
65112778 | 901 | TargetList.add(Target)\r |
e8449e1d FB |
902 | self._BuildTargets[FileType].add(Target)\r |
903 | \r | |
904 | if not Source.IsBinary and Source == File:\r | |
905 | self._IntroBuildTargetList.add(Target)\r | |
906 | \r | |
907 | # to avoid cyclic rule\r | |
908 | if FileType in RuleChain:\r | |
65112778 | 909 | EdkLogger.error("build", ERROR_STATEMENT, "Cyclic dependency detected while generating rule for %s" % str(Source))\r |
e8449e1d FB |
910 | \r |
911 | RuleChain.add(FileType)\r | |
912 | SourceList.extend(Target.Outputs)\r | |
65112778 PG |
913 | \r |
914 | # For each final target name, retrieve the corresponding TargetDescBlock instance.\r | |
915 | for FTargetName in FinalTargetName:\r | |
916 | for Target in TargetList:\r | |
917 | if FTargetName == Target.Target:\r | |
918 | self._FinalBuildTargetList.add(Target)\r | |
e8449e1d FB |
919 | \r |
920 | @cached_property\r | |
921 | def Targets(self):\r | |
922 | if self._BuildTargets is None:\r | |
923 | self._IntroBuildTargetList = set()\r | |
924 | self._FinalBuildTargetList = set()\r | |
925 | self._BuildTargets = defaultdict(set)\r | |
926 | self._FileTypes = defaultdict(set)\r | |
927 | \r | |
928 | #TRICK: call SourceFileList property to apply build rule for source files\r | |
929 | self.SourceFileList\r | |
930 | \r | |
931 | #TRICK: call _GetBinaryFileList to apply build rule for binary files\r | |
932 | self.BinaryFileList\r | |
933 | \r | |
934 | return self._BuildTargets\r | |
935 | \r | |
936 | @cached_property\r | |
937 | def IntroTargetList(self):\r | |
938 | self.Targets\r | |
939 | return self._IntroBuildTargetList\r | |
940 | \r | |
941 | @cached_property\r | |
942 | def CodaTargetList(self):\r | |
943 | self.Targets\r | |
944 | return self._FinalBuildTargetList\r | |
945 | \r | |
946 | @cached_property\r | |
947 | def FileTypes(self):\r | |
948 | self.Targets\r | |
949 | return self._FileTypes\r | |
950 | \r | |
bf1ea933 | 951 | ## Get the list of package object the module depends on and the Platform depends on\r |
e8449e1d FB |
952 | #\r |
953 | # @retval list The package object list\r | |
954 | #\r | |
955 | @cached_property\r | |
956 | def DependentPackageList(self):\r | |
bf1ea933 | 957 | return self.PackageList\r |
e8449e1d FB |
958 | \r |
959 | ## Return the list of auto-generated code file\r | |
960 | #\r | |
961 | # @retval list The list of auto-generated file\r | |
962 | #\r | |
963 | @cached_property\r | |
964 | def AutoGenFileList(self):\r | |
965 | AutoGenUniIdf = self.BuildType != 'UEFI_HII'\r | |
966 | UniStringBinBuffer = BytesIO()\r | |
967 | IdfGenBinBuffer = BytesIO()\r | |
968 | RetVal = {}\r | |
969 | AutoGenC = TemplateString()\r | |
970 | AutoGenH = TemplateString()\r | |
971 | StringH = TemplateString()\r | |
972 | StringIdf = TemplateString()\r | |
973 | GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, AutoGenUniIdf, UniStringBinBuffer, StringIdf, AutoGenUniIdf, IdfGenBinBuffer)\r | |
974 | #\r | |
975 | # AutoGen.c is generated if there are library classes in inf, or there are object files\r | |
976 | #\r | |
977 | if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0\r | |
978 | or TAB_OBJECT_FILE in self.FileTypes):\r | |
979 | AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)\r | |
980 | RetVal[AutoFile] = str(AutoGenC)\r | |
981 | self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r | |
982 | if str(AutoGenH) != "":\r | |
983 | AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)\r | |
984 | RetVal[AutoFile] = str(AutoGenH)\r | |
985 | self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r | |
986 | if str(StringH) != "":\r | |
987 | AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)\r | |
988 | RetVal[AutoFile] = str(StringH)\r | |
989 | self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r | |
990 | if UniStringBinBuffer is not None and UniStringBinBuffer.getvalue() != b"":\r | |
991 | AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)\r | |
992 | RetVal[AutoFile] = UniStringBinBuffer.getvalue()\r | |
993 | AutoFile.IsBinary = True\r | |
994 | self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r | |
995 | if UniStringBinBuffer is not None:\r | |
996 | UniStringBinBuffer.close()\r | |
997 | if str(StringIdf) != "":\r | |
998 | AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir)\r | |
999 | RetVal[AutoFile] = str(StringIdf)\r | |
1000 | self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r | |
1001 | if IdfGenBinBuffer is not None and IdfGenBinBuffer.getvalue() != b"":\r | |
1002 | AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir)\r | |
1003 | RetVal[AutoFile] = IdfGenBinBuffer.getvalue()\r | |
1004 | AutoFile.IsBinary = True\r | |
1005 | self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r | |
1006 | if IdfGenBinBuffer is not None:\r | |
1007 | IdfGenBinBuffer.close()\r | |
1008 | return RetVal\r | |
1009 | \r | |
1010 | ## Return the list of library modules explicitly or implicitly used by this module\r | |
1011 | @cached_property\r | |
1012 | def DependentLibraryList(self):\r | |
1013 | # only merge library classes and PCD for non-library module\r | |
1014 | if self.IsLibrary:\r | |
1015 | return []\r | |
1016 | return self.PlatformInfo.ApplyLibraryInstance(self.Module)\r | |
1017 | \r | |
1018 | ## Get the list of PCDs from current module\r | |
1019 | #\r | |
1020 | # @retval list The list of PCD\r | |
1021 | #\r | |
1022 | @cached_property\r | |
1023 | def ModulePcdList(self):\r | |
1024 | # apply PCD settings from platform\r | |
09af9bd9 | 1025 | RetVal = self.PlatformInfo.ApplyPcdSetting(self, self.Module.Pcds)\r |
e8449e1d FB |
1026 | \r |
1027 | return RetVal\r | |
1028 | @cached_property\r | |
1029 | def _PcdComments(self):\r | |
1030 | ReVal = OrderedListDict()\r | |
1031 | ExtendCopyDictionaryLists(ReVal, self.Module.PcdComments)\r | |
1032 | if not self.IsLibrary:\r | |
1033 | for Library in self.DependentLibraryList:\r | |
1034 | ExtendCopyDictionaryLists(ReVal, Library.PcdComments)\r | |
1035 | return ReVal\r | |
1036 | \r | |
1037 | ## Get the list of PCDs from dependent libraries\r | |
1038 | #\r | |
1039 | # @retval list The list of PCD\r | |
1040 | #\r | |
1041 | @cached_property\r | |
1042 | def LibraryPcdList(self):\r | |
1043 | if self.IsLibrary:\r | |
1044 | return []\r | |
1045 | RetVal = []\r | |
1046 | Pcds = set()\r | |
1047 | # get PCDs from dependent libraries\r | |
1048 | for Library in self.DependentLibraryList:\r | |
1049 | PcdsInLibrary = OrderedDict()\r | |
1050 | for Key in Library.Pcds:\r | |
1051 | # skip duplicated PCDs\r | |
1052 | if Key in self.Module.Pcds or Key in Pcds:\r | |
1053 | continue\r | |
1054 | Pcds.add(Key)\r | |
1055 | PcdsInLibrary[Key] = copy.copy(Library.Pcds[Key])\r | |
09af9bd9 | 1056 | RetVal.extend(self.PlatformInfo.ApplyPcdSetting(self, PcdsInLibrary, Library=Library))\r |
e8449e1d FB |
1057 | return RetVal\r |
1058 | \r | |
1059 | ## Get the GUID value mapping\r | |
1060 | #\r | |
1061 | # @retval dict The mapping between GUID cname and its value\r | |
1062 | #\r | |
1063 | @cached_property\r | |
1064 | def GuidList(self):\r | |
1065 | RetVal = self.Module.Guids\r | |
1066 | for Library in self.DependentLibraryList:\r | |
1067 | RetVal.update(Library.Guids)\r | |
1068 | ExtendCopyDictionaryLists(self._GuidComments, Library.GuidComments)\r | |
1069 | ExtendCopyDictionaryLists(self._GuidComments, self.Module.GuidComments)\r | |
1070 | return RetVal\r | |
1071 | \r | |
1072 | @cached_property\r | |
1073 | def GetGuidsUsedByPcd(self):\r | |
1074 | RetVal = OrderedDict(self.Module.GetGuidsUsedByPcd())\r | |
1075 | for Library in self.DependentLibraryList:\r | |
1076 | RetVal.update(Library.GetGuidsUsedByPcd())\r | |
1077 | return RetVal\r | |
1078 | ## Get the protocol value mapping\r | |
1079 | #\r | |
1080 | # @retval dict The mapping between protocol cname and its value\r | |
1081 | #\r | |
1082 | @cached_property\r | |
1083 | def ProtocolList(self):\r | |
1084 | RetVal = OrderedDict(self.Module.Protocols)\r | |
1085 | for Library in self.DependentLibraryList:\r | |
1086 | RetVal.update(Library.Protocols)\r | |
1087 | ExtendCopyDictionaryLists(self._ProtocolComments, Library.ProtocolComments)\r | |
1088 | ExtendCopyDictionaryLists(self._ProtocolComments, self.Module.ProtocolComments)\r | |
1089 | return RetVal\r | |
1090 | \r | |
1091 | ## Get the PPI value mapping\r | |
1092 | #\r | |
1093 | # @retval dict The mapping between PPI cname and its value\r | |
1094 | #\r | |
1095 | @cached_property\r | |
1096 | def PpiList(self):\r | |
1097 | RetVal = OrderedDict(self.Module.Ppis)\r | |
1098 | for Library in self.DependentLibraryList:\r | |
1099 | RetVal.update(Library.Ppis)\r | |
1100 | ExtendCopyDictionaryLists(self._PpiComments, Library.PpiComments)\r | |
1101 | ExtendCopyDictionaryLists(self._PpiComments, self.Module.PpiComments)\r | |
1102 | return RetVal\r | |
1103 | \r | |
1104 | ## Get the list of include search path\r | |
1105 | #\r | |
1106 | # @retval list The list path\r | |
1107 | #\r | |
1108 | @cached_property\r | |
1109 | def IncludePathList(self):\r | |
1110 | RetVal = []\r | |
1111 | RetVal.append(self.MetaFile.Dir)\r | |
1112 | RetVal.append(self.DebugDir)\r | |
1113 | \r | |
bf1ea933 | 1114 | for Package in self.PackageList:\r |
e8449e1d FB |
1115 | PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)\r |
1116 | if PackageDir not in RetVal:\r | |
1117 | RetVal.append(PackageDir)\r | |
1118 | IncludesList = Package.Includes\r | |
1119 | if Package._PrivateIncludes:\r | |
1120 | if not self.MetaFile.OriginalPath.Path.startswith(PackageDir):\r | |
1121 | IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r | |
1122 | for Inc in IncludesList:\r | |
1123 | if Inc not in RetVal:\r | |
1124 | RetVal.append(str(Inc))\r | |
0c3e8e99 | 1125 | RetVal.extend(self.IncPathFromBuildOptions)\r |
e8449e1d FB |
1126 | return RetVal\r |
1127 | \r | |
0c3e8e99 BF |
1128 | @cached_property\r |
1129 | def IncPathFromBuildOptions(self):\r | |
1130 | IncPathList = []\r | |
1131 | for tool in self.BuildOption:\r | |
1132 | if 'FLAGS' in self.BuildOption[tool]:\r | |
1133 | flags = self.BuildOption[tool]['FLAGS']\r | |
1134 | whitespace = False\r | |
1135 | for flag in flags.split(" "):\r | |
1136 | flag = flag.strip()\r | |
1137 | if flag.startswith(("/I","-I")):\r | |
1138 | if len(flag)>2:\r | |
1139 | if os.path.exists(flag[2:]):\r | |
1140 | IncPathList.append(flag[2:])\r | |
1141 | else:\r | |
1142 | whitespace = True\r | |
1143 | continue\r | |
1144 | if whitespace and flag:\r | |
1145 | if os.path.exists(flag):\r | |
1146 | IncPathList.append(flag)\r | |
1147 | whitespace = False\r | |
1148 | return IncPathList\r | |
1149 | \r | |
e8449e1d FB |
1150 | @cached_property\r |
1151 | def IncludePathLength(self):\r | |
1152 | return sum(len(inc)+1 for inc in self.IncludePathList)\r | |
1153 | \r | |
82407bd1 RC |
1154 | ## Get the list of include paths from the packages\r |
1155 | #\r | |
1156 | # @IncludesList list The list path\r | |
1157 | #\r | |
1158 | @cached_property\r | |
1159 | def PackageIncludePathList(self):\r | |
1160 | IncludesList = []\r | |
bf1ea933 | 1161 | for Package in self.PackageList:\r |
82407bd1 RC |
1162 | PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)\r |
1163 | IncludesList = Package.Includes\r | |
1164 | if Package._PrivateIncludes:\r | |
1165 | if not self.MetaFile.Path.startswith(PackageDir):\r | |
1166 | IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r | |
1167 | return IncludesList\r | |
1168 | \r | |
e8449e1d FB |
1169 | ## Get HII EX PCDs which maybe used by VFR\r |
1170 | #\r | |
1171 | # efivarstore used by VFR may relate with HII EX PCDs\r | |
1172 | # Get the variable name and GUID from efivarstore and HII EX PCD\r | |
1173 | # List the HII EX PCDs in As Built INF if both name and GUID match.\r | |
1174 | #\r | |
1175 | # @retval list HII EX PCDs\r | |
1176 | #\r | |
1177 | def _GetPcdsMaybeUsedByVfr(self):\r | |
1178 | if not self.SourceFileList:\r | |
1179 | return []\r | |
1180 | \r | |
1181 | NameGuids = set()\r | |
1182 | for SrcFile in self.SourceFileList:\r | |
1183 | if SrcFile.Ext.lower() != '.vfr':\r | |
1184 | continue\r | |
1185 | Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')\r | |
1186 | if not os.path.exists(Vfri):\r | |
1187 | continue\r | |
1188 | VfriFile = open(Vfri, 'r')\r | |
1189 | Content = VfriFile.read()\r | |
1190 | VfriFile.close()\r | |
1191 | Pos = Content.find('efivarstore')\r | |
1192 | while Pos != -1:\r | |
1193 | #\r | |
1194 | # Make sure 'efivarstore' is the start of efivarstore statement\r | |
1195 | # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'\r | |
1196 | #\r | |
1197 | Index = Pos - 1\r | |
1198 | while Index >= 0 and Content[Index] in ' \t\r\n':\r | |
1199 | Index -= 1\r | |
1200 | if Index >= 0 and Content[Index] != ';':\r | |
1201 | Pos = Content.find('efivarstore', Pos + len('efivarstore'))\r | |
1202 | continue\r | |
1203 | #\r | |
1204 | # 'efivarstore' must be followed by name and guid\r | |
1205 | #\r | |
1206 | Name = gEfiVarStoreNamePattern.search(Content, Pos)\r | |
1207 | if not Name:\r | |
1208 | break\r | |
1209 | Guid = gEfiVarStoreGuidPattern.search(Content, Pos)\r | |
1210 | if not Guid:\r | |
1211 | break\r | |
1212 | NameArray = _ConvertStringToByteArray('L"' + Name.group(1) + '"')\r | |
1213 | NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r | |
1214 | Pos = Content.find('efivarstore', Name.end())\r | |
1215 | if not NameGuids:\r | |
1216 | return []\r | |
1217 | HiiExPcds = []\r | |
1218 | for Pcd in self.PlatformInfo.Pcds.values():\r | |
1219 | if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:\r | |
1220 | continue\r | |
1221 | for SkuInfo in Pcd.SkuInfoList.values():\r | |
1222 | Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)\r | |
1223 | if not Value:\r | |
1224 | continue\r | |
1225 | Name = _ConvertStringToByteArray(SkuInfo.VariableName)\r | |
1226 | Guid = GuidStructureStringToGuidString(Value)\r | |
1227 | if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:\r | |
1228 | HiiExPcds.append(Pcd)\r | |
1229 | break\r | |
1230 | \r | |
1231 | return HiiExPcds\r | |
1232 | \r | |
1233 | def _GenOffsetBin(self):\r | |
1234 | VfrUniBaseName = {}\r | |
1235 | for SourceFile in self.Module.Sources:\r | |
1236 | if SourceFile.Type.upper() == ".VFR" :\r | |
1237 | #\r | |
1238 | # search the .map file to find the offset of vfr binary in the PE32+/TE file.\r | |
1239 | #\r | |
1240 | VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r | |
1241 | elif SourceFile.Type.upper() == ".UNI" :\r | |
1242 | #\r | |
1243 | # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.\r | |
1244 | #\r | |
1245 | VfrUniBaseName["UniOffsetName"] = (self.Name + "Strings")\r | |
1246 | \r | |
1247 | if not VfrUniBaseName:\r | |
1248 | return None\r | |
1249 | MapFileName = os.path.join(self.OutputDir, self.Name + ".map")\r | |
1250 | EfiFileName = os.path.join(self.OutputDir, self.Name + ".efi")\r | |
1251 | VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, list(VfrUniBaseName.values()))\r | |
1252 | if not VfrUniOffsetList:\r | |
1253 | return None\r | |
1254 | \r | |
1255 | OutputName = '%sOffset.bin' % self.Name\r | |
1256 | UniVfrOffsetFileName = os.path.join( self.OutputDir, OutputName)\r | |
1257 | \r | |
1258 | try:\r | |
1259 | fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r | |
1260 | except:\r | |
1261 | EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName, None)\r | |
1262 | \r | |
1263 | # Use a instance of BytesIO to cache data\r | |
1264 | fStringIO = BytesIO()\r | |
1265 | \r | |
1266 | for Item in VfrUniOffsetList:\r | |
1267 | if (Item[0].find("Strings") != -1):\r | |
1268 | #\r | |
1269 | # UNI offset in image.\r | |
1270 | # GUID + Offset\r | |
1271 | # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r | |
1272 | #\r | |
1273 | UniGuid = b'\xe0\xc5\x13\x89\xf63\x86M\x9b\xf1C\xef\x89\xfc\x06f'\r | |
1274 | fStringIO.write(UniGuid)\r | |
1275 | UniValue = pack ('Q', int (Item[1], 16))\r | |
1276 | fStringIO.write (UniValue)\r | |
1277 | else:\r | |
1278 | #\r | |
1279 | # VFR binary offset in image.\r | |
1280 | # GUID + Offset\r | |
1281 | # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r | |
1282 | #\r | |
1283 | VfrGuid = b'\xb4|\xbc\xd0Gj_I\xaa\x11q\x07F\xda\x06\xa2'\r | |
1284 | fStringIO.write(VfrGuid)\r | |
1285 | VfrValue = pack ('Q', int (Item[1], 16))\r | |
1286 | fStringIO.write (VfrValue)\r | |
1287 | #\r | |
1288 | # write data into file.\r | |
1289 | #\r | |
1290 | try :\r | |
1291 | fInputfile.write (fStringIO.getvalue())\r | |
1292 | except:\r | |
1293 | EdkLogger.error("build", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the "\r | |
1294 | "file been locked or using by other applications." %UniVfrOffsetFileName, None)\r | |
1295 | \r | |
1296 | fStringIO.close ()\r | |
1297 | fInputfile.close ()\r | |
1298 | return OutputName\r | |
d01a9986 | 1299 | \r |
e8449e1d FB |
1300 | @cached_property\r |
1301 | def OutputFile(self):\r | |
1302 | retVal = set()\r | |
40db176d | 1303 | \r |
91f6c533 | 1304 | for Root, Dirs, Files in os.walk(self.BuildDir):\r |
e8449e1d | 1305 | for File in Files:\r |
40db176d | 1306 | # lib file is already added through above CodaTargetList, skip it here\r |
91f6c533 SS |
1307 | if not (File.lower().endswith('.obj') or File.lower().endswith('.debug')):\r |
1308 | NewFile = path.join(Root, File)\r | |
40db176d | 1309 | retVal.add(NewFile)\r |
e8449e1d | 1310 | \r |
40db176d | 1311 | for Root, Dirs, Files in os.walk(self.FfsOutputDir):\r |
d01a9986 | 1312 | for File in Files:\r |
91f6c533 | 1313 | NewFile = path.join(Root, File)\r |
40db176d | 1314 | retVal.add(NewFile)\r |
d01a9986 | 1315 | \r |
e8449e1d FB |
1316 | return retVal\r |
1317 | \r | |
1318 | ## Create AsBuilt INF file the module\r | |
1319 | #\r | |
1320 | def CreateAsBuiltInf(self):\r | |
1321 | \r | |
1322 | if self.IsAsBuiltInfCreated:\r | |
1323 | return\r | |
1324 | \r | |
1325 | # Skip INF file generation for libraries\r | |
1326 | if self.IsLibrary:\r | |
1327 | return\r | |
1328 | \r | |
1329 | # Skip the following code for modules with no source files\r | |
1330 | if not self.SourceFileList:\r | |
1331 | return\r | |
1332 | \r | |
1333 | # Skip the following code for modules without any binary files\r | |
1334 | if self.BinaryFileList:\r | |
1335 | return\r | |
1336 | \r | |
1337 | ### TODO: How to handles mixed source and binary modules\r | |
1338 | \r | |
1339 | # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r | |
1340 | # Also find all packages that the DynamicEx PCDs depend on\r | |
1341 | Pcds = []\r | |
1342 | PatchablePcds = []\r | |
1343 | Packages = []\r | |
1344 | PcdCheckList = []\r | |
1345 | PcdTokenSpaceList = []\r | |
1346 | for Pcd in self.ModulePcdList + self.LibraryPcdList:\r | |
1347 | if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r | |
1348 | PatchablePcds.append(Pcd)\r | |
1349 | PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, TAB_PCDS_PATCHABLE_IN_MODULE))\r | |
1350 | elif Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET:\r | |
1351 | if Pcd not in Pcds:\r | |
1352 | Pcds.append(Pcd)\r | |
1353 | PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC_EX))\r | |
1354 | PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC))\r | |
1355 | PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r | |
1356 | GuidList = OrderedDict(self.GuidList)\r | |
1357 | for TokenSpace in self.GetGuidsUsedByPcd:\r | |
1358 | # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r | |
1359 | # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs\r | |
1360 | if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:\r | |
1361 | GuidList.pop(TokenSpace)\r | |
1362 | CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)\r | |
1363 | for Package in self.DerivedPackageList:\r | |
1364 | if Package in Packages:\r | |
1365 | continue\r | |
1366 | BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)\r | |
1367 | Found = False\r | |
1368 | for Index in range(len(BeChecked)):\r | |
1369 | for Item in CheckList[Index]:\r | |
1370 | if Item in BeChecked[Index]:\r | |
1371 | Packages.append(Package)\r | |
1372 | Found = True\r | |
1373 | break\r | |
1374 | if Found:\r | |
1375 | break\r | |
1376 | \r | |
1377 | VfrPcds = self._GetPcdsMaybeUsedByVfr()\r | |
1378 | for Pkg in self.PlatformInfo.PackageList:\r | |
1379 | if Pkg in Packages:\r | |
1380 | continue\r | |
1381 | for VfrPcd in VfrPcds:\r | |
1382 | if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC_EX) in Pkg.Pcds or\r | |
1383 | (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, TAB_PCDS_DYNAMIC) in Pkg.Pcds):\r | |
1384 | Packages.append(Pkg)\r | |
1385 | break\r | |
1386 | \r | |
1387 | ModuleType = SUP_MODULE_DXE_DRIVER if self.ModuleType == SUP_MODULE_UEFI_DRIVER and self.DepexGenerated else self.ModuleType\r | |
1388 | DriverType = self.PcdIsDriver if self.PcdIsDriver else ''\r | |
1389 | Guid = self.Guid\r | |
1390 | MDefs = self.Module.Defines\r | |
1391 | \r | |
1392 | AsBuiltInfDict = {\r | |
1393 | 'module_name' : self.Name,\r | |
1394 | 'module_guid' : Guid,\r | |
1395 | 'module_module_type' : ModuleType,\r | |
1396 | 'module_version_string' : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],\r | |
1397 | 'pcd_is_driver_string' : [],\r | |
1398 | 'module_uefi_specification_version' : [],\r | |
1399 | 'module_pi_specification_version' : [],\r | |
1400 | 'module_entry_point' : self.Module.ModuleEntryPointList,\r | |
1401 | 'module_unload_image' : self.Module.ModuleUnloadImageList,\r | |
1402 | 'module_constructor' : self.Module.ConstructorList,\r | |
1403 | 'module_destructor' : self.Module.DestructorList,\r | |
1404 | 'module_shadow' : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],\r | |
1405 | 'module_pci_vendor_id' : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],\r | |
1406 | 'module_pci_device_id' : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],\r | |
1407 | 'module_pci_class_code' : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],\r | |
1408 | 'module_pci_revision' : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],\r | |
1409 | 'module_build_number' : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],\r | |
1410 | 'module_spec' : [MDefs['SPEC']] if 'SPEC' in MDefs else [],\r | |
1411 | 'module_uefi_hii_resource_section' : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],\r | |
1412 | 'module_uni_file' : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],\r | |
1413 | 'module_arch' : self.Arch,\r | |
1414 | 'package_item' : [Package.MetaFile.File.replace('\\', '/') for Package in Packages],\r | |
1415 | 'binary_item' : [],\r | |
1416 | 'patchablepcd_item' : [],\r | |
1417 | 'pcd_item' : [],\r | |
1418 | 'protocol_item' : [],\r | |
1419 | 'ppi_item' : [],\r | |
1420 | 'guid_item' : [],\r | |
1421 | 'flags_item' : [],\r | |
1422 | 'libraryclasses_item' : []\r | |
1423 | }\r | |
1424 | \r | |
1425 | if 'MODULE_UNI_FILE' in MDefs:\r | |
1426 | UNIFile = os.path.join(self.MetaFile.Dir, MDefs['MODULE_UNI_FILE'])\r | |
1427 | if os.path.isfile(UNIFile):\r | |
1428 | shutil.copy2(UNIFile, self.OutputDir)\r | |
1429 | \r | |
1430 | if self.AutoGenVersion > int(gInfSpecVersion, 0):\r | |
1431 | AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion\r | |
1432 | else:\r | |
1433 | AsBuiltInfDict['module_inf_version'] = gInfSpecVersion\r | |
1434 | \r | |
1435 | if DriverType:\r | |
1436 | AsBuiltInfDict['pcd_is_driver_string'].append(DriverType)\r | |
1437 | \r | |
1438 | if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r | |
1439 | AsBuiltInfDict['module_uefi_specification_version'].append(self.Specification['UEFI_SPECIFICATION_VERSION'])\r | |
1440 | if 'PI_SPECIFICATION_VERSION' in self.Specification:\r | |
1441 | AsBuiltInfDict['module_pi_specification_version'].append(self.Specification['PI_SPECIFICATION_VERSION'])\r | |
1442 | \r | |
1443 | OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r | |
1444 | DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r | |
1445 | for Item in self.CodaTargetList:\r | |
1446 | File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r | |
1447 | if os.path.isabs(File):\r | |
1448 | File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r | |
1449 | if Item.Target.Ext.lower() == '.aml':\r | |
1450 | AsBuiltInfDict['binary_item'].append('ASL|' + File)\r | |
1451 | elif Item.Target.Ext.lower() == '.acpi':\r | |
1452 | AsBuiltInfDict['binary_item'].append('ACPI|' + File)\r | |
1453 | elif Item.Target.Ext.lower() == '.efi':\r | |
1454 | AsBuiltInfDict['binary_item'].append('PE32|' + self.Name + '.efi')\r | |
1455 | else:\r | |
1456 | AsBuiltInfDict['binary_item'].append('BIN|' + File)\r | |
1457 | if not self.DepexGenerated:\r | |
1458 | DepexFile = os.path.join(self.OutputDir, self.Name + '.depex')\r | |
1459 | if os.path.exists(DepexFile):\r | |
1460 | self.DepexGenerated = True\r | |
1461 | if self.DepexGenerated:\r | |
1462 | if self.ModuleType in [SUP_MODULE_PEIM]:\r | |
1463 | AsBuiltInfDict['binary_item'].append('PEI_DEPEX|' + self.Name + '.depex')\r | |
1464 | elif self.ModuleType in [SUP_MODULE_DXE_DRIVER, SUP_MODULE_DXE_RUNTIME_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, SUP_MODULE_UEFI_DRIVER]:\r | |
1465 | AsBuiltInfDict['binary_item'].append('DXE_DEPEX|' + self.Name + '.depex')\r | |
1466 | elif self.ModuleType in [SUP_MODULE_DXE_SMM_DRIVER]:\r | |
1467 | AsBuiltInfDict['binary_item'].append('SMM_DEPEX|' + self.Name + '.depex')\r | |
1468 | \r | |
1469 | Bin = self._GenOffsetBin()\r | |
1470 | if Bin:\r | |
1471 | AsBuiltInfDict['binary_item'].append('BIN|%s' % Bin)\r | |
1472 | \r | |
1473 | for Root, Dirs, Files in os.walk(OutputDir):\r | |
1474 | for File in Files:\r | |
1475 | if File.lower().endswith('.pdb'):\r | |
1476 | AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File)\r | |
1477 | HeaderComments = self.Module.HeaderComments\r | |
1478 | StartPos = 0\r | |
1479 | for Index in range(len(HeaderComments)):\r | |
1480 | if HeaderComments[Index].find('@BinaryHeader') != -1:\r | |
1481 | HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')\r | |
1482 | StartPos = Index\r | |
1483 | break\r | |
1484 | AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')\r | |
1485 | AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)\r | |
1486 | \r | |
1487 | GenList = [\r | |
1488 | (self.ProtocolList, self._ProtocolComments, 'protocol_item'),\r | |
1489 | (self.PpiList, self._PpiComments, 'ppi_item'),\r | |
1490 | (GuidList, self._GuidComments, 'guid_item')\r | |
1491 | ]\r | |
1492 | for Item in GenList:\r | |
1493 | for CName in Item[0]:\r | |
1494 | Comments = '\n '.join(Item[1][CName]) if CName in Item[1] else ''\r | |
1495 | Entry = Comments + '\n ' + CName if Comments else CName\r | |
1496 | AsBuiltInfDict[Item[2]].append(Entry)\r | |
1497 | PatchList = parsePcdInfoFromMapFile(\r | |
1498 | os.path.join(self.OutputDir, self.Name + '.map'),\r | |
1499 | os.path.join(self.OutputDir, self.Name + '.efi')\r | |
1500 | )\r | |
1501 | if PatchList:\r | |
1502 | for Pcd in PatchablePcds:\r | |
1503 | TokenCName = Pcd.TokenCName\r | |
1504 | for PcdItem in GlobalData.MixedPcd:\r | |
1505 | if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r | |
1506 | TokenCName = PcdItem[0]\r | |
1507 | break\r | |
1508 | for PatchPcd in PatchList:\r | |
1509 | if TokenCName == PatchPcd[0]:\r | |
1510 | break\r | |
1511 | else:\r | |
1512 | continue\r | |
1513 | PcdValue = ''\r | |
1514 | if Pcd.DatumType == 'BOOLEAN':\r | |
1515 | BoolValue = Pcd.DefaultValue.upper()\r | |
1516 | if BoolValue == 'TRUE':\r | |
1517 | Pcd.DefaultValue = '1'\r | |
1518 | elif BoolValue == 'FALSE':\r | |
1519 | Pcd.DefaultValue = '0'\r | |
1520 | \r | |
1521 | if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:\r | |
1522 | HexFormat = '0x%02x'\r | |
1523 | if Pcd.DatumType == TAB_UINT16:\r | |
1524 | HexFormat = '0x%04x'\r | |
1525 | elif Pcd.DatumType == TAB_UINT32:\r | |
1526 | HexFormat = '0x%08x'\r | |
1527 | elif Pcd.DatumType == TAB_UINT64:\r | |
1528 | HexFormat = '0x%016x'\r | |
1529 | PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r | |
1530 | else:\r | |
1531 | if Pcd.MaxDatumSize is None or Pcd.MaxDatumSize == '':\r | |
1532 | EdkLogger.error("build", AUTOGEN_ERROR,\r | |
1533 | "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)\r | |
1534 | )\r | |
1535 | ArraySize = int(Pcd.MaxDatumSize, 0)\r | |
1536 | PcdValue = Pcd.DefaultValue\r | |
1537 | if PcdValue[0] != '{':\r | |
1538 | Unicode = False\r | |
1539 | if PcdValue[0] == 'L':\r | |
1540 | Unicode = True\r | |
1541 | PcdValue = PcdValue.lstrip('L')\r | |
1542 | PcdValue = eval(PcdValue)\r | |
1543 | NewValue = '{'\r | |
1544 | for Index in range(0, len(PcdValue)):\r | |
1545 | if Unicode:\r | |
1546 | CharVal = ord(PcdValue[Index])\r | |
1547 | NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \\r | |
1548 | + '0x%02x' % (CharVal >> 8) + ', '\r | |
1549 | else:\r | |
1550 | NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '\r | |
1551 | Padding = '0x00, '\r | |
1552 | if Unicode:\r | |
1553 | Padding = Padding * 2\r | |
1554 | ArraySize = ArraySize // 2\r | |
1555 | if ArraySize < (len(PcdValue) + 1):\r | |
1556 | if Pcd.MaxSizeUserSet:\r | |
1557 | EdkLogger.error("build", AUTOGEN_ERROR,\r | |
1558 | "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r | |
1559 | )\r | |
1560 | else:\r | |
1561 | ArraySize = len(PcdValue) + 1\r | |
1562 | if ArraySize > len(PcdValue) + 1:\r | |
1563 | NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r | |
1564 | PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r | |
1565 | elif len(PcdValue.split(',')) <= ArraySize:\r | |
1566 | PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r | |
1567 | PcdValue += '}'\r | |
1568 | else:\r | |
1569 | if Pcd.MaxSizeUserSet:\r | |
1570 | EdkLogger.error("build", AUTOGEN_ERROR,\r | |
1571 | "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r | |
1572 | )\r | |
1573 | else:\r | |
1574 | ArraySize = len(PcdValue) + 1\r | |
1575 | PcdItem = '%s.%s|%s|0x%X' % \\r | |
1576 | (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r | |
1577 | PcdComments = ''\r | |
1578 | if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r | |
1579 | PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r | |
1580 | if PcdComments:\r | |
1581 | PcdItem = PcdComments + '\n ' + PcdItem\r | |
1582 | AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r | |
1583 | \r | |
1584 | for Pcd in Pcds + VfrPcds:\r | |
1585 | PcdCommentList = []\r | |
1586 | HiiInfo = ''\r | |
1587 | TokenCName = Pcd.TokenCName\r | |
1588 | for PcdItem in GlobalData.MixedPcd:\r | |
1589 | if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r | |
1590 | TokenCName = PcdItem[0]\r | |
1591 | break\r | |
1592 | if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r | |
1593 | for SkuName in Pcd.SkuInfoList:\r | |
1594 | SkuInfo = Pcd.SkuInfoList[SkuName]\r | |
1595 | HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)\r | |
1596 | break\r | |
1597 | if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r | |
1598 | PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r | |
1599 | if HiiInfo:\r | |
1600 | UsageIndex = -1\r | |
1601 | UsageStr = ''\r | |
1602 | for Index, Comment in enumerate(PcdCommentList):\r | |
1603 | for Usage in UsageList:\r | |
1604 | if Comment.find(Usage) != -1:\r | |
1605 | UsageStr = Usage\r | |
1606 | UsageIndex = Index\r | |
1607 | break\r | |
1608 | if UsageIndex != -1:\r | |
1609 | PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, ''))\r | |
1610 | else:\r | |
1611 | PcdCommentList.append('## UNDEFINED ' + HiiInfo)\r | |
1612 | PcdComments = '\n '.join(PcdCommentList)\r | |
1613 | PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName\r | |
1614 | if PcdComments:\r | |
1615 | PcdEntry = PcdComments + '\n ' + PcdEntry\r | |
1616 | AsBuiltInfDict['pcd_item'].append(PcdEntry)\r | |
1617 | for Item in self.BuildOption:\r | |
1618 | if 'FLAGS' in self.BuildOption[Item]:\r | |
1619 | AsBuiltInfDict['flags_item'].append('%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip()))\r | |
1620 | \r | |
1621 | # Generated LibraryClasses section in comments.\r | |
1622 | for Library in self.LibraryAutoGenList:\r | |
1623 | AsBuiltInfDict['libraryclasses_item'].append(Library.MetaFile.File.replace('\\', '/'))\r | |
1624 | \r | |
1625 | # Generated UserExtensions TianoCore section.\r | |
1626 | # All tianocore user extensions are copied.\r | |
1627 | UserExtStr = ''\r | |
1628 | for TianoCore in self._GetTianoCoreUserExtensionList():\r | |
1629 | UserExtStr += '\n'.join(TianoCore)\r | |
1630 | ExtensionFile = os.path.join(self.MetaFile.Dir, TianoCore[1])\r | |
1631 | if os.path.isfile(ExtensionFile):\r | |
1632 | shutil.copy2(ExtensionFile, self.OutputDir)\r | |
1633 | AsBuiltInfDict['userextension_tianocore_item'] = UserExtStr\r | |
1634 | \r | |
1635 | # Generated depex expression section in comments.\r | |
1636 | DepexExpression = self._GetDepexExpresionString()\r | |
1637 | AsBuiltInfDict['depexsection_item'] = DepexExpression if DepexExpression else ''\r | |
1638 | \r | |
1639 | AsBuiltInf = TemplateString()\r | |
1640 | AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r | |
1641 | \r | |
1642 | SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r | |
1643 | \r | |
1644 | self.IsAsBuiltInfCreated = True\r | |
1645 | \r | |
3bfbc915 | 1646 | def CacheCopyFile(self, DestDir, SourceDir, File):\r |
fc8b8dea SS |
1647 | if os.path.isdir(File):\r |
1648 | return\r | |
1649 | \r | |
3bfbc915 SS |
1650 | sub_dir = os.path.relpath(File, SourceDir)\r |
1651 | destination_file = os.path.join(DestDir, sub_dir)\r | |
0e7e7a26 SS |
1652 | destination_dir = os.path.dirname(destination_file)\r |
1653 | CreateDirectory(destination_dir)\r | |
1654 | try:\r | |
1655 | CopyFileOnChange(File, destination_dir)\r | |
1656 | except:\r | |
1657 | EdkLogger.quiet("[cache warning]: fail to copy file:%s to folder:%s" % (File, destination_dir))\r | |
1658 | return\r | |
1659 | \r | |
e8449e1d | 1660 | def CopyModuleToCache(self):\r |
fc8b8dea SS |
1661 | # Find the MakeHashStr and PreMakeHashStr from latest MakeHashFileList\r |
1662 | # and PreMakeHashFileList files\r | |
1663 | MakeHashStr = None\r | |
1664 | PreMakeHashStr = None\r | |
1665 | MakeTimeStamp = 0\r | |
1666 | PreMakeTimeStamp = 0\r | |
1667 | Files = [f for f in os.listdir(LongFilePath(self.BuildDir)) if path.isfile(LongFilePath(path.join(self.BuildDir, f)))]\r | |
1668 | for File in Files:\r | |
1669 | if ".MakeHashFileList." in File:\r | |
1670 | #find lastest file through time stamp\r | |
1671 | FileTimeStamp = os.stat(LongFilePath(path.join(self.BuildDir, File)))[8]\r | |
1672 | if FileTimeStamp > MakeTimeStamp:\r | |
1673 | MakeTimeStamp = FileTimeStamp\r | |
1674 | MakeHashStr = File.split('.')[-1]\r | |
1675 | if len(MakeHashStr) != 32:\r | |
1676 | EdkLogger.quiet("[cache error]: wrong MakeHashFileList file:%s" % (File))\r | |
1677 | if ".PreMakeHashFileList." in File:\r | |
1678 | FileTimeStamp = os.stat(LongFilePath(path.join(self.BuildDir, File)))[8]\r | |
1679 | if FileTimeStamp > PreMakeTimeStamp:\r | |
1680 | PreMakeTimeStamp = FileTimeStamp\r | |
1681 | PreMakeHashStr = File.split('.')[-1]\r | |
1682 | if len(PreMakeHashStr) != 32:\r | |
1683 | EdkLogger.quiet("[cache error]: wrong PreMakeHashFileList file:%s" % (File))\r | |
0e7e7a26 | 1684 | \r |
fc8b8dea SS |
1685 | if not MakeHashStr:\r |
1686 | EdkLogger.quiet("[cache error]: No MakeHashFileList file for module:%s[%s]" % (self.MetaFile.Path, self.Arch))\r | |
1687 | return\r | |
1688 | if not PreMakeHashStr:\r | |
1689 | EdkLogger.quiet("[cache error]: No PreMakeHashFileList file for module:%s[%s]" % (self.MetaFile.Path, self.Arch))\r | |
1690 | return\r | |
0e7e7a26 | 1691 | \r |
fc8b8dea SS |
1692 | # Create Cache destination dirs\r |
1693 | FileDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r | |
1694 | FfsDir = path.join(GlobalData.gBinCacheDest, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name)\r | |
1695 | CacheFileDir = path.join(FileDir, MakeHashStr)\r | |
1696 | CacheFfsDir = path.join(FfsDir, MakeHashStr)\r | |
1697 | CreateDirectory (CacheFileDir)\r | |
1698 | CreateDirectory (CacheFfsDir)\r | |
0e7e7a26 | 1699 | \r |
fc8b8dea SS |
1700 | # Create ModuleHashPair file to support multiple version cache together\r |
1701 | ModuleHashPair = path.join(FileDir, self.Name + ".ModuleHashPair")\r | |
1702 | ModuleHashPairList = [] # tuple list: [tuple(PreMakefileHash, MakeHash)]\r | |
1703 | if os.path.exists(ModuleHashPair):\r | |
1704 | with open(ModuleHashPair, 'r') as f:\r | |
1705 | ModuleHashPairList = json.load(f)\r | |
1706 | if not (PreMakeHashStr, MakeHashStr) in set(map(tuple, ModuleHashPairList)):\r | |
1707 | ModuleHashPairList.insert(0, (PreMakeHashStr, MakeHashStr))\r | |
1708 | with open(ModuleHashPair, 'w') as f:\r | |
1709 | json.dump(ModuleHashPairList, f, indent=2)\r | |
1710 | \r | |
1711 | # Copy files to Cache destination dirs\r | |
e8449e1d FB |
1712 | if not self.OutputFile:\r |
1713 | Ma = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r | |
1714 | self.OutputFile = Ma.Binaries\r | |
1715 | for File in self.OutputFile:\r | |
fc8b8dea SS |
1716 | if File.startswith(os.path.abspath(self.FfsOutputDir)+os.sep):\r |
1717 | self.CacheCopyFile(CacheFfsDir, self.FfsOutputDir, File)\r | |
1718 | else:\r | |
1719 | if self.Name + ".autogen.hash." in File or \\r | |
1720 | self.Name + ".autogen.hashchain." in File or \\r | |
1721 | self.Name + ".hash." in File or \\r | |
1722 | self.Name + ".hashchain." in File or \\r | |
1723 | self.Name + ".PreMakeHashFileList." in File or \\r | |
1724 | self.Name + ".MakeHashFileList." in File:\r | |
1725 | self.CacheCopyFile(FileDir, self.BuildDir, File)\r | |
d01a9986 | 1726 | else:\r |
fc8b8dea | 1727 | self.CacheCopyFile(CacheFileDir, self.BuildDir, File)\r |
e8449e1d FB |
1728 | ## Create makefile for the module and its dependent libraries\r |
1729 | #\r | |
1730 | # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of\r | |
1731 | # dependent libraries will be created\r | |
1732 | #\r | |
1733 | @cached_class_function\r | |
1734 | def CreateMakeFile(self, CreateLibraryMakeFile=True, GenFfsList = []):\r | |
0e7e7a26 | 1735 | \r |
e8449e1d FB |
1736 | # nest this function inside it's only caller.\r |
1737 | def CreateTimeStamp():\r | |
1738 | FileSet = {self.MetaFile.Path}\r | |
1739 | \r | |
1740 | for SourceFile in self.Module.Sources:\r | |
1741 | FileSet.add (SourceFile.Path)\r | |
1742 | \r | |
1743 | for Lib in self.DependentLibraryList:\r | |
1744 | FileSet.add (Lib.MetaFile.Path)\r | |
1745 | \r | |
1746 | for f in self.AutoGenDepSet:\r | |
1747 | FileSet.add (f.Path)\r | |
1748 | \r | |
1749 | if os.path.exists (self.TimeStampPath):\r | |
1750 | os.remove (self.TimeStampPath)\r | |
df43ea6c FB |
1751 | \r |
1752 | SaveFileOnChange(self.TimeStampPath, "\n".join(FileSet), False)\r | |
e8449e1d FB |
1753 | \r |
1754 | # Ignore generating makefile when it is a binary module\r | |
1755 | if self.IsBinaryModule:\r | |
1756 | return\r | |
1757 | \r | |
1758 | self.GenFfsList = GenFfsList\r | |
1759 | \r | |
1760 | if not self.IsLibrary and CreateLibraryMakeFile:\r | |
1761 | for LibraryAutoGen in self.LibraryAutoGenList:\r | |
1762 | LibraryAutoGen.CreateMakeFile()\r | |
673d09a2 | 1763 | \r |
0e7e7a26 SS |
1764 | # CanSkip uses timestamps to determine build skipping\r |
1765 | if self.CanSkip():\r | |
e8449e1d FB |
1766 | return\r |
1767 | \r | |
1768 | if len(self.CustomMakefile) == 0:\r | |
1769 | Makefile = GenMake.ModuleMakefile(self)\r | |
1770 | else:\r | |
1771 | Makefile = GenMake.CustomMakefile(self)\r | |
1772 | if Makefile.Generate():\r | |
1773 | EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %\r | |
1774 | (self.Name, self.Arch))\r | |
1775 | else:\r | |
1776 | EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r | |
1777 | (self.Name, self.Arch))\r | |
1778 | \r | |
1779 | CreateTimeStamp()\r | |
1780 | \r | |
0e7e7a26 SS |
1781 | MakefileType = Makefile._FileType\r |
1782 | MakefileName = Makefile._FILE_NAME_[MakefileType]\r | |
1783 | MakefilePath = os.path.join(self.MakeFileDir, MakefileName)\r | |
fc8b8dea SS |
1784 | FilePath = path.join(self.BuildDir, self.Name + ".makefile")\r |
1785 | SaveFileOnChange(FilePath, MakefilePath, False)\r | |
0e7e7a26 | 1786 | \r |
e8449e1d FB |
1787 | def CopyBinaryFiles(self):\r |
1788 | for File in self.Module.Binaries:\r | |
1789 | SrcPath = File.Path\r | |
1790 | DstPath = os.path.join(self.OutputDir, os.path.basename(SrcPath))\r | |
1791 | CopyLongFilePath(SrcPath, DstPath)\r | |
1792 | ## Create autogen code for the module and its dependent libraries\r | |
1793 | #\r | |
1794 | # @param CreateLibraryCodeFile Flag indicating if or not the code of\r | |
1795 | # dependent libraries will be created\r | |
1796 | #\r | |
1797 | def CreateCodeFile(self, CreateLibraryCodeFile=True):\r | |
0e7e7a26 | 1798 | \r |
e8449e1d FB |
1799 | if self.IsCodeFileCreated:\r |
1800 | return\r | |
1801 | \r | |
1802 | # Need to generate PcdDatabase even PcdDriver is binarymodule\r | |
1803 | if self.IsBinaryModule and self.PcdIsDriver != '':\r | |
1804 | CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r | |
1805 | return\r | |
1806 | if self.IsBinaryModule:\r | |
1807 | if self.IsLibrary:\r | |
1808 | self.CopyBinaryFiles()\r | |
1809 | return\r | |
1810 | \r | |
1811 | if not self.IsLibrary and CreateLibraryCodeFile:\r | |
1812 | for LibraryAutoGen in self.LibraryAutoGenList:\r | |
1813 | LibraryAutoGen.CreateCodeFile()\r | |
0e7e7a26 | 1814 | \r |
1f5e4d91 | 1815 | self.LibraryAutoGenList\r |
e8449e1d FB |
1816 | AutoGenList = []\r |
1817 | IgoredAutoGenList = []\r | |
1818 | \r | |
1819 | for File in self.AutoGenFileList:\r | |
1820 | if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r | |
1821 | AutoGenList.append(str(File))\r | |
1822 | else:\r | |
1823 | IgoredAutoGenList.append(str(File))\r | |
1824 | \r | |
1825 | \r | |
1826 | for ModuleType in self.DepexList:\r | |
1827 | # Ignore empty [depex] section or [depex] section for SUP_MODULE_USER_DEFINED module\r | |
1828 | if len(self.DepexList[ModuleType]) == 0 or ModuleType == SUP_MODULE_USER_DEFINED or ModuleType == SUP_MODULE_HOST_APPLICATION:\r | |
1829 | continue\r | |
1830 | \r | |
1831 | Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r | |
1832 | DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r | |
1833 | \r | |
1834 | if len(Dpx.PostfixNotation) != 0:\r | |
1835 | self.DepexGenerated = True\r | |
1836 | \r | |
1837 | if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r | |
1838 | AutoGenList.append(str(DpxFile))\r | |
1839 | else:\r | |
1840 | IgoredAutoGenList.append(str(DpxFile))\r | |
1841 | \r | |
1842 | if IgoredAutoGenList == []:\r | |
1843 | EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %\r | |
1844 | (" ".join(AutoGenList), self.Name, self.Arch))\r | |
1845 | elif AutoGenList == []:\r | |
1846 | EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %\r | |
1847 | (" ".join(IgoredAutoGenList), self.Name, self.Arch))\r | |
1848 | else:\r | |
1849 | EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %\r | |
1850 | (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))\r | |
1851 | \r | |
1852 | self.IsCodeFileCreated = True\r | |
0e7e7a26 | 1853 | \r |
e8449e1d FB |
1854 | return AutoGenList\r |
1855 | \r | |
1856 | ## Summarize the ModuleAutoGen objects of all libraries used by this module\r | |
1857 | @cached_property\r | |
1858 | def LibraryAutoGenList(self):\r | |
1859 | RetVal = []\r | |
1860 | for Library in self.DependentLibraryList:\r | |
1861 | La = ModuleAutoGen(\r | |
1862 | self.Workspace,\r | |
1863 | Library.MetaFile,\r | |
1864 | self.BuildTarget,\r | |
1865 | self.ToolChain,\r | |
1866 | self.Arch,\r | |
1867 | self.PlatformInfo.MetaFile,\r | |
1868 | self.DataPipe\r | |
1869 | )\r | |
1870 | La.IsLibrary = True\r | |
1871 | if La not in RetVal:\r | |
1872 | RetVal.append(La)\r | |
1873 | for Lib in La.CodaTargetList:\r | |
1874 | self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)\r | |
1875 | return RetVal\r | |
1876 | \r | |
fc8b8dea SS |
1877 | def GenCMakeHash(self):\r |
1878 | # GenCMakeHash can only be called in --binary-destination\r | |
1879 | # Never called in multiprocessing and always directly save result in main process,\r | |
1880 | # so no need remote dict to share the gCMakeHashFile result with main process\r | |
e8449e1d | 1881 | \r |
fc8b8dea SS |
1882 | DependencyFileSet = set()\r |
1883 | # Add AutoGen files\r | |
1884 | if self.AutoGenFileList:\r | |
1885 | for File in set(self.AutoGenFileList):\r | |
1886 | DependencyFileSet.add(File)\r | |
1887 | \r | |
1888 | # Add Makefile\r | |
1889 | abspath = path.join(self.BuildDir, self.Name + ".makefile")\r | |
1890 | try:\r | |
1891 | with open(LongFilePath(abspath),"r") as fd:\r | |
1892 | lines = fd.readlines()\r | |
1893 | except Exception as e:\r | |
1894 | EdkLogger.error("build",FILE_NOT_FOUND, "%s doesn't exist" % abspath, ExtraData=str(e), RaiseError=False)\r | |
1895 | if lines:\r | |
1896 | DependencyFileSet.update(lines)\r | |
e8449e1d | 1897 | \r |
fc8b8dea | 1898 | # Caculate all above dependency files hash\r |
e8449e1d | 1899 | # Initialze hash object\r |
fc8b8dea | 1900 | FileList = []\r |
e8449e1d | 1901 | m = hashlib.md5()\r |
fc8b8dea SS |
1902 | for File in sorted(DependencyFileSet, key=lambda x: str(x)):\r |
1903 | if not path.exists(LongFilePath(str(File))):\r | |
1904 | EdkLogger.quiet("[cache warning]: header file %s is missing for module: %s[%s]" % (File, self.MetaFile.Path, self.Arch))\r | |
1905 | continue\r | |
1906 | with open(LongFilePath(str(File)), 'rb') as f:\r | |
e8449e1d | 1907 | Content = f.read()\r |
fc8b8dea SS |
1908 | m.update(Content)\r |
1909 | FileList.append((str(File), hashlib.md5(Content).hexdigest()))\r | |
e8449e1d | 1910 | \r |
fc8b8dea SS |
1911 | HashChainFile = path.join(self.BuildDir, self.Name + ".autogen.hashchain." + m.hexdigest())\r |
1912 | GlobalData.gCMakeHashFile[(self.MetaFile.Path, self.Arch)] = HashChainFile\r | |
1913 | try:\r | |
1914 | with open(LongFilePath(HashChainFile), 'w') as f:\r | |
1915 | json.dump(FileList, f, indent=2)\r | |
1916 | except:\r | |
1917 | EdkLogger.quiet("[cache warning]: fail to save hashchain file:%s" % HashChainFile)\r | |
1918 | return False\r | |
0e7e7a26 | 1919 | \r |
fc8b8dea SS |
1920 | def GenModuleHash(self):\r |
1921 | # GenModuleHash only called after autogen phase\r | |
1922 | # Never called in multiprocessing and always directly save result in main process,\r | |
1923 | # so no need remote dict to share the gModuleHashFile result with main process\r | |
1924 | #\r | |
1925 | # GenPreMakefileHashList consume no dict.\r | |
1926 | # GenPreMakefileHashList produce local gModuleHashFile dict.\r | |
94459080 | 1927 | \r |
0e7e7a26 SS |
1928 | DependencyFileSet = set()\r |
1929 | # Add Module Meta file\r | |
fc8b8dea | 1930 | DependencyFileSet.add(self.MetaFile.Path)\r |
0e7e7a26 SS |
1931 | \r |
1932 | # Add Module's source files\r | |
1933 | if self.SourceFileList:\r | |
1934 | for File in set(self.SourceFileList):\r | |
fc8b8dea | 1935 | DependencyFileSet.add(File.Path)\r |
0e7e7a26 SS |
1936 | \r |
1937 | # Add modules's include header files\r | |
fc8b8dea SS |
1938 | # Directly use the deps.txt file in the module BuildDir\r |
1939 | abspath = path.join(self.BuildDir, "deps.txt")\r | |
1940 | rt = None\r | |
1941 | try:\r | |
1942 | with open(LongFilePath(abspath),"r") as fd:\r | |
1943 | lines = fd.readlines()\r | |
1944 | if lines:\r | |
1945 | rt = set([item.lstrip().strip("\n") for item in lines if item.strip("\n").endswith(".h")])\r | |
1946 | except Exception as e:\r | |
1947 | EdkLogger.error("build",FILE_NOT_FOUND, "%s doesn't exist" % abspath, ExtraData=str(e), RaiseError=False)\r | |
1948 | \r | |
1949 | if rt:\r | |
1950 | DependencyFileSet.update(rt)\r | |
0e7e7a26 | 1951 | \r |
0e7e7a26 SS |
1952 | \r |
1953 | # Caculate all above dependency files hash\r | |
1954 | # Initialze hash object\r | |
1955 | FileList = []\r | |
1956 | m = hashlib.md5()\r | |
fc8b8dea | 1957 | BuildDirStr = path.abspath(self.BuildDir).lower()\r |
0e7e7a26 | 1958 | for File in sorted(DependencyFileSet, key=lambda x: str(x)):\r |
fc8b8dea SS |
1959 | # Skip the AutoGen files in BuildDir which already been\r |
1960 | # included in .autogen.hash. file\r | |
1961 | if BuildDirStr in path.abspath(File).lower():\r | |
1962 | continue\r | |
1963 | if not path.exists(LongFilePath(File)):\r | |
0e7e7a26 SS |
1964 | EdkLogger.quiet("[cache warning]: header file %s is missing for module: %s[%s]" % (File, self.MetaFile.Path, self.Arch))\r |
1965 | continue\r | |
fc8b8dea | 1966 | with open(LongFilePath(File), 'rb') as f:\r |
94459080 | 1967 | Content = f.read()\r |
0e7e7a26 | 1968 | m.update(Content)\r |
fc8b8dea | 1969 | FileList.append((File, hashlib.md5(Content).hexdigest()))\r |
0e7e7a26 | 1970 | \r |
fc8b8dea SS |
1971 | HashChainFile = path.join(self.BuildDir, self.Name + ".hashchain." + m.hexdigest())\r |
1972 | GlobalData.gModuleHashFile[(self.MetaFile.Path, self.Arch)] = HashChainFile\r | |
1973 | try:\r | |
1974 | with open(LongFilePath(HashChainFile), 'w') as f:\r | |
1975 | json.dump(FileList, f, indent=2)\r | |
1976 | except:\r | |
1977 | EdkLogger.quiet("[cache warning]: fail to save hashchain file:%s" % HashChainFile)\r | |
1978 | return False\r | |
0e7e7a26 | 1979 | \r |
fc8b8dea SS |
1980 | def GenPreMakefileHashList(self):\r |
1981 | # GenPreMakefileHashList consume below dicts:\r | |
1982 | # gPlatformHashFile\r | |
1983 | # gPackageHashFile\r | |
1984 | # gModuleHashFile\r | |
1985 | # GenPreMakefileHashList produce no dict.\r | |
1986 | # gModuleHashFile items might be produced in multiprocessing, so\r | |
1987 | # need check gModuleHashFile remote dict\r | |
94459080 | 1988 | \r |
0e7e7a26 SS |
1989 | # skip binary module\r |
1990 | if self.IsBinaryModule:\r | |
1991 | return\r | |
1992 | \r | |
fc8b8dea | 1993 | FileList = []\r |
0e7e7a26 | 1994 | m = hashlib.md5()\r |
0e7e7a26 | 1995 | # Add Platform level hash\r |
fc8b8dea SS |
1996 | HashFile = GlobalData.gPlatformHashFile\r |
1997 | if path.exists(LongFilePath(HashFile)):\r | |
1998 | FileList.append(HashFile)\r | |
1999 | m.update(HashFile.encode('utf-8'))\r | |
0e7e7a26 | 2000 | else:\r |
fc8b8dea | 2001 | EdkLogger.quiet("[cache warning]: No Platform HashFile: %s" % HashFile)\r |
0e7e7a26 SS |
2002 | \r |
2003 | # Add Package level hash\r | |
2004 | if self.DependentPackageList:\r | |
2005 | for Pkg in sorted(self.DependentPackageList, key=lambda x: x.PackageName):\r | |
fc8b8dea SS |
2006 | if not (Pkg.PackageName, Pkg.Arch) in GlobalData.gPackageHashFile:\r |
2007 | EdkLogger.quiet("[cache warning]:No Package %s for module %s[%s]" % (Pkg.PackageName, self.MetaFile.Path, self.Arch))\r | |
2008 | continue\r | |
2009 | HashFile = GlobalData.gPackageHashFile[(Pkg.PackageName, Pkg.Arch)]\r | |
2010 | if path.exists(LongFilePath(HashFile)):\r | |
2011 | FileList.append(HashFile)\r | |
2012 | m.update(HashFile.encode('utf-8'))\r | |
0e7e7a26 | 2013 | else:\r |
fc8b8dea | 2014 | EdkLogger.quiet("[cache warning]:No Package HashFile: %s" % HashFile)\r |
0e7e7a26 SS |
2015 | \r |
2016 | # Add Module self\r | |
fc8b8dea SS |
2017 | # GenPreMakefileHashList needed in both --binary-destination\r |
2018 | # and --hash. And --hash might save ModuleHashFile in remote dict\r | |
2019 | # during multiprocessing.\r | |
2020 | if (self.MetaFile.Path, self.Arch) in GlobalData.gModuleHashFile:\r | |
2021 | HashFile = GlobalData.gModuleHashFile[(self.MetaFile.Path, self.Arch)]\r | |
0e7e7a26 | 2022 | else:\r |
fc8b8dea SS |
2023 | EdkLogger.quiet("[cache error]:No ModuleHashFile for module: %s[%s]" % (self.MetaFile.Path, self.Arch))\r |
2024 | if path.exists(LongFilePath(HashFile)):\r | |
2025 | FileList.append(HashFile)\r | |
2026 | m.update(HashFile.encode('utf-8'))\r | |
0e7e7a26 | 2027 | else:\r |
fc8b8dea | 2028 | EdkLogger.quiet("[cache warning]:No Module HashFile: %s" % HashFile)\r |
0e7e7a26 | 2029 | \r |
fc8b8dea SS |
2030 | # Add Library hash\r |
2031 | if self.LibraryAutoGenList:\r | |
2032 | for Lib in sorted(self.LibraryAutoGenList, key=lambda x: x.MetaFile.Path):\r | |
0e7e7a26 | 2033 | \r |
fc8b8dea SS |
2034 | if (Lib.MetaFile.Path, Lib.Arch) in GlobalData.gModuleHashFile:\r |
2035 | HashFile = GlobalData.gModuleHashFile[(Lib.MetaFile.Path, Lib.Arch)]\r | |
2036 | else:\r | |
2037 | EdkLogger.quiet("[cache error]:No ModuleHashFile for lib: %s[%s]" % (Lib.MetaFile.Path, Lib.Arch))\r | |
2038 | if path.exists(LongFilePath(HashFile)):\r | |
2039 | FileList.append(HashFile)\r | |
2040 | m.update(HashFile.encode('utf-8'))\r | |
2041 | else:\r | |
2042 | EdkLogger.quiet("[cache warning]:No Lib HashFile: %s" % HashFile)\r | |
0e7e7a26 | 2043 | \r |
fc8b8dea SS |
2044 | # Save PreMakeHashFileList\r |
2045 | FilePath = path.join(self.BuildDir, self.Name + ".PreMakeHashFileList." + m.hexdigest())\r | |
2046 | try:\r | |
2047 | with open(LongFilePath(FilePath), 'w') as f:\r | |
2048 | json.dump(FileList, f, indent=0)\r | |
2049 | except:\r | |
2050 | EdkLogger.quiet("[cache warning]: fail to save PreMake HashFileList: %s" % FilePath)\r | |
0e7e7a26 | 2051 | \r |
fc8b8dea SS |
2052 | def GenMakefileHashList(self):\r |
2053 | # GenMakefileHashList only need in --binary-destination which will\r | |
2054 | # everything in local dict. So don't need check remote dict.\r | |
94459080 | 2055 | \r |
0e7e7a26 SS |
2056 | # skip binary module\r |
2057 | if self.IsBinaryModule:\r | |
2058 | return\r | |
2059 | \r | |
fc8b8dea | 2060 | FileList = []\r |
0e7e7a26 | 2061 | m = hashlib.md5()\r |
fc8b8dea SS |
2062 | # Add AutoGen hash\r |
2063 | HashFile = GlobalData.gCMakeHashFile[(self.MetaFile.Path, self.Arch)]\r | |
2064 | if path.exists(LongFilePath(HashFile)):\r | |
2065 | FileList.append(HashFile)\r | |
2066 | m.update(HashFile.encode('utf-8'))\r | |
2067 | else:\r | |
2068 | EdkLogger.quiet("[cache warning]:No AutoGen HashFile: %s" % HashFile)\r | |
0e7e7a26 | 2069 | \r |
fc8b8dea SS |
2070 | # Add Module self\r |
2071 | if (self.MetaFile.Path, self.Arch) in GlobalData.gModuleHashFile:\r | |
2072 | HashFile = GlobalData.gModuleHashFile[(self.MetaFile.Path, self.Arch)]\r | |
2073 | else:\r | |
2074 | EdkLogger.quiet("[cache error]:No ModuleHashFile for module: %s[%s]" % (self.MetaFile.Path, self.Arch))\r | |
2075 | if path.exists(LongFilePath(HashFile)):\r | |
2076 | FileList.append(HashFile)\r | |
2077 | m.update(HashFile.encode('utf-8'))\r | |
2078 | else:\r | |
2079 | EdkLogger.quiet("[cache warning]:No Module HashFile: %s" % HashFile)\r | |
0e7e7a26 SS |
2080 | \r |
2081 | # Add Library hash\r | |
2082 | if self.LibraryAutoGenList:\r | |
fc8b8dea SS |
2083 | for Lib in sorted(self.LibraryAutoGenList, key=lambda x: x.MetaFile.Path):\r |
2084 | if (Lib.MetaFile.Path, Lib.Arch) in GlobalData.gModuleHashFile:\r | |
2085 | HashFile = GlobalData.gModuleHashFile[(Lib.MetaFile.Path, Lib.Arch)]\r | |
2086 | else:\r | |
2087 | EdkLogger.quiet("[cache error]:No ModuleHashFile for lib: %s[%s]" % (Lib.MetaFile.Path, Lib.Arch))\r | |
2088 | if path.exists(LongFilePath(HashFile)):\r | |
2089 | FileList.append(HashFile)\r | |
2090 | m.update(HashFile.encode('utf-8'))\r | |
2091 | else:\r | |
2092 | EdkLogger.quiet("[cache warning]:No Lib HashFile: %s" % HashFile)\r | |
0e7e7a26 | 2093 | \r |
fc8b8dea SS |
2094 | # Save MakeHashFileList\r |
2095 | FilePath = path.join(self.BuildDir, self.Name + ".MakeHashFileList." + m.hexdigest())\r | |
2096 | try:\r | |
2097 | with open(LongFilePath(FilePath), 'w') as f:\r | |
2098 | json.dump(FileList, f, indent=0)\r | |
2099 | except:\r | |
2100 | EdkLogger.quiet("[cache warning]: fail to save Make HashFileList: %s" % FilePath)\r | |
2101 | \r | |
2102 | def CheckHashChainFile(self, HashChainFile):\r | |
2103 | # Assume the HashChainFile basename format is the 'x.hashchain.16BytesHexStr'\r | |
2104 | # The x is module name and the 16BytesHexStr is md5 hexdigest of\r | |
2105 | # all hashchain files content\r | |
2106 | HashStr = HashChainFile.split('.')[-1]\r | |
2107 | if len(HashStr) != 32:\r | |
2108 | EdkLogger.quiet("[cache error]: wrong format HashChainFile:%s" % (File))\r | |
2109 | return False\r | |
0e7e7a26 | 2110 | \r |
fc8b8dea SS |
2111 | try:\r |
2112 | with open(LongFilePath(HashChainFile), 'r') as f:\r | |
2113 | HashChainList = json.load(f)\r | |
2114 | except:\r | |
2115 | EdkLogger.quiet("[cache error]: fail to load HashChainFile: %s" % HashChainFile)\r | |
2116 | return False\r | |
0e7e7a26 | 2117 | \r |
fc8b8dea SS |
2118 | # Print the different file info\r |
2119 | # print(HashChainFile)\r | |
2120 | for idx, (SrcFile, SrcHash) in enumerate (HashChainList):\r | |
2121 | if SrcFile in GlobalData.gFileHashDict:\r | |
2122 | DestHash = GlobalData.gFileHashDict[SrcFile]\r | |
2123 | else:\r | |
2124 | try:\r | |
2125 | with open(LongFilePath(SrcFile), 'rb') as f:\r | |
2126 | Content = f.read()\r | |
2127 | DestHash = hashlib.md5(Content).hexdigest()\r | |
2128 | GlobalData.gFileHashDict[SrcFile] = DestHash\r | |
2129 | except IOError as X:\r | |
2130 | # cache miss if SrcFile is removed in new version code\r | |
2131 | GlobalData.gFileHashDict[SrcFile] = 0\r | |
2132 | EdkLogger.quiet("[cache insight]: first cache miss file in %s is %s" % (HashChainFile, SrcFile))\r | |
2133 | return False\r | |
2134 | if SrcHash != DestHash:\r | |
2135 | EdkLogger.quiet("[cache insight]: first cache miss file in %s is %s" % (HashChainFile, SrcFile))\r | |
2136 | return False\r | |
2137 | \r | |
2138 | return True\r | |
0e7e7a26 SS |
2139 | \r |
2140 | ## Decide whether we can skip the left autogen and make process\r | |
fc8b8dea SS |
2141 | def CanSkipbyMakeCache(self):\r |
2142 | # For --binary-source only\r | |
2143 | # CanSkipbyMakeCache consume below dicts:\r | |
2144 | # gModuleMakeCacheStatus\r | |
2145 | # gHashChainStatus\r | |
2146 | # GenPreMakefileHashList produce gModuleMakeCacheStatus, gModuleHashFile dict.\r | |
2147 | # all these dicts might be produced in multiprocessing, so\r | |
2148 | # need check these remote dict\r | |
2149 | \r | |
0e7e7a26 SS |
2150 | if not GlobalData.gBinCacheSource:\r |
2151 | return False\r | |
2152 | \r | |
fc8b8dea SS |
2153 | if (self.MetaFile.Path, self.Arch) in GlobalData.gModuleMakeCacheStatus:\r |
2154 | return GlobalData.gModuleMakeCacheStatus[(self.MetaFile.Path, self.Arch)]\r | |
94459080 | 2155 | \r |
fc8b8dea | 2156 | # If Module is binary, which has special build rule, do not skip by cache.\r |
0e7e7a26 | 2157 | if self.IsBinaryModule:\r |
fc8b8dea SS |
2158 | print("[cache miss]: MakeCache: Skip BinaryModule:", self.MetaFile.Path, self.Arch)\r |
2159 | GlobalData.gModuleMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
0e7e7a26 SS |
2160 | return False\r |
2161 | \r | |
fc8b8dea | 2162 | # see .inc as binary file, do not skip by hash\r |
0e7e7a26 SS |
2163 | for f_ext in self.SourceFileList:\r |
2164 | if '.inc' in str(f_ext):\r | |
fc8b8dea SS |
2165 | print("[cache miss]: MakeCache: Skip '.inc' File:", self.MetaFile.Path, self.Arch)\r |
2166 | GlobalData.gModuleMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
0e7e7a26 SS |
2167 | return False\r |
2168 | \r | |
fc8b8dea | 2169 | ModuleCacheDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r |
0e7e7a26 SS |
2170 | FfsDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name)\r |
2171 | \r | |
2172 | ModuleHashPairList = [] # tuple list: [tuple(PreMakefileHash, MakeHash)]\r | |
fc8b8dea | 2173 | ModuleHashPair = path.join(ModuleCacheDir, self.Name + ".ModuleHashPair")\r |
0e7e7a26 | 2174 | try:\r |
fc8b8dea | 2175 | with open(LongFilePath(ModuleHashPair), 'r') as f:\r |
94459080 | 2176 | ModuleHashPairList = json.load(f)\r |
0e7e7a26 | 2177 | except:\r |
fc8b8dea SS |
2178 | # ModuleHashPair might not exist for new added module\r |
2179 | GlobalData.gModuleMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
0e7e7a26 | 2180 | EdkLogger.quiet("[cache warning]: fail to load ModuleHashPair file: %s" % ModuleHashPair)\r |
fc8b8dea | 2181 | print("[cache miss]: MakeCache:", self.MetaFile.Path, self.Arch)\r |
0e7e7a26 SS |
2182 | return False\r |
2183 | \r | |
fc8b8dea | 2184 | # Check the PreMakeHash in ModuleHashPairList one by one\r |
0e7e7a26 | 2185 | for idx, (PreMakefileHash, MakeHash) in enumerate (ModuleHashPairList):\r |
fc8b8dea SS |
2186 | SourceHashDir = path.join(ModuleCacheDir, MakeHash)\r |
2187 | SourceFfsHashDir = path.join(FfsDir, MakeHash)\r | |
2188 | PreMakeHashFileList_FilePah = path.join(ModuleCacheDir, self.Name + ".PreMakeHashFileList." + PreMakefileHash)\r | |
2189 | MakeHashFileList_FilePah = path.join(ModuleCacheDir, self.Name + ".MakeHashFileList." + MakeHash)\r | |
0e7e7a26 | 2190 | \r |
fc8b8dea SS |
2191 | try:\r |
2192 | with open(LongFilePath(MakeHashFileList_FilePah), 'r') as f:\r | |
2193 | MakeHashFileList = json.load(f)\r | |
2194 | except:\r | |
2195 | EdkLogger.quiet("[cache error]: fail to load MakeHashFileList file: %s" % MakeHashFileList_FilePah)\r | |
2196 | continue\r | |
0e7e7a26 | 2197 | \r |
fc8b8dea SS |
2198 | HashMiss = False\r |
2199 | for HashChainFile in MakeHashFileList:\r | |
2200 | HashChainStatus = None\r | |
2201 | if HashChainFile in GlobalData.gHashChainStatus:\r | |
2202 | HashChainStatus = GlobalData.gHashChainStatus[HashChainFile]\r | |
2203 | if HashChainStatus == False:\r | |
2204 | HashMiss = True\r | |
2205 | break\r | |
2206 | elif HashChainStatus == True:\r | |
2207 | continue\r | |
2208 | # Convert to path start with cache source dir\r | |
2209 | RelativePath = os.path.relpath(HashChainFile, self.WorkspaceDir)\r | |
2210 | NewFilePath = os.path.join(GlobalData.gBinCacheSource, RelativePath)\r | |
2211 | if self.CheckHashChainFile(NewFilePath):\r | |
2212 | GlobalData.gHashChainStatus[HashChainFile] = True\r | |
2213 | # Save the module self HashFile for GenPreMakefileHashList later usage\r | |
2214 | if self.Name + ".hashchain." in HashChainFile:\r | |
2215 | GlobalData.gModuleHashFile[(self.MetaFile.Path, self.Arch)] = HashChainFile\r | |
2216 | else:\r | |
2217 | GlobalData.gHashChainStatus[HashChainFile] = False\r | |
2218 | HashMiss = True\r | |
2219 | break\r | |
0e7e7a26 | 2220 | \r |
fc8b8dea SS |
2221 | if HashMiss:\r |
2222 | continue\r | |
0e7e7a26 | 2223 | \r |
fc8b8dea SS |
2224 | # PreMakefile cache hit, restore the module build result\r |
2225 | for root, dir, files in os.walk(SourceHashDir):\r | |
0e7e7a26 SS |
2226 | for f in files:\r |
2227 | File = path.join(root, f)\r | |
fc8b8dea SS |
2228 | self.CacheCopyFile(self.BuildDir, SourceHashDir, File)\r |
2229 | if os.path.exists(SourceFfsHashDir):\r | |
2230 | for root, dir, files in os.walk(SourceFfsHashDir):\r | |
2231 | for f in files:\r | |
2232 | File = path.join(root, f)\r | |
2233 | self.CacheCopyFile(self.FfsOutputDir, SourceFfsHashDir, File)\r | |
2234 | \r | |
2235 | if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r | |
2236 | CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r | |
2237 | \r | |
2238 | print("[cache hit]: MakeCache:", self.MetaFile.Path, self.Arch)\r | |
2239 | GlobalData.gModuleMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = True\r | |
2240 | return True\r | |
0e7e7a26 | 2241 | \r |
fc8b8dea SS |
2242 | print("[cache miss]: MakeCache:", self.MetaFile.Path, self.Arch)\r |
2243 | GlobalData.gModuleMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
2244 | return False\r | |
0e7e7a26 | 2245 | \r |
fc8b8dea SS |
2246 | ## Decide whether we can skip the left autogen and make process\r |
2247 | def CanSkipbyPreMakeCache(self):\r | |
2248 | # CanSkipbyPreMakeCache consume below dicts:\r | |
2249 | # gModulePreMakeCacheStatus\r | |
2250 | # gHashChainStatus\r | |
2251 | # gModuleHashFile\r | |
2252 | # GenPreMakefileHashList produce gModulePreMakeCacheStatus dict.\r | |
2253 | # all these dicts might be produced in multiprocessing, so\r | |
2254 | # need check these remote dicts\r | |
2255 | \r | |
2256 | if not GlobalData.gUseHashCache or GlobalData.gBinCacheDest:\r | |
0e7e7a26 SS |
2257 | return False\r |
2258 | \r | |
fc8b8dea SS |
2259 | if (self.MetaFile.Path, self.Arch) in GlobalData.gModulePreMakeCacheStatus:\r |
2260 | return GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)]\r | |
94459080 | 2261 | \r |
fc8b8dea | 2262 | # If Module is binary, which has special build rule, do not skip by cache.\r |
0e7e7a26 | 2263 | if self.IsBinaryModule:\r |
fc8b8dea SS |
2264 | print("[cache miss]: PreMakeCache: Skip BinaryModule:", self.MetaFile.Path, self.Arch)\r |
2265 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
0e7e7a26 SS |
2266 | return False\r |
2267 | \r | |
fc8b8dea | 2268 | # see .inc as binary file, do not skip by hash\r |
0e7e7a26 SS |
2269 | for f_ext in self.SourceFileList:\r |
2270 | if '.inc' in str(f_ext):\r | |
fc8b8dea SS |
2271 | print("[cache miss]: PreMakeCache: Skip '.inc' File:", self.MetaFile.Path, self.Arch)\r |
2272 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
0e7e7a26 SS |
2273 | return False\r |
2274 | \r | |
fc8b8dea | 2275 | # For --hash only in the incremental build\r |
56c786b0 | 2276 | if not GlobalData.gBinCacheSource:\r |
fc8b8dea SS |
2277 | Files = [path.join(self.BuildDir, f) for f in os.listdir(self.BuildDir) if path.isfile(path.join(self.BuildDir, f))]\r |
2278 | PreMakeHashFileList_FilePah = None\r | |
2279 | MakeTimeStamp = 0\r | |
2280 | # Find latest PreMakeHashFileList file in self.BuildDir folder\r | |
2281 | for File in Files:\r | |
2282 | if ".PreMakeHashFileList." in File:\r | |
2283 | FileTimeStamp = os.stat(path.join(self.BuildDir, File))[8]\r | |
2284 | if FileTimeStamp > MakeTimeStamp:\r | |
2285 | MakeTimeStamp = FileTimeStamp\r | |
2286 | PreMakeHashFileList_FilePah = File\r | |
2287 | if not PreMakeHashFileList_FilePah:\r | |
2288 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
2289 | return False\r | |
56c786b0 | 2290 | \r |
fc8b8dea SS |
2291 | try:\r |
2292 | with open(LongFilePath(PreMakeHashFileList_FilePah), 'r') as f:\r | |
2293 | PreMakeHashFileList = json.load(f)\r | |
2294 | except:\r | |
2295 | EdkLogger.quiet("[cache error]: fail to load PreMakeHashFileList file: %s" % PreMakeHashFileList_FilePah)\r | |
2296 | print("[cache miss]: PreMakeCache:", self.MetaFile.Path, self.Arch)\r | |
2297 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
2298 | return False\r | |
56c786b0 | 2299 | \r |
fc8b8dea SS |
2300 | HashMiss = False\r |
2301 | for HashChainFile in PreMakeHashFileList:\r | |
2302 | HashChainStatus = None\r | |
2303 | if HashChainFile in GlobalData.gHashChainStatus:\r | |
2304 | HashChainStatus = GlobalData.gHashChainStatus[HashChainFile]\r | |
2305 | if HashChainStatus == False:\r | |
2306 | HashMiss = True\r | |
2307 | break\r | |
2308 | elif HashChainStatus == True:\r | |
2309 | continue\r | |
2310 | if self.CheckHashChainFile(HashChainFile):\r | |
2311 | GlobalData.gHashChainStatus[HashChainFile] = True\r | |
2312 | # Save the module self HashFile for GenPreMakefileHashList later usage\r | |
2313 | if self.Name + ".hashchain." in HashChainFile:\r | |
2314 | GlobalData.gModuleHashFile[(self.MetaFile.Path, self.Arch)] = HashChainFile\r | |
2315 | else:\r | |
2316 | GlobalData.gHashChainStatus[HashChainFile] = False\r | |
2317 | HashMiss = True\r | |
2318 | break\r | |
56c786b0 | 2319 | \r |
fc8b8dea SS |
2320 | if HashMiss:\r |
2321 | print("[cache miss]: PreMakeCache:", self.MetaFile.Path, self.Arch)\r | |
2322 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
2323 | return False\r | |
2324 | else:\r | |
2325 | print("[cache hit]: PreMakeCache:", self.MetaFile.Path, self.Arch)\r | |
2326 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = True\r | |
2327 | return True\r | |
56c786b0 | 2328 | \r |
fc8b8dea SS |
2329 | ModuleCacheDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r |
2330 | FfsDir = path.join(GlobalData.gBinCacheSource, self.PlatformInfo.OutputDir, self.BuildTarget + "_" + self.ToolChain, TAB_FV_DIRECTORY, "Ffs", self.Guid + self.Name)\r | |
56c786b0 SS |
2331 | \r |
2332 | ModuleHashPairList = [] # tuple list: [tuple(PreMakefileHash, MakeHash)]\r | |
fc8b8dea | 2333 | ModuleHashPair = path.join(ModuleCacheDir, self.Name + ".ModuleHashPair")\r |
56c786b0 | 2334 | try:\r |
fc8b8dea | 2335 | with open(LongFilePath(ModuleHashPair), 'r') as f:\r |
94459080 | 2336 | ModuleHashPairList = json.load(f)\r |
56c786b0 | 2337 | except:\r |
fc8b8dea SS |
2338 | # ModuleHashPair might not exist for new added module\r |
2339 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
2340 | EdkLogger.quiet("[cache warning]: fail to load ModuleHashPair file: %s" % ModuleHashPair)\r | |
2341 | print("[cache miss]: PreMakeCache:", self.MetaFile.Path, self.Arch)\r | |
2342 | return False\r | |
56c786b0 | 2343 | \r |
fc8b8dea | 2344 | # Check the PreMakeHash in ModuleHashPairList one by one\r |
56c786b0 | 2345 | for idx, (PreMakefileHash, MakeHash) in enumerate (ModuleHashPairList):\r |
fc8b8dea SS |
2346 | SourceHashDir = path.join(ModuleCacheDir, MakeHash)\r |
2347 | SourceFfsHashDir = path.join(FfsDir, MakeHash)\r | |
2348 | PreMakeHashFileList_FilePah = path.join(ModuleCacheDir, self.Name + ".PreMakeHashFileList." + PreMakefileHash)\r | |
2349 | MakeHashFileList_FilePah = path.join(ModuleCacheDir, self.Name + ".MakeHashFileList." + MakeHash)\r | |
56c786b0 | 2350 | \r |
56c786b0 | 2351 | try:\r |
fc8b8dea SS |
2352 | with open(LongFilePath(PreMakeHashFileList_FilePah), 'r') as f:\r |
2353 | PreMakeHashFileList = json.load(f)\r | |
56c786b0 | 2354 | except:\r |
fc8b8dea SS |
2355 | EdkLogger.quiet("[cache error]: fail to load PreMakeHashFileList file: %s" % PreMakeHashFileList_FilePah)\r |
2356 | continue\r | |
56c786b0 | 2357 | \r |
fc8b8dea SS |
2358 | HashMiss = False\r |
2359 | for HashChainFile in PreMakeHashFileList:\r | |
2360 | HashChainStatus = None\r | |
2361 | if HashChainFile in GlobalData.gHashChainStatus:\r | |
2362 | HashChainStatus = GlobalData.gHashChainStatus[HashChainFile]\r | |
2363 | if HashChainStatus == False:\r | |
2364 | HashMiss = True\r | |
2365 | break\r | |
2366 | elif HashChainStatus == True:\r | |
2367 | continue\r | |
2368 | # Convert to path start with cache source dir\r | |
2369 | RelativePath = os.path.relpath(HashChainFile, self.WorkspaceDir)\r | |
2370 | NewFilePath = os.path.join(GlobalData.gBinCacheSource, RelativePath)\r | |
2371 | if self.CheckHashChainFile(NewFilePath):\r | |
2372 | GlobalData.gHashChainStatus[HashChainFile] = True\r | |
2373 | else:\r | |
2374 | GlobalData.gHashChainStatus[HashChainFile] = False\r | |
2375 | HashMiss = True\r | |
2376 | break\r | |
e8449e1d | 2377 | \r |
fc8b8dea SS |
2378 | if HashMiss:\r |
2379 | continue\r | |
e8449e1d | 2380 | \r |
fc8b8dea SS |
2381 | # PreMakefile cache hit, restore the module build result\r |
2382 | for root, dir, files in os.walk(SourceHashDir):\r | |
2383 | for f in files:\r | |
2384 | File = path.join(root, f)\r | |
2385 | self.CacheCopyFile(self.BuildDir, SourceHashDir, File)\r | |
2386 | if os.path.exists(SourceFfsHashDir):\r | |
2387 | for root, dir, files in os.walk(SourceFfsHashDir):\r | |
2388 | for f in files:\r | |
2389 | File = path.join(root, f)\r | |
2390 | self.CacheCopyFile(self.FfsOutputDir, SourceFfsHashDir, File)\r | |
2391 | \r | |
2392 | if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r | |
2393 | CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r | |
2394 | \r | |
2395 | print("[cache hit]: PreMakeCache:", self.MetaFile.Path, self.Arch)\r | |
2396 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = True\r | |
2397 | return True\r | |
e8449e1d | 2398 | \r |
fc8b8dea SS |
2399 | print("[cache miss]: PreMakeCache:", self.MetaFile.Path, self.Arch)\r |
2400 | GlobalData.gModulePreMakeCacheStatus[(self.MetaFile.Path, self.Arch)] = False\r | |
2401 | return False\r | |
e8449e1d | 2402 | \r |
fc8b8dea SS |
2403 | ## Decide whether we can skip the Module build\r |
2404 | def CanSkipbyCache(self, gHitSet):\r | |
2405 | # Hashing feature is off\r | |
2406 | if not GlobalData.gBinCacheSource:\r | |
0e7e7a26 SS |
2407 | return False\r |
2408 | \r | |
fc8b8dea | 2409 | if self in gHitSet:\r |
0e7e7a26 | 2410 | return True\r |
e8449e1d | 2411 | \r |
0e7e7a26 | 2412 | return False\r |
e8449e1d FB |
2413 | \r |
2414 | ## Decide whether we can skip the ModuleAutoGen process\r | |
2415 | # If any source file is newer than the module than we cannot skip\r | |
2416 | #\r | |
2417 | def CanSkip(self):\r | |
0e7e7a26 SS |
2418 | # Don't skip if cache feature enabled\r |
2419 | if GlobalData.gUseHashCache or GlobalData.gBinCacheDest or GlobalData.gBinCacheSource:\r | |
2420 | return False\r | |
e8449e1d FB |
2421 | if self.MakeFileDir in GlobalData.gSikpAutoGenCache:\r |
2422 | return True\r | |
2423 | if not os.path.exists(self.TimeStampPath):\r | |
2424 | return False\r | |
2425 | #last creation time of the module\r | |
2426 | DstTimeStamp = os.stat(self.TimeStampPath)[8]\r | |
2427 | \r | |
2428 | SrcTimeStamp = self.Workspace._SrcTimeStamp\r | |
2429 | if SrcTimeStamp > DstTimeStamp:\r | |
2430 | return False\r | |
2431 | \r | |
2432 | with open(self.TimeStampPath,'r') as f:\r | |
2433 | for source in f:\r | |
2434 | source = source.rstrip('\n')\r | |
2435 | if not os.path.exists(source):\r | |
2436 | return False\r | |
2437 | if source not in ModuleAutoGen.TimeDict :\r | |
2438 | ModuleAutoGen.TimeDict[source] = os.stat(source)[8]\r | |
2439 | if ModuleAutoGen.TimeDict[source] > DstTimeStamp:\r | |
2440 | return False\r | |
2441 | GlobalData.gSikpAutoGenCache.add(self.MakeFileDir)\r | |
2442 | return True\r | |
2443 | \r | |
2444 | @cached_property\r | |
2445 | def TimeStampPath(self):\r | |
2446 | return os.path.join(self.MakeFileDir, 'AutoGenTimeStamp')\r |