From 79b74a03e018ecbf03d8d50e6f20301e249c1ba5 Mon Sep 17 00:00:00 2001 From: lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> Date: Tue, 11 Oct 2011 02:49:48 +0000 Subject: Sync BaseTools Branch (version r2362) to EDKII main trunk. Signed-off-by: lgao4 Reviewed-by: jsu1 Reviewed-by: ydliu git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12525 6f19259b-4bc3-4df7-8a09-765794883524 --- BaseTools/Source/Python/AutoGen/AutoGen.py | 177 +++++++++++++++++++++- BaseTools/Source/Python/AutoGen/GenMake.py | 9 +- BaseTools/Source/Python/AutoGen/StrGather.py | 32 ++-- BaseTools/Source/Python/AutoGen/UniClassObject.py | 44 ++++-- 4 files changed, 220 insertions(+), 42 deletions(-) (limited to 'BaseTools/Source/Python/AutoGen') diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py index 55a6a81ccc..8150ea0b69 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -155,7 +155,7 @@ class AutoGen(object): class WorkspaceAutoGen(AutoGen): ## Real constructor of WorkspaceAutoGen # - # This method behaves the same as __init__ except that it needs explict invoke + # This method behaves the same as __init__ except that it needs explicit invoke # (in super class's __new__ method) # # @param WorkspaceDir Root directory of workspace @@ -246,6 +246,9 @@ class WorkspaceAutoGen(AutoGen): # self._CheckPcdDefineAndType() + if self.FdfFile: + self._CheckDuplicateInFV(Fdf) + self._BuildDir = None self._FvDir = None self._MakeFileDir = None @@ -253,6 +256,130 @@ class WorkspaceAutoGen(AutoGen): return True + ## _CheckDuplicateInFV() method + # + # Check whether there is duplicate modules/files exist in FV section. + # The check base on the file GUID; + # + def _CheckDuplicateInFV(self, Fdf): + for Fv in Fdf.Profile.FvDict: + _GuidDict = {} + for FfsFile in Fdf.Profile.FvDict[Fv].FfsList: + if FfsFile.InfFileName and FfsFile.NameGuid == None: + # + # Get INF file GUID + # + InfFoundFlag = False + for Pa in self.AutoGenObjectList: + for Module in Pa.ModuleAutoGenList: + if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName): + InfFoundFlag = True + if not Module.Guid.upper() in _GuidDict.keys(): + _GuidDict[Module.Guid.upper()] = FfsFile + else: + EdkLogger.error("build", + FORMAT_INVALID, + "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum, + FfsFile.CurrentLineContent, + _GuidDict[Module.Guid.upper()].CurrentLineNum, + _GuidDict[Module.Guid.upper()].CurrentLineContent, + Module.Guid.upper()), + ExtraData=self.FdfFile) + # + # Some INF files not have entity in DSC file. + # + if not InfFoundFlag: + if FfsFile.InfFileName.find('$') == -1: + InfPath = NormPath(FfsFile.InfFileName) + if not os.path.exists(InfPath): + EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName)) + + PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir) + # + # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use + # BuildObject from one of AutoGenObjectList is enough. + # + InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain] + if not InfObj.Guid.upper() in _GuidDict.keys(): + _GuidDict[InfObj.Guid.upper()] = FfsFile + else: + EdkLogger.error("build", + FORMAT_INVALID, + "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum, + FfsFile.CurrentLineContent, + _GuidDict[InfObj.Guid.upper()].CurrentLineNum, + _GuidDict[InfObj.Guid.upper()].CurrentLineContent, + InfObj.Guid.upper()), + ExtraData=self.FdfFile) + InfFoundFlag = False + + if FfsFile.NameGuid != None: + _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$") + + # + # If the NameGuid reference a PCD name. + # The style must match: PCD(xxxx.yyy) + # + if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid): + # + # Replace the PCD value. + # + _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")") + PcdFoundFlag = False + for Pa in self.AutoGenObjectList: + if not PcdFoundFlag: + for PcdItem in Pa.AllPcdList: + if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName: + # + # First convert from CFormatGuid to GUID string + # + _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue) + + if not _PcdGuidString: + # + # Then try Byte array. + # + _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue) + + if not _PcdGuidString: + # + # Not Byte array or CFormat GUID, raise error. + # + EdkLogger.error("build", + FORMAT_INVALID, + "The format of PCD value is incorrect. PCD: %s , Value: %s\n"%(_PcdName, PcdItem.DefaultValue), + ExtraData=self.FdfFile) + + if not _PcdGuidString.upper() in _GuidDict.keys(): + _GuidDict[_PcdGuidString.upper()] = FfsFile + PcdFoundFlag = True + break + else: + EdkLogger.error("build", + FORMAT_INVALID, + "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum, + FfsFile.CurrentLineContent, + _GuidDict[_PcdGuidString.upper()].CurrentLineNum, + _GuidDict[_PcdGuidString.upper()].CurrentLineContent, + FfsFile.NameGuid.upper()), + ExtraData=self.FdfFile) + + if not FfsFile.NameGuid.upper() in _GuidDict.keys(): + _GuidDict[FfsFile.NameGuid.upper()] = FfsFile + else: + # + # Two raw file GUID conflict. + # + EdkLogger.error("build", + FORMAT_INVALID, + "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum, + FfsFile.CurrentLineContent, + _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum, + _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent, + FfsFile.NameGuid.upper()), + ExtraData=self.FdfFile) + + def _CheckPcdDefineAndType(self): PcdTypeList = [ "FixedAtBuild", "PatchableInModule", "FeatureFlag", @@ -1749,6 +1876,7 @@ class ModuleAutoGen(AutoGen): self._DepexList = None self._DepexExpressionList = None self._BuildOption = None + self._BuildOptionIncPathList = None self._BuildTargets = None self._IntroBuildTargetList = None self._FinalBuildTargetList = None @@ -2004,6 +2132,50 @@ class ModuleAutoGen(AutoGen): self._BuildOption = self.PlatformInfo.ApplyBuildOption(self.Module) return self._BuildOption + ## Get include path list from tool option for the module build + # + # @retval list The include path list + # + def _GetBuildOptionIncPathList(self): + if self._BuildOptionIncPathList == None: + # + # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC + # is the former use /I , the Latter used -I to specify include directories + # + if self.PlatformInfo.ToolChainFamily in ('MSFT'): + gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL) + elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC'): + gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL) + + BuildOptionIncPathList = [] + for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'): + Attr = 'FLAGS' + try: + FlagOption = self.BuildOption[Tool][Attr] + except KeyError: + FlagOption = '' + + IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)] + # + # EDK II modules must not reference header files outside of the packages they depend on or + # within the module's directory tree. Report error if violation. + # + if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0: + for Path in IncPathList: + if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir): + ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption) + EdkLogger.error("build", + PARAMETER_INVALID, + ExtraData = ErrMsg, + File = str(self.MetaFile)) + + + BuildOptionIncPathList += IncPathList + + self._BuildOptionIncPathList = BuildOptionIncPathList + + return self._BuildOptionIncPathList + ## Return a list of files which can be built from source # # What kind of files can be built is determined by build rules in @@ -2256,7 +2428,7 @@ class ModuleAutoGen(AutoGen): # def _GetLibraryPcdList(self): if self._LibraryPcdList == None: - Pcds = {} + Pcds = sdict() if not self.IsLibrary: # get PCDs from dependent libraries for Library in self.DependentLibraryList: @@ -2584,6 +2756,7 @@ class ModuleAutoGen(AutoGen): DxsFile = property(_GetDxsFile) DepexExpressionList = property(_GetDepexExpressionTokenList) BuildOption = property(_GetModuleBuildOption) + BuildOptionIncPathList = property(_GetBuildOptionIncPathList) BuildCommand = property(_GetBuildCommand) # This acts like the main() function for the script, unless it is 'import'ed into another script. diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 5bf693c50f..3720c8bfed 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -614,7 +614,7 @@ cleanlib: self.FileDependency = self.GetFileDependency( SourceFileList, ForceIncludedFile, - self._AutoGenObject.IncludePathList + self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList ) DepSet = None for File in self.FileDependency: @@ -1253,7 +1253,7 @@ ${END}\t@cd $(BUILD_DIR) # fds: init \t-@cd $(FV_DIR) -${BEGIN}\tGenFds -f ${fdf_file} -o $(BUILD_DIR) -t $(TOOLCHAIN) -b $(TARGET) -p ${active_platform} -a ${build_architecture_list} ${extra_options}${END}${BEGIN} -r ${fd} ${END}${BEGIN} -i ${fv} ${END}${BEGIN} -C ${cap} ${END}${BEGIN} -D ${macro} ${END} +${BEGIN}\tGenFds -f ${fdf_file} -o $(BUILD_DIR) -t $(TOOLCHAIN) -b $(TARGET) -p ${active_platform} -a ${build_architecture_list}${END}${BEGIN}${extra_options}${END}${BEGIN} -r ${fd}${END}${BEGIN} -i ${fv}${END}${BEGIN} -C ${cap}${END}${BEGIN} -D${macro}${END} # # run command for emulator platform only @@ -1335,6 +1335,9 @@ ${END}\t@cd $(BUILD_DIR)\n if GlobalData.gCaseInsensitive: ExtraOption += " -c" + ExtraOptionList = [] + if ExtraOption: + ExtraOptionList.append(ExtraOption) MakefileName = self._FILE_NAME_[self._FileType] SubBuildCommandList = [] @@ -1366,7 +1369,7 @@ ${END}\t@cd $(BUILD_DIR)\n "fd" : PlatformInfo.FdTargetList, "fv" : PlatformInfo.FvTargetList, "cap" : PlatformInfo.CapTargetList, - "extra_options" : ExtraOption, + "extra_options" : ExtraOptionList, "macro" : MacroList, } diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py index 3df493834c..7187f0a440 100644 --- a/BaseTools/Source/Python/AutoGen/StrGather.py +++ b/BaseTools/Source/Python/AutoGen/StrGather.py @@ -168,8 +168,9 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag): Str = WriteLine(Str, Line) Line = COMMENT_DEFINE_STR + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + PRINTABLE_LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(1, 4) + COMMENT_NOT_REFERENCED Str = WriteLine(Str, Line) + UnusedStr = '' - #Group the referred STRING token together. + #Group the referred/Unused STRING token together. for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])): StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index] Name = StringItem.StringName @@ -183,21 +184,14 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag): else: Line = DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) Str = WriteLine(Str, Line) - - #Group the unused STRING token together. - for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])): - StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index] - Name = StringItem.StringName - Token = StringItem.Token - Referenced = StringItem.Referenced - if Name != None: - Line = '' - if Referenced == False: + else: if (ValueStartPtr - len(DEFINE_STR + Name)) <= 0: Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED else: Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED - Str = WriteLine(Str, Line) + UnusedStr = WriteLine(UnusedStr, Line) + + Str = ''.join([Str,UnusedStr]) Str = WriteLine(Str, '') if IsCompatibleMode or UniGenCFlag: @@ -383,7 +377,6 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, # for IndexI in range(len(UniObjectClass.LanguageDef)): Language = UniObjectClass.LanguageDef[IndexI][0] - LangPrintName = UniObjectClass.LanguageDef[IndexI][1] if Language not in UniLanguageListFiltered: continue @@ -393,12 +386,12 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, NumberOfUseOtherLangDef = 0 Index = 0 for IndexJ in range(1, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[IndexI][0]])): - Item = UniObjectClass.FindByToken(IndexJ, Language) + Item = UniObjectClass.OrderedStringListByToken[Language][IndexJ] + Name = Item.StringName Value = Item.StringValueByteList Referenced = Item.Referenced Token = Item.Token - Length = Item.Length UseOtherLangDef = Item.UseOtherLangDef if UseOtherLangDef != '' and Referenced: @@ -595,10 +588,7 @@ def SearchString(UniObjectClass, FileList, IsCompatibleMode): # This function is used for UEFI2.1 spec # # -def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None, FilterInfo = [True, []]): - Status = True - ErrorMessage = '' - +def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None, FilterInfo = [True, []]): if len(UniFilList) > 0: if ShellMode: # @@ -627,13 +617,13 @@ def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, Ski # Write an item # def Write(Target, Item): - return Target + Item + return ''.join([Target,Item]) # # Write an item with a break line # def WriteLine(Target, Item): - return Target + Item + '\n' + return ''.join([Target,Item,'\n']) # This acts like the main() function for the script, unless it is 'import'ed into another # script. diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py index 1825c81d91..54751bab4e 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -193,6 +193,8 @@ class UniFileClassObject(object): self.Token = 2 self.LanguageDef = [] #[ [u'LanguageIdentifier', u'PrintableName'], ... ] self.OrderedStringList = {} #{ u'LanguageIdentifier' : [StringDefClassObject] } + self.OrderedStringDict = {} #{ u'LanguageIdentifier' : {StringName:(IndexInList)} } + self.OrderedStringListByToken = {} #{ u'LanguageIdentifier' : {Token: StringDefClassObject} } self.IsCompatibleMode = IsCompatibleMode self.IncludePathList = IncludePathList if len(self.FileList) > 0: @@ -246,14 +248,13 @@ class UniFileClassObject(object): else: OtherLang = FirstLangName self.OrderedStringList[LangName].append (StringDefClassObject(Item.StringName, '', Item.Referenced, Item.Token, OtherLang)) - + self.OrderedStringDict[LangName][Item.StringName] = len(self.OrderedStringList[LangName]) - 1 return True # # Get String name and value # def GetStringObject(self, Item): - Name = '' Language = '' Value = '' @@ -476,20 +477,22 @@ class UniFileClassObject(object): if Language not in self.OrderedStringList: self.OrderedStringList[Language] = [] + self.OrderedStringDict[Language] = {} IsAdded = True - for Item in self.OrderedStringList[Language]: - if Name == Item.StringName: - IsAdded = False - if Value != None: - Item.UpdateValue(Value) - Item.UseOtherLangDef = '' - break + if Name in self.OrderedStringDict[Language]: + IsAdded = False + if Value != None: + ItemIndexInList = self.OrderedStringDict[Language][Name] + Item = self.OrderedStringList[Language][ItemIndexInList] + Item.UpdateValue(Value) + Item.UseOtherLangDef = '' if IsAdded: Token = len(self.OrderedStringList[Language]) if Index == -1: self.OrderedStringList[Language].append(StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef)) + self.OrderedStringDict[Language][Name] = Token for LangName in self.LanguageDef: # # New STRING token will be added into all language string lists. @@ -501,8 +504,10 @@ class UniFileClassObject(object): else: OtherLangDef = Language self.OrderedStringList[LangName[0]].append(StringDefClassObject(Name, '', Referenced, Token, OtherLangDef)) + self.OrderedStringDict[LangName[0]][Name] = len(self.OrderedStringList[LangName[0]]) - 1 else: self.OrderedStringList[Language].insert(Index, StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef)) + self.OrderedStringDict[Language][Name] = Index # # Set the string as referenced @@ -513,17 +518,18 @@ class UniFileClassObject(object): # So, only update the status of string stoken in first language string list. # Lang = self.LanguageDef[0][0] - for Item in self.OrderedStringList[Lang]: - if Name == Item.StringName: - Item.Referenced = True - break + if Name in self.OrderedStringDict[Lang]: + ItemIndexInList = self.OrderedStringDict[Lang][Name] + Item = self.OrderedStringList[Lang][ItemIndexInList] + Item.Referenced = True + # # Search the string in language definition by Name # def FindStringValue(self, Name, Lang): - for Item in self.OrderedStringList[Lang]: - if Item.StringName == Name: - return Item + if Name in self.OrderedStringDict[Lang]: + ItemIndexInList = self.OrderedStringDict[Lang][Name] + return self.OrderedStringList[Lang][ItemIndexInList] return None @@ -546,6 +552,10 @@ class UniFileClassObject(object): # FirstLangName = self.LanguageDef[0][0] + # Convert the OrderedStringList to be OrderedStringListByToken in order to faciliate future search by token + for LangNameItem in self.LanguageDef: + self.OrderedStringListByToken[LangNameItem[0]] = {} + # # Use small token for all referred string stoken. # @@ -558,6 +568,7 @@ class UniFileClassObject(object): OtherLangItem = self.OrderedStringList[LangName][Index] OtherLangItem.Referenced = True OtherLangItem.Token = RefToken + self.OrderedStringListByToken[LangName][OtherLangItem.Token] = OtherLangItem RefToken = RefToken + 1 # @@ -571,6 +582,7 @@ class UniFileClassObject(object): LangName = LangNameItem[0] OtherLangItem = self.OrderedStringList[LangName][Index] OtherLangItem.Token = RefToken + UnRefToken + self.OrderedStringListByToken[LangName][OtherLangItem.Token] = OtherLangItem UnRefToken = UnRefToken + 1 # -- cgit v1.2.3