Ejemplo n.º 1
0
    def SetUnloadImages(self, UnloadImages, Comments):
        #
        # It can be a list
        #
        ValueList = []
        TokenList = GetSplitValueList(UnloadImages, DT.TAB_VALUE_SPLIT)
        ValueList[0:len(TokenList)] = TokenList
        InfDefineUnloadImageItemObj = InfDefineUnloadImageItem()
        if not IsValidCVariableName(ValueList[0]):
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (ValueList[0]),
                       LineInfo=self.CurrentLine)
        InfDefineUnloadImageItemObj.SetCName(ValueList[0])
        if len(ValueList) == 2:
            if ValueList[1].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[1]),
                           LineInfo=self.CurrentLine)
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[1].strip())
            if not FeatureFlagRtv[0]:
                ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                           (FeatureFlagRtv[1]),
                           LineInfo=self.CurrentLine)
            InfDefineUnloadImageItemObj.SetFeatureFlagExp(ValueList[1])

        if len(ValueList) > 2:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (UnloadImages),
                       LineInfo=self.CurrentLine)
        InfDefineUnloadImageItemObj.Comments = Comments
        self.UnloadImages.append(InfDefineUnloadImageItemObj)
Ejemplo n.º 2
0
def IsValidPcdDatum(Type, Value):
    if not Value:
        return False, ST.ERR_DECPARSE_PCD_VALUE_EMPTY
    Valid = True
    Cause = ""
    if Type not in ["UINT8", "UINT16", "UINT32", "UINT64", "VOID*", "BOOLEAN"]:
        return False, ST.ERR_DECPARSE_PCD_TYPE
    if Type == "VOID*":
        if not ((Value.startswith('L"') or Value.startswith('"') and \
                 Value.endswith('"'))
                or (IsValidCArray(Value)) or (IsValidCFormatGuid(Value)) \
                or (IsValidNList(Value)) or (CheckGuidRegFormat(Value))
               ):
            return False, ST.ERR_DECPARSE_PCD_VOID % (Value, Type)
        RealString = Value[Value.find('"') + 1:-1]
        if RealString:
            if not IsValidBareCString(RealString):
                return False, ST.ERR_DECPARSE_PCD_VOID % (Value, Type)
    elif Type == 'BOOLEAN':
        if Value in [
                'TRUE', 'FALSE', 'true', 'false', 'True', 'False', '0x1',
                '0x01', '1', '0x0', '0x00', '0'
        ]:
            return True, ""
        Valid, Cause = IsValidStringTest(Value, True)
        if not Valid:
            Valid, Cause = IsValidFeatureFlagExp(Value, True)
        if not Valid:
            return False, Cause
    else:
        if Value and (Value[0] == '-' or Value[0] == '+'):
            return False, ST.ERR_DECPARSE_PCD_INT_NEGTIVE % (Value, Type)
        try:
            StrVal = Value
            if Value and not Value.startswith('0x') \
                and not Value.startswith('0X'):
                Value = Value.lstrip('0')
                if not Value:
                    return True, ""
            Value = int(Value, 0)
            MAX_VAL_TYPE = {
                "BOOLEAN": 0x01,
                'UINT8': 0xFF,
                'UINT16': 0xFFFF,
                'UINT32': 0xFFFFFFFF,
                'UINT64': 0xFFFFFFFFFFFFFFFF
            }
            if Value > MAX_VAL_TYPE[Type]:
                return False, ST.ERR_DECPARSE_PCD_INT_EXCEED % (StrVal, Type)
        except BaseException:
            Valid, Cause = IsValidLogicalExpr(Value, True)
        if not Valid:
            return False, Cause

    return True, ""
