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])
 def SetDefines(self, DefineContent, Arch=None):
     #
     # Validate Arch
     #
     HasFoundInfVersionFalg = False
     LineInfo = ['', -1, '']
     ArchListString = ' '.join(Arch)
     #
     # Parse Define items.
     #
     for InfDefMemberObj in DefineContent:
         ProcessFunc = None
         Name = InfDefMemberObj.GetName()
         Value = InfDefMemberObj.GetValue()
         if Name == DT.TAB_INF_DEFINES_MODULE_UNI_FILE:
             ValidateUNIFilePath(Value)
             Value = os.path.join(
                 os.path.dirname(InfDefMemberObj.CurrentLine.FileName),
                 Value)
             if not os.path.isfile(Value) or not os.path.exists(Value):
                 LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
                 LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
                 LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
                 ErrorInInf(
                     ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID %
                     (Name),
                     LineInfo=LineInfo)
         InfLineCommentObj = InfLineCommentObject()
         InfLineCommentObj.SetHeaderComments(
             InfDefMemberObj.Comments.GetHeaderComments())
         InfLineCommentObj.SetTailComments(
             InfDefMemberObj.Comments.GetTailComments())
         if Name == 'COMPONENT_TYPE':
             ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
                        ErrorCode=ToolError.EDK1_INF_ERROR,
                        RaiseError=True)
         if Name == DT.TAB_INF_DEFINES_INF_VERSION:
             HasFoundInfVersionFalg = True
         if not (Name == '' or Name == None):
             #
             # Process "SPEC" Keyword definition.
             #
             ReName = re.compile(r"SPEC ", re.DOTALL)
             if ReName.match(Name):
                 SpecValue = Name[Name.find("SPEC") + len("SPEC"):].strip()
                 Name = "SPEC"
                 Value = SpecValue + " = " + Value
             if self.Defines.has_key(ArchListString):
                 DefineList = self.Defines[ArchListString]
                 LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
                 LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
                 LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
                 DefineList.CurrentLine = LineInfo
                 #
                 # Found the process function from mapping table.
                 #
                 if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys():
                     ErrorInInf(
                         ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID %
                         (Name),
                         LineInfo=LineInfo)
                 else:
                     ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[
                         Name]
                 if (ProcessFunc != None):
                     ProcessFunc(DefineList, Value, InfLineCommentObj)
                 self.Defines[ArchListString] = DefineList
             else:
                 DefineList = InfDefSection()
                 LineInfo[0] = InfDefMemberObj.CurrentLine.GetFileName()
                 LineInfo[1] = InfDefMemberObj.CurrentLine.GetLineNo()
                 LineInfo[2] = InfDefMemberObj.CurrentLine.GetLineString()
                 DefineList.CurrentLine = LineInfo
                 #
                 # Found the process function from mapping table.
                 #
                 if Name not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION.keys():
                     ErrorInInf(
                         ST.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID %
                         (Name),
                         LineInfo=LineInfo)
                 #
                 # Found the process function from mapping table.
                 #
                 else:
                     ProcessFunc = gFUNCTION_MAPPING_FOR_DEFINE_SECTION[
                         Name]
                 if (ProcessFunc != None):
                     ProcessFunc(DefineList, Value, InfLineCommentObj)
                 self.Defines[ArchListString] = DefineList
     #
     # After set, check whether INF_VERSION defined.
     #
     if not HasFoundInfVersionFalg:
         ErrorInInf(ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF,
                    ErrorCode=ToolError.EDK1_INF_ERROR,
                    RaiseError=True)
     return True