Exemple #1
0
    def ToXml(self, PackageObject2, Key):
        if self.PackagePath:
            pass
        Element1 = CreateXmlElement('Name', PackageObject2.GetName(), [], \
                         [['BaseName', PackageObject2.GetBaseName()]])
        Element2 = CreateXmlElement('GUID', PackageObject2.GetGuid(), [], \
                                    [['Version', PackageObject2.GetVersion()]])
        NodeList = [Element1, Element2]

        UNIPackageAbrstractList = []
        UNIPackageDescriptionList = []
        # Get Abstract and Description from Uni File
        # if the Uni File exists
        if PackageObject2.UniFileClassObject is not None:
            UniStrDict = PackageObject2.UniFileClassObject.OrderedStringList
            for Lang in UniStrDict:
                for StringDefClassObject in UniStrDict[Lang]:
                    if not StringDefClassObject.StringValue:
                        continue
                    if StringDefClassObject.StringName == DataType.TAB_DEC_PACKAGE_ABSTRACT:
                        UNIPackageAbrstractList.append(
                            (GetLanguageCode1766(Lang),
                             ConvertSpecialUnicodes(
                                 StringDefClassObject.StringValue)))

                    if StringDefClassObject.StringName == DataType.TAB_DEC_PACKAGE_DESCRIPTION:
                        UNIPackageDescriptionList.append(
                            (GetLanguageCode1766(Lang),
                             ConvertSpecialUnicodes(
                                 StringDefClassObject.StringValue)))

        # Get Abstract and Description from DEC File Header
        for (Lang, Value) in PackageObject2.GetCopyright():
            if Value:
                NodeList.append(
                    CreateXmlElement(DataType.TAB_HEADER_COPYRIGHT, Value, [],
                                     []))
        for (Lang, Value) in PackageObject2.GetLicense():
            if Value:
                NodeList.append(
                    CreateXmlElement(DataType.TAB_HEADER_LICENSE, Value, [],
                                     []))
        for (Lang,
             Value) in PackageObject2.GetAbstract() + UNIPackageAbrstractList:
            if Value:
                NodeList.append(
                    CreateXmlElement(DataType.TAB_HEADER_ABSTRACT, Value, [],
                                     [['Lang', Lang]]))
        for (Lang, Value
             ) in PackageObject2.GetDescription() + UNIPackageDescriptionList:
            if Value:
                NodeList.append(
                    CreateXmlElement(DataType.TAB_HEADER_DESCRIPTION, Value,
                                     [], [['Lang', Lang]]))

        NodeList.append(['PackagePath', PackageObject2.GetPackagePath()])
        AttributeList = []
        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
        return Root