Ejemplo n.º 3
0
    def SetDestructor(self, Destructor, Comments):
        #
        # It can be a list and only 1 set to TRUE
        #
        ValueList = []
        TokenList = GetSplitValueList(Destructor, DT.TAB_VALUE_SPLIT)
        ValueList[0:len(TokenList)] = TokenList
        InfDefineDestructorItemObj = InfDefineDestructorItem()
        if not IsValidCVariableName(ValueList[0]):
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                       (ValueList[0]),
                       LineInfo=self.CurrentLine)
        InfDefineDestructorItemObj.SetCName(ValueList[0])
        if len(ValueList) >= 2:
            ModList = GetSplitValueList(ValueList[1].strip(), ' ')
            if ValueList[1].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[1]),
                           LineInfo=self.CurrentLine)
            for ModItem in ModList:
                if ModItem not in DT.MODULE_LIST:
                    ErrorInInf(ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID %
                               (ModItem),
                               LineInfo=self.CurrentLine)
            InfDefineDestructorItemObj.SetSupModList(ModList)
        if len(ValueList) == 3:
            if ValueList[2].strip() == '':
                ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                           (ValueList[2]),
                           LineInfo=self.CurrentLine)
            #
            # Validate FFE
            #
            FeatureFlagRtv = IsValidFeatureFlagExp(ValueList[2].strip())
            if not FeatureFlagRtv[0]:
                ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                           (FeatureFlagRtv[1]),
                           LineInfo=self.CurrentLine)
            InfDefineDestructorItemObj.SetFeatureFlagExp(ValueList[2])

        if len(ValueList) > 3:
            ErrorInInf(ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Destructor),
                       LineInfo=self.CurrentLine)

        InfDefineDestructorItemObj.Comments = Comments
        self.Destructor.append(InfDefineDestructorItemObj)
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    def SetLibraryClasses(self, LibContent, KeyList=None):
        #
        # Validate Arch
        #
        (__SupArchList, __SupModuleList) = GetArchModuleType(KeyList)

        for LibItem in LibContent:
            LibItemObj = InfLibraryClassItem()
            if not GlobalData.gIS_BINARY_INF:
                HelpStringObj = LibItem[1]
                LibItemObj.CurrentLine.SetFileName(LibItem[2][2])
                LibItemObj.CurrentLine.SetLineNo(LibItem[2][1])
                LibItemObj.CurrentLine.SetLineString(LibItem[2][0])
                LibItem = LibItem[0]
                if HelpStringObj is not None:
                    LibItemObj.SetHelpString(HelpStringObj)
                if len(LibItem) >= 1:
                    if LibItem[0].strip() != '':
                        if IsValidLibName(LibItem[0].strip()):
                            if LibItem[0].strip() != 'NULL':
                                LibItemObj.SetLibName(LibItem[0])
                            else:
                                Logger.Error(
                                    "InfParser",
                                    ToolError.FORMAT_INVALID,
                                    ST.ERR_INF_PARSER_DEFINE_LIB_NAME_INVALID,
                                    File=GlobalData.gINF_MODULE_NAME,
                                    Line=LibItemObj.CurrentLine.GetLineNo(),
                                    ExtraData=LibItemObj.CurrentLine.
                                    GetLineString())
                        else:
                            Logger.Error(
                                "InfParser",
                                ToolError.FORMAT_INVALID,
                                ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID %
                                (LibItem[0]),
                                File=GlobalData.gINF_MODULE_NAME,
                                Line=LibItemObj.CurrentLine.GetLineNo(),
                                ExtraData=LibItemObj.CurrentLine.GetLineString(
                                ))
                    else:
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_LIBRARY_SECTION_LIBNAME_MISSING,
                            File=GlobalData.gINF_MODULE_NAME,
                            Line=LibItemObj.CurrentLine.GetLineNo(),
                            ExtraData=LibItemObj.CurrentLine.GetLineString())
                if len(LibItem) == 2:
                    if LibItem[1].strip() == '':
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                            File=GlobalData.gINF_MODULE_NAME,
                            Line=LibItemObj.CurrentLine.GetLineNo(),
                            ExtraData=LibItemObj.CurrentLine.GetLineString())
                    #
                    # Validate FFE
                    #
                    FeatureFlagRtv = IsValidFeatureFlagExp(LibItem[1].strip())
                    if not FeatureFlagRtv[0]:
                        Logger.Error(
                            "InfParser",
                            ToolError.FORMAT_INVALID,
                            ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                            (FeatureFlagRtv[1]),
                            File=GlobalData.gINF_MODULE_NAME,
                            Line=LibItemObj.CurrentLine.GetLineNo(),
                            ExtraData=LibItemObj.CurrentLine.GetLineString())
                    LibItemObj.SetFeatureFlagExp(LibItem[1].strip())

                #
                # Invalid strings
                #
                if len(LibItem) < 1 or len(LibItem) > 2:
                    Logger.Error(
                        "InfParser",
                        ToolError.FORMAT_INVALID,
                        ST.ERR_INF_PARSER_LIBRARY_SECTION_CONTENT_ERROR,
                        File=GlobalData.gINF_MODULE_NAME,
                        Line=LibItemObj.CurrentLine.GetLineNo(),
                        ExtraData=LibItemObj.CurrentLine.GetLineString())

                LibItemObj.SetSupArchList(__SupArchList)
                LibItemObj.SetSupModuleList(__SupModuleList)

                #
                # Determine Library class duplicate. Follow below rule:
                #
                # A library class keyword must not be duplicated within a
                # [LibraryClasses] section. Library class keywords may appear in
                # multiple architectural and module type [LibraryClasses] sections.
                # A library class keyword listed in an architectural or module type
                # [LibraryClasses] section must not be listed in the common
                # architectural or module type [LibraryClasses] section.
                #
                # NOTE: This check will not report error now. But keep code for future enhancement.
                #
