コード例 #1
0
 def SetCustomMakefile(self, CustomMakefile, Comments):
     if not (CustomMakefile == '' or CustomMakefile is None):
         ValueList = GetSplitValueList(CustomMakefile)
         if len(ValueList) == 1:
             FileName = ValueList[0]
             Family = ''
         else:
             Family = ValueList[0]
             FileName = ValueList[1]
         Family = Family.strip()
         if Family != '':
             if not IsValidFamily(Family):
                 ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(Family),
                            LineInfo=self.CurrentLine)
                 return False
         #
         # The MakefileName specified file should exist
         #
         IsValidFileFlag = False
         ModulePath = os.path.split(self.CurrentLine[0])[0]
         if IsValidPath(FileName, ModulePath):
             IsValidFileFlag = True           
         else:
             ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(FileName),
                        LineInfo=self.CurrentLine)
             return False
         if IsValidFileFlag:
             FileName = ConvPathFromAbsToRel(FileName, GlobalData.gINF_MODULE_DIR)                     
             self.CustomMakefile.append((Family, FileName, Comments))
             IsValidFileFlag = False
         return True
     else:
         return False
コード例 #2
0
ファイル: MkPkg.py プロジェクト: aspirefhaha/vbox50
def CheckFileList(QualifiedExt, FileList, ErrorStringExt, ErrorStringFullPath):
    if not FileList:
        return
    WorkspaceDir = GlobalData.gWORKSPACE
    WorkspaceDir = os.path.normpath(WorkspaceDir)
    for Item in FileList:
        Ext = os.path.splitext(Item)[1]
        if Ext.upper() != QualifiedExt.upper():
            Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
                         ErrorStringExt % Item)

        Item = os.path.normpath(Item)
        Path = os.path.normpath(os.path.join(WorkspaceDir, Item))
        if not os.path.exists(Path):
            Logger.Error("\nMkPkg", FILE_NOT_FOUND, ST.ERR_NOT_FOUND % Item)
        elif Item == Path:
            Logger.Error("\nMkPkg", OPTION_VALUE_INVALID,
                         ErrorStringFullPath % Item)
        elif not IsValidPath(Item, WorkspaceDir):
            Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
                         ErrorStringExt % Item)

        if not os.path.split(Item)[0]:
            Logger.Error("\nMkPkg", OPTION_VALUE_INVALID, \
                         ST.ERR_INVALID_METAFILE_PATH % Item)
コード例 #3
0
 def _ParseItem(self):
     Line = self._RawData.CurrentLine
     TokenList = GetSplitValueList(Line, DT.TAB_VALUE_SPLIT)
     if len(TokenList) != 2:
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_SPLIT) 
     if TokenList[0] == '' or TokenList[1] == '':
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_EMPTY)
     if not IsValidToken('[A-Z][0-9A-Za-z]*', TokenList[0]):
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_LIB)
     
     self._CheckReDefine(TokenList[0])
     
     Value = TokenList[1]
     #
     # Must end with .h
     #
     if not Value.endswith('.h'):
         self._LoggerError(ST.ERR_DECPARSE_LIBCLASS_PATH_EXT)
     
     #
     # Path must be existed
     #
     if not IsValidPath(Value, self._RawData.PackagePath):
         self._LoggerError(ST.ERR_DECPARSE_INCLUDE % Value)
     
     Item = DecLibraryclassItemObject(TokenList[0], StripRoot(self._RawData.PackagePath, Value),
                                      self._RawData.PackagePath)
     self.ItemObject.AddItem(Item, self._RawData.CurrentScope)
     return Item
コード例 #4
0
 def _ParseItem(self):
     Line = self._RawData.CurrentLine
     
     if not IsValidPath(Line, self._RawData.PackagePath):
         self._LoggerError(ST.ERR_DECPARSE_INCLUDE % Line) 
     
     Item = DecIncludeItemObject(StripRoot(self._RawData.PackagePath, Line), self._RawData.PackagePath)
     self.ItemObject.AddItem(Item, self._RawData.CurrentScope)
     return Item
コード例 #5
0
def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):

    if not LineNo:
        LineNo = -1

    #
    # Validate file name exist.
    #
    FullFileName = os.path.normpath(
        os.path.realpath(os.path.join(WorkSpace, FileName)))
    if not (ValidFile(FullFileName)):
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_FILELIST_EXIST % (FileName),
                     File=GlobalData.gINF_MODULE_NAME,
                     Line=LineNo,
                     ExtraData=OriginalString)

    #
    # Validate file exist/format.
    #
    if IsValidPath(FileName, WorkSpace):
        IsValidFileFlag = True
    else:
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                     (FileName),
                     File=GlobalData.gINF_MODULE_NAME,
                     Line=LineNo,
                     ExtraData=OriginalString)
        return False

    FileLinesList = []

    if IsValidFileFlag:
        try:
            FullFileName = FullFileName.replace('\\', '/')
            Inputfile = open(FullFileName, "rb", 0)
            try:
                FileLinesList = Inputfile.readlines()
            except BaseException:
                Logger.Error("InfParser",
                             ToolError.FILE_READ_FAILURE,
                             ST.ERR_FILE_OPEN_FAILURE,
                             File=FullFileName)
            finally:
                Inputfile.close()
        except BaseException:
            Logger.Error("InfParser",
                         ToolError.FILE_READ_FAILURE,
                         ST.ERR_FILE_OPEN_FAILURE,
                         File=FullFileName)

        FileLinesList = ProcessLineExtender(FileLinesList)

    return FileLinesList