Exemple #2
0
    def _GenUserExtensions(self):
        #
        # UserExtensions
        #
        UserExtensionObj = self.Parser.InfUserExtensionSection.UserExtension
        Keys = UserExtensionObj.keys()

        for Key in Keys:
            UserExtensionData = UserExtensionObj[Key]
            for UserExtensionDataObj in UserExtensionData:
                UserExtension = CommonObject.UserExtensionObject()
                UserId = UserExtensionDataObj.GetUserId()
                if UserId.startswith('"') and UserId.endswith('"'):
                    UserId = UserId[1:-1]
                UserExtension.SetUserID(UserId)
                Identifier = UserExtensionDataObj.GetIdString()
                if Identifier.startswith('"') and Identifier.endswith('"'):
                    Identifier = Identifier[1:-1]
                #
                # Generate miscellaneous files on INF file
                #
                if UserId == 'TianoCore' and Identifier == 'ExtraFiles':
                    self._GenMiscFiles(UserExtensionDataObj.GetContent())
                UserExtension.SetIdentifier(Identifier)
                UserExtension.SetStatement(UserExtensionDataObj.GetContent())
                UserExtension.SetSupArchList(ConvertArchList(UserExtensionDataObj.GetSupArchList()))
                self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension])

        #
        #  Gen UserExtensions of TianoCore."BinaryHeader"
        #

        #Get Binary header from INF file
        BinaryAbstractList = self.BinaryHeaderAbstractList
        BinaryDescriptionList = self.BinaryHeaderDescriptionList
        BinaryCopyrightList = self.BinaryHeaderCopyrightList
        BinaryLicenseList = self.BinaryHeaderLicenseList
        #Get Binary header from UNI file
        # Initialize UniStrDict, the top keys are language codes
        UniStrDict = {}
        if self.UniFileClassObject:
            UniStrDict = self.UniFileClassObject.OrderedStringList
            for Lang in UniStrDict:
                for StringDefClassObject in UniStrDict[Lang]:
                    Lang = GetLanguageCode1766(Lang)
                    if StringDefClassObject.StringName == DT.TAB_INF_BINARY_ABSTRACT:
                        BinaryAbstractList.append((Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
                    if StringDefClassObject.StringName == DT.TAB_INF_BINARY_DESCRIPTION:
                        BinaryDescriptionList.append((Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
        if BinaryAbstractList or BinaryDescriptionList or BinaryCopyrightList or BinaryLicenseList:
            BinaryUserExtension = CommonObject.UserExtensionObject()
            BinaryUserExtension.SetBinaryAbstract(BinaryAbstractList)
            BinaryUserExtension.SetBinaryDescription(BinaryDescriptionList)
            BinaryUserExtension.SetBinaryCopyright(BinaryCopyrightList)
            BinaryUserExtension.SetBinaryLicense(BinaryLicenseList)
            BinaryUserExtension.SetIdentifier(DT.TAB_BINARY_HEADER_IDENTIFIER)
            BinaryUserExtension.SetUserID(DT.TAB_BINARY_HEADER_USERID)
            self.SetUserExtensionList(self.GetUserExtensionList() + [BinaryUserExtension])
Exemple #3
0
    def ToXml(self, Header, Key):
        if self.GUID:
            pass
        Element1 = CreateXmlElement(
            'Name', Header.GetName(), [],
            [['BaseName', Header.GetBaseName()]])
        Element2 = CreateXmlElement(
            'GUID', Header.GetGuid(), [],
            [['Version', Header.GetVersion()]])
        NodeList = [
            Element1,
            Element2,
        ]

        UNIInfAbstractList = []
        UNIInfDescriptionList = []
        # Get Abstract and Description from Uni File
        # if the Uni File exists
        if Header.UniFileClassObject is not None:
            UniStrDict = Header.UniFileClassObject.OrderedStringList
            for Lang in UniStrDict:
                for StringDefClassObject in UniStrDict[Lang]:
                    if not StringDefClassObject.StringValue:
                        continue
                    if StringDefClassObject.StringName == DataType.TAB_INF_ABSTRACT:
                        UNIInfAbstractList.append(
                            (GetLanguageCode1766(Lang),
                             ConvertSpecialUnicodes(
                                 StringDefClassObject.StringValue)))

                    if StringDefClassObject.StringName == DataType.TAB_INF_DESCRIPTION:
                        UNIInfDescriptionList.append(
                            (GetLanguageCode1766(Lang),
                             ConvertSpecialUnicodes(
                                 StringDefClassObject.StringValue)))

        # Get Abstract and Description from INF File Header
        for (Lang, Value) in Header.GetCopyright():
            if Value:
                NodeList.append(CreateXmlElement('Copyright', Value, [], []))
        for (Lang, Value) in Header.GetLicense():
            if Value:
                NodeList.append(CreateXmlElement('License', Value, [], []))
        for (Lang, Value) in Header.GetAbstract() + UNIInfAbstractList:
            if Value:
                NodeList.append(
                    CreateXmlElement('Abstract', Value, [], [['Lang', Lang]]))
        for (Lang, Value) in Header.GetDescription() + UNIInfDescriptionList:
            if Value:
                NodeList.append(
                    CreateXmlElement('Description', Value, [],
                                     [['Lang', Lang]]))

        AttributeList = []
        Root = CreateXmlElement('%s' % Key, '', NodeList, AttributeList)
        return Root
Exemple #4
0
def GenHeaderCommentSection(Abstract, Description, Copyright, License, IsBinaryHeader=False, \
                            CommChar=TAB_COMMENT_SPLIT):
    Content = ''

    #
    # Convert special character to (c), (r) and (tm).
    #
    if isinstance(Abstract, unicode):
        Abstract = ConvertSpecialUnicodes(Abstract)
    if isinstance(Description, unicode):
        Description = ConvertSpecialUnicodes(Description)
    if IsBinaryHeader:
        Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_BINARY_HEADER_COMMENT + '\r\n'
    elif CommChar == TAB_COMMENT_EDK1_SPLIT:
        Content += CommChar + TAB_SPACE_SPLIT + TAB_COMMENT_EDK1_START + TAB_STAR + TAB_SPACE_SPLIT +\
         TAB_HEADER_COMMENT + '\r\n'
    else:
        Content += CommChar * 2 + TAB_SPACE_SPLIT + TAB_HEADER_COMMENT + '\r\n'
    if Abstract:
        Abstract = Abstract.rstrip('\r\n')
        Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
                                                                                                (Abstract, '\n'))
        Content += '\r\n' + CommChar + '\r\n'
    else:
        Content += CommChar + '\r\n'

    if Description:
        Description = Description.rstrip('\r\n')
        Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
                                                  (Description, '\n'))
        Content += '\r\n' + CommChar + '\r\n'

    #
    # There is no '#\n' line to separate multiple copyright lines in code base
    #
    if Copyright:
        Copyright = Copyright.rstrip('\r\n')
        Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join\
        (GetSplitValueList(Copyright, '\n'))
        Content += '\r\n' + CommChar + '\r\n'

    if License:
        License = License.rstrip('\r\n')
        Content += CommChar + TAB_SPACE_SPLIT + ('\r\n' + CommChar + TAB_SPACE_SPLIT).join(GetSplitValueList\
                                                  (License, '\n'))
        Content += '\r\n' + CommChar + '\r\n'

    if CommChar == TAB_COMMENT_EDK1_SPLIT:
        Content += CommChar + TAB_SPACE_SPLIT + TAB_STAR + TAB_COMMENT_EDK1_END + '\r\n'
    else:
        Content += CommChar * 2 + '\r\n'

    return Content
    def GenPackageHeader(self, ContainerFile):
        Logger.Debug(2, "Generate PackageHeader ...")
        DefinesDict = {}

        #
        # Update all defines item in database
        #
        DefObj = self.DecParser.GetDefineSectionObject()
        for Item in DefObj.GetDefines():
            #
            # put items into Dict except for PackageName, Guid, Version, DEC_SPECIFICATION
            #
            SkipItemList = [TAB_DEC_DEFINES_PACKAGE_NAME, \
                TAB_DEC_DEFINES_PACKAGE_GUID, TAB_DEC_DEFINES_PACKAGE_VERSION, \
                TAB_DEC_DEFINES_DEC_SPECIFICATION, TAB_DEC_DEFINES_PKG_UNI_FILE]
            if Item.Key in SkipItemList:
                continue
            DefinesDict['%s = %s' % (Item.Key, Item.Value)] = TAB_ARCH_COMMON

        self.SetBaseName(DefObj.GetPackageName())
        self.SetVersion(DefObj.GetPackageVersion())
#        self.SetName(DefObj.GetPackageName() + ' Version ' + \
#                     DefObj.GetPackageVersion())
        self.SetName(os.path.splitext(self.GetFileName())[0])
        self.SetGuid(DefObj.GetPackageGuid())
        if DefObj.GetPackageUniFile():
            ValidateUNIFilePath(DefObj.GetPackageUniFile())
            self.UniFileClassObject = \
            UniFileClassObject([PathClass(os.path.join(DefObj.GetPackagePath(), DefObj.GetPackageUniFile()))])
        else:
            self.UniFileClassObject = None

        if DefinesDict:
            UserExtension = UserExtensionObject()
            UserExtension.SetDefinesDict(DefinesDict)
            UserExtension.SetIdentifier('DefineModifiers')
            UserExtension.SetUserID('EDK2')
            self.SetUserExtensionList(
                self.GetUserExtensionList() + [UserExtension]
            )

        #
        # Get File header information
        #
        if self.UniFileClassObject:
            Lang = TAB_LANGUAGE_EN_X
        else:
            Lang = TAB_LANGUAGE_EN_US
        Abstract, Description, Copyright, License = \
            ParseHeaderCommentSection(self.DecParser.GetHeadComment(),
                                      ContainerFile)
        if Abstract:
            self.SetAbstract((Lang, Abstract))
        if Description:
            self.SetDescription((Lang, Description))
        if Copyright:
            self.SetCopyright(('', Copyright))
        if License:
            self.SetLicense(('', License))

        #
        # Get Binary header information
        #
        if self.DecParser.BinaryHeadComment:
            Abstract, Description, Copyright, License = \
                ParseHeaderCommentSection(self.DecParser.BinaryHeadComment,
                                      ContainerFile, True)

            if not Abstract  or not Description or not Copyright or not License:
                Logger.Error('MkPkg',
                             FORMAT_INVALID,
                             ST.ERR_INVALID_BINARYHEADER_FORMAT,
                             ContainerFile)
            else:
                self.SetBinaryHeaderAbstract((Lang, Abstract))
                self.SetBinaryHeaderDescription((Lang, Description))
                self.SetBinaryHeaderCopyright(('', Copyright))
                self.SetBinaryHeaderLicense(('', License))

        BinaryAbstractList = []
        BinaryDescriptionList = []

        #Get Binary header from UNI file
        # Initialize the UniStrDict dictionary, top keys are language codes
        UniStrDict = {}
        if self.UniFileClassObject:
            UniStrDict = self.UniFileClassObject.OrderedStringList
            for Lang in UniStrDict:
                for StringDefClassObject in UniStrDict[Lang]:
                    Lang = GetLanguageCode1766(Lang)
                    if StringDefClassObject.StringName == TAB_DEC_BINARY_ABSTRACT:
                        if (Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)) \
                        not in self.GetBinaryHeaderAbstract():
                            BinaryAbstractList.append((Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
                    if StringDefClassObject.StringName == TAB_DEC_BINARY_DESCRIPTION:
                        if (Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)) \
                        not in self.GetBinaryHeaderDescription():
                            BinaryDescriptionList.append((Lang,
                                                          ConvertSpecialUnicodes(StringDefClassObject.StringValue)))
        #Combine Binary header from DEC file and UNI file
        BinaryAbstractList = self.GetBinaryHeaderAbstract() + BinaryAbstractList
        BinaryDescriptionList = self.GetBinaryHeaderDescription() + BinaryDescriptionList
        BinaryCopyrightList = self.GetBinaryHeaderCopyright()
        BinaryLicenseList = self.GetBinaryHeaderLicense()
        #Generate the UserExtensionObject for TianoCore."BinaryHeader"
        if BinaryAbstractList or BinaryDescriptionList or BinaryCopyrightList or BinaryLicenseList:
            BinaryUserExtension = UserExtensionObject()
            BinaryUserExtension.SetBinaryAbstract(BinaryAbstractList)
            BinaryUserExtension.SetBinaryDescription(BinaryDescriptionList)
            BinaryUserExtension.SetBinaryCopyright(BinaryCopyrightList)
            BinaryUserExtension.SetBinaryLicense(BinaryLicenseList)
            BinaryUserExtension.SetIdentifier(TAB_BINARY_HEADER_IDENTIFIER)
            BinaryUserExtension.SetUserID(TAB_BINARY_HEADER_USERID)
            self.SetUserExtensionList(self.GetUserExtensionList() + [BinaryUserExtension])