#                for Item in self.LibraryClasses:
#                    if Item.GetLibName() == LibItemObj.GetLibName():
#                        ItemSupArchList = Item.GetSupArchList()
#                        ItemSupModuleList = Item.GetSupModuleList()
#                        for ItemArch in ItemSupArchList:
#                            for ItemModule in ItemSupModuleList:
#                                for LibItemObjArch in __SupArchList:
#                                    for LibItemObjModule in __SupModuleList:
#                                        if ItemArch == LibItemObjArch and LibItemObjModule == ItemModule:
#                                            #
#                                            # ERR_INF_PARSER_ITEM_DUPLICATE
#                                            #
#                                            pass
#                                        if (ItemArch.upper() == 'COMMON' or LibItemObjArch.upper() == 'COMMON') \
#                                           and LibItemObjModule == ItemModule:
#                                            #
#                                            # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
#                                            #
#                                            pass
            else:
                #
                # Assume the file GUID is well formatted.
                #
                LibItemObj.SetFileGuid(LibItem[0])
                LibItemObj.SetVersion(LibItem[1])
                LibItemObj.SetSupArchList(__SupArchList)

            if (LibItemObj) in self.LibraryClasses:
                LibraryList = self.LibraryClasses[LibItemObj]
                LibraryList.append(LibItemObj)
                self.LibraryClasses[LibItemObj] = LibraryList
            else:
                LibraryList = []
                LibraryList.append(LibItemObj)
                self.LibraryClasses[LibItemObj] = LibraryList

        return True
Ejemplo n.º 8
0
    def SetProtocol(
        self,
        ProtocolContent,
        Arch=None,
    ):
        __SupArchList = []
        for ArchItem in Arch:
            #
            # Validate Arch
            #
            if (ArchItem == '' or ArchItem is None):
                ArchItem = 'COMMON'
            __SupArchList.append(ArchItem)

        for Item in ProtocolContent:
            #
            # Get Comment content of this protocol
            #
            CommentsList = None
            if len(Item) == 3:
                CommentsList = Item[1]
            CurrentLineOfItem = Item[2]
            LineInfo = (CurrentLineOfItem[2], CurrentLineOfItem[1],
                        CurrentLineOfItem[0])
            Item = Item[0]
            InfProtocolItemObj = InfProtocolItem()
            if len(Item) >= 1 and len(Item) <= 2:
                #
                # Only CName contained
                #
                if not IsValidCVariableName(Item[0]):
                    ErrorInInf(ST.ERR_INF_PARSER_INVALID_CNAME % (Item[0]),
                               LineInfo=LineInfo)
                if (Item[0] != ''):
                    InfProtocolItemObj.SetName(Item[0])
                else:
                    ErrorInInf(ST.ERR_INF_PARSER_CNAME_MISSING,
                               LineInfo=LineInfo)
            if len(Item) == 2:
                #
                # Contained CName and Feature Flag Express
                # <statements>           ::=  <CName> ["|"
                # <FeatureFlagExpress>]
                # For Protocol Object
                #
                if Item[1].strip() == '':
                    ErrorInInf(ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                               LineInfo=LineInfo)
                #
                # Validate Feature Flag Express for Item[1]
                #
                FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip())
                if not FeatureFlagRtv[0]:
                    ErrorInInf(
                        ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID %
                        (FeatureFlagRtv[1]),
                        LineInfo=LineInfo)
                InfProtocolItemObj.SetFeatureFlagExp(Item[1])

            if len(Item) < 1 or len(Item) > 2:
                #
                # Invalid format of Protocols statement
                #
                ErrorInInf(
                    ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
                    LineInfo=LineInfo)

            #
            # Get/Set Usage and HelpString for Protocol entry
            #
            if CommentsList is not None and len(CommentsList) != 0:
                InfProtocolItemObj = ParseProtocolComment(
                    CommentsList, InfProtocolItemObj)
            else:
                CommentItemIns = InfProtocolItemCommentContent()
                CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
                CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
                InfProtocolItemObj.SetCommentList([CommentItemIns])

            InfProtocolItemObj.SetSupArchList(__SupArchList)

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

            if (InfProtocolItemObj) in self.Protocols:
                ProcotolList = self.Protocols[InfProtocolItemObj]
                ProcotolList.append(InfProtocolItemObj)
                self.Protocols[InfProtocolItemObj] = ProcotolList
            else:
                ProcotolList = []
                ProcotolList.append(InfProtocolItemObj)
                self.Protocols[InfProtocolItemObj] = ProcotolList

        return True
Ejemplo n.º 9
0
def IsValidPcdValue(PcdValue):
    for Char in PcdValue:
        if Char == '\n' or Char == '\t' or Char == '\f':
            return False

    #
    # <Boolean>
    #
    if IsValidFeatureFlagExp(PcdValue, True)[0]:
        return True

    #
    # <Number>                ::=  {<Integer>} {<HexNumber>}
    # <Integer>               ::=  {(0-9)} {(1-9)(0-9){1,}}
    # <HexNumber>             ::=  "0x" <HexDigit>{1,}
    # <HexDigit>              ::=  (a-fA-F0-9)
    #
    if IsValidHex(PcdValue):
        return True

    ReIsValidIntegerSingle = re.compile(r"^\s*[0-9]\s*$", re.DOTALL)
    if ReIsValidIntegerSingle.match(PcdValue) is not None:
        return True

    ReIsValidIntegerMulti = re.compile(r"^\s*[1-9][0-9]+\s*$", re.DOTALL)
    if ReIsValidIntegerMulti.match(PcdValue) is not None:
        return True

    #
    # <StringVal>              ::=  {<StringType>} {<Array>} {"$(" <MACRO> ")"}
    # <StringType>             ::=  {<UnicodeString>} {<CString>}
    #
    ReIsValidStringType = re.compile(r"^\s*[\"L].*[\"]\s*$")
    if ReIsValidStringType.match(PcdValue):
        IsTrue = False
        if PcdValue.strip().startswith('L\"'):
            StringValue = PcdValue.strip().lstrip('L\"').rstrip('\"')
            if IsValidBareCString(StringValue):
                IsTrue = True
        elif PcdValue.strip().startswith('\"'):
            StringValue = PcdValue.strip().lstrip('\"').rstrip('\"')
            if IsValidBareCString(StringValue):
                IsTrue = True
        if IsTrue:
            return IsTrue

    #
    # <Array>                 ::=   {<CArray>} {<NList>} {<CFormatGUID>}
    # <CArray>                ::=   "{" [<NList>] <CArray>{0,} "}"
    # <NList>                 ::=   <HexByte> ["," <HexByte>]{0,}
    # <HexDigit>              ::=  (a-fA-F0-9)
    # <HexByte>               ::=  "0x" <HexDigit>{1,2}
    #
    if IsValidCFormatGuid(PcdValue):
        return True

    ReIsValidByteHex = re.compile(r"^\s*0x[0-9a-fA-F]{1,2}\s*$", re.DOTALL)
    if PcdValue.strip().startswith('{') and PcdValue.strip().endswith('}'):
        StringValue = PcdValue.strip().lstrip('{').rstrip('}')
        ValueList = StringValue.split(',')
        AllValidFlag = True
        for ValueItem in ValueList:
            if not ReIsValidByteHex.match(ValueItem.strip()):
                AllValidFlag = False

        if AllValidFlag:
            return True

    #
    # NList
    #
    AllValidFlag = True
    ValueList = PcdValue.split(',')
    for ValueItem in ValueList:
        if not ReIsValidByteHex.match(ValueItem.strip()):
            AllValidFlag = False

    if AllValidFlag:
        return True

    return False
