X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FWorkspace%2FDscBuildData.py;h=f50059551e2e6708c2a71903456be5c5c88b35d5;hp=9d787702c2e6624414234a1c55278d6e96152bb4;hb=9e508f3acc10b96e957b277493ee527803b022bb;hpb=1667eec6990fae902981504887546f5a4913fde0 diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index 9d787702c2..f50059551e 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -21,7 +21,7 @@ from Common.String import * from Common.DataType import * from Common.Misc import * from types import * - +from Common.Expression import * from CommonDataClass.CommonClass import SkuInfoClass from Common.TargetTxtClassObject import * from Common.ToolDefClassObject import * @@ -95,6 +95,70 @@ MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C LIBS = -lCommon ''' +## regular expressions for finding decimal and hex numbers +Pattern = re.compile('^[1-9]\d*|0$') +HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$') +## Regular expression for finding header file inclusions +from AutoGen.GenMake import gIncludePattern + +## Find dependencies for one source file +# +# By searching recursively "#include" directive in file, find out all the +# files needed by given source file. The dependecies will be only searched +# in given search path list. +# +# @param SearchPathList The list of search path +# +# @retval list The list of files the given source file depends on +# +def GetDependencyList(FileStack,SearchPathList): + DepDb = dict() + DependencySet = set(FileStack) + while len(FileStack) > 0: + F = FileStack.pop() + FullPathDependList = [] + CurrentFileDependencyList = [] + if F in DepDb: + CurrentFileDependencyList = DepDb[F] + else: + try: + Fd = open(F, 'r') + FileContent = Fd.read() + except BaseException, X: + EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F + "\n\t" + str(X)) + finally: + if "Fd" in dir(locals()): + Fd.close() + + if len(FileContent) == 0: + continue + + if FileContent[0] == 0xff or FileContent[0] == 0xfe: + FileContent = unicode(FileContent, "utf-16") + IncludedFileList = gIncludePattern.findall(FileContent) + + for Inc in IncludedFileList: + Inc = Inc.strip() + Inc = os.path.normpath(Inc) + CurrentFileDependencyList.append(Inc) + DepDb[F] = CurrentFileDependencyList + + CurrentFilePath = os.path.dirname(F) + PathList = [CurrentFilePath] + SearchPathList + for Inc in CurrentFileDependencyList: + for SearchPath in PathList: + FilePath = os.path.join(SearchPath, Inc) + if not os.path.exists(FilePath): + continue + if FilePath not in DependencySet: + FileStack.append(FilePath) + FullPathDependList.append(FilePath) + break + DependencySet.update(FullPathDependList) + DependencyList = list(DependencySet) # remove duplicate ones + + return DependencyList + class DscBuildData(PlatformBuildClassObject): # dict used to convert PCD type in database to string used by build tool _PCD_TYPE_STRING_ = { @@ -218,8 +282,6 @@ class DscBuildData(PlatformBuildClassObject): ## handle Override Path of Module def _HandleOverridePath(self): RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch] - Macros = self._Macros - Macros["EDK_SOURCE"] = GlobalData.gEcpSource for Record in RecordList: ModuleId = Record[6] LineNo = Record[7] @@ -237,7 +299,7 @@ class DscBuildData(PlatformBuildClassObject): ## Get current effective macros def _GetMacros(self): - if self.__Macros == None: + if self.__Macros is None: self.__Macros = {} self.__Macros.update(GlobalData.gPlatformDefines) self.__Macros.update(GlobalData.gGlobalDefines) @@ -307,7 +369,7 @@ class DscBuildData(PlatformBuildClassObject): elif Name == TAB_DSC_DEFINES_BUILD_TARGETS: self._BuildTargets = GetSplitValueList(Record[2]) elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER: - if self._SkuName == None: + if self._SkuName is None: self._SkuName = Record[2] if GlobalData.gSKUID_CMD: self._SkuName = GlobalData.gSKUID_CMD @@ -366,76 +428,76 @@ class DscBuildData(PlatformBuildClassObject): ## Retrieve platform name def _GetPlatformName(self): - if self._PlatformName == None: - if self._Header == None: + if self._PlatformName is None: + if self._Header is None: self._GetHeaderInfo() - if self._PlatformName == None: + if self._PlatformName is None: EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile) return self._PlatformName ## Retrieve file guid def _GetFileGuid(self): - if self._Guid == None: - if self._Header == None: + if self._Guid is None: + if self._Header is None: self._GetHeaderInfo() - if self._Guid == None: + if self._Guid is None: EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_GUID", File=self.MetaFile) return self._Guid ## Retrieve platform version def _GetVersion(self): - if self._Version == None: - if self._Header == None: + if self._Version is None: + if self._Header is None: self._GetHeaderInfo() - if self._Version == None: + if self._Version is None: EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_VERSION", File=self.MetaFile) return self._Version ## Retrieve platform description file version def _GetDscSpec(self): - if self._DscSpecification == None: - if self._Header == None: + if self._DscSpecification is None: + if self._Header is None: self._GetHeaderInfo() - if self._DscSpecification == None: + if self._DscSpecification is None: EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No DSC_SPECIFICATION", File=self.MetaFile) return self._DscSpecification ## Retrieve OUTPUT_DIRECTORY def _GetOutpuDir(self): - if self._OutputDirectory == None: - if self._Header == None: + if self._OutputDirectory is None: + if self._Header is None: self._GetHeaderInfo() - if self._OutputDirectory == None: + if self._OutputDirectory is None: self._OutputDirectory = os.path.join("Build", self._PlatformName) return self._OutputDirectory ## Retrieve SUPPORTED_ARCHITECTURES def _GetSupArch(self): - if self._SupArchList == None: - if self._Header == None: + if self._SupArchList is None: + if self._Header is None: self._GetHeaderInfo() - if self._SupArchList == None: + if self._SupArchList is None: EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No SUPPORTED_ARCHITECTURES", File=self.MetaFile) return self._SupArchList ## Retrieve BUILD_TARGETS def _GetBuildTarget(self): - if self._BuildTargets == None: - if self._Header == None: + if self._BuildTargets is None: + if self._Header is None: self._GetHeaderInfo() - if self._BuildTargets == None: + if self._BuildTargets is None: EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BUILD_TARGETS", File=self.MetaFile) return self._BuildTargets def _GetPcdInfoFlag(self): - if self._PcdInfoFlag == None or self._PcdInfoFlag.upper() == 'FALSE': + if self._PcdInfoFlag is None or self._PcdInfoFlag.upper() == 'FALSE': return False elif self._PcdInfoFlag.upper() == 'TRUE': return True else: return False def _GetVarCheckFlag(self): - if self._VarCheckFlag == None or self._VarCheckFlag.upper() == 'FALSE': + if self._VarCheckFlag is None or self._VarCheckFlag.upper() == 'FALSE': return False elif self._VarCheckFlag.upper() == 'TRUE': return True @@ -444,10 +506,10 @@ class DscBuildData(PlatformBuildClassObject): # # Retrieve SKUID_IDENTIFIER def _GetSkuName(self): - if self._SkuName == None: - if self._Header == None: + if self._SkuName is None: + if self._Header is None: self._GetHeaderInfo() - if self._SkuName == None: + if self._SkuName is None: self._SkuName = 'DEFAULT' return self._SkuName @@ -456,72 +518,72 @@ class DscBuildData(PlatformBuildClassObject): self._SkuName = Value def _GetFdfFile(self): - if self._FlashDefinition == None: - if self._Header == None: + if self._FlashDefinition is None: + if self._Header is None: self._GetHeaderInfo() - if self._FlashDefinition == None: + if self._FlashDefinition is None: self._FlashDefinition = '' return self._FlashDefinition def _GetPrebuild(self): - if self._Prebuild == None: - if self._Header == None: + if self._Prebuild is None: + if self._Header is None: self._GetHeaderInfo() - if self._Prebuild == None: + if self._Prebuild is None: self._Prebuild = '' return self._Prebuild def _GetPostbuild(self): - if self._Postbuild == None: - if self._Header == None: + if self._Postbuild is None: + if self._Header is None: self._GetHeaderInfo() - if self._Postbuild == None: + if self._Postbuild is None: self._Postbuild = '' return self._Postbuild ## Retrieve FLASH_DEFINITION def _GetBuildNumber(self): - if self._BuildNumber == None: - if self._Header == None: + if self._BuildNumber is None: + if self._Header is None: self._GetHeaderInfo() - if self._BuildNumber == None: + if self._BuildNumber is None: self._BuildNumber = '' return self._BuildNumber ## Retrieve MAKEFILE_NAME def _GetMakefileName(self): - if self._MakefileName == None: - if self._Header == None: + if self._MakefileName is None: + if self._Header is None: self._GetHeaderInfo() - if self._MakefileName == None: + if self._MakefileName is None: self._MakefileName = '' return self._MakefileName ## Retrieve BsBaseAddress def _GetBsBaseAddress(self): - if self._BsBaseAddress == None: - if self._Header == None: + if self._BsBaseAddress is None: + if self._Header is None: self._GetHeaderInfo() - if self._BsBaseAddress == None: + if self._BsBaseAddress is None: self._BsBaseAddress = '' return self._BsBaseAddress ## Retrieve RtBaseAddress def _GetRtBaseAddress(self): - if self._RtBaseAddress == None: - if self._Header == None: + if self._RtBaseAddress is None: + if self._Header is None: self._GetHeaderInfo() - if self._RtBaseAddress == None: + if self._RtBaseAddress is None: self._RtBaseAddress = '' return self._RtBaseAddress ## Retrieve the top address for the load fix address def _GetLoadFixAddress(self): - if self._LoadFixAddress == None: - if self._Header == None: + if self._LoadFixAddress is None: + if self._Header is None: self._GetHeaderInfo() - if self._LoadFixAddress == None: + if self._LoadFixAddress is None: self._LoadFixAddress = self._Macros.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS, '0') try: @@ -547,34 +609,34 @@ class DscBuildData(PlatformBuildClassObject): ## Retrieve RFCLanguage filter def _GetRFCLanguages(self): - if self._RFCLanguages == None: - if self._Header == None: + if self._RFCLanguages is None: + if self._Header is None: self._GetHeaderInfo() - if self._RFCLanguages == None: + if self._RFCLanguages is None: self._RFCLanguages = [] return self._RFCLanguages ## Retrieve ISOLanguage filter def _GetISOLanguages(self): - if self._ISOLanguages == None: - if self._Header == None: + if self._ISOLanguages is None: + if self._Header is None: self._GetHeaderInfo() - if self._ISOLanguages == None: + if self._ISOLanguages is None: self._ISOLanguages = [] return self._ISOLanguages ## Retrieve the GUID string for VPD tool def _GetVpdToolGuid(self): - if self._VpdToolGuid == None: - if self._Header == None: + if self._VpdToolGuid is None: + if self._Header is None: self._GetHeaderInfo() - if self._VpdToolGuid == None: + if self._VpdToolGuid is None: self._VpdToolGuid = '' return self._VpdToolGuid ## Retrieve [SkuIds] section information def _GetSkuIds(self): - if self._SkuIds == None: - self._SkuIds = sdict() + if self._SkuIds is None: + self._SkuIds = OrderedDict() RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch] for Record in RecordList: if Record[0] in [None, '']: @@ -583,25 +645,26 @@ class DscBuildData(PlatformBuildClassObject): if Record[1] in [None, '']: EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name', File=self.MetaFile, Line=Record[-1]) - Pattern = re.compile('^[1-9]\d*|0$') - HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$') - if Pattern.match(Record[0]) == None and HexPattern.match(Record[0]) == None: + if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]): EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID number is invalid. It only support Integer and HexNumber", File=self.MetaFile, Line=Record[-1]) if not IsValidWord(Record[1]): EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'", File=self.MetaFile, Line=Record[-1]) - self._SkuIds[Record[1].upper()] = (str(self.ToInt(Record[0])), Record[1].upper(), Record[2].upper()) + self._SkuIds[Record[1].upper()] = (str(DscBuildData.ToInt(Record[0])), Record[1].upper(), Record[2].upper()) if 'DEFAULT' not in self._SkuIds: self._SkuIds['DEFAULT'] = ("0","DEFAULT","DEFAULT") if 'COMMON' not in self._SkuIds: self._SkuIds['COMMON'] = ("0","DEFAULT","DEFAULT") return self._SkuIds - def ToInt(self,intstr): + + @staticmethod + def ToInt(intstr): return int(intstr,16) if intstr.upper().startswith("0X") else int(intstr) + def _GetDefaultStores(self): - if self.DefaultStores == None: - self.DefaultStores = sdict() + if self.DefaultStores is None: + self.DefaultStores = OrderedDict() RecordList = self._RawData[MODEL_EFI_DEFAULT_STORES, self._Arch] for Record in RecordList: if Record[0] in [None, '']: @@ -610,15 +673,13 @@ class DscBuildData(PlatformBuildClassObject): if Record[1] in [None, '']: EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name', File=self.MetaFile, Line=Record[-1]) - Pattern = re.compile('^[1-9]\d*|0$') - HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$') - if Pattern.match(Record[0]) == None and HexPattern.match(Record[0]) == None: + if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]): EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber", File=self.MetaFile, Line=Record[-1]) if not IsValidWord(Record[1]): EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'", File=self.MetaFile, Line=Record[-1]) - self.DefaultStores[Record[1].upper()] = (self.ToInt(Record[0]),Record[1].upper()) + self.DefaultStores[Record[1].upper()] = (DscBuildData.ToInt(Record[0]),Record[1].upper()) if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores: self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] = (0,TAB_DEFAULT_STORES_DEFAULT) GlobalData.gDefaultStores = self.DefaultStores.keys() @@ -628,10 +689,10 @@ class DscBuildData(PlatformBuildClassObject): ## Retrieve [Components] section information def _GetModules(self): - if self._Modules != None: + if self._Modules is not None: return self._Modules - self._Modules = sdict() + self._Modules = OrderedDict() RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch] Macros = self._Macros Macros["EDK_SOURCE"] = GlobalData.gEcpSource @@ -727,13 +788,13 @@ class DscBuildData(PlatformBuildClassObject): ## Retrieve all possible library instances used in this platform def _GetLibraryInstances(self): - if self._LibraryInstances == None: + if self._LibraryInstances is None: self._GetLibraryClasses() return self._LibraryInstances ## Retrieve [LibraryClasses] information def _GetLibraryClasses(self): - if self._LibraryClasses == None: + if self._LibraryClasses is None: self._LibraryInstances = [] # # tdict is a special dict kind of type, used for selecting correct @@ -771,7 +832,7 @@ class DscBuildData(PlatformBuildClassObject): # try all possible module types for ModuleType in SUP_MODULE_LIST: LibraryInstance = LibraryClassDict[self._Arch, ModuleType, LibraryClass] - if LibraryInstance == None: + if LibraryInstance is None: continue self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance @@ -798,7 +859,7 @@ class DscBuildData(PlatformBuildClassObject): return self._LibraryClasses def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo): - if self._DecPcds == None: + if self._DecPcds is None: FdfInfList = [] if GlobalData.gFdfParser: @@ -886,55 +947,25 @@ class DscBuildData(PlatformBuildClassObject): for pcd in HiiPcd: for skuid in pcd.SkuInfoList: skuobj = pcd.SkuInfoList.get(skuid) - if "STANDARD" not in skuobj.DefaultStoreDict: + if TAB_DEFAULT_STORES_DEFAULT not in skuobj.DefaultStoreDict: PcdDefaultStoreSet = set([defaultstorename for defaultstorename in skuobj.DefaultStoreDict]) mindefaultstorename = DefaultStoreMgr.GetMin(PcdDefaultStoreSet) - skuobj.DefaultStoreDict['STANDARD'] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename]) + skuobj.DefaultStoreDict[TAB_DEFAULT_STORES_DEFAULT] = copy.deepcopy(skuobj.DefaultStoreDict[mindefaultstorename]) return Pcds def RecoverCommandLinePcd(self): - pcdset = [] - if GlobalData.BuildOptionPcd: - for pcd in GlobalData.BuildOptionPcd: - if pcd[2] == "": - pcdset.append((pcd[0],pcd[1],pcd[3])) - else: - if (pcd[1],pcd[0]) not in self._Pcds: - pcdvalue = pcd[3] if len(pcd) == 4 else pcd[2] - pcdset.append((pcd[0],pcd[1],pcdvalue)) - #else: - # remove the settings from command line since it has been handled. - GlobalData.BuildOptionPcd = pcdset - def GetFieldValueFromComm(self,ValueStr,TokenSpaceGuidCName, TokenCName, FieldName): - PredictedFieldType = "VOID*" - if ValueStr.startswith('L'): - if not ValueStr[1]: - EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"') - ValueStr = ValueStr[0] + '"' + ValueStr[1:] + '"' - PredictedFieldType = "VOID*" - elif ValueStr.startswith('H') or ValueStr.startswith('{'): - EdkLogger.error("build", FORMAT_INVALID, 'Currently we do not support assign H"{...}" format for Pcd field.', ExtraData="%s.%s.%s from command line" % (TokenSpaceGuidCName, TokenCName, FieldName)) - ValueStr = ValueStr[1:] - PredictedFieldType = "VOID*" - elif ValueStr.upper() in ['TRUE', '0X1', '0X01', '1', 'FALSE', '0X0', '0X00', '0']: - PredictedFieldType = "BOOLEAN" - elif ValueStr.isdigit() or ValueStr.upper().startswith('0X'): - PredictedFieldType = TAB_UINT16 - else: - if not ValueStr[0]: - EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"') - ValueStr = '"' + ValueStr + '"' - PredictedFieldType = "VOID*" - IsValid, Cause = CheckPcdDatum(PredictedFieldType, ValueStr) - if not IsValid: - EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s.%s from command line" % (TokenSpaceGuidCName, TokenCName, FieldName)) - if PredictedFieldType == 'BOOLEAN': - ValueStr = ValueStr.upper() - if ValueStr == 'TRUE' or ValueStr == '1': - ValueStr = '1' - elif ValueStr == 'FALSE' or ValueStr == '0': - ValueStr = '0' - return ValueStr + def UpdateCommandLineValue(pcd): + if pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], + self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: + pcd.PcdValueFromComm = pcd.DefaultValue + elif pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]: + pcd.PcdValueFromComm = pcd.SkuInfoList.get("DEFAULT").HiiDefaultValue + else: + pcd.PcdValueFromComm = pcd.SkuInfoList.get("DEFAULT").DefaultValue + for pcd in self._Pcds: + if isinstance(self._Pcds[pcd],StructurePcd) and (self._Pcds[pcd].PcdValueFromComm or self._Pcds[pcd].PcdFieldValueFromComm): + UpdateCommandLineValue(self._Pcds[pcd]) + def __ParsePcdFromCommandLine(self): if GlobalData.BuildOptionPcd: for i, pcd in enumerate(GlobalData.BuildOptionPcd): @@ -975,152 +1006,124 @@ class DscBuildData(PlatformBuildClassObject): TokenSpaceGuidCNameList = [] FoundFlag = False PcdDatumType = '' - NewValue = '' + DisplayName = TokenCName + if FieldName: + DisplayName = TokenCName + '.' + FieldName if not HasTokenSpace: for key in self.DecPcds: - if TokenCName == key[0]: - if TokenSpaceGuidCName: - EdkLogger.error( - 'build', - AUTOGEN_ERROR, - "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, TokenSpaceGuidCName, key[1]) - ) - else: - TokenSpaceGuidCName = key[1] - FoundFlag = True + PcdItem = self.DecPcds[key] + if TokenCName == PcdItem.TokenCName: + if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList: + if len (TokenSpaceGuidCNameList) < 1: + TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName) + TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName + PcdDatumType = PcdItem.DatumType + FoundFlag = True + else: + EdkLogger.error( + 'build', + AUTOGEN_ERROR, + "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (DisplayName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0]) + ) else: if (TokenCName, TokenSpaceGuidCName) in self.DecPcds: + PcdDatumType = self.DecPcds[(TokenCName, TokenSpaceGuidCName)].DatumType FoundFlag = True - if FieldName: - NewValue = self.GetFieldValueFromComm(pcdvalue, TokenSpaceGuidCName, TokenCName, FieldName) - GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName,NewValue,("build command options",1)) - else: - # Replace \' to ', \\\' to \' - pcdvalue = pcdvalue.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'") - for key in self.DecPcds: - PcdItem = self.DecPcds[key] - if HasTokenSpace: - if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName): - PcdDatumType = PcdItem.DatumType - if pcdvalue.startswith('H'): - try: - pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']: - pcdvalue = 'H' + pcdvalue - elif pcdvalue.startswith("L'"): - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']: - pcdvalue = 'H' + pcdvalue - elif pcdvalue.startswith("'"): - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']: - pcdvalue = 'H' + pcdvalue - elif pcdvalue.startswith('L'): - pcdvalue = 'L"' + pcdvalue[1:] + '"' - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - else: - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - try: - pcdvalue = '"' + pcdvalue + '"' - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue) - FoundFlag = True - else: - if PcdItem.TokenCName == TokenCName: - if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList: - if len (TokenSpaceGuidCNameList) < 1: - TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName) - PcdDatumType = PcdItem.DatumType - TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName - if pcdvalue.startswith('H'): - try: - pcdvalue = ValueExpressionEx(pcdvalue[1:], PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64,'BOOLEAN']: - pcdvalue = 'H' + pcdvalue - elif pcdvalue.startswith("L'"): - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)( - True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']: - pcdvalue = 'H' + pcdvalue - elif pcdvalue.startswith("'"): - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)( - True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - if PcdDatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, 'BOOLEAN']: - pcdvalue = 'H' + pcdvalue - elif pcdvalue.startswith('L'): - pcdvalue = 'L"' + pcdvalue[1:] + '"' - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)( - True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - else: - try: - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - try: - pcdvalue = '"' + pcdvalue + '"' - pcdvalue = ValueExpressionEx(pcdvalue, PcdDatumType, self._GuidDict)(True) - except BadExpression, Value: - EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % - (TokenSpaceGuidCName, TokenCName, pcdvalue, Value)) - NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue) - FoundFlag = True - else: - EdkLogger.error( - 'build', - AUTOGEN_ERROR, - "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0]) - ) - GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName,NewValue,("build command options",1)) if not FoundFlag: if HasTokenSpace: - EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName)) + EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, DisplayName)) else: - EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName)) + EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (DisplayName)) + pcdvalue = pcdvalue.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'") + if FieldName: + pcdvalue = DscBuildData.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict, FieldName) + else: + pcdvalue = DscBuildData.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict) + IsValid, Cause = CheckPcdDatum(PcdDatumType, pcdvalue) + if not IsValid: + EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName)) + GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, FieldName, pcdvalue,("build command options",1)) + for BuildData in self._Bdb._CACHE_.values(): if BuildData.MetaFile.Ext == '.dec' or BuildData.MetaFile.Ext == '.dsc': continue for key in BuildData.Pcds: PcdItem = BuildData.Pcds[key] if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName) and FieldName =="": - PcdItem.DefaultValue = NewValue + PcdItem.DefaultValue = pcdvalue + + @staticmethod + def HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''): + if FieldName: + IsArray = False + TokenCName += '.' + FieldName + if PcdValue.startswith('H'): + if FieldName and IsFieldValueAnArray(PcdValue[1:]): + PcdDatumType = 'VOID*' + IsArray = True + if FieldName and not IsArray: + return PcdValue + try: + PcdValue = ValueExpressionEx(PcdValue[1:], PcdDatumType, GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % + (TokenSpaceGuidCName, TokenCName, PcdValue, Value)) + elif PcdValue.startswith("L'") or PcdValue.startswith("'"): + if FieldName and IsFieldValueAnArray(PcdValue): + PcdDatumType = 'VOID*' + IsArray = True + if FieldName and not IsArray: + return PcdValue + try: + PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % + (TokenSpaceGuidCName, TokenCName, PcdValue, Value)) + elif PcdValue.startswith('L'): + PcdValue = 'L"' + PcdValue[1:] + '"' + if FieldName and IsFieldValueAnArray(PcdValue): + PcdDatumType = 'VOID*' + IsArray = True + if FieldName and not IsArray: + return PcdValue + try: + PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % + (TokenSpaceGuidCName, TokenCName, PcdValue, Value)) + else: + if PcdValue.upper() == 'FALSE': + PcdValue = str(0) + if PcdValue.upper() == 'TRUE': + PcdValue = str(1) + if not FieldName: + if PcdDatumType not in ['UINT8','UINT16','UINT32','UINT64','BOOLEAN']: + PcdValue = '"' + PcdValue + '"' + else: + IsArray = False + Base = 10 + if PcdValue.upper().startswith('0X'): + Base = 16 + try: + Num = int(PcdValue, Base) + except: + PcdValue = '"' + PcdValue + '"' + if IsFieldValueAnArray(PcdValue): + PcdDatumType = 'VOID*' + IsArray = True + if not IsArray: + return PcdValue + try: + PcdValue = ValueExpressionEx(PcdValue, PcdDatumType, GuidDict)(True) + except BadExpression, Value: + EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % + (TokenSpaceGuidCName, TokenCName, PcdValue, Value)) + return PcdValue + ## Retrieve all PCD settings in platform def _GetPcds(self): - if self._Pcds == None: - self._Pcds = sdict() + if self._Pcds is None: + self._Pcds = OrderedDict() self.__ParsePcdFromCommandLine() self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD)) self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE)) @@ -1141,21 +1144,10 @@ class DscBuildData(PlatformBuildClassObject): self.RecoverCommandLinePcd() return self._Pcds - def _dumpPcdInfo(self,Pcds): - for pcd in Pcds: - pcdobj = Pcds[pcd] - if not pcdobj.TokenCName.startswith("Test"): - continue - for skuid in pcdobj.SkuInfoList: - if pcdobj.Type in (self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]): - for storename in pcdobj.SkuInfoList[skuid].DefaultStoreDict: - print "PcdCName: %s, SkuName: %s, StoreName: %s, Value: %s" % (".".join((pcdobj.TokenSpaceGuidCName, pcdobj.TokenCName)), skuid,storename,str(pcdobj.SkuInfoList[skuid].DefaultStoreDict[storename])) - else: - print "PcdCName: %s, SkuName: %s, Value: %s" % (".".join((pcdobj.TokenSpaceGuidCName, pcdobj.TokenCName)), skuid,str(pcdobj.SkuInfoList[skuid].DefaultValue)) ## Retrieve [BuildOptions] def _GetBuildOptions(self): - if self._BuildOptions == None: - self._BuildOptions = sdict() + if self._BuildOptions is None: + self._BuildOptions = OrderedDict() # # Retrieve build option for EDKII and EDK style module # @@ -1176,10 +1168,10 @@ class DscBuildData(PlatformBuildClassObject): return self._BuildOptions def GetBuildOptionsByModuleType(self, Edk, ModuleType): - if self._ModuleTypeOptions == None: - self._ModuleTypeOptions = sdict() + if self._ModuleTypeOptions is None: + self._ModuleTypeOptions = OrderedDict() if (Edk, ModuleType) not in self._ModuleTypeOptions: - options = sdict() + options = OrderedDict() self._ModuleTypeOptions[Edk, ModuleType] = options DriverType = '%s.%s' % (Edk, ModuleType) CommonDriverType = '%s.%s' % ('COMMON', ModuleType) @@ -1203,7 +1195,9 @@ class DscBuildData(PlatformBuildClassObject): structure_pcd_data[(item[0],item[1])].append(item) return structure_pcd_data - def OverrideByFdfComm(self,StruPcds): + + @staticmethod + def OverrideByFdfComm(StruPcds): StructurePcdInCom = OrderedDict() for item in GlobalData.BuildOptionPcd: if len(item) == 5 and (item[1],item[0]) in StruPcds: @@ -1223,6 +1217,7 @@ class DscBuildData(PlatformBuildClassObject): Pcd.PcdFieldValueFromComm[field][1] = FieldValues[field][1][0] Pcd.PcdFieldValueFromComm[field][2] = FieldValues[field][1][1] return StruPcds + def OverrideByFdfCommOverAll(self,AllPcds): def CheckStructureInComm(commpcds): if not commpcds: @@ -1242,6 +1237,7 @@ class DscBuildData(PlatformBuildClassObject): if isinstance(self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName), None),StructurePcd): self._DecPcds.get((Pcd.TokenCName,Pcd.TokenSpaceGuidCName)).PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0] else: + Pcd.PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0] Pcd.DefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0] for sku in Pcd.SkuInfoList: SkuInfo = Pcd.SkuInfoList[sku] @@ -1251,26 +1247,21 @@ class DscBuildData(PlatformBuildClassObject): SkuInfo.HiiDefaultValue = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0] for defaultstore in SkuInfo.DefaultStoreDict: SkuInfo.DefaultStoreDict[defaultstore] = NoFiledValues[(Pcd.TokenSpaceGuidCName,Pcd.TokenCName)][0] - if Pcd.DatumType == "VOID*": - if Pcd.MaxDatumSize is None: - Pcd.MaxDatumSize = '0' - MaxSize = int(Pcd.MaxDatumSize,10) - if Pcd.DefaultValue.startswith("{") and Pcd.DefaultValue.endswith("}"): - MaxSize = max([len(Pcd.DefaultValue.split(",")),MaxSize]) - elif Pcd.DefaultValue.startswith("\"") or Pcd.DefaultValue.startswith("\'"): - MaxSize = max([len(Pcd.DefaultValue)-2+1,MaxSize]) - elif Pcd.DefaultValue.startswith("L\""): - MaxSize = max([2*(len(Pcd.DefaultValue)-3+1),MaxSize]) - else: - MaxSize = max([len(Pcd.DefaultValue),MaxSize]) - Pcd.MaxDatumSize = str(MaxSize) + if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII]]: + if Pcd.DatumType == "VOID*": + if not Pcd.MaxDatumSize: + Pcd.MaxDatumSize = '0' + CurrentSize = int(Pcd.MaxDatumSize,16) if Pcd.MaxDatumSize.upper().startswith("0X") else int(Pcd.MaxDatumSize) + OptionSize = len((StringToArray(Pcd.PcdValueFromComm)).split(",")) + MaxSize = max(CurrentSize, OptionSize) + Pcd.MaxDatumSize = str(MaxSize) else: PcdInDec = self.DecPcds.get((Name,Guid)) - if isinstance(PcdInDec,StructurePcd): - PcdInDec.PcdValueFromComm = NoFiledValues[(Guid,Name)][0] if PcdInDec: + PcdInDec.PcdValueFromComm = NoFiledValues[(Guid,Name)][0] if PcdInDec.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], - self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: + self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE], + self._PCD_TYPE_STRING_[MODEL_PCD_FEATURE_FLAG]]: self.Pcds[Name, Guid] = copy.deepcopy(PcdInDec) self.Pcds[Name, Guid].DefaultValue = NoFiledValues[( Guid,Name)][0] return AllPcds @@ -1327,7 +1318,7 @@ class DscBuildData(PlatformBuildClassObject): str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList} for str_pcd_data in StrPcdSet[str_pcd]: if str_pcd_data[3] in SkuIds: - str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],'STANDARD' if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:],LineNo=str_pcd_data[5]) + str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], str(str_pcd_data[6]), 'DEFAULT' if str_pcd_data[3] == 'COMMON' else str_pcd_data[3],TAB_DEFAULT_STORES_DEFAULT if str_pcd_data[4] == 'COMMON' else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:],LineNo=str_pcd_data[5]) S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str else: EdkLogger.error('build', PARSER_ERROR, @@ -1361,7 +1352,7 @@ class DscBuildData(PlatformBuildClassObject): NoDefault = True break nextskuid = self.SkuIdMgr.GetNextSkuId(nextskuid) - stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {'STANDARD':stru_pcd.DefaultValues}) + stru_pcd.SkuOverrideValues[skuid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid]) if not NoDefault else copy.deepcopy({defaultstorename: stru_pcd.DefaultValues for defaultstorename in DefaultStores} if DefaultStores else {TAB_DEFAULT_STORES_DEFAULT:stru_pcd.DefaultValues}) if not NoDefault: stru_pcd.ValueChain[(skuid,'')]= (nextskuid,'') if stru_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]: @@ -1383,7 +1374,7 @@ class DscBuildData(PlatformBuildClassObject): if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]: stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename]) stru_pcd.ValueChain[(skuid,defaultstoreid)]= (nextskuid,mindefaultstorename) - S_pcd_set = self.OverrideByFdfComm(S_pcd_set) + S_pcd_set = DscBuildData.OverrideByFdfComm(S_pcd_set) Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set) if Str_Pcd_Values: for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values: @@ -1448,7 +1439,7 @@ class DscBuildData(PlatformBuildClassObject): # @retval a dict object contains settings of given PCD type # def _GetPcd(self, Type): - Pcds = sdict() + Pcds = OrderedDict() # # tdict is a special dict kind of type, used for selecting correct # PCD settings for certain ARCH @@ -1459,7 +1450,7 @@ class DscBuildData(PlatformBuildClassObject): PcdSet = set() # Find out all possible PCD candidates for self._Arch RecordList = self._RawData[Type, self._Arch] - PcdValueDict = sdict() + PcdValueDict = OrderedDict() for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4,Dummy5 in RecordList: SkuName = SkuName.upper() SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName @@ -1473,7 +1464,7 @@ class DscBuildData(PlatformBuildClassObject): for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet: Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName] - if Setting == None: + if Setting is None: continue PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4) if (PcdCName, TokenSpaceGuid) in PcdValueDict: @@ -1511,26 +1502,6 @@ class DscBuildData(PlatformBuildClassObject): return Pcds - def __UNICODE2OCTList(self,Value): - Value = Value.strip() - Value = Value[2:-1] - List = [] - for Item in Value: - Temp = '%04X' % ord(Item) - List.append('0x' + Temp[2:4]) - List.append('0x' + Temp[0:2]) - List.append('0x00') - List.append('0x00') - return List - def __STRING2OCTList(self,Value): - OCTList = [] - Value = Value.strip('"') - for char in Value: - Temp = '%02X' % ord(char) - OCTList.append('0x' + Temp) - OCTList.append('0x00') - return OCTList - def GetStructurePcdMaxSize(self, str_pcd): pcd_default_value = str_pcd.DefaultValue sku_values = [skuobj.HiiDefaultValue if str_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]] else skuobj.DefaultValue for skuobj in str_pcd.SkuInfoList.values()] @@ -1555,23 +1526,8 @@ class DscBuildData(PlatformBuildClassObject): return str(max([pcd_size for pcd_size in [get_length(item) for item in sku_values]])) - def IsFieldValueAnArray (self, Value): - Value = Value.strip() - if Value.startswith('GUID') and Value.endswith(')'): - return True - if Value.startswith('L"') and Value.endswith('"') and len(list(Value[2:-1])) > 1: - return True - if Value[0] == '"' and Value[-1] == '"' and len(list(Value[1:-1])) > 1: - return True - if Value[0] == '{' and Value[-1] == '}': - return True - if Value.startswith("L'") and Value.endswith("'") and len(list(Value[2:-1])) > 1: - return True - if Value[0] == "'" and Value[-1] == "'" and len(list(Value[1:-1])) > 1: - return True - return False - - def ExecuteCommand (self, Command): + @staticmethod + def ExecuteCommand (Command): try: Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) except: @@ -1579,7 +1535,8 @@ class DscBuildData(PlatformBuildClassObject): Result = Process.communicate() return Process.returncode, Result[0], Result[1] - def IntToCString(self, Value, ValueSize): + @staticmethod + def IntToCString(Value, ValueSize): Result = '"' if not isinstance (Value, str): for Index in range(0, ValueSize): @@ -1588,7 +1545,8 @@ class DscBuildData(PlatformBuildClassObject): Result = Result + '"' return Result - def GetPcdMaxSize(self,Pcd): + @staticmethod + def GetPcdMaxSize(Pcd): MaxSize = int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0 if Pcd.DatumType not in ['BOOLEAN','UINT8','UINT16','UINT32','UINT64']: if Pcd.PcdValueFromComm: @@ -1609,6 +1567,7 @@ class DscBuildData(PlatformBuildClassObject): elif Pcd.DatumType == 'UINT64': MaxSize = 8 return MaxSize + def GenerateSizeFunction(self,Pcd): CApp = "// Default Value in Dec \n" CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) @@ -1617,7 +1576,7 @@ class DscBuildData(PlatformBuildClassObject): continue for FieldName in FieldList: FieldName = "." + FieldName - IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0]) + IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0]) if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')): try: Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True) @@ -1647,7 +1606,7 @@ class DscBuildData(PlatformBuildClassObject): continue for FieldName in FieldList: FieldName = "." + FieldName - IsArray = self.IsFieldValueAnArray(FieldList[FieldName.strip(".")][0]) + IsArray = IsFieldValueAnArray(FieldList[FieldName.strip(".")][0]) if IsArray and not (FieldList[FieldName.strip(".")][0].startswith('{GUID') and FieldList[FieldName.strip(".")][0].endswith('}')): try: Value = ValueExpressionEx(FieldList[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True) @@ -1671,7 +1630,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + "// From Command Line \n" for FieldName in Pcd.PcdFieldValueFromComm: FieldName = "." + FieldName - IsArray = self.IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]) + IsArray = IsFieldValueAnArray(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0]) if IsArray and not (Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].startswith('{GUID') and Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0].endswith('}')): try: Value = ValueExpressionEx(Pcd.PcdFieldValueFromComm[FieldName.strip(".")][0], "VOID*", self._GuidDict)(True) @@ -1691,26 +1650,30 @@ class DscBuildData(PlatformBuildClassObject): while '[' in FieldName: FieldName = FieldName.rsplit('[', 1)[0] CApp = CApp + ' __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0]) - CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (self.GetPcdMaxSize(Pcd),self.GetPcdMaxSize(Pcd),self.GetPcdMaxSize(Pcd)) + CApp = CApp + " *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd)) CApp = CApp + "}\n" return CApp - def GenerateSizeStatments(self,Pcd): + + @staticmethod + def GenerateSizeStatments(Pcd): CApp = ' Size = sizeof(%s);\n' % (Pcd.DatumType) CApp = CApp + ' Cal_%s_%s_Size(&Size);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) return CApp + def GenerateDefaultValueAssignFunction(self,Pcd): CApp = "// Default value in Dec \n" CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType) CApp = CApp + ' UINT32 FieldSize;\n' CApp = CApp + ' CHAR8 *Value;\n' DefaultValueFromDec = Pcd.DefaultValueFromDec - IsArray = self.IsFieldValueAnArray(Pcd.DefaultValueFromDec) + IsArray = IsFieldValueAnArray(Pcd.DefaultValueFromDec) if IsArray: try: DefaultValueFromDec = ValueExpressionEx(Pcd.DefaultValueFromDec, "VOID*")(True) except BadExpression: EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DEC: %s" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, DefaultValueFromDec)) + DefaultValueFromDec = StringToArray(DefaultValueFromDec) Value, ValueSize = ParseFieldValue (DefaultValueFromDec) if isinstance(Value, str): CApp = CApp + ' Pcd = %s; // From DEC Default Value %s\n' % (Value, Pcd.DefaultValueFromDec) @@ -1718,13 +1681,13 @@ class DscBuildData(PlatformBuildClassObject): # # Use memcpy() to copy value into field # - CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec) + CApp = CApp + ' Value = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec) CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) for FieldList in [Pcd.DefaultValues]: if not FieldList: continue for FieldName in FieldList: - IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0]) + IsArray = IsFieldValueAnArray(FieldList[FieldName][0]) if IsArray: try: FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True) @@ -1743,7 +1706,7 @@ class DscBuildData(PlatformBuildClassObject): # Use memcpy() to copy value into field # CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName) - CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) + CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) else: if ValueSize > 4: @@ -1752,19 +1715,22 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + "}\n" return CApp - def GenerateDefaultValueAssignStatement(self,Pcd): + + @staticmethod + def GenerateDefaultValueAssignStatement(Pcd): CApp = ' Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) return CApp + def GenerateInitValueFunction(self,Pcd,SkuName,DefaultStoreName): CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName,DefaultStoreName) CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,DefaultStoreName,Pcd.DatumType) CApp = CApp + ' UINT32 FieldSize;\n' CApp = CApp + ' CHAR8 *Value;\n' - CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % ('DEFAULT', 'STANDARD') + CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % ('DEFAULT', TAB_DEFAULT_STORES_DEFAULT) inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName] - if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'): - pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue + if (SkuName,DefaultStoreName) == ('DEFAULT',TAB_DEFAULT_STORES_DEFAULT): + pcddefaultvalue = Pcd.DefaultFromDSC.get('DEFAULT',{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue else: if not Pcd.DscRawValue: # handle the case that structure pcd is not appear in DSC @@ -1774,7 +1740,7 @@ class DscBuildData(PlatformBuildClassObject): if not FieldList: continue if pcddefaultvalue and FieldList == pcddefaultvalue: - IsArray = self.IsFieldValueAnArray(FieldList) + IsArray = IsFieldValueAnArray(FieldList) if IsArray: try: FieldList = ValueExpressionEx(FieldList, "VOID*")(True) @@ -1783,14 +1749,14 @@ class DscBuildData(PlatformBuildClassObject): (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList)) Value, ValueSize = ParseFieldValue (FieldList) - if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD'): + if (SkuName,DefaultStoreName) == ('DEFAULT',TAB_DEFAULT_STORES_DEFAULT): if isinstance(Value, str): - CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp = CApp + ' Pcd = %s; // From DSC Default Value %s\n' % (Value, Pcd.DefaultFromDSC.get('DEFAULT',{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) elif IsArray: # # Use memcpy() to copy value into field # - CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) + CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get(TAB_DEFAULT_STORES_DEFAULT, Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue) CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) else: if isinstance(Value, str): @@ -1799,12 +1765,12 @@ class DscBuildData(PlatformBuildClassObject): # # Use memcpy() to copy value into field # - CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName)) + CApp = CApp + ' Value = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName)) CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) continue - if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD') or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )): + if (SkuName,DefaultStoreName) == ('DEFAULT',TAB_DEFAULT_STORES_DEFAULT) or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )): for FieldName in FieldList: - IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0]) + IsArray = IsFieldValueAnArray(FieldList[FieldName][0]) if IsArray: try: FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True) @@ -1822,7 +1788,7 @@ class DscBuildData(PlatformBuildClassObject): # Use memcpy() to copy value into field # CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName) - CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) + CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) else: if ValueSize > 4: @@ -1831,9 +1797,12 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + "}\n" return CApp - def GenerateInitValueStatement(self,Pcd,SkuName,DefaultStoreName): + + @staticmethod + def GenerateInitValueStatement(Pcd,SkuName,DefaultStoreName): CApp = ' Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,DefaultStoreName) return CApp + def GenerateCommandLineValue(self,Pcd): CApp = "// Value in CommandLine\n" CApp = CApp + "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType) @@ -1845,12 +1814,12 @@ class DscBuildData(PlatformBuildClassObject): if not FieldList: continue if pcddefaultvalue and FieldList == pcddefaultvalue: - IsArray = self.IsFieldValueAnArray(FieldList) + IsArray = IsFieldValueAnArray(FieldList) if IsArray: try: FieldList = ValueExpressionEx(FieldList, "VOID*")(True) except BadExpression: - EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from DSC: %s" % + EdkLogger.error("Build", FORMAT_INVALID, "Invalid value format for %s.%s, from Command: %s" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, FieldList)) Value, ValueSize = ParseFieldValue (FieldList) @@ -1860,11 +1829,11 @@ class DscBuildData(PlatformBuildClassObject): # # Use memcpy() to copy value into field # - CApp = CApp + ' Value = %s; // From Command Line.\n' % (self.IntToCString(Value, ValueSize)) + CApp = CApp + ' Value = %s; // From Command Line.\n' % (DscBuildData.IntToCString(Value, ValueSize)) CApp = CApp + ' memcpy (Pcd, Value, %d);\n' % (ValueSize) continue for FieldName in FieldList: - IsArray = self.IsFieldValueAnArray(FieldList[FieldName][0]) + IsArray = IsFieldValueAnArray(FieldList[FieldName][0]) if IsArray: try: FieldList[FieldName][0] = ValueExpressionEx(FieldList[FieldName][0], "VOID*", self._GuidDict)(True) @@ -1884,7 +1853,7 @@ class DscBuildData(PlatformBuildClassObject): # Use memcpy() to copy value into field # CApp = CApp + ' FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName) - CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) + CApp = CApp + ' Value = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + ' memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize) else: if ValueSize > 4: @@ -1893,9 +1862,12 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + ' Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0]) CApp = CApp + "}\n" return CApp - def GenerateCommandLineValueStatement(self,Pcd): + + @staticmethod + def GenerateCommandLineValueStatement(Pcd): CApp = ' Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) return CApp + def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteValue, CApp): OverrideValues = {DefaultStore:""} if Pcd.SkuOverrideValues: @@ -1935,7 +1907,7 @@ class DscBuildData(PlatformBuildClassObject): # in a structure. The size formula for this case is: # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1) # - CApp = CApp + self.GenerateSizeStatments(Pcd) + CApp = CApp + DscBuildData.GenerateSizeStatments(Pcd) # # Allocate and zero buffer for the PCD @@ -1954,20 +1926,20 @@ class DscBuildData(PlatformBuildClassObject): # # Assign field values in PCD # - CApp = CApp + self.GenerateDefaultValueAssignStatement(Pcd) + CApp = CApp + DscBuildData.GenerateDefaultValueAssignStatement(Pcd) if Pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: for skuname in self.SkuIdMgr.GetSkuChain(SkuName): - storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName] + storeset = [DefaultStoreName] if DefaultStoreName == TAB_DEFAULT_STORES_DEFAULT else [TAB_DEFAULT_STORES_DEFAULT, DefaultStoreName] for defaultstorenameitem in storeset: CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (skuname, defaultstorenameitem) - CApp = CApp + self.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem) + CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem) if skuname == SkuName: break else: CApp = CApp + "// SkuName: %s, DefaultStoreName: STANDARD \n" % self.SkuIdMgr.SystemSkuId - CApp = CApp + self.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,"STANDARD") - CApp = CApp + self.GenerateCommandLineValueStatement(Pcd) + CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,TAB_DEFAULT_STORES_DEFAULT) + CApp = CApp + DscBuildData.GenerateCommandLineValueStatement(Pcd) # # Set new PCD value and size # @@ -1992,11 +1964,13 @@ class DscBuildData(PlatformBuildClassObject): CApp = PcdMainCHeader Includes = {} + IncludeFiles = set() for PcdName in StructuredPcds: Pcd = StructuredPcds[PcdName] for IncludeFile in Pcd.StructuredPcdIncludeFile: if IncludeFile not in Includes: Includes[IncludeFile] = True + IncludeFiles.add(IncludeFile) CApp = CApp + '#include <%s>\n' % (IncludeFile) CApp = CApp + '\n' for PcdName in StructuredPcds: @@ -2006,7 +1980,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + self.GenerateCommandLineValue(Pcd) if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: - CApp = CApp + self.GenerateInitValueFunction(Pcd,self.SkuIdMgr.SystemSkuId, 'STANDARD') + CApp = CApp + self.GenerateInitValueFunction(Pcd,self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT) else: for SkuName in self.SkuIdMgr.SkuOverrideOrder(): if SkuName not in Pcd.SkuOverrideValues: @@ -2015,7 +1989,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + self.GenerateInitValueFunction(Pcd,SkuName,DefaultStoreName) if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: - InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd, InitByteValue, CApp) + InitByteValue, CApp = self.GenerateInitializeFunc(self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd, InitByteValue, CApp) else: for SkuName in self.SkuIdMgr.SkuOverrideOrder(): if SkuName not in Pcd.SkuOverrideValues: @@ -2031,7 +2005,7 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + '{\n' for Pcd in StructuredPcds.values(): if not Pcd.SkuOverrideValues or Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: - CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, 'STANDARD', Pcd.TokenSpaceGuidCName, Pcd.TokenCName) + CApp = CApp + ' Initialize_%s_%s_%s_%s();\n' % (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT_STORES_DEFAULT, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) else: for SkuName in self.SkuIdMgr.SkuOverrideOrder(): if SkuName not in Pcd.SkuOverrideValues: @@ -2055,13 +2029,16 @@ class DscBuildData(PlatformBuildClassObject): MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o\n' % (self.OutputPath, PcdValueInitName) + \ 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +=' + IncSearchList = [] PlatformInc = {} for Cache in self._Bdb._CACHE_.values(): if Cache.MetaFile.Ext.lower() != '.dec': continue if Cache.Includes: if str(Cache.MetaFile.Path) not in PlatformInc: - PlatformInc[str(Cache.MetaFile.Path)] = Cache.CommonIncludes + PlatformInc[str(Cache.MetaFile.Path)] = [] + PlatformInc[str(Cache.MetaFile.Path)].append (os.path.dirname(Cache.MetaFile.Path)) + PlatformInc[str(Cache.MetaFile.Path)].extend (Cache.CommonIncludes) PcdDependDEC = [] for Pcd in StructuredPcds.values(): @@ -2077,6 +2054,7 @@ class DscBuildData(PlatformBuildClassObject): if pkg in PlatformInc: for inc in PlatformInc[pkg]: MakeApp += '-I' + str(inc) + ' ' + IncSearchList.append(inc) MakeApp = MakeApp + '\n' CC_FLAGS = LinuxCFLAGS @@ -2124,7 +2102,23 @@ class DscBuildData(PlatformBuildClassObject): if sys.platform == "win32": MakeApp = MakeApp + PcdMakefileEnd + MakeApp = MakeApp + '\n' + IncludeFileFullPaths = [] + for includefile in IncludeFiles: + for includepath in IncSearchList: + includefullpath = os.path.join(str(includepath),includefile) + if os.path.exists(includefullpath): + IncludeFileFullPaths.append(os.path.normpath(includefullpath)) + break + SearchPathList = [] + SearchPathList.append(os.path.normpath(mws.join(GlobalData.gWorkspace, "BaseTools/Source/C/Include"))) + SearchPathList.append(os.path.normpath(mws.join(GlobalData.gWorkspace, "BaseTools/Source/C/Common"))) + SearchPathList.extend([str(item) for item in IncSearchList]) + IncFileList = GetDependencyList(IncludeFileFullPaths,SearchPathList) + for include_file in IncFileList: + MakeApp += "$(OBJECTS) : %s\n" % include_file MakeFileName = os.path.join(self.OutputPath, 'Makefile') + MakeApp += "$(OBJECTS) : %s\n" % MakeFileName SaveFileOnChange(MakeFileName, MakeApp, False) InputValueFile = os.path.join(self.OutputPath, 'Input.txt') @@ -2136,61 +2130,63 @@ class DscBuildData(PlatformBuildClassObject): PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Source', 'C', 'bin', PcdValueInitName) else: PcdValueInitExe = os.path.join(os.getenv("EDK_TOOLS_PATH"), 'Bin', 'Win32', PcdValueInitName) +".exe" - if not os.path.exists(PcdValueInitExe) or self.NeedUpdateOutput(OutputValueFile, CAppBaseFileName + '.c',MakeFileName,InputValueFile): - Messages = '' - if sys.platform == "win32": - MakeCommand = 'nmake clean & nmake -f %s' % (MakeFileName) - returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand) - Messages = StdOut - else: - MakeCommand = 'make clean & make -f %s' % (MakeFileName) - returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand) - Messages = StdErr - Messages = Messages.split('\n') - MessageGroup = [] - if returncode <>0: - CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName) - File = open (CAppBaseFileName + '.c', 'r') - FileData = File.readlines() - File.close() - for Message in Messages: - if " error" in Message or "warning" in Message: - FileInfo = Message.strip().split('(') - if len (FileInfo) > 1: - FileName = FileInfo [0] - FileLine = FileInfo [1].split (')')[0] + + Messages = '' + if sys.platform == "win32": + MakeCommand = 'nmake -f %s' % (MakeFileName) + returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand) + Messages = StdOut + else: + MakeCommand = 'make -f %s' % (MakeFileName) + returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand) + Messages = StdErr + Messages = Messages.split('\n') + MessageGroup = [] + if returncode <>0: + CAppBaseFileName = os.path.join(self.OutputPath, PcdValueInitName) + File = open (CAppBaseFileName + '.c', 'r') + FileData = File.readlines() + File.close() + for Message in Messages: + if " error" in Message or "warning" in Message: + FileInfo = Message.strip().split('(') + if len (FileInfo) > 1: + FileName = FileInfo [0] + FileLine = FileInfo [1].split (')')[0] + else: + FileInfo = Message.strip().split(':') + FileName = FileInfo [0] + FileLine = FileInfo [1] + if FileLine.isdigit(): + error_line = FileData[int (FileLine) - 1] + if r"//" in error_line: + c_line,dsc_line = error_line.split(r"//") else: - FileInfo = Message.strip().split(':') - FileName = FileInfo [0] - FileLine = FileInfo [1] - if FileLine.isdigit(): - error_line = FileData[int (FileLine) - 1] - if r"//" in error_line: - c_line,dsc_line = error_line.split(r"//") - else: - dsc_line = error_line - message_itmes = Message.split(":") - Index = 0 - if "PcdValueInit.c" not in Message: - if not MessageGroup: - MessageGroup.append(Message) - break - else: - for item in message_itmes: - if "PcdValueInit.c" in item: - Index = message_itmes.index(item) - message_itmes[Index] = dsc_line.strip() - break - MessageGroup.append(":".join(message_itmes[Index:]).strip()) - continue + dsc_line = error_line + message_itmes = Message.split(":") + Index = 0 + if "PcdValueInit.c" not in Message: + if not MessageGroup: + MessageGroup.append(Message) + break else: - MessageGroup.append(Message) - if MessageGroup: - EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) ) - else: - EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand) + for item in message_itmes: + if "PcdValueInit.c" in item: + Index = message_itmes.index(item) + message_itmes[Index] = dsc_line.strip() + break + MessageGroup.append(":".join(message_itmes[Index:]).strip()) + continue + else: + MessageGroup.append(Message) + if MessageGroup: + EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "\n".join(MessageGroup) ) + else: + EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand) + + if DscBuildData.NeedUpdateOutput(OutputValueFile, PcdValueInitExe ,InputValueFile): Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile) - returncode, StdOut, StdErr = self.ExecuteCommand (Command) + returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (Command) if returncode <> 0: EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command) @@ -2205,13 +2201,12 @@ class DscBuildData(PlatformBuildClassObject): StructurePcdSet.append((PcdInfo[0],PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip())) return StructurePcdSet - def NeedUpdateOutput(self,OutputFile, ValueCFile, MakeFile, StructureInput): + @staticmethod + def NeedUpdateOutput(OutputFile, ValueCFile, StructureInput): if not os.path.exists(OutputFile): return True if os.stat(OutputFile).st_mtime <= os.stat(ValueCFile).st_mtime: return True - if os.stat(OutputFile).st_mtime <= os.stat(MakeFile).st_mtime: - return True if os.stat(OutputFile).st_mtime <= os.stat(StructureInput).st_mtime: return True return False @@ -2225,7 +2220,7 @@ class DscBuildData(PlatformBuildClassObject): def _GetDynamicPcd(self, Type): - Pcds = sdict() + Pcds = OrderedDict() # # tdict is a special dict kind of type, used for selecting correct # PCD settings for certain ARCH and SKU @@ -2251,7 +2246,7 @@ class DscBuildData(PlatformBuildClassObject): for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList: Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid] - if Setting == None: + if Setting is None: continue PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4) @@ -2287,7 +2282,7 @@ class DscBuildData(PlatformBuildClassObject): pcdDecObject = self._DecPcds[pcd.TokenCName, pcd.TokenSpaceGuidCName] # Only fix the value while no value provided in DSC file. for sku in pcd.SkuInfoList.values(): - if (sku.DefaultValue == "" or sku.DefaultValue==None): + if not sku.DefaultValue: sku.DefaultValue = pcdDecObject.DefaultValue if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys(): valuefromDec = pcdDecObject.DefaultValue @@ -2317,8 +2312,8 @@ class DscBuildData(PlatformBuildClassObject): return PcdObj - - def CompareVarAttr(self, Attr1, Attr2): + @staticmethod + def CompareVarAttr(Attr1, Attr2): if not Attr1 or not Attr2: # for empty string return True Attr1s = [attr.strip() for attr in Attr1.split(",")] @@ -2329,20 +2324,21 @@ class DscBuildData(PlatformBuildClassObject): return True else: return False + def CopyDscRawValue(self,Pcd): if Pcd.DscRawValue is None: Pcd.DscRawValue = dict() if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]: if self.SkuIdMgr.SystemSkuId not in Pcd.DscRawValue: Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = {} - Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId]['STANDARD'] = Pcd.DefaultValue + Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = Pcd.DefaultValue for skuname in Pcd.SkuInfoList: Pcd.DscRawValue[skuname] = {} if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]: for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict: Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore] else: - Pcd.DscRawValue[skuname]['STANDARD'] = Pcd.SkuInfoList[skuname].DefaultValue + Pcd.DscRawValue[skuname][TAB_DEFAULT_STORES_DEFAULT] = Pcd.SkuInfoList[skuname].DefaultValue def CompletePcdValues(self,PcdSet): Pcds = {} DefaultStoreObj = DefaultStore(self._GetDefaultStores()) @@ -2390,7 +2386,7 @@ class DscBuildData(PlatformBuildClassObject): VariableAttrs = {} - Pcds = sdict() + Pcds = OrderedDict() # # tdict is a special dict kind of type, used for selecting correct # PCD settings for certain ARCH and SKU @@ -2407,7 +2403,7 @@ class DscBuildData(PlatformBuildClassObject): SkuName = 'DEFAULT' if SkuName == 'COMMON' else SkuName DefaultStore = DefaultStore.upper() if DefaultStore == "COMMON": - DefaultStore = "STANDARD" + DefaultStore = TAB_DEFAULT_STORES_DEFAULT if SkuName not in AvailableSkuIdSet: EdkLogger.error('build', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName, File=self.MetaFile, Line=Dummy5) @@ -2423,7 +2419,7 @@ class DscBuildData(PlatformBuildClassObject): for PcdCName, TokenSpaceGuid, SkuName,DefaultStore, Dummy4 in PcdSet: Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid,DefaultStore] - if Setting == None: + if Setting is None: continue VariableName, VariableGuid, VariableOffset, DefaultValue, VarAttribute = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4) @@ -2456,7 +2452,7 @@ class DscBuildData(PlatformBuildClassObject): if (VariableName, VariableGuid) not in VariableAttrs: VariableAttrs[(VariableName, VariableGuid)] = VarAttribute else: - if not self.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute): + if not DscBuildData.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute): EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAttrs[(VariableName, VariableGuid)])) pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid] @@ -2493,7 +2489,7 @@ class DscBuildData(PlatformBuildClassObject): pcd.DatumType = pcdDecObject.DatumType # Only fix the value while no value provided in DSC file. for sku in pcd.SkuInfoList.values(): - if (sku.HiiDefaultValue == "" or sku.HiiDefaultValue == None): + if (sku.HiiDefaultValue == "" or sku.HiiDefaultValue is None): sku.HiiDefaultValue = pcdDecObject.DefaultValue for default_store in sku.DefaultStoreDict: sku.DefaultStoreDict[default_store]=pcdDecObject.DefaultValue @@ -2523,7 +2519,7 @@ class DscBuildData(PlatformBuildClassObject): skuobj.DefaultStoreDict[defaultst] = StringToArray(skuobj.DefaultStoreDict[defaultst]) pcd.DefaultValue = StringToArray(pcd.DefaultValue) pcd.MaxDatumSize = str(MaxSize) - rt, invalidhii = self.CheckVariableNameAssignment(Pcds) + rt, invalidhii = DscBuildData.CheckVariableNameAssignment(Pcds) if not rt: invalidpcd = ",".join(invalidhii) EdkLogger.error('build', PCD_VARIABLE_INFO_ERROR, Message='The same HII PCD must map to the same EFI variable for all SKUs', File=self.MetaFile, ExtraData=invalidpcd) @@ -2532,7 +2528,8 @@ class DscBuildData(PlatformBuildClassObject): return Pcds - def CheckVariableNameAssignment(self,Pcds): + @staticmethod + def CheckVariableNameAssignment(Pcds): invalidhii = [] for pcdname in Pcds: pcd = Pcds[pcdname] @@ -2552,7 +2549,7 @@ class DscBuildData(PlatformBuildClassObject): def _GetDynamicVpdPcd(self, Type): - Pcds = sdict() + Pcds = OrderedDict() # # tdict is a special dict kind of type, used for selecting correct # PCD settings for certain ARCH and SKU @@ -2577,7 +2574,7 @@ class DscBuildData(PlatformBuildClassObject): # Remove redundant PCD candidates, per the ARCH and SKU for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList: Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid] - if Setting == None: + if Setting is None: continue # # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue @@ -2619,7 +2616,7 @@ class DscBuildData(PlatformBuildClassObject): pcd.DatumType = pcdDecObject.DatumType # Only fix the value while no value provided in DSC file. for sku in pcd.SkuInfoList.values(): - if (sku.DefaultValue == "" or sku.DefaultValue==None): + if not sku.DefaultValue: sku.DefaultValue = pcdDecObject.DefaultValue if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys(): valuefromDec = pcdDecObject.DefaultValue @@ -2686,7 +2683,7 @@ class DscBuildData(PlatformBuildClassObject): self.Pcds[Name, Guid].DefaultValue = Value @property def DecPcds(self): - if self._DecPcds == None: + if self._DecPcds is None: FdfInfList = [] if GlobalData.gFdfParser: FdfInfList = GlobalData.gFdfParser.Profile.InfList