コード例 #6
0
 def SetDpxSource(self, DpxSource, Comments):    
     #
     # The MakefileName specified file should exist
     #
     IsValidFileFlag = False
     ModulePath = os.path.split(self.CurrentLine[0])[0]
     if IsValidPath(DpxSource, ModulePath):
         IsValidFileFlag = True           
     else:
         ErrorInInf(ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(DpxSource),
                    LineInfo=self.CurrentLine)
         return False
     if IsValidFileFlag:
         DpxSource = ConvPathFromAbsToRel(DpxSource, 
                         GlobalData.gINF_MODULE_DIR)     
         self.DpxSource.append((DpxSource, Comments))
         IsValidFileFlag = False
     return True               
コード例 #7
0
def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):

    if not LineNo:
        LineNo = -1

    #
    # Validate file name exist.
    #
    FullFileName = os.path.normpath(
        os.path.realpath(os.path.join(WorkSpace, FileName)))
    if not (ValidFile(FullFileName)):
        return []

    #
    # Validate file exist/format.
    #
    if not IsValidPath(FileName, WorkSpace):
        return []

    FileLinesList = []

    try:
        FullFileName = FullFileName.replace('\\', '/')
        Inputfile = open(FullFileName, "rb", 0)
        try:
            FileLinesList = Inputfile.readlines()
        except BaseException:
            Logger.Error("InfParser",
                         ToolError.FILE_READ_FAILURE,
                         ST.ERR_FILE_OPEN_FAILURE,
                         File=FullFileName)
        finally:
            Inputfile.close()
    except BaseException:
        Logger.Error("InfParser",
                     ToolError.FILE_READ_FAILURE,
                     ST.ERR_FILE_OPEN_FAILURE,
                     File=FullFileName)

    FileLinesList = ProcessLineExtender(FileLinesList)

    return FileLinesList
コード例 #8
0
 def GenMiscFiles(self, Content):
     MiscFileObj = MiscFileObject()
     for Line in Content.splitlines():
         FileName = ''
         if '#' in Line:
             FileName = Line[:Line.find('#')]
         else:
             FileName = Line
         if FileName:
             if IsValidPath(FileName, self.GetRelaPath()):
                 FileObj = FileObject()
                 FileObj.SetURI(FileName)
                 MiscFileObj.SetFileList(MiscFileObj.GetFileList()+[FileObj])
             else:
                 Logger.Error("InfParser",
                              FORMAT_INVALID,
                              ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(Line),
                              File=self.GetFileName(),
                              ExtraData=Line)
     self.SetMiscFileList(self.GetMiscFileList()+[MiscFileObj])
コード例 #9
0
ファイル: InfBinaryObject.py プロジェクト: zha0/google-ctf
    def SetBinary(self,
                  UiInf=None,
                  Ver=None,
                  CommonBinary=None,
                  ArchList=None):

        __SupArchList = []
        for ArchItem in ArchList:
            #
            # Validate Arch
            #
            if (ArchItem == '' or ArchItem is None):
                ArchItem = 'COMMON'
            __SupArchList.append(ArchItem)

        if UiInf is not None:
            if len(UiInf) > 0:
                #
                # Check UI
                #
                for UiItem in UiInf:
                    IsValidFileFlag = False
                    InfBianryUiItemObj = None
                    UiContent = UiItem[0]
                    UiComment = UiItem[1]
                    UiCurrentLine = UiItem[2]
                    GlobalData.gINF_CURRENT_LINE = deepcopy(UiItem[2])
                    #
                    # Should not less than 2 elements
                    #
                    if len(UiContent) < 2:
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID %
                            (UiContent[0], 2),
                            File=UiCurrentLine.GetFileName(),
                            Line=UiCurrentLine.GetLineNo(),
                            ExtraData=UiCurrentLine.GetLineString())
                        return False

                    if len(UiContent) > 4:
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX %
                            (UiContent[0], 4),
                            File=UiCurrentLine.GetFileName(),
                            Line=UiCurrentLine.GetLineNo(),
                            ExtraData=UiCurrentLine.GetLineString())
                        return False
                    if len(UiContent) >= 2:
                        #
                        # Create an Ui Object.
                        #
                        InfBianryUiItemObj = InfBianryUiItem()
                        if UiContent[0] != 'UI':
                            Logger.Error(
                                "InfParser",
                                ToolError.FORMAT_INVALID,
                                ST.ERR_INF_PARSER_BINARY_VER_TYPE % ('UI'),
                                File=UiCurrentLine.GetFileName(),
                                Line=UiCurrentLine.GetLineNo(),
                                ExtraData=UiCurrentLine.GetLineString())
                        InfBianryUiItemObj.SetUiTypeName(UiContent[0])
                        InfBianryUiItemObj.SetType(UiContent[0])
                        #
                        # Verify File exist or not
                        #
                        FullFileName = os.path.normpath(
                            os.path.realpath(
                                os.path.join(GlobalData.gINF_MODULE_DIR,
                                             UiContent[1])))
                        if not (ValidFile(FullFileName)
                                or ValidFile(UiContent[1])):
                            Logger.Error(
                                "InfParser",
                                ToolError.FORMAT_INVALID,
                                ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST %
                                (UiContent[1]),
                                File=UiCurrentLine.GetFileName(),
                                Line=UiCurrentLine.GetLineNo(),
                                ExtraData=UiCurrentLine.GetLineString())
                        #
                        # Validate file exist/format.
                        #
                        if IsValidPath(UiContent[1],
                                       GlobalData.gINF_MODULE_DIR):
                            IsValidFileFlag = True
                        else:
                            Logger.Error(
                                "InfParser",
                                ToolError.FORMAT_INVALID,
                                ST.
                                ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                                (UiContent[1]),
                                File=UiCurrentLine.GetFileName(),
                                Line=UiCurrentLine.GetLineNo(),
                                ExtraData=UiCurrentLine.GetLineString())
                            return False
                        if IsValidFileFlag:
                            UiContent[0] = ConvPathFromAbsToRel(
                                UiContent[0], GlobalData.gINF_MODULE_DIR)
                            InfBianryUiItemObj.SetFileName(UiContent[1])
                    if len(UiContent) >= 3:
                        #
                        # Add Target information
                        #
                        InfBianryUiItemObj.SetTarget(UiContent[2])
                    if len(UiContent) == 4:
                        if UiContent[3].strip() == '':
                            Logger.Error(
                                "InfParser",
                                ToolError.FORMAT_INVALID,
                                ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                                File=UiCurrentLine.GetFileName(),
                                Line=UiCurrentLine.GetLineNo(),
                                ExtraData=UiCurrentLine.GetLineString())
                        #
                        # Validate Feature Flag Express
                        #
                        FeatureFlagRtv = IsValidFeatureFlagExp(
                            UiContent[3].strip())
                        if not FeatureFlagRtv[0]:
                            Logger.Error(
                                "InfParser",
                                ToolError.FORMAT_INVALID,
                                ST.
                                ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                                (FeatureFlagRtv[1]),
                                File=UiCurrentLine.GetFileName(),
                                Line=UiCurrentLine.GetLineNo(),
                                ExtraData=UiCurrentLine.GetLineString())
                        InfBianryUiItemObj.SetFeatureFlagExp(UiContent[3])

                    InfBianryUiItemObj.SetSupArchList(__SupArchList)

                    #
                    # Determine binary file name duplicate. Follow below rule:
                    #
                    # A binary filename must not be duplicated within
                    # a [Binaries] section. A binary filename may appear in
                    # multiple architectural [Binaries] sections. A binary
                    # filename listed in an architectural [Binaries] section
                    # must not be listed in the common architectural
                    # [Binaries] section.
                    #
                    # NOTE: This check will not report error now.
                    #
                    #                    for Item in self.Binaries:
                    #                        if Item.GetFileName() == InfBianryUiItemObj.GetFileName():
                    #                            ItemSupArchList = Item.GetSupArchList()
                    #                            for ItemArch in ItemSupArchList:
                    #                                for UiItemObjArch in __SupArchList:
                    #                                    if ItemArch == UiItemObjArch:
                    #                                        #
                    #                                        # ST.ERR_INF_PARSER_ITEM_DUPLICATE
                    #                                        #
                    #                                        pass
                    #                                    if ItemArch.upper() == 'COMMON' or UiItemObjArch.upper() == 'COMMON':
                    #                                        #
                    #                                        # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
                    #                                        #
                    #                                        pass

                    if InfBianryUiItemObj is not None:
                        if (InfBianryUiItemObj) in self.Binaries:
                            BinariesList = self.Binaries[InfBianryUiItemObj]
                            BinariesList.append(
                                (InfBianryUiItemObj, UiComment))
                            self.Binaries[InfBianryUiItemObj] = BinariesList
                        else:
                            BinariesList = []
                            BinariesList.append(
                                (InfBianryUiItemObj, UiComment))
                            self.Binaries[InfBianryUiItemObj] = BinariesList
        if Ver is not None and len(Ver) > 0:
            self.CheckVer(Ver, __SupArchList)
        if CommonBinary and len(CommonBinary) > 0:
            self.ParseCommonBinary(CommonBinary, __SupArchList)

        return True
コード例 #10
0
ファイル: InfBinaryObject.py プロジェクト: zha0/google-ctf
    def ParseCommonBinary(self, CommonBinary, __SupArchList):
        #
        # Check common binary definitions
        # Type | FileName | Target | Family | TagName | FeatureFlagExp
        #
        for Item in CommonBinary:
            IsValidFileFlag = False
            ItemContent = Item[0]
            ItemComment = Item[1]
            CurrentLineOfItem = Item[2]
            GlobalData.gINF_CURRENT_LINE = CurrentLineOfItem
            InfBianryCommonItemObj = None
            if ItemContent[0] == 'SUBTYPE_GUID':
                if len(ItemContent) < 3:
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID %
                                 (ItemContent[0], 3),
                                 File=CurrentLineOfItem.GetFileName(),
                                 Line=CurrentLineOfItem.GetLineNo(),
                                 ExtraData=CurrentLineOfItem.GetLineString())
                    return False
            else:
                if len(ItemContent) < 2:
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID %
                                 (ItemContent[0], 2),
                                 File=CurrentLineOfItem.GetFileName(),
                                 Line=CurrentLineOfItem.GetLineNo(),
                                 ExtraData=CurrentLineOfItem.GetLineString())
                    return False

            if len(ItemContent) > 7:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX %
                             (ItemContent[0], 7),
                             File=CurrentLineOfItem.GetFileName(),
                             Line=CurrentLineOfItem.GetLineNo(),
                             ExtraData=CurrentLineOfItem.GetLineString())
                return False
            if len(ItemContent) >= 2:
                #
                # Create a Common Object.
                #
                InfBianryCommonItemObj = InfBianryCommonItem()
                #
                # Convert Binary type.
                #
                BinaryFileType = ItemContent[0].strip()
                if BinaryFileType == 'RAW' or BinaryFileType == 'ACPI' or BinaryFileType == 'ASL':
                    BinaryFileType = 'BIN'

                if BinaryFileType not in DT.BINARY_FILE_TYPE_LIST:
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \
                                 (DT.BINARY_FILE_TYPE_LIST.__str__()),
                                 File=CurrentLineOfItem.GetFileName(),
                                 Line=CurrentLineOfItem.GetLineNo(),
                                 ExtraData=CurrentLineOfItem.GetLineString())

                if BinaryFileType == 'SUBTYPE_GUID':
                    BinaryFileType = 'FREEFORM'

                if BinaryFileType == 'LIB' or BinaryFileType == 'UEFI_APP':
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \
                                 (DT.BINARY_FILE_TYPE_LIST.__str__()),
                                 File=CurrentLineOfItem.GetFileName(),
                                 Line=CurrentLineOfItem.GetLineNo(),
                                 ExtraData=CurrentLineOfItem.GetLineString())

                InfBianryCommonItemObj.SetType(BinaryFileType)
                InfBianryCommonItemObj.SetCommonType(ItemContent[0])
                FileName = ''
                if BinaryFileType == 'FREEFORM':
                    InfBianryCommonItemObj.SetGuidValue(ItemContent[1])
                    if len(ItemContent) >= 3:
                        FileName = ItemContent[2]
                    else:
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_BINARY_ITEM_FILENAME_NOT_EXIST,
                            File=CurrentLineOfItem.GetFileName(),
                            Line=CurrentLineOfItem.GetLineNo(),
                            ExtraData=CurrentLineOfItem.GetLineString())
                else:
                    FileName = ItemContent[1]
                #
                # Verify File exist or not
                #
                FullFileName = os.path.normpath(
                    os.path.realpath(
                        os.path.join(GlobalData.gINF_MODULE_DIR, FileName)))
                if not (ValidFile(FullFileName) or ValidFile(FileName)):
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST %
                                 (FileName),
                                 File=CurrentLineOfItem.GetFileName(),
                                 Line=CurrentLineOfItem.GetLineNo(),
                                 ExtraData=CurrentLineOfItem.GetLineString())
                #
                # Validate file exist/format.
                #
                if IsValidPath(FileName, GlobalData.gINF_MODULE_DIR):
                    IsValidFileFlag = True
                else:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                        (FileName),
                        File=CurrentLineOfItem.GetFileName(),
                        Line=CurrentLineOfItem.GetLineNo(),
                        ExtraData=CurrentLineOfItem.GetLineString())
                    return False
                if IsValidFileFlag:
                    ItemContent[0] = ConvPathFromAbsToRel(
                        ItemContent[0], GlobalData.gINF_MODULE_DIR)
                    InfBianryCommonItemObj.SetFileName(FileName)
            if len(ItemContent) >= 3:
                #
                # Add Target information
                #
                if BinaryFileType != 'FREEFORM':
                    InfBianryCommonItemObj.SetTarget(ItemContent[2])

            if len(ItemContent) >= 4:
                #
                # Add Family information
                #
                if BinaryFileType != 'FREEFORM':
                    InfBianryCommonItemObj.SetFamily(ItemContent[3])
                else:
                    InfBianryCommonItemObj.SetTarget(ItemContent[3])

            if len(ItemContent) >= 5:
                #
                # TagName entries are build system specific. If there
                # is content in the entry, the tool must exit
                # gracefully with an error message that indicates build
                # system specific content cannot be distributed using
                # the UDP
                #
                if BinaryFileType != 'FREEFORM':
                    if ItemContent[4].strip() != '':
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED %
                            (ItemContent[4]),
                            File=CurrentLineOfItem.GetFileName(),
                            Line=CurrentLineOfItem.GetLineNo(),
                            ExtraData=CurrentLineOfItem.GetLineString())
                else:
                    InfBianryCommonItemObj.SetFamily(ItemContent[4])

            if len(ItemContent) >= 6:
                #
                # Add FeatureFlagExp
                #
                if BinaryFileType != 'FREEFORM':
                    if ItemContent[5].strip() == '':
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                            File=CurrentLineOfItem.GetFileName(),
                            Line=CurrentLineOfItem.GetLineNo(),
                            ExtraData=CurrentLineOfItem.GetLineString())
                    #
                    # Validate Feature Flag Express
                    #
                    FeatureFlagRtv = IsValidFeatureFlagExp(
                        ItemContent[5].strip())
                    if not FeatureFlagRtv[0]:
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                            (FeatureFlagRtv[1]),
                            File=CurrentLineOfItem.GetFileName(),
                            Line=CurrentLineOfItem.GetLineNo(),
                            ExtraData=CurrentLineOfItem.GetLineString())
                    InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[5])
                else:
                    if ItemContent[5].strip() != '':
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED %
                            (ItemContent[5]),
                            File=CurrentLineOfItem.GetFileName(),
                            Line=CurrentLineOfItem.GetLineNo(),
                            ExtraData=CurrentLineOfItem.GetLineString())

            if len(ItemContent) == 7:
                if ItemContent[6].strip() == '':
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                                 File=CurrentLineOfItem.GetFileName(),
                                 Line=CurrentLineOfItem.GetLineNo(),
                                 ExtraData=CurrentLineOfItem.GetLineString())
                #
                # Validate Feature Flag Express
                #
                FeatureFlagRtv = IsValidFeatureFlagExp(ItemContent[6].strip())
                if not FeatureFlagRtv[0]:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                        (FeatureFlagRtv[1]),
                        File=CurrentLineOfItem.GetFileName(),
                        Line=CurrentLineOfItem.GetLineNo(),
                        ExtraData=CurrentLineOfItem.GetLineString())
                InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[6])

            InfBianryCommonItemObj.SetSupArchList(__SupArchList)

            #
            # Determine binary file name duplicate. Follow below rule:
            #
            # A binary filename must not be duplicated within
            # a [Binaries] section. A binary filename may appear in
            # multiple architectural [Binaries] sections. A binary
            # filename listed in an architectural [Binaries] section
            # must not be listed in the common architectural
            # [Binaries] section.
            #
            # NOTE: This check will not report error now.
            #
            #            for Item in self.Binaries:
            #                if Item.GetFileName() == InfBianryCommonItemObj.GetFileName():
            #                    ItemSupArchList = Item.GetSupArchList()
            #                    for ItemArch in ItemSupArchList:
            #                        for ComItemObjArch in __SupArchList:
            #                            if ItemArch == ComItemObjArch:
            #                                #
            #                                # ST.ERR_INF_PARSER_ITEM_DUPLICATE
            #                                #
            #                                pass
            #
            #                            if ItemArch.upper() == 'COMMON' or ComItemObjArch.upper() == 'COMMON':
            #                                #
            #                                # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
            #                                #
            #                                pass

            if InfBianryCommonItemObj is not None:
                if (InfBianryCommonItemObj) in self.Binaries:
                    BinariesList = self.Binaries[InfBianryCommonItemObj]
                    BinariesList.append((InfBianryCommonItemObj, ItemComment))
                    self.Binaries[InfBianryCommonItemObj] = BinariesList
                else:
                    BinariesList = []
                    BinariesList.append((InfBianryCommonItemObj, ItemComment))
                    self.Binaries[InfBianryCommonItemObj] = BinariesList
コード例 #11
0
ファイル: InfBinaryObject.py プロジェクト: zha0/google-ctf
    def CheckVer(self, Ver, __SupArchList):
        #
        # Check Ver
        #
        for VerItem in Ver:
            IsValidFileFlag = False
            VerContent = VerItem[0]
            VerComment = VerItem[1]
            VerCurrentLine = VerItem[2]
            GlobalData.gINF_CURRENT_LINE = VerCurrentLine
            InfBianryVerItemObj = None
            #
            # Should not less than 2 elements
            #
            if len(VerContent) < 2:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID %
                             (VerContent[0], 2),
                             File=VerCurrentLine.GetFileName(),
                             Line=VerCurrentLine.GetLineNo(),
                             ExtraData=VerCurrentLine.GetLineString())
                return False
            if len(VerContent) > 4:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX %
                             (VerContent[0], 4),
                             File=VerCurrentLine.GetFileName(),
                             Line=VerCurrentLine.GetLineNo(),
                             ExtraData=VerCurrentLine.GetLineString())
                return False
            if len(VerContent) >= 2:
                #
                # Create a Ver Object.
                #
                InfBianryVerItemObj = InfBianryVerItem()

                if VerContent[0] != DT.BINARY_FILE_TYPE_VER:
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_VER_TYPE %
                                 DT.BINARY_FILE_TYPE_VER,
                                 File=VerCurrentLine.GetFileName(),
                                 Line=VerCurrentLine.GetLineNo(),
                                 ExtraData=VerCurrentLine.GetLineString())

                InfBianryVerItemObj.SetVerTypeName(VerContent[0])
                InfBianryVerItemObj.SetType(VerContent[0])
                #
                # Verify File exist or not
                #
                FullFileName = os.path.normpath(
                    os.path.realpath(
                        os.path.join(GlobalData.gINF_MODULE_DIR,
                                     VerContent[1])))
                if not (ValidFile(FullFileName) or ValidFile(VerContent[1])):
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST %
                                 (VerContent[1]),
                                 File=VerCurrentLine.GetFileName(),
                                 Line=VerCurrentLine.GetLineNo(),
                                 ExtraData=VerCurrentLine.GetLineString())
                #
                # Validate file exist/format.
                #
                if IsValidPath(VerContent[1], GlobalData.gINF_MODULE_DIR):
                    IsValidFileFlag = True
                else:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                        (VerContent[1]),
                        File=VerCurrentLine.GetFileName(),
                        Line=VerCurrentLine.GetLineNo(),
                        ExtraData=VerCurrentLine.GetLineString())
                    return False
                if IsValidFileFlag:
                    VerContent[0] = ConvPathFromAbsToRel(
                        VerContent[0], GlobalData.gINF_MODULE_DIR)
                    InfBianryVerItemObj.SetFileName(VerContent[1])
            if len(VerContent) >= 3:
                #
                # Add Target information
                #
                InfBianryVerItemObj.SetTarget(VerContent[2])
            if len(VerContent) == 4:
                if VerContent[3].strip() == '':
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                                 File=VerCurrentLine.GetFileName(),
                                 Line=VerCurrentLine.GetLineNo(),
                                 ExtraData=VerCurrentLine.GetLineString())
                #
                # Validate Feature Flag Express
                #
                FeatureFlagRtv = IsValidFeatureFlagExp(VerContent[3].\
                                                       strip())
                if not FeatureFlagRtv[0]:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                        (FeatureFlagRtv[1]),
                        File=VerCurrentLine.GetFileName(),
                        Line=VerCurrentLine.GetLineNo(),
                        ExtraData=VerCurrentLine.GetLineString())
                InfBianryVerItemObj.SetFeatureFlagExp(VerContent[3])

            InfBianryVerItemObj.SetSupArchList(__SupArchList)

            #
            # Determine binary file name duplicate. Follow below rule:
            #
            # A binary filename must not be duplicated within
            # a [Binaries] section. A binary filename may appear in
            # multiple architectural [Binaries] sections. A binary
            # filename listed in an architectural [Binaries] section
            # must not be listed in the common architectural
            # [Binaries] section.
            #
            # NOTE: This check will not report error now.
            #
            for Item in self.Binaries:
                if Item.GetFileName() == InfBianryVerItemObj.GetFileName():
                    ItemSupArchList = Item.GetSupArchList()
                    for ItemArch in ItemSupArchList:
                        for VerItemObjArch in __SupArchList:
                            if ItemArch == VerItemObjArch:
                                #
                                # ST.ERR_INF_PARSER_ITEM_DUPLICATE
                                #
                                pass
                            if ItemArch.upper(
                            ) == 'COMMON' or VerItemObjArch.upper(
                            ) == 'COMMON':
                                #
                                # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
                                #
                                pass

            if InfBianryVerItemObj is not None:
                if (InfBianryVerItemObj) in self.Binaries:
                    BinariesList = self.Binaries[InfBianryVerItemObj]
                    BinariesList.append((InfBianryVerItemObj, VerComment))
                    self.Binaries[InfBianryVerItemObj] = BinariesList
                else:
                    BinariesList = []
                    BinariesList.append((InfBianryVerItemObj, VerComment))
                    self.Binaries[InfBianryVerItemObj] = BinariesList
コード例 #12
0
ファイル: Misc.py プロジェクト: vamsi12340/ppc64le-edk2
def GetLibInstanceInfo(String, WorkSpace, LineNo):

    FileGuidString = ""
    VerString = ""

    OrignalString = String
    String = String.strip()
    if not String:
        return None, None
    #
    # Remove "#" characters at the beginning
    #
    String = GetHelpStringByRemoveHashKey(String)
    String = String.strip()

    #
    # Validate file name exist.
    #
    FullFileName = os.path.normpath(
        os.path.realpath(os.path.join(WorkSpace, String)))
    if not (ValidFile(FullFileName)):
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_FILELIST_EXIST % (String),
                     File=GlobalData.gINF_MODULE_NAME,
                     Line=LineNo,
                     ExtraData=OrignalString)

    #
    # Validate file exist/format.
    #
    if IsValidPath(String, WorkSpace):
        IsValidFileFlag = True
    else:
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                     (String),
                     File=GlobalData.gINF_MODULE_NAME,
                     Line=LineNo,
                     ExtraData=OrignalString)
        return False
    if IsValidFileFlag:
        FileLinesList = []

        try:
            FInputfile = open(FullFileName, "rb", 0)
            try:
                FileLinesList = FInputfile.readlines()
            except BaseException:
                Logger.Error("InfParser",
                             ToolError.FILE_READ_FAILURE,
                             ST.ERR_FILE_OPEN_FAILURE,
                             File=FullFileName)
            finally:
                FInputfile.close()
        except BaseException:
            Logger.Error("InfParser",
                         ToolError.FILE_READ_FAILURE,
                         ST.ERR_FILE_OPEN_FAILURE,
                         File=FullFileName)

        ReFileGuidPattern = re.compile("^\s*FILE_GUID\s*=.*$")
        ReVerStringPattern = re.compile("^\s*VERSION_STRING\s*=.*$")

        FileLinesList = ProcessLineExtender(FileLinesList)

        for Line in FileLinesList:
            if ReFileGuidPattern.match(Line):
                FileGuidString = Line
            if ReVerStringPattern.match(Line):
                VerString = Line

        if FileGuidString:
            FileGuidString = GetSplitValueList(FileGuidString, '=', 1)[1]
        if VerString:
            VerString = GetSplitValueList(VerString, '=', 1)[1]

        return FileGuidString, VerString
コード例 #13
0
ファイル: IniToXml.py プロジェクト: 380121850/qemu-5.1.0
def __ValidatePath(Path, Root):
    Path = Path.strip()
    if os.path.isabs(Path) or not IsValidPath(Path, Root):
        return False, ST.ERR_FILELIST_LOCATION % (Root, Path)
    return True, ''
コード例 #14
0
    def SetPackages(self, PackageData, Arch=None):
        IsValidFileFlag = False
        SupArchList = []
        for ArchItem in Arch:
            #
            # Validate Arch
            #
            if (ArchItem == '' or ArchItem is None):
                ArchItem = 'COMMON'
            SupArchList.append(ArchItem)

        for PackageItem in PackageData:
            PackageItemObj = InfPackageItem()
            HelpStringObj = PackageItem[1]
            CurrentLineOfPackItem = PackageItem[2]
            PackageItem = PackageItem[0]
            if HelpStringObj is not None:
                HelpString = HelpStringObj.HeaderComments + HelpStringObj.TailComments
                PackageItemObj.SetHelpString(HelpString)
            if len(PackageItem) >= 1:
                #
                # Validate file exist/format.
                #
                if IsValidPath(PackageItem[0], ''):
                    IsValidFileFlag = True
                elif IsValidPath(PackageItem[0], GlobalData.gINF_MODULE_DIR):
                    IsValidFileFlag = True
                elif IsValidPath(PackageItem[0], GlobalData.gWORKSPACE):
                    IsValidFileFlag = True
                else:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                        (PackageItem[0]),
                        File=CurrentLineOfPackItem[2],
                        Line=CurrentLineOfPackItem[1],
                        ExtraData=CurrentLineOfPackItem[0])
                    return False
                if IsValidFileFlag:
                    PackageItemObj.SetPackageName(PackageItem[0])
            if len(PackageItem) == 2:
                #
                # Validate Feature Flag Express
                #
                if PackageItem[1].strip() == '':
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                                 File=CurrentLineOfPackItem[2],
                                 Line=CurrentLineOfPackItem[1],
                                 ExtraData=CurrentLineOfPackItem[0])
                #
                # Validate FFE
                #
                FeatureFlagRtv = IsValidFeatureFlagExp(PackageItem[1].strip())
                if not FeatureFlagRtv[0]:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                        (FeatureFlagRtv[1]),
                        File=CurrentLineOfPackItem[2],
                        Line=CurrentLineOfPackItem[1],
                        ExtraData=CurrentLineOfPackItem[0])

                PackageItemObj.SetFeatureFlagExp(PackageItem[1].strip())

            if len(PackageItem) > 2:
                #
                # Invalid format of Package statement
                #
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_PACKAGE_SECTION_CONTENT_ERROR,
                             File=CurrentLineOfPackItem[2],
                             Line=CurrentLineOfPackItem[1],
                             ExtraData=CurrentLineOfPackItem[0])
            PackageItemObj.SetSupArchList(SupArchList)

            #
            # Determine package file name duplicate. Follow below rule:
            #
            # A package filename must not be duplicated within a [Packages]
            # section. Package filenames may appear in multiple architectural
            # [Packages] sections. A package filename listed in an
            # architectural [Packages] section must not be listed in the common
            # architectural [Packages] section.
            #
            # NOTE: This check will not report error now.
            #
            for Item in self.Packages:
                if Item.GetPackageName() == PackageItemObj.GetPackageName():
                    ItemSupArchList = Item.GetSupArchList()
                    for ItemArch in ItemSupArchList:
                        for PackageItemObjArch in SupArchList:
                            if ItemArch == PackageItemObjArch:
                                #
                                # ST.ERR_INF_PARSER_ITEM_DUPLICATE
                                #
                                pass
                            if ItemArch.upper(
                            ) == 'COMMON' or PackageItemObjArch.upper(
                            ) == 'COMMON':
                                #
                                # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
                                #
                                pass

            if (PackageItemObj) in self.Packages:
                PackageList = self.Packages[PackageItemObj]
                PackageList.append(PackageItemObj)
                self.Packages[PackageItemObj] = PackageList
            else:
                PackageList = []
                PackageList.append(PackageItemObj)
                self.Packages[PackageItemObj] = PackageList

        return True
コード例 #15
0
def GenSourceInstance(Item, CurrentLineOfItem, ItemObj):

    IsValidFileFlag = False

    if len(Item) < 6 and len(Item) >= 1:
        #
        # File | Family | TagName | ToolCode | FeatureFlagExpr
        #
        if len(Item) == 5:
            #
            # Validate Feature Flag Express
            #
            if Item[4].strip() == '':
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(Item[4].strip())
            if not FeatureFlagRtv[0]:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                             (FeatureFlagRtv[1]),
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])
            ItemObj.SetFeatureFlagExp(Item[4])
        if len(Item) >= 4:
            if Item[3].strip() == '':
                ItemObj.SetToolCode(Item[3])
            else:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_TOOLCODE_NOT_PERMITTED %
                             (Item[2]),
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])
        if len(Item) >= 3:
            if Item[2].strip() == '':
                ItemObj.SetTagName(Item[2])
            else:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED %
                             (Item[2]),
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])
        if len(Item) >= 2:
            if IsValidFamily(Item[1].strip()):
                #
                # To align with UDP specification. "*" is not permitted in UDP specification
                #
                if Item[1].strip() == "*":
                    Item[1] = ""
                ItemObj.SetFamily(Item[1])
            else:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_SOURCE_SECTION_FAMILY_INVALID %
                             (Item[1]),
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])
        if len(Item) >= 1:
            #
            # Validate file name exist.
            #
            FullFileName = os.path.normpath(
                os.path.realpath(
                    os.path.join(GlobalData.gINF_MODULE_DIR, Item[0])))
            if not (ValidFile(FullFileName) or ValidFile(Item[0])):
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_FILELIST_EXIST % (Item[0]),
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])

            #
            # Validate file exist/format.
            #

            if IsValidPath(Item[0], GlobalData.gINF_MODULE_DIR):
                IsValidFileFlag = True
            else:
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                             (Item[0]),
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])
                return False
            if IsValidFileFlag:
                ItemObj.SetSourceFileName(Item[0])
    else:
        Logger.Error("InfParser",
                     ToolError.FORMAT_INVALID,
                     ST.ERR_INF_PARSER_SOURCES_SECTION_CONTENT_ERROR,
                     File=CurrentLineOfItem[2],
                     Line=CurrentLineOfItem[1],
                     ExtraData=CurrentLineOfItem[0])

    return ItemObj