Ejemplo n.º 10
0
    def SetPpi(self, PpiList, Arch = None):
        __SupArchList = []
        for ArchItem in Arch:
            #
            # Validate Arch
            #
            if (ArchItem == '' or ArchItem is None):
                ArchItem = 'COMMON'
            __SupArchList.append(ArchItem)

        for Item in PpiList:
            #
            # Get Comment content of this protocol
            #
            CommentsList = None
            if len(Item) == 3:
                CommentsList = Item[1]
            CurrentLineOfItem = Item[2]
            Item = Item[0]
            InfPpiItemObj = InfPpiItem()
            if len(Item) >= 1 and len(Item) <= 2:
                #
                # Only CName contained
                #
                if not IsValidCVariableName(Item[0]):
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_INVALID_CNAME%(Item[0]),
                                 File=CurrentLineOfItem[2],
                                 Line=CurrentLineOfItem[1],
                                 ExtraData=CurrentLineOfItem[0])
                if (Item[0] != ''):
                    InfPpiItemObj.SetName(Item[0])
                else:
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_CNAME_MISSING,
                                 File=CurrentLineOfItem[2],
                                 Line=CurrentLineOfItem[1],
                                 ExtraData=CurrentLineOfItem[0])
            #
            # Have FeatureFlag information
            #
            if len(Item) == 2:
                #
                # Contained CName and Feature Flag Express
                # <statements>           ::=  <CName> ["|" <FeatureFlagExpress>]
                # Item[1] should not be empty
                #
                if Item[1].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 Feature Flag Express for PPI entry
                # Item[1] contain FFE information
                #
                FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].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])
                InfPpiItemObj.SetFeatureFlagExp(Item[1])
            if len(Item) != 1 and len(Item) != 2:
                #
                # Invalid format of Ppi statement
                #
                Logger.Error("InfParser",
                             ToolError.FORMAT_INVALID,
                             ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR,
                             File=CurrentLineOfItem[2],
                             Line=CurrentLineOfItem[1],
                             ExtraData=CurrentLineOfItem[0])

            #
            # Get/Set Usage and HelpString for PPI entry
            #
            if CommentsList is not None and len(CommentsList) != 0:
                InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj)
            else:
                CommentItemIns = InfPpiItemCommentContent()
                CommentItemIns.SetUsage(DT.ITEM_UNDEFINED)
                CommentItemIns.SetNotify(DT.ITEM_UNDEFINED)
                InfPpiItemObj.SetCommentList([CommentItemIns])

            InfPpiItemObj.SetSupArchList(__SupArchList)

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

            if (InfPpiItemObj) in self.Ppis:
                PpiList = self.Ppis[InfPpiItemObj]
                PpiList.append(InfPpiItemObj)
                self.Ppis[InfPpiItemObj] = PpiList
            else:
                PpiList = []
                PpiList.append(InfPpiItemObj)
                self.Ppis[InfPpiItemObj] = PpiList

        return True
Ejemplo n.º 11
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
Ejemplo n.º 12
0
    def SetPcds(self, PcdContent, KeysList=None, PackageInfo=None):

        if GlobalData.gIS_BINARY_INF:
            self.SetAsBuildPcds(PcdContent, KeysList, PackageInfo)
            return True

        #
        # Validate Arch
        #
        SupArchList = []
        SupArchDict = {}
        PcdTypeItem = ''
        for (PcdTypeItem1, ArchItem, LineNo) in KeysList:
            SupArchList, SupArchDict = ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList)

            #
            # Validate PcdType
            #
            if (PcdTypeItem1 == '' or PcdTypeItem1 is None):
                return False
            else:
                if not IsValidPcdType(PcdTypeItem1):
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_PCD_SECTION_TYPE_ERROR % (DT.PCD_USAGE_TYPE_LIST_OF_MODULE),
                                 File=GlobalData.gINF_MODULE_NAME,
                                 Line=LineNo,
                                 ExtraData=PcdTypeItem1)
                    return False

            PcdTypeItem = PcdTypeItem1

            for PcdItem in PcdContent:
                PcdItemObj = InfPcdItem()
                CommentList = PcdItem[1]
                CurrentLineOfPcdItem = PcdItem[2]
                PcdItem = PcdItem[0]

                if CommentList is not None and len(CommentList) != 0:
                    PcdItemObj = ParsePcdComment(CommentList, PcdTypeItem, PcdItemObj)
                else:
                    CommentItemIns = InfPcdItemCommentContent()
                    CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED)
                    PcdItemObj.SetHelpStringList([CommentItemIns])

                if len(PcdItem) >= 1 and len(PcdItem) <= 3:
                    PcdItemObj = SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj)

                if len(PcdItem) >= 2 and len(PcdItem) <= 3:
                    #
                    # Contain PcdName and Value, validate value.
                    #
                    if IsValidPcdValue(PcdItem[1]) or PcdItem[1].strip() == "":
                        PcdItemObj.SetDefaultValue(PcdItem[1])
                    else:
                        Logger.Error("InfParser",
                                     ToolError.FORMAT_INVALID,
                                     ST.ERR_INF_PARSER_PCD_VALUE_INVALID,
                                     File=CurrentLineOfPcdItem[2],
                                     Line=CurrentLineOfPcdItem[1],
                                     ExtraData=PcdItem[1])

                if len(PcdItem) == 3:
                    #
                    # Contain PcdName, value, and FeatureFlag express
                    #
                    #
                    # Validate Feature Flag Express
                    #
                    if PcdItem[2].strip() == '':
                        Logger.Error("InfParser",
                                     ToolError.FORMAT_INVALID,
                                     ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
                                     File=CurrentLineOfPcdItem[2],
                                     Line=CurrentLineOfPcdItem[1],
                                     ExtraData=CurrentLineOfPcdItem[0])
                    #
                    # Validate FFE
                    #
                    FeatureFlagRtv = IsValidFeatureFlagExp(PcdItem[2].strip())
                    if not FeatureFlagRtv[0]:
                        Logger.Error("InfParser",
                                     ToolError.FORMAT_INVALID,
                                     ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),
                                     File=CurrentLineOfPcdItem[2],
                                     Line=CurrentLineOfPcdItem[1],
                                     ExtraData=CurrentLineOfPcdItem[0])
                    PcdItemObj.SetFeatureFlagExp(PcdItem[2])

                if len(PcdItem) < 1 or len(PcdItem) > 3:
                    Logger.Error("InfParser",
                                 ToolError.FORMAT_INVALID,
                                 ST.ERR_INF_PARSER_PCD_SECTION_CONTENT_ERROR,
                                 File=CurrentLineOfPcdItem[2],
                                 Line=CurrentLineOfPcdItem[1],
                                 ExtraData=CurrentLineOfPcdItem[0])
                    return False

                if PcdTypeItem.upper != DT.TAB_INF_FEATURE_PCD.upper():
                    PcdItemObj.SetSupportArchList(SupArchDict[PcdTypeItem])
                else:
                    PcdItemObj.SetSupportArchList(SupArchList)

                if (PcdTypeItem, PcdItemObj) in self.Pcds:
                    PcdsList = self.Pcds[PcdTypeItem, PcdItemObj]
                    PcdsList.append(PcdItemObj)
                    self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList
                else:
                    PcdsList = []
                    PcdsList.append(PcdItemObj)
                    self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList

        return True