def RaiseParserError(Line, Section, File, Format='', LineNo= -1):
    if LineNo == -1:
        LineNo = GetLineNo(open(os.path.normpath(File), 'r').read(), Line)
    ErrorMsg = "Invalid statement '%s' is found in section '%s'" % (Line, Section)
    if Format != '':
        Format = "Correct format is " + Format
    EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=File, Line=LineNo, ExtraData=Format, RaiseError=EdkLogger.IsRaiseError)
    def GenPackages(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_PACKAGES)
        Packages = {}
        #
        # Get all Packages
        #
        RecordSet = self.RecordSet[MODEL_META_DATA_PACKAGE]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (Package, Pcd) = GetPackage(Record[0], ContainerFile, self.WorkspaceDir, Record[2])
                    MergeArches(Packages, (Package, Pcd), Arch)
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
                                        where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Package), ConvertToSqlString2(Pcd), Record[3])
                        self.TblInf.Exec(SqlCommand)


        for Key in Packages.keys():
            Package = ModulePackageDependencyClass()
            Package.FilePath = NormPath(Key[0])
            Package.SupArchList = Packages[Key]
            Package.FeatureFlag = Key[1]
            self.Module.PackageDependencies.append(Package)
示例#3
0
    def ConvertTextFileToDict(self, FileName, CommentCharacter, KeySplitCharacter):
        F = None
        try:
            F = open(FileName, 'r')
            self.ConfDirectoryPath = os.path.dirname(FileName)
        except:
            EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)
            if F != None:
                F.close()

        for Line in F:
            Line = Line.strip()
            if Line.startswith(CommentCharacter) or Line == '':
                continue

            LineList = Line.split(KeySplitCharacter, 1)
            Key = LineList[0].strip()
            if len(LineList) == 2:
                Value = LineList[1].strip()
            else:
                Value = ""

            if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \
                       DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:
                self.TargetTxtDictionary[Key] = Value.replace('\\', '/')
                if Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF and self.TargetTxtDictionary[Key]:
                    if self.TargetTxtDictionary[Key].startswith("Conf/"):
                        Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())
                        if not os.path.exists(Tools_Def) or not os.path.isfile(Tools_Def):
                            # If Conf/Conf does not exist, try just the Conf/ directory
                            Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())
                    else:
                        # The File pointed to by TOOL_CHAIN_CONF is not in a Conf/ directory
                        Tools_Def = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())
                    self.TargetTxtDictionary[Key] = Tools_Def
                if Key == DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF and self.TargetTxtDictionary[Key]:
                    if self.TargetTxtDictionary[Key].startswith("Conf/"):
                        Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())
                        if not os.path.exists(Build_Rule) or not os.path.isfile(Build_Rule):
                            # If Conf/Conf does not exist, try just the Conf/ directory
                            Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].replace("Conf/", "", 1).strip())
                    else:
                        # The File pointed to by BUILD_RULE_CONF is not in a Conf/ directory
                        Build_Rule = os.path.join(self.ConfDirectoryPath, self.TargetTxtDictionary[Key].strip())
                    self.TargetTxtDictionary[Key] = Build_Rule
            elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \
                         DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:
                self.TargetTxtDictionary[Key] = Value.split()
            elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:
                try:
                    V = int(Value, 0)
                except:
                    EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),
                                    File=FileName)
                self.TargetTxtDictionary[Key] = Value
            #elif Key not in GlobalData.gGlobalDefines:
            #    GlobalData.gGlobalDefines[Key] = Value

        F.close()
        return 0
    def GenLibraryClasses(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)
        LibraryClasses = {}
        #
        # Get all LibraryClasses
        #
        RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (LibClassName, LibClassIns, Pcd, SupModelList) = GetLibraryClassOfInf([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])
                    MergeArches(LibraryClasses, (LibClassName, LibClassIns, Pcd, SupModelList), Arch)
                    #
                    # Update to Database
                    #
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
                                        where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(LibClassName), ConvertToSqlString2(LibClassIns), ConvertToSqlString2(SupModelList), Record[3])
                        self.TblInf.Exec(SqlCommand)

        for Key in LibraryClasses.keys():
            KeyList = Key[0].split(DataType.TAB_VALUE_SPLIT)
            LibraryClass = LibraryClassClass()
            LibraryClass.LibraryClass = Key[0]
            LibraryClass.RecommendedInstance = NormPath(Key[1])
            LibraryClass.FeatureFlag = Key[2]
            LibraryClass.SupArchList = LibraryClasses[Key]
            LibraryClass.SupModuleList = GetSplitValueList(Key[3])
            self.Module.LibraryClasses.append(LibraryClass)
    def GenBuildOptions(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)
        BuildOptions = {}
        #
        # Get all BuildOptions
        #
        RecordSet = self.RecordSet[MODEL_META_DATA_BUILD_OPTION]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (Family, ToolChain, Flag) = GetBuildOption(Record[0], ContainerFile, Record[2])
                    MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)
                    #
                    # Update to Database
                    #
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'
                                        where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Family), ConvertToSqlString2(ToolChain), ConvertToSqlString2(Flag), Record[3])
                        self.TblInf.Exec(SqlCommand)

        for Key in BuildOptions.keys():
            BuildOption = BuildOptionClass(Key[0], Key[1], Key[2])
            BuildOption.SupArchList = BuildOptions[Key]
            self.Module.BuildOptions.append(BuildOption)
    def GenGuidProtocolPpis(self, Type, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % Type)
        Lists = {}
        #
        # Get all Items
        #
        RecordSet = self.RecordSet[Section[Type.upper()]]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (Name, Value) = GetGuidsProtocolsPpisOfInf(Record[0], Type, ContainerFile, Record[2])
                    MergeArches(Lists, (Name, Value), Arch)
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
                                        where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Name), ConvertToSqlString2(Value), Record[3])
                        self.TblInf.Exec(SqlCommand)

        ListMember = None
        if Type == TAB_GUIDS:
            ListMember = self.Module.Guids
        elif Type == TAB_PROTOCOLS:
            ListMember = self.Module.Protocols
        elif Type == TAB_PPIS:
            ListMember = self.Module.Ppis

        for Key in Lists.keys():
            ListClass = GuidProtocolPpiCommonClass()
            ListClass.CName = Key[0]
            ListClass.SupArchList = Lists[Key]
            ListClass.FeatureFlag = Key[1]
            ListMember.append(ListClass)
    def GenSources(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_SOURCES)
        Sources = {}

        #
        # Get all Nmakes
        #
        RecordSet = self.RecordSet[MODEL_EFI_SOURCE_FILE]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (Filename, Family, TagName, ToolCode, Pcd) = GetSource(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2])
                    MergeArches(Sources, (Filename, Family, TagName, ToolCode, Pcd), Arch)
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
                                        where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Filename), ConvertToSqlString2(Family), ConvertToSqlString2(TagName), ConvertToSqlString2(ToolCode), ConvertToSqlString2(Pcd), Record[3])
                        self.TblInf.Exec(SqlCommand)

        for Key in Sources.keys():
            Source = ModuleSourceFileClass(Key[0], Key[2], Key[3], Key[1], Key[4], Sources[Key])
            self.Module.Sources.append(Source)
    def GenBinaries(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_BINARIES)
        Binaries = {}

        #
        # Get all Guids
        #
        RecordSet = self.RecordSet[MODEL_EFI_BINARY_FILE]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (FileType, Filename, Target, Pcd) = GetBinary(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2])
                    MergeArches(Binaries, (FileType, Filename, Target, Pcd), Arch)
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'
                                        where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(FileType), ConvertToSqlString2(Filename), ConvertToSqlString2(Target), ConvertToSqlString2(Pcd), Record[3])
                        self.TblInf.Exec(SqlCommand)

        for Key in Binaries.keys():
            Binary = ModuleBinaryFileClass(NormPath(Key[1]), Key[0], Key[2], Key[3], Binaries[Key])
            self.Module.Binaries.append(Binary)
示例#9
0
    def GenModuleHeader(self, ContainerFile):
        EdkLogger.debug(2, "Generate ModuleHeader ...")
        # Update all defines item in database
        RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]

        ModuleHeader = ModuleHeaderClass()
        ModuleExtern = ModuleExternClass()
        OtherDefines = []
        for Record in RecordSet:
            ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)
            if len(ValueList) != 2:
                OtherDefines.append(Record[0])
            else:
                Name = ValueList[0]
                Value = ValueList[1]
                if Name == TAB_INF_DEFINES_BASE_NAME:
                    ModuleHeader.Name = Value
                    ModuleHeader.BaseName = Value
                elif Name == TAB_INF_DEFINES_FILE_GUID:
                    ModuleHeader.Guid = Value
                elif Name == TAB_INF_DEFINES_VERSION_STRING:
                    ModuleHeader.Version = Value
                elif Name == TAB_INF_DEFINES_PCD_IS_DRIVER:
                    ModuleHeader.PcdIsDriver = Value
                elif Name == TAB_INF_DEFINES_MODULE_TYPE:
                    ModuleHeader.ModuleType = Value
                elif Name in (TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION, TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION):
                    ModuleHeader.UefiSpecificationVersion = Value
                elif Name == TAB_INF_DEFINES_PI_SPECIFICATION_VERSION:
                    ModuleHeader.PiSpecificationVersion = Value
                elif Name == TAB_INF_DEFINES_ENTRY_POINT:
                    ModuleExtern.EntryPoint = Value
                elif Name == TAB_INF_DEFINES_UNLOAD_IMAGE:
                    ModuleExtern.UnloadImage = Value
                elif Name == TAB_INF_DEFINES_CONSTRUCTOR:
                    ModuleExtern.Constructor = Value
                elif Name == TAB_INF_DEFINES_DESTRUCTOR:
                    ModuleExtern.Destructor = Value
                else:
                    OtherDefines.append(Record[0])
        ModuleHeader.FileName = self.Identification.FileName
        ModuleHeader.FullPath = self.Identification.FullPath
        ModuleHeader.RelaPath = self.Identification.RelaPath
        ModuleHeader.PackagePath = self.Identification.PackagePath
        ModuleHeader.ModulePath = self.Identification.ModulePath
        ModuleHeader.CombinePath = os.path.normpath(
            os.path.join(ModuleHeader.PackagePath, ModuleHeader.ModulePath, ModuleHeader.FileName)
        )

        if MODEL_META_DATA_HEADER in self.SectionHeaderCommentDict:
            ModuleHeader.Description = self.SectionHeaderCommentDict[MODEL_META_DATA_HEADER]
        self.Module.ModuleHeader = ModuleHeader
        self.Module.Externs.append(ModuleExtern)
        UE = self.Module.UserExtensions
        if UE == None:
            UE = UserExtensionsClass()
        UE.Defines = OtherDefines
        self.Module.UserExtensions = UE
示例#10
0
 def GenBuildOptions(self, ContainerFile):
     EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)
     BuildOptions = {}
     # Get all BuildOptions
     RecordSet = self.RecordSet[MODEL_META_DATA_BUILD_OPTION]
     UE = self.Module.UserExtensions
     if UE == None:
         UE = UserExtensionsClass()
     for Record in RecordSet:
         UE.BuildOptions.append(Record[0])
     self.Module.UserExtensions = UE
def CheckFileType(CheckFilename, ExtName, ContainerFilename, SectionName, Line, LineNo= -1):
    if CheckFilename != '' and CheckFilename != None:
        (Root, Ext) = os.path.splitext(CheckFilename)
        if Ext.upper() != ExtName.upper():
            ContainerFile = open(ContainerFilename, 'r').read()
            if LineNo == -1:
                LineNo = GetLineNo(ContainerFile, Line)
            ErrorMsg = "Invalid %s. '%s' is found, but '%s' file is needed" % (SectionName, CheckFilename, ExtName)
            EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, Line=LineNo,
                            File=ContainerFilename, RaiseError=EdkLogger.IsRaiseError)

    return True
示例#12
0
 def GenIncludes(self, ContainerFile):
     EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)
     Includes = sdict()
     # Get all Includes
     RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]
     for Record in RecordSet:
         Include = IncludeClass()
         Include.FilePath = Record[0]
         Include.SupArchList = Record[1]
         if GenerateHelpText(Record[5], ""):
             Include.HelpTextList.append(GenerateHelpText(Record[5], ""))
         self.Module.Includes.append(Include)
def CheckFileExist(WorkspaceDir, CheckFilename, ContainerFilename, SectionName, Line, LineNo= -1):
    CheckFile = ''
    if CheckFilename != '' and CheckFilename != None:
        CheckFile = WorkspaceFile(WorkspaceDir, CheckFilename)
        if not os.path.isfile(CheckFile):
            ContainerFile = open(ContainerFilename, 'r').read()
            if LineNo == -1:
                LineNo = GetLineNo(ContainerFile, Line)
            ErrorMsg = "Can't find file '%s' defined in section '%s'" % (CheckFile, SectionName)
            EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg,
                            File=ContainerFilename, Line=LineNo, RaiseError=EdkLogger.IsRaiseError)

    return CheckFile
示例#14
0
 def GenPackages(self, ContainerFile):
     EdkLogger.debug(2, "Generate %s ..." % TAB_PACKAGES)
     Packages = {}
     # Get all Packages
     RecordSet = self.RecordSet[MODEL_META_DATA_PACKAGE]
     for Record in RecordSet:
         (PackagePath, Pcd) = GetPackage(Record[0], ContainerFile, self.WorkspaceDir, Record[2])
         Package = ModulePackageDependencyClass()
         Package.FilePath = NormPath(PackagePath)
         Package.SupArchList = Record[1]
         Package.FeatureFlag = Pcd
         if GenerateHelpText(Record[5], ""):
             Package.HelpTextList.append(GenerateHelpText(Record[5], ""))
         self.Module.PackageDependencies.append(Package)
示例#15
0
    def GenBinaries(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_BINARIES)
        Binaries = {}

        # Get all Guids
        RecordSet = self.RecordSet[MODEL_EFI_BINARY_FILE]
        for Record in RecordSet:
            (FileType, Filename, Target, Pcd) = GetBinary(
                Record[0], ContainerFile, self.Identification.RelaPath, Record[2]
            )
            Binary = ModuleBinaryFileClass(Filename, FileType, Target, Pcd, Record[1])
            if GenerateHelpText(Record[5], ""):
                Binary.HelpTextList.append(GenerateHelpText(Record[5], ""))
            self.Module.Binaries.append(Binary)
    def GenNmakes(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_NMAKE)
        Nmakes = sdict()
        #
        # Get all Nmakes
        #
        RecordSet = self.RecordSet[MODEL_META_DATA_NMAKE]


        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    MergeArches(Nmakes, Record[0], Arch)

        for Key in Nmakes.keys():
            List = GetSplitValueList(Key, DataType.TAB_EQUAL_SPLIT, MaxSplit=1)
            if len(List) != 2:
                RaiseParserError(Key, 'Nmake', ContainerFile, '<MacroName> = <Value>')
                continue
            Nmake = ModuleNmakeClass()
            Nmake.Name = List[0]
            Nmake.Value = List[1]
            Nmake.SupArchList = Nmakes[Key]
            self.Module.Nmake.append(Nmake)

            # convert Edk format to EdkII format
            if Nmake.Name == "IMAGE_ENTRY_POINT":
                Image = ModuleExternImageClass()
                Image.ModuleEntryPoint = Nmake.Value
                self.Module.ExternImages.append(Image)
            elif Nmake.Name == "DPX_SOURCE":
                Source = ModuleSourceFileClass(NormPath(Nmake.Value), "", "", "", "", Nmake.SupArchList)
                self.Module.Sources.append(Source)
            else:
                ToolList = gNmakeFlagPattern.findall(Nmake.Name)
                if len(ToolList) == 0 or len(ToolList) != 1:
                    EdkLogger.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake.Name,
                                   ExtraData=ContainerFile)
                else:
                    if ToolList[0] in gNmakeFlagName2ToolCode:
                        Tool = gNmakeFlagName2ToolCode[ToolList[0]]
                    else:
                        Tool = ToolList[0]
                    BuildOption = BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool, Nmake.Value)
                    BuildOption.SupArchList = Nmake.SupArchList
                    self.Module.BuildOptions.append(BuildOption)
示例#17
0
    def GenSources(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_SOURCES)
        Sources = {}

        # Get all Sources
        RecordSet = self.RecordSet[MODEL_EFI_SOURCE_FILE]
        for Record in RecordSet:
            (Filename, Family, TagName, ToolCode, Pcd) = GetSource(
                Record[0], ContainerFile, self.Identification.RelaPath, Record[2]
            )
            Source = ModuleSourceFileClass(Filename, TagName, ToolCode, Family, Pcd, Record[1])
            if GenerateHelpText(Record[5], ""):
                Source.HelpTextList.append(GenerateHelpText(Record[5], ""))
            if MODEL_EFI_SOURCE_FILE in self.SectionHeaderCommentDict:
                Source.HelpText = self.SectionHeaderCommentDict[MODEL_EFI_SOURCE_FILE]
            self.Module.Sources.append(Source)
示例#18
0
def GetTextFileInfo(FileName, TagTuple):
    ValueTuple = [""] * len(TagTuple)
    try:
        for Line in open(FileName):
            Line = Line.split("#", 1)[0]
            MatchEquation = mReEquation.match(Line)
            if MatchEquation:
                Tag = MatchEquation.group(1).upper()
                Value = MatchEquation.group(2)
                for Index in range(len(TagTuple)):
                    if TagTuple[Index] == Tag:
                        ValueTuple[Index] = Value
    except:
        EdkLogger.info("IO Error in reading file %s" % FileName)
        
    return ValueTuple
示例#19
0
 def GenDepexes(self, ContainerFile):
     EdkLogger.debug(2, "Generate %s ..." % TAB_DEPEX)
     Depex = {}
     # Get all Depexes
     RecordSet = self.RecordSet[MODEL_EFI_DEPEX]
     DepexString = ""
     for Record in RecordSet:
         DepexString = DepexString + Record[0] + "\n"
     Dep = ModuleDepexClass()
     if DepexString.endswith("\n"):
         DepexString = DepexString[: len(DepexString) - len("\n")]
     Dep.Depex = DepexString
     if self.Module.ModuleHeader.ModuleType in ["DXE_SMM_DRIVER"]:
         self.Module.SmmDepex = Dep
     elif self.Module.ModuleHeader.ModuleType in ["PEI_CORE", "PEIM"]:
         self.Module.PeiDepex = Dep
     else:
         self.Module.DxeDepex = Dep
示例#20
0
 def GenLibraryClasses(self, ContainerFile):
     EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)
     LibraryClasses = {}
     # Get all LibraryClasses
     RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]
     for Record in RecordSet:
         (LibClassName, LibClassIns, Pcd, SupModelList) = GetLibraryClassOfInf(
             [Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2]
         )
         LibraryClass = CommonClass.LibraryClassClass()
         LibraryClass.LibraryClass = LibClassName
         LibraryClass.RecommendedInstance = LibClassIns
         LibraryClass.FeatureFlag = Pcd
         LibraryClass.SupArchList = Record[1]
         LibraryClass.SupModuleList = Record[4]
         if GenerateHelpText(Record[5], ""):
             LibraryClass.HelpTextList.append(GenerateHelpText(Record[5], ""))
         self.Module.LibraryClasses.append(LibraryClass)
def ConvertTextFileToDictionary(FileName, Dictionary, CommentCharacter, KeySplitCharacter, ValueSplitFlag, ValueSplitCharacter):
    try:
        F = open(FileName,'r')
        Keys = []
        for Line in F:
            if Line.startswith(CommentCharacter):
                continue
            LineList = Line.split(KeySplitCharacter,1)
            if len(LineList) >= 2:
                Key = LineList[0].split()
            if len(Key) == 1 and Key[0][0] != CommentCharacter and Key[0] not in Keys:
                if ValueSplitFlag:
                    Dictionary[Key[0]] = LineList[1].replace('\\','/').split(ValueSplitCharacter)
                else:
                    Dictionary[Key[0]] = LineList[1].strip().replace('\\','/')
                Keys += [Key[0]]
        F.close()
        return 0
    except:
        EdkLogger.info('Open file failed')
        return 1
    def GenIncludes(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)
        Includes = sdict()
        #
        # Get all Includes
        #
        RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    MergeArches(Includes, Record[0], Arch)

        for Key in Includes.keys():
            Include = IncludeClass()
            Include.FilePath = NormPath(Key)
            Include.SupArchList = Includes[Key]
            self.Module.Includes.append(Include)
示例#23
0
    def GenGuidProtocolPpis(self, Type, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % Type)
        Lists = {}
        # Get all Items
        if Type == TAB_GUIDS:
            ListMember = self.Module.Guids
        elif Type == TAB_PROTOCOLS:
            ListMember = self.Module.Protocols
        elif Type == TAB_PPIS:
            ListMember = self.Module.Ppis

        RecordSet = self.RecordSet[Section[Type.upper()]]
        for Record in RecordSet:
            (Name, Value) = GetGuidsProtocolsPpisOfInf(Record[0], Type, ContainerFile, Record[2])
            ListClass = GuidProtocolPpiCommonClass()
            ListClass.CName = Name
            ListClass.SupArchList = Record[1]
            ListClass.FeatureFlag = Value
            if GenerateHelpText(Record[5], ""):
                ListClass.HelpTextList.append(GenerateHelpText(Record[5], ""))
            ListMember.append(ListClass)
    def GenLibraries(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARIES)
        Libraries = sdict()
        #
        # Get all Includes
        #
        RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_INSTANCE]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    MergeArches(Libraries, Record[0], Arch)

        for Key in Libraries.keys():
            Library = ModuleLibraryClass()
            # replace macro and remove file extension
            Library.Library = Key.rsplit('.', 1)[0]
            Library.SupArchList = Libraries[Key]
            self.Module.Libraries.append(Library)
    def ConvertTextFileToDict(self, FileName, CommentCharacter, KeySplitCharacter):
        F = None
        try:
            F = open(FileName,'r')
        except:
            EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)
            if F != None:
                F.close()

        for Line in F:
            Line = Line.strip()
            if Line.startswith(CommentCharacter) or Line == '':
                continue

            LineList = Line.split(KeySplitCharacter, 1)
            Key = LineList[0].strip()
            if len(LineList) == 2:
                Value = LineList[1].strip()
            else:
                Value = ""

            if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \
                       DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:
                self.TargetTxtDictionary[Key] = Value.replace('\\', '/')
            elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \
                         DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:
                self.TargetTxtDictionary[Key] = Value.split()
            elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:
                try:
                    V = int(Value, 0)
                except:
                    EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),
                                    File=FileName)
                self.TargetTxtDictionary[Key] = Value
            #elif Key not in GlobalData.gGlobalDefines:
            #    GlobalData.gGlobalDefines[Key] = Value

        F.close()
        return 0
示例#26
0
文件: Database.py 项目: kraxel/edk2
    def InitDatabase(self):
        EdkLogger.verbose("\nInitialize ECC database started ...")
        #
        # Drop all old existing tables
        #
#        self.TblDataModel.Drop()
#        self.TblDsc.Drop()
#        self.TblFile.Drop()
        
        #
        # Create new tables
        #
        self.TblDataModel.Create()
        self.TblFile.Create()
        self.TblInf.Create()
        self.TblDec.Create()
        self.TblDsc.Create()
        
        #
        # Initialize table DataModel
        #
        self.TblDataModel.InitTable()
        EdkLogger.verbose("Initialize ECC database ... DONE!")
示例#27
0
def CheckFileExist(WorkspaceDir,
                   CheckFilename,
                   ContainerFilename,
                   SectionName,
                   Line,
                   LineNo=-1):
    CheckFile = ''
    if CheckFilename != '' and CheckFilename != None:
        CheckFile = WorkspaceFile(WorkspaceDir, CheckFilename)
        if not os.path.isfile(CheckFile):
            ContainerFile = open(ContainerFilename, 'r').read()
            if LineNo == -1:
                LineNo = GetLineNo(ContainerFile, Line)
            ErrorMsg = "Can't find file '%s' defined in section '%s'" % (
                CheckFile, SectionName)
            EdkLogger.error("Parser",
                            PARSER_ERROR,
                            ErrorMsg,
                            File=ContainerFilename,
                            Line=LineNo,
                            RaiseError=EdkLogger.IsRaiseError)

    return CheckFile
示例#28
0
    def InitDatabase(self):
        EdkLogger.verbose("\nInitialize ECC database started ...")
        #
        # Drop all old existing tables
        #
        #        self.TblDataModel.Drop()
        #        self.TblDsc.Drop()
        #        self.TblFile.Drop()

        #
        # Create new tables
        #
        self.TblDataModel.Create()
        self.TblFile.Create()
        self.TblInf.Create()
        self.TblDec.Create()
        self.TblDsc.Create()

        #
        # Initialize table DataModel
        #
        self.TblDataModel.InitTable()
        EdkLogger.verbose("Initialize ECC database ... DONE!")
示例#29
0
    def GenSources(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_SOURCES)
        Sources = {}

        #
        # Get all Nmakes
        #
        RecordSet = self.RecordSet[MODEL_EFI_SOURCE_FILE]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (Filename, Family, TagName, ToolCode,
                     Pcd) = GetSource(Record[0], ContainerFile,
                                      self.Identification.FileRelativePath,
                                      Record[2])
                    MergeArches(Sources,
                                (Filename, Family, TagName, ToolCode, Pcd),
                                Arch)
                    if self.IsToDatabase:
                        SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'
                                        where ID = %s""" % (
                            self.TblInf.Table, ConvertToSqlString2(Filename),
                            ConvertToSqlString2(Family),
                            ConvertToSqlString2(TagName),
                            ConvertToSqlString2(ToolCode),
                            ConvertToSqlString2(Pcd), Record[3])
                        self.TblInf.Exec(SqlCommand)

        for Key in Sources.keys():
            Source = ModuleSourceFileClass(Key[0], Key[2], Key[3], Key[1],
                                           Key[4], Sources[Key])
            self.Module.Sources.append(Source)
示例#30
0
    def GenDepexes(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_DEPEX)
        Depex = {}
        #
        # Get all Depexes
        #
        RecordSet = self.RecordSet[MODEL_EFI_DEPEX]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            Line = ''
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    Line = Line + Record[0] + ' '
            if Line != '':
                MergeArches(Depex, Line, Arch)

        for Key in Depex.keys():
            Dep = ModuleDepexClass()
            Dep.Depex = Key
            Dep.SupArchList = Depex[Key]
            self.Module.Depex.append(Dep)
    def GenDepexes(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_DEPEX)
        Depex = {}
        #
        # Get all Depexes
        #
        RecordSet = self.RecordSet[MODEL_EFI_DEPEX]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            Line = ''
            for Record in RecordSet:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    Line = Line + Record[0] + ' '
            if Line != '':
                MergeArches(Depex, Line, Arch)

        for Key in Depex.keys():
            Dep = ModuleDepexClass()
            Dep.Depex = Key
            Dep.SupArchList = Depex[Key]
            self.Module.Depex.append(Dep)
示例#32
0
    def GenPcds(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)
        Pcds = {}
        PcdToken = {}

        # Get all Pcds
        RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]
        RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]
        RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]
        RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]
        RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]

        # Go through each arch
        for Record in RecordSet1:
            (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(
                Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2]
            )
            self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
        for Record in RecordSet2:
            (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(
                Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2]
            )
            self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
        for Record in RecordSet3:
            (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(
                Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2]
            )
            self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
        for Record in RecordSet4:
            (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(
                Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2]
            )
            self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
        for Record in RecordSet5:
            (TokenSpaceGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], "", ContainerFile, Record[2])
            self.AddPcd(TokenName, TokenSpaceGuidCName, Value, Type, Record[1], Record[5])
示例#33
0
def PreCheck(FileName, FileContent, SupSectionTag):
    LineNo = 0
    IsFailed = False
    NewFileContent = ''
    for Line in FileContent.splitlines():
        LineNo = LineNo + 1
        #
        # Clean current line
        #
        Line = CleanString(Line)

        #
        # Remove commented line
        #
        if Line.find(DataType.TAB_COMMA_SPLIT) == 0:
            Line = ''
        #
        # Check $()
        #
        if Line.find('$') > -1:
            if Line.find('$(') < 0 or Line.find(')') < 0:
                EdkLogger.error("Parser",
                                FORMAT_INVALID,
                                Line=LineNo,
                                File=FileName,
                                RaiseError=EdkLogger.IsRaiseError)

        #
        # Check []
        #
        if Line.find('[') > -1 or Line.find(']') > -1:
            #
            # Only get one '[' or one ']'
            #
            if not (Line.find('[') > -1 and Line.find(']') > -1):
                EdkLogger.error("Parser",
                                FORMAT_INVALID,
                                Line=LineNo,
                                File=FileName,
                                RaiseError=EdkLogger.IsRaiseError)

        #
        # Regenerate FileContent
        #
        NewFileContent = NewFileContent + Line + '\r\n'

    if IsFailed:
        EdkLogger.error("Parser",
                        FORMAT_INVALID,
                        Line=LineNo,
                        File=FileName,
                        RaiseError=EdkLogger.IsRaiseError)

    return NewFileContent
示例#34
0
    def ConvertTextFileToDict(self, FileName, CommentCharacter,
                              KeySplitCharacter):
        F = None
        try:
            F = open(FileName, 'r')
        except:
            EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)
            if F != None:
                F.close()

        for Line in F:
            Line = Line.strip()
            if Line.startswith(CommentCharacter) or Line == '':
                continue

            LineList = Line.split(KeySplitCharacter, 1)
            Key = LineList[0].strip()
            if len(LineList) == 2:
                Value = LineList[1].strip()
            else:
                Value = ""

            if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \
                       DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:
                self.TargetTxtDictionary[Key] = Value.replace('\\', '/')
            elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \
                         DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:
                self.TargetTxtDictionary[Key] = Value.split()
            elif Key == DataType.TAB_TAT_DEFINES_MULTIPLE_THREAD:
                if Value not in ["Enable", "Disable"]:
                    EdkLogger.error(
                        "build",
                        FORMAT_INVALID,
                        "Invalid setting of [%s]: %s." % (Key, Value),
                        ExtraData="\tSetting must be one of [Enable, Disable]",
                        File=FileName)
                self.TargetTxtDictionary[Key] = Value
            elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:
                try:
                    V = int(Value, 0)
                except:
                    EdkLogger.error("build",
                                    FORMAT_INVALID,
                                    "Invalid number of [%s]: %s." %
                                    (Key, Value),
                                    File=FileName)
                self.TargetTxtDictionary[Key] = Value
            #elif Key not in GlobalData.gGlobalDefines:
            #    GlobalData.gGlobalDefines[Key] = Value

        F.close()
        return 0
def PreCheck(FileName, FileContent, SupSectionTag):
    LineNo = 0
    IsFailed = False
    NewFileContent = ''
    for Line in FileContent.splitlines():
        LineNo = LineNo + 1
        #
        # Clean current line
        #
        Line = CleanString(Line)

        #
        # Remove commented line
        #
        if Line.find(DataType.TAB_COMMA_SPLIT) == 0:
            Line = ''
        #
        # Check $()
        #
        if Line.find('$') > -1:
            if Line.find('$(') < 0 or Line.find(')') < 0:
                EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName, RaiseError=EdkLogger.IsRaiseError)

        #
        # Check []
        #
        if Line.find('[') > -1 or Line.find(']') > -1:
            #
            # Only get one '[' or one ']'
            #
            if not (Line.find('[') > -1 and Line.find(']') > -1):
                EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName, RaiseError=EdkLogger.IsRaiseError)

        #
        # Regenerate FileContent
        #
        NewFileContent = NewFileContent + Line + '\r\n'

    if IsFailed:
       EdkLogger.error("Parser", FORMAT_INVALID, Line=LineNo, File=FileName, RaiseError=EdkLogger.IsRaiseError)

    return NewFileContent
示例#36
0
def MigrationOptionParser(Source, Destinate, ToolName, VersionNumber = 1.0):
    # use clearer usage to override default usage message
    UsageString = "%s [-a] [-v|-q] [-o <output_file>] <input_file>" % ToolName
    Version = "%s Version %.2f" % (ToolName, VersionNumber)
    Copyright = "Copyright (c) 2007, Intel Corporation. All rights reserved."
    
    Parser = OptionParser(description=Copyright, version=Version, usage=UsageString)
    Parser.add_option("-o", "--output", dest="OutputFile", help="The name of the %s file to be created." % Destinate)
    Parser.add_option("-a", "--auto", dest="AutoWrite", action="store_true", default=False, help="Automatically create the %s file using the name of the %s file and replacing file extension" % (Source, Destinate))
    Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")
    Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed.")

    Options, Args = Parser.parse_args()

    # Set logging level
    if Options.verbose:
        EdkLogger.setLevel(EdkLogger.VERBOSE)
    elif Options.quiet:
        EdkLogger.setLevel(EdkLogger.QUIET)
    else:
        EdkLogger.setLevel(EdkLogger.INFO)
        
    # error check
    if len(Args) == 0:
        raise MigrationError(PARAMETER_MISSING, name="Input file", usage=Parser.get_usage())
    if len(Args) > 1:
        raise MigrationError(PARAMETER_INVALID, name="Too many input files", usage=Parser.get_usage())

    InputFile = Args[0]
    if not os.path.exists(InputFile):
        raise MigrationError(FILE_NOT_FOUND, name=InputFile)

    if Options.OutputFile:
        if Options.AutoWrite:
            raise MigrationError(OPTION_CONFLICT, arg1="-o", arg2="-a", usage=Parser.get_usage())
    else:
        if Options.AutoWrite:
            Options.OutputFile = os.path.splitext(InputFile)[0] + "." + Destinate.lower()
        else:
            raise MigrationError(OPTION_MISSING, name="-o", usage=Parser.get_usage())

    return Options, InputFile
示例#37
0
        elif Type == TAB_PPIS:
            ListMember = self.Module.Ppis

        for Key in Lists.keys():
            ListClass = GuidProtocolPpiCommonClass()
            ListClass.CName = Key[0]
            ListClass.SupArchList = Lists[Key]
            ListClass.FeatureFlag = Key[1]
            ListMember.append(ListClass)


##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
    EdkLogger.Initialize()
    EdkLogger.SetLevel(EdkLogger.DEBUG_0)

    W = os.getenv('WORKSPACE')
    F = os.path.join(W, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')

    Db = Database.Database('Inf.db')
    Db.InitDatabase()

    P = Inf(os.path.normpath(F), True, True, W, Db)
    P.ShowModule()

    Db.Close()
示例#38
0
            ListMember = self.Module.Protocols
        elif Type == TAB_PPIS:
            ListMember = self.Module.Ppis

        RecordSet = self.RecordSet[Section[Type.upper()]]
        for Record in RecordSet:
            (Name, Value) = GetGuidsProtocolsPpisOfInf(Record[0], Type, ContainerFile, Record[2])
            ListClass = GuidProtocolPpiCommonClass()
            ListClass.CName = Name
            ListClass.SupArchList = Record[1]
            ListClass.FeatureFlag = Value
            if GenerateHelpText(Record[5], ''):
                ListClass.HelpTextList.append(GenerateHelpText(Record[5], ''))
            ListMember.append(ListClass)
       
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
    EdkLogger.Initialize()
    EdkLogger.SetLevel(EdkLogger.QUIET)
        
    W = os.getenv('WORKSPACE')
    F = os.path.join(W, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')
    
    P = Inf(os.path.normpath(F), True, W, 'MdeModulePkg')
    P.ShowModule()
    print P.ModuleToInf(P.Module)
示例#39
0
def StoreTextFile(TextFile, Content):
    EdkLogger.verbose(Content)
    TextFile.write(Content)
示例#40
0
    def LoadInfFile(self, Filename):     
        # Insert a record for file
        Filename = NormPath(Filename)
        
        self.Identification.FullPath = Filename
        (self.Identification.RelaPath, self.Identification.FileName) = os.path.split(Filename)
        if self.Identification.FullPath.find(self.WorkspaceDir) > -1:
            self.Identification.ModulePath = os.path.dirname(self.Identification.FullPath[len(self.WorkspaceDir) + 1:])        
        if self.PackageDir:
            self.Identification.PackagePath = self.PackageDir
            if self.Identification.ModulePath.find(self.PackageDir) == 0:
                self.Identification.ModulePath = self.Identification.ModulePath[len(self.PackageDir) + 1:]
        
        # Init common datas
        IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \
        [], [], TAB_UNKNOWN, [], [], []
        LineNo = 0
        
        # Parse file content
        IsFindBlockComment = False
        ReservedLine = ''
        Comment = ''
        for Line in open(Filename, 'r'):
            LineNo = LineNo + 1
            # Remove comment block
            if Line.find(TAB_COMMENT_R8_START) > -1:
                ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0]
                if ReservedLine.strip().startswith(TAB_COMMENT_SPLIT):
                    Comment = Comment + Line.strip() + '\n'
                    ReservedLine = ''
                else:
                    Comment = Comment + Line[len(ReservedLine):] + '\n'
                IsFindBlockComment = True
                if not ReservedLine:
                    continue
            if Line.find(TAB_COMMENT_R8_END) > -1:
                Comment = Comment + Line[:Line.find(TAB_COMMENT_R8_END) + len(TAB_COMMENT_R8_END)] + '\n'
                Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1]
                ReservedLine = ''
                IsFindBlockComment = False
            if IsFindBlockComment:
                Comment = Comment + Line.strip() + '\n'
                continue
            
            # Remove comments at tail and remove spaces again
            if Line.strip().startswith(TAB_COMMENT_SPLIT) or Line.strip().startswith('--/'):
                Comment = Comment + Line.strip() + '\n'
            Line = CleanString(Line)
            if Line == '':
                continue
            
            ## Find a new section tab
            # First insert previous section items
            # And then parse the content of the new section
            if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):
                if Line[1:3] == "--":
                    continue
                Model = Section[CurrentSection.upper()]
                # Insert items data of previous section
                InsertSectionItems(Model, CurrentSection, SectionItemList, ArchList, ThirdList, self.RecordSet)
                
                # Parse the new section
                SectionItemList = []
                ArchList = []
                ThirdList = []
                
                CurrentSection = ''
                LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)
                for Item in LineList:
                    ItemList = GetSplitValueList(Item, TAB_SPLIT)
                    if CurrentSection == '':
                        CurrentSection = ItemList[0]
                    else:
                        if CurrentSection != ItemList[0]:
                            EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)
                    if CurrentSection.upper() not in self.KeyList:
                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)
                    ItemList.append('')
                    ItemList.append('')
                    if len(ItemList) > 5:
                        RaiseParserError(Line, CurrentSection, Filename, '', LineNo)
                    else:
                        if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:
                            EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)
                        ArchList.append(ItemList[1].upper())
                        ThirdList.append(ItemList[2])

                if Comment:
                    if Comment.endswith('\n'):
                        Comment = Comment[:len(Comment) - len('\n')]
                    self.SectionHeaderCommentDict[Section[CurrentSection.upper()]] = Comment
                    Comment = ''
                continue
            
            # Not in any defined section
            if CurrentSection == TAB_UNKNOWN:
                ErrorMsg = "%s is not in any defined section" % Line
                EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)

            # Add a section item
            SectionItemList.append([Line, LineNo, Comment])
            Comment = ''
            # End of parse
        #End of For
        
        # Insert items data of last section
        Model = Section[CurrentSection.upper()]
        InsertSectionItems(Model, CurrentSection, SectionItemList, ArchList, ThirdList, self.RecordSet)
        if Comment != '':
            self.SectionHeaderCommentDict[Model] = Comment
            Comment = ''
示例#41
0
    def GenPcds(self, ContainerFile):
        EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)
        Pcds = {}
        PcdToken = {}

        #
        # Get all Guids
        #
        RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]
        RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]
        RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]
        RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]
        RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]

        #
        # Go through each arch
        #
        for Arch in self.SupArchList:
            for Record in RecordSet1:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    if self.Module.Header[Arch].LibraryClass != {}:
                        pass
                    (TokenGuidCName, TokenName, Value,
                     Type) = GetPcdOfInf(Record[0], TAB_PCDS_FIXED_AT_BUILD,
                                         ContainerFile, Record[2])
                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type),
                                Arch)
                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)
            for Record in RecordSet2:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (TokenGuidCName, TokenName, Value,
                     Type) = GetPcdOfInf(Record[0],
                                         TAB_PCDS_PATCHABLE_IN_MODULE,
                                         ContainerFile, Record[2])
                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type),
                                Arch)
                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)
            for Record in RecordSet3:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (TokenGuidCName, TokenName, Value,
                     Type) = GetPcdOfInf(Record[0], TAB_PCDS_FEATURE_FLAG,
                                         ContainerFile, Record[2])
                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type),
                                Arch)
                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)
            for Record in RecordSet4:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (TokenGuidCName, TokenName, Value,
                     Type) = GetPcdOfInf(Record[0], TAB_PCDS_DYNAMIC_EX,
                                         ContainerFile, Record[2])
                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type),
                                Arch)
                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)
            for Record in RecordSet5:
                if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:
                    (TokenGuidCName, TokenName, Value,
                     Type) = GetPcdOfInf(Record[0], "", ContainerFile,
                                         Record[2])
                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type),
                                Arch)
                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)
        #
        # Update to database
        #
        if self.IsToDatabase:
            for Key in PcdToken.keys():
                SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (
                    self.TblInf.Table, ".".join(
                        (PcdToken[Key][0], PcdToken[Key][1])), Key)
                self.TblInf.Exec(SqlCommand)

        for Key in Pcds.keys():
            Pcd = PcdClass()
            Pcd.CName = Key[1]
            Pcd.TokenSpaceGuidCName = Key[0]
            Pcd.DefaultValue = Key[2]
            Pcd.ItemType = Key[3]
            Pcd.SupArchList = Pcds[Key]
            self.Module.PcdCodes.append(Pcd)
示例#42
0
    def GenModuleHeader(self, ContainerFile):
        EdkLogger.debug(2, "Generate ModuleHeader ...")
        File = self.Identification.FileFullPath
        #
        # Update all defines item in database
        #
        RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]
        for Record in RecordSet:
            ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)
            if len(ValueList) != 2:
                RaiseParserError(Record[0], 'Defines', ContainerFile,
                                 '<Key> = <Value>', Record[2])
            ID, Value1, Value2, Arch, LineNo = Record[3], ValueList[
                0], ValueList[1], Record[1], Record[2]
            SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'
                            where ID = %s""" % (
                self.TblInf.Table, ConvertToSqlString2(Value1),
                ConvertToSqlString2(Value2), ID)
            self.TblInf.Exec(SqlCommand)

        for Arch in DataType.ARCH_LIST:
            ModuleHeader = InfHeader()
            ModuleHeader.FileName = self.Identification.FileName
            ModuleHeader.FullPath = self.Identification.FileFullPath
            DefineList = QueryDefinesItem2(self.TblInf, Arch, self.FileID)

            NotProcessedDefineList = []
            for D in DefineList:
                if D[0] in ModuleHeader:
                    ModuleHeader[D[0]] = GetSplitValueList(D[1])[0]
                else:
                    NotProcessedDefineList.append(D)

            if ModuleHeader.ComponentType == "LIBRARY":
                Lib = LibraryClassClass()
                Lib.LibraryClass = ModuleHeader.Name
                Lib.SupModuleList = DataType.SUP_MODULE_LIST
                ModuleHeader.LibraryClass.append(Lib)

            # we need to make some key defines resolved first
            for D in NotProcessedDefineList:
                if D[0] == TAB_INF_DEFINES_LIBRARY_CLASS:
                    List = GetSplitValueList(D[1], DataType.TAB_VALUE_SPLIT, 1)
                    Lib = LibraryClassClass()
                    Lib.LibraryClass = CleanString(List[0])
                    if len(List) == 1:
                        Lib.SupModuleList = DataType.SUP_MODULE_LIST
                    elif len(List) == 2:
                        Lib.SupModuleList = GetSplitValueList(
                            CleanString(List[1]), ' ')
                    ModuleHeader.LibraryClass.append(Lib)
                elif D[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
                    List = D[1].split(DataType.TAB_VALUE_SPLIT)
                    if len(List) == 2:
                        ModuleHeader.CustomMakefile[CleanString(
                            List[0])] = CleanString(List[1])
                    else:
                        RaiseParserError(
                            D[1], 'CUSTOM_MAKEFILE of Defines', File,
                            'CUSTOM_MAKEFILE=<Family>|<Filename>', D[2])
                elif D[0] == TAB_INF_DEFINES_ENTRY_POINT:
                    Image = ModuleExternImageClass()
                    Image.ModuleEntryPoint = CleanString(D[1])
                    self.Module.ExternImages.append(Image)
                elif D[0] == TAB_INF_DEFINES_UNLOAD_IMAGE:
                    Image = ModuleExternImageClass()
                    Image.ModuleUnloadImage = CleanString(D[1])
                    self.Module.ExternImages.append(Image)
                elif D[0] == TAB_INF_DEFINES_CONSTRUCTOR:
                    LibraryClass = ModuleExternLibraryClass()
                    LibraryClass.Constructor = CleanString(D[1])
                    self.Module.ExternLibraries.append(LibraryClass)
                elif D[0] == TAB_INF_DEFINES_DESTRUCTOR:
                    LibraryClass = ModuleExternLibraryClass()
                    LibraryClass.Destructor = CleanString(D[1])
                    self.Module.ExternLibraries.append(LibraryClass)
                elif D[0] == TAB_INF_DEFINES_DEFINE:
                    List = D[1].split(DataType.TAB_EQUAL_SPLIT)
                    if len(List) != 2:
                        RaiseParserError(Item, 'DEFINE of Defines', File,
                                         'DEFINE <Word> = <Word>', D[2])
                    else:
                        ModuleHeader.Define[CleanString(
                            List[0])] = CleanString(List[1])
                elif D[0] == TAB_INF_DEFINES_SPEC:
                    List = D[1].split(DataType.TAB_EQUAL_SPLIT)
                    if len(List) != 2:
                        RaiseParserError(Item, 'SPEC of Defines', File,
                                         'SPEC <Word> = <Version>', D[2])
                    else:
                        ModuleHeader.Specification[CleanString(
                            List[0])] = CleanString(List[1])

            #
            # Get version of INF
            #
            if ModuleHeader.InfVersion != "":
                # EdkII inf
                VersionNumber = ModuleHeader.VersionNumber
                VersionString = ModuleHeader.VersionString
                if len(VersionNumber) > 0 and len(VersionString) == 0:
                    EdkLogger.warn(
                        2000,
                        'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.'
                        % self.Identification.FileFullPath)
                    ModuleHeader.Version = VersionNumber
                if len(VersionString) > 0:
                    if len(VersionNumber) > 0:
                        EdkLogger.warn(
                            2001,
                            'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING'
                            % self.Identification.FileFullPath)
                    ModuleHeader.Version = VersionString
            else:
                # Edk inf
                ModuleHeader.InfVersion = "0x00010000"
                if ModuleHeader.ComponentType in gComponentType2ModuleType:
                    ModuleHeader.ModuleType = gComponentType2ModuleType[
                        ModuleHeader.ComponentType]
                elif ModuleHeader.ComponentType != '':
                    EdkLogger.error("Parser",
                                    PARSER_ERROR,
                                    "Unsupported Edk component type [%s]" %
                                    ModuleHeader.ComponentType,
                                    ExtraData=File,
                                    RaiseError=EdkLogger.IsRaiseError)

            self.Module.Header[Arch] = ModuleHeader
示例#43
0
    def ConvertTextFileToDict(self, FileName, CommentCharacter,
                              KeySplitCharacter):
        F = None
        try:
            F = open(FileName, 'r')
            self.ConfDirectoryPath = os.path.dirname(FileName)
        except:
            EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)
            if F is not None:
                F.close()

        for Line in F:
            Line = Line.strip()
            if Line.startswith(CommentCharacter) or Line == '':
                continue

            LineList = Line.split(KeySplitCharacter, 1)
            Key = LineList[0].strip()
            if len(LineList) == 2:
                Value = LineList[1].strip()
            else:
                Value = ""

            if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \
                       DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:
                self.TargetTxtDictionary[Key] = Value.replace('\\', '/')
                if Key == DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF and self.TargetTxtDictionary[
                        Key]:
                    if self.TargetTxtDictionary[Key].startswith("Conf/"):
                        Tools_Def = os.path.join(
                            self.ConfDirectoryPath,
                            self.TargetTxtDictionary[Key].strip())
                        if not os.path.exists(Tools_Def) or not os.path.isfile(
                                Tools_Def):
                            # If Conf/Conf does not exist, try just the Conf/ directory
                            Tools_Def = os.path.join(
                                self.ConfDirectoryPath,
                                self.TargetTxtDictionary[Key].replace(
                                    "Conf/", "", 1).strip())
                    else:
                        # The File pointed to by TOOL_CHAIN_CONF is not in a Conf/ directory
                        Tools_Def = os.path.join(
                            self.ConfDirectoryPath,
                            self.TargetTxtDictionary[Key].strip())
                    self.TargetTxtDictionary[Key] = Tools_Def
                if Key == DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF and self.TargetTxtDictionary[
                        Key]:
                    if self.TargetTxtDictionary[Key].startswith("Conf/"):
                        Build_Rule = os.path.join(
                            self.ConfDirectoryPath,
                            self.TargetTxtDictionary[Key].strip())
                        if not os.path.exists(
                                Build_Rule) or not os.path.isfile(Build_Rule):
                            # If Conf/Conf does not exist, try just the Conf/ directory
                            Build_Rule = os.path.join(
                                self.ConfDirectoryPath,
                                self.TargetTxtDictionary[Key].replace(
                                    "Conf/", "", 1).strip())
                    else:
                        # The File pointed to by BUILD_RULE_CONF is not in a Conf/ directory
                        Build_Rule = os.path.join(
                            self.ConfDirectoryPath,
                            self.TargetTxtDictionary[Key].strip())
                    self.TargetTxtDictionary[Key] = Build_Rule
            elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \
                         DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:
                self.TargetTxtDictionary[Key] = Value.split()
            elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:
                try:
                    V = int(Value, 0)
                except:
                    EdkLogger.error("build",
                                    FORMAT_INVALID,
                                    "Invalid number of [%s]: %s." %
                                    (Key, Value),
                                    File=FileName)
                self.TargetTxtDictionary[Key] = Value
            #elif Key not in GlobalData.gGlobalDefines:
            #    GlobalData.gGlobalDefines[Key] = Value

        F.close()
        return 0
示例#44
0
    def LoadInfFile(self, Filename):
        #
        # Insert a record for file
        #
        Filename = NormPath(Filename)
        self.Identification.FileFullPath = Filename
        (self.Identification.FileRelativePath,
         self.Identification.FileName) = os.path.split(Filename)
        self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_INF)

        #
        # Init InfTable
        #
        #self.TblInf.Table = "Inf%s" % self.FileID
        #self.TblInf.Create()

        #
        # Init common datas
        #
        IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \
        [], [], TAB_UNKNOWN, [], [], []
        LineNo = 0

        #
        # Parse file content
        #
        IsFindBlockComment = False
        ReservedLine = ''
        for Line in open(Filename, 'r'):
            LineNo = LineNo + 1
            #
            # Remove comment block
            #
            if Line.find(TAB_COMMENT_EDK_START) > -1:
                ReservedLine = GetSplitList(Line, TAB_COMMENT_EDK_START, 1)[0]
                IsFindBlockComment = True
            if Line.find(TAB_COMMENT_EDK_END) > -1:
                Line = ReservedLine + GetSplitList(Line, TAB_COMMENT_EDK_END,
                                                   1)[1]
                ReservedLine = ''
                IsFindBlockComment = False
            if IsFindBlockComment:
                continue

            #
            # Remove comments at tail and remove spaces again
            #
            Line = CleanString(Line)
            if Line == '':
                continue

            #
            # Find a new section tab
            # First insert previous section items
            # And then parse the content of the new section
            #
            if Line.startswith(TAB_SECTION_START) and Line.endswith(
                    TAB_SECTION_END):
                if Line[1:3] == "--":
                    continue
                Model = Section[CurrentSection.upper()]
                #
                # Insert items data of previous section
                #
                InsertSectionItemsIntoDatabase(self.TblInf, self.FileID,
                                               Filename, Model, CurrentSection,
                                               SectionItemList, ArchList,
                                               ThirdList, IfDefList,
                                               self.RecordSet)
                #
                # Parse the new section
                #
                SectionItemList = []
                ArchList = []
                ThirdList = []

                CurrentSection = ''
                LineList = GetSplitValueList(
                    Line[len(TAB_SECTION_START):len(Line) -
                         len(TAB_SECTION_END)], TAB_COMMA_SPLIT)
                for Item in LineList:
                    ItemList = GetSplitValueList(Item, TAB_SPLIT)
                    if CurrentSection == '':
                        CurrentSection = ItemList[0]
                    else:
                        if CurrentSection != ItemList[0]:
                            EdkLogger.error(
                                "Parser",
                                PARSER_ERROR,
                                "Different section names '%s' and '%s' are found in one section definition, this is not allowed."
                                % (CurrentSection, ItemList[0]),
                                File=Filename,
                                Line=LineNo,
                                RaiseError=EdkLogger.IsRaiseError)
                    if CurrentSection.upper() not in self.KeyList:
                        RaiseParserError(Line, CurrentSection, Filename, '',
                                         LineNo)
                        CurrentSection = TAB_UNKNOWN
                        continue
                    ItemList.append('')
                    ItemList.append('')
                    if len(ItemList) > 5:
                        RaiseParserError(Line, CurrentSection, Filename, '',
                                         LineNo)
                    else:
                        if ItemList[1] != '' and ItemList[1].upper(
                        ) not in ARCH_LIST_FULL:
                            EdkLogger.error(
                                "Parser",
                                PARSER_ERROR,
                                "Invalid Arch definition '%s' found" %
                                ItemList[1],
                                File=Filename,
                                Line=LineNo,
                                RaiseError=EdkLogger.IsRaiseError)
                        ArchList.append(ItemList[1].upper())
                        ThirdList.append(ItemList[2])

                continue

            #
            # Not in any defined section
            #
            if CurrentSection == TAB_UNKNOWN:
                ErrorMsg = "%s is not in any defined section" % Line
                EdkLogger.error("Parser",
                                PARSER_ERROR,
                                ErrorMsg,
                                File=Filename,
                                Line=LineNo,
                                RaiseError=EdkLogger.IsRaiseError)

            #
            # Add a section item
            #
            SectionItemList.append([Line, LineNo])
            # End of parse
        #End of For

        #
        # Insert items data of last section
        #
        Model = Section[CurrentSection.upper()]
        InsertSectionItemsIntoDatabase(self.TblInf, self.FileID, Filename,
                                       Model, CurrentSection, SectionItemList,
                                       ArchList, ThirdList, IfDefList,
                                       self.RecordSet)

        #
        # Replace all DEFINE macros with its actual values
        #
        ParseDefineMacro2(self.TblInf, self.RecordSet,
                          GlobalData.gGlobalDefines)
示例#45
0
    def IncludeToolDefFile(self, FileName):
        FileContent = []
        if os.path.isfile(FileName):
            try:
                F = open(FileName, 'r')
                FileContent = F.readlines()
            except:
                EdkLogger.error("tools_def.txt parser", FILE_OPEN_FAILURE, ExtraData=FileName)
        else:
            EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=FileName)

        for Index in range(len(FileContent)):
            Line = FileContent[Index].strip()
            if Line == "" or Line[0] == '#':
                continue

            if Line.startswith("!include"):
                IncFile = Line[8:].strip()
                Done, IncFile = self.ExpandMacros(IncFile)
                if not Done:
                    EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
                                    "Macro or Environment has not been defined",
                                ExtraData=IncFile[4:-1], File=FileName, Line=Index+1)
                IncFile = NormPath(IncFile)

                if not os.path.isabs(IncFile):
                    #
                    # try WORKSPACE
                    #
                    IncFileTmp = PathClass(IncFile, GlobalData.gWorkspace)
                    ErrorCode = IncFileTmp.Validate()[0]
                    if ErrorCode != 0:
                        #
                        # try PACKAGES_PATH
                        #
                        IncFileTmp = mws.join(GlobalData.gWorkspace, IncFile)
                        if not os.path.exists(IncFileTmp):
                            #
                            # try directory of current file
                            #
                            IncFileTmp = PathClass(IncFile, os.path.dirname(FileName))
                            ErrorCode = IncFileTmp.Validate()[0]
                            if ErrorCode != 0:
                                EdkLogger.error("tools_def.txt parser", FILE_NOT_FOUND, ExtraData=IncFile)

                    if type(IncFileTmp) is PathClass:
                        IncFile = IncFileTmp.Path
                    else:
                        IncFile = IncFileTmp

                self.IncludeToolDefFile(IncFile)
                continue

            NameValuePair = Line.split("=", 1)
            if len(NameValuePair) != 2:
                EdkLogger.warn("tools_def.txt parser", "Line %d: not correct assignment statement, skipped" % (Index + 1))
                continue

            Name = NameValuePair[0].strip()
            Value = NameValuePair[1].strip()

            if Name == "IDENTIFIER":
                EdkLogger.debug(EdkLogger.DEBUG_8, "Line %d: Found identifier statement, skipped: %s" % ((Index + 1), Value))
                continue

            MacroDefinition = gMacroDefPattern.findall(Name)
            if MacroDefinition != []:
                Done, Value = self.ExpandMacros(Value)
                if not Done:
                    EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
                                    "Macro or Environment has not been defined",
                                ExtraData=Value[4:-1], File=FileName, Line=Index+1)

                MacroName = MacroDefinition[0].strip()
                self.MacroDictionary["DEF(%s)" % MacroName] = Value
                EdkLogger.debug(EdkLogger.DEBUG_8, "Line %d: Found macro: %s = %s" % ((Index + 1), MacroName, Value))
                continue

            Done, Value = self.ExpandMacros(Value)
            if not Done:
                EdkLogger.error("tools_def.txt parser", ATTRIBUTE_NOT_AVAILABLE,
                                "Macro or Environment has not been defined",
                                ExtraData=Value[4:-1], File=FileName, Line=Index+1)

            List = Name.split('_')
            if len(List) != 5:
                EdkLogger.verbose("Line %d: Not a valid name of definition: %s" % ((Index + 1), Name))
                continue
            elif List[4] == '*':
                EdkLogger.verbose("Line %d: '*' is not allowed in last field: %s" % ((Index + 1), Name))
                continue
            else:
                self.ToolsDefTxtDictionary[Name] = Value
                if List[0] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] += [List[0]]
                if List[1] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] += [List[1]]
                if List[2] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] += [List[2]]
                if List[3] != '*':
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] += [List[3]]
                if List[4] == TAB_TOD_DEFINES_FAMILY and List[2] == '*' and List[3] == '*':
                    if TAB_TOD_DEFINES_FAMILY not in self.ToolsDefTxtDatabase:
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY] = {}
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][List[1]] = Value
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY] = {}
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value
                    elif List[1] not in self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]:
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][List[1]] = Value
                        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value
                    elif self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY][List[1]] != Value:
                        EdkLogger.verbose("Line %d: No override allowed for the family of a tool chain: %s" % ((Index + 1), Name))
                if List[4] == TAB_TOD_DEFINES_BUILDRULEFAMILY and List[2] == '*' and List[3] == '*':
                    if TAB_TOD_DEFINES_BUILDRULEFAMILY not in self.ToolsDefTxtDatabase \
                       or List[1] not in self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_FAMILY]:
                        EdkLogger.verbose("Line %d: The family is not specified, but BuildRuleFamily is specified for the tool chain: %s" % ((Index + 1), Name))
                    self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value

        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]))
        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]))
        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]))
        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]))

        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort()
        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort()
        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort()
        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort()

        KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE]
        for Index in range(3, -1, -1):
            for Key in dict(self.ToolsDefTxtDictionary):
                List = Key.split('_')
                if List[Index] == '*':
                    for String in self.ToolsDefTxtDatabase[KeyList[Index]]:
                        List[Index] = String
                        NewKey = '%s_%s_%s_%s_%s' % tuple(List)
                        if NewKey not in self.ToolsDefTxtDictionary:
                            self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key]
                        continue
                    del self.ToolsDefTxtDictionary[Key]
                elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:
                    del self.ToolsDefTxtDictionary[Key]
示例#46
0
 def LoadTargetTxtFile(self, Filename):
     if os.path.exists(Filename) and os.path.isfile(Filename):
          return self.ConvertTextFileToDict(Filename, '#', '=')
     else:
         EdkLogger.error("Target.txt Parser", FILE_NOT_FOUND, ExtraData=Filename)
         return 1