def GenSources(ModuleObject): # # generate [Sources] section # Content = '' NewSectionDict = {} for Source in ModuleObject.GetSourceFileList(): SourceFile = Source.GetSourceFile() Family = Source.GetFamily() FeatureFlag = Source.GetFeatureFlag() SupArchList = Source.GetSupArchList() SupArchList.sort() SortedArch = ' '.join(SupArchList) Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [ Statement ] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('Sources', NewSectionDict) return Content
def InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly, ModuleList): # # Extract other files under current module path in content Zip file but not listed in the description # if ContentZipFile: for FileName in ContentZipFile.GetZipFile().namelist(): FileName = os.path.normpath(FileName) CheckPath = os.path.normpath(os.path.join(FromPath, ModulePath)) if FileUnderPath(FileName, CheckPath): if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) FromFile = FileName ToFile = os.path.normpath(os.path.join(WorkspaceDir, ConvertPath(FileName.replace(FromPath, NewPath, 1)))) CheckList = copy.copy(Module.FileList) if Package: CheckList += Package.FileList for Item in CheckList: if Item[0] == ToFile: break else: Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) ModuleList.append((Module, Package))
def GenBinaries(ModuleObject): NewSectionDict = {} BinariesDict = [] for UserExtension in ModuleObject.GetUserExtensionList(): BinariesDict = UserExtension.GetBinariesDict() if BinariesDict: break for BinaryFile in ModuleObject.GetBinaryFileList(): FileNameObjList = BinaryFile.GetFileNameList() for FileNameObj in FileNameObjList: FileName = ConvertPath(FileNameObj.GetFilename()) FileType = FileNameObj.GetFileType() FFE = FileNameObj.GetFeatureFlag() ArchList = FileNameObj.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) Key = (FileName, FileType, FFE, SortedArch) if Key in BinariesDict: ValueList = BinariesDict[Key] for ValueItem in ValueList: Statement = GenBinaryStatement(Key, ValueItem) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[ SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] # # as we already generated statement for this DictKey here set the Valuelist to be empty # to avoid generate duplicate entries as the DictKey may have multiple entries # BinariesDict[Key] = [] else: if FileType == 'SUBTYPE_GUID' and FileNameObj.GetGuidValue(): Statement = GenBinaryStatement(Key, None, FileNameObj.GetGuidValue()) else: Statement = GenBinaryStatement(Key, None) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [ Statement ] else: NewSectionDict[SortedArch] = [Statement] Content = GenSection('Binaries', NewSectionDict) return Content
def GenToolMisc(DistPkg, WorkspaceDir, ContentZipFile): ToolObject = DistPkg.Tools MiscObject = DistPkg.MiscellaneousFiles DistPkg.FileList = [] FileList = [] ToolFileNum = 0 FileNum = 0 RootDir = WorkspaceDir # # FileList stores both tools files and misc files # Misc file list must be appended to FileList *AFTER* Tools file list # if ToolObject: FileList += ToolObject.GetFileList() ToolFileNum = len(ToolObject.GetFileList()) if 'EDK_TOOLS_PATH' in os.environ: RootDir = os.environ['EDK_TOOLS_PATH'] if MiscObject: FileList += MiscObject.GetFileList() for FileObject in FileList: FileNum += 1 if FileNum > ToolFileNum: # # Misc files, root should be changed to WORKSPACE # RootDir = WorkspaceDir File = ConvertPath(FileObject.GetURI()) ToFile = os.path.normpath(os.path.join(RootDir, File)) if os.path.exists(ToFile): Logger.Info(ST.WRN_FILE_EXISTED % ToFile) # # ask for user input the new file name # Logger.Info(ST.MSG_NEW_FILE_NAME) Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') OrigPath = os.path.split(ToFile)[0] ToFile = os.path.normpath(os.path.join(OrigPath, Input)) FromFile = os.path.join(FileObject.GetURI()) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, DistPkg.Header.ReadOnly, FileObject.GetExecutable()) DistPkg.FileList.append((ToFile, Md5Sum))
def InstallNewModule(WorkspaceDir, Path, PathList=None): if PathList is None: PathList = [] Path = ConvertPath(Path) Path = os.path.normpath(Path) FullPath = os.path.normpath(os.path.join(WorkspaceDir, Path)) if os.path.exists(FullPath) and FullPath not in PathList: Logger.Info(ST.ERR_DIR_ALREADY_EXIST % Path) elif Path == FullPath: Logger.Info(ST.MSG_RELATIVE_PATH_ONLY % FullPath) else: return Path Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input == '': Logger.Error("InstallPkg", UNKNOWN_ERROR, ST.ERR_USER_INTERRUPT) Input = Input.replace('\r', '').replace('\n', '') return InstallNewModule(WorkspaceDir, Input, PathList)
def InstallNewPackage(WorkspaceDir, Path, CustomPath=False): if os.path.isabs(Path): Logger.Info(ST.MSG_RELATIVE_PATH_ONLY % Path) elif CustomPath: Logger.Info(ST.MSG_NEW_PKG_PATH) else: Path = ConvertPath(Path) Path = os.path.normpath(Path) FullPath = os.path.normpath(os.path.join(WorkspaceDir, Path)) if os.path.exists(FullPath): Logger.Info(ST.ERR_DIR_ALREADY_EXIST % FullPath) else: return Path Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input == '': Logger.Error("InstallPkg", UNKNOWN_ERROR, ST.ERR_USER_INTERRUPT) Input = Input.replace('\r', '').replace('\n', '') return InstallNewPackage(WorkspaceDir, Input, False)
def PackageToDec(Package, DistHeader=None): # # Init global information for the file # ContainerFile = Package.GetFullPath() Content = '' # # Generate file header # PackageAbstract = GetLocalValue(Package.GetAbstract()) PackageDescription = GetLocalValue(Package.GetDescription()) PackageCopyright = '' PackageLicense = '' for (Lang, Copyright) in Package.GetCopyright(): if Lang: pass PackageCopyright = Copyright for (Lang, License) in Package.GetLicense(): if Lang: pass PackageLicense = License if not PackageAbstract and DistHeader: PackageAbstract = GetLocalValue(DistHeader.GetAbstract()) if not PackageDescription and DistHeader: PackageDescription = GetLocalValue(DistHeader.GetDescription()) if not PackageCopyright and DistHeader: for (Lang, Copyright) in DistHeader.GetCopyright(): PackageCopyright = Copyright if not PackageLicense and DistHeader: for (Lang, License) in DistHeader.GetLicense(): PackageLicense = License # # Generate header comment section of DEC file # Content += GenHeaderCommentSection(PackageAbstract, \ PackageDescription, \ PackageCopyright, \ PackageLicense).replace('\r\n', '\n') # # Generate Binary header # for UserExtension in Package.GetUserExtensionList(): if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID \ and UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER: PackageBinaryAbstract = GetLocalValue( UserExtension.GetBinaryAbstract()) PackageBinaryDescription = GetLocalValue( UserExtension.GetBinaryDescription()) PackageBinaryCopyright = '' PackageBinaryLicense = '' for (Lang, Copyright) in UserExtension.GetBinaryCopyright(): PackageBinaryCopyright = Copyright for (Lang, License) in UserExtension.GetBinaryLicense(): PackageBinaryLicense = License if PackageBinaryAbstract and PackageBinaryDescription and \ PackageBinaryCopyright and PackageBinaryLicense: Content += GenHeaderCommentSection(PackageBinaryAbstract, PackageBinaryDescription, PackageBinaryCopyright, PackageBinaryLicense, True) # # Generate PACKAGE_UNI_FILE for the Package # FileHeader = GenHeaderCommentSection(PackageAbstract, PackageDescription, PackageCopyright, PackageLicense, False, \ TAB_COMMENT_EDK1_SPLIT) GenPackageUNIEncodeFile(Package, FileHeader) # # for each section, maintain a dict, sorted arch will be its key, #statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], # 'Arch1' : [statement1, statement3] # } # # # generate [Defines] section # LeftOffset = 31 NewSectionDict = {TAB_ARCH_COMMON: []} SpecialItemList = [] Statement = (u'%s ' % TAB_DEC_DEFINES_DEC_SPECIFICATION ).ljust(LeftOffset) + u'= %s' % '0x00010017' SpecialItemList.append(Statement) BaseName = Package.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_NAME ).ljust(LeftOffset) + u'= %s' % BaseName SpecialItemList.append(Statement) Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_VERSION ).ljust(LeftOffset) + u'= %s' % Package.GetVersion() SpecialItemList.append(Statement) Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_GUID ).ljust(LeftOffset) + u'= %s' % Package.GetGuid() SpecialItemList.append(Statement) if Package.UNIFlag: Statement = (u'%s ' % TAB_DEC_DEFINES_PKG_UNI_FILE).ljust( LeftOffset) + u'= %s' % Package.GetBaseName() + '.uni' SpecialItemList.append(Statement) for SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + SpecialItemList Content += GenSection('Defines', NewSectionDict) # # generate [Includes] section # NewSectionDict = {} IncludeArchList = Package.GetIncludeArchList() if IncludeArchList: for Path, ArchList in IncludeArchList: Statement = Path ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [ConvertPath(Statement)] else: NewSectionDict[SortedArch] = [ConvertPath(Statement)] Content += GenSection('Includes', NewSectionDict) # # generate [guids][protocols][ppis] sections # Content = GenGuidProtocolPpi(Package, Content) # # generate [LibraryClasses] section # NewSectionDict = {} for LibraryClass in Package.GetLibraryClassList(): # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) if HelpStr: HelpStr = '@libraryclass' + HelpStr CommentStr = GenGenericCommentF(HelpStr, 2, False, True) Statement = CommentStr Name = LibraryClass.GetLibraryClass() IncludeHeader = LibraryClass.GetIncludeHeader() Statement += Name + '|' + ConvertPath(IncludeHeader) # # generate tail comment # if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) ArchList = sorted(LibraryClass.GetSupArchList()) SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict, True, True) # # Generate '# [Error.<TokenSpcCName>]' section # Content = GenPcdErrorMsgSection(Package, Content) Content = GenPcd(Package, Content) # # generate [UserExtensions] section # NewSectionDict = {} for UserExtension in Package.GetUserExtensionList(): if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID and \ UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER: continue # Generate Private Section first if UserExtension.GetUserID( ) == DT.TAB_INTEL and UserExtension.GetIdentifier() == DT.TAB_PRIVATE: Content += '\n' + UserExtension.GetStatement() continue Statement = UserExtension.GetStatement() if not Statement: continue else: LineList = Statement.split('\n') NewStatement = "" for Line in LineList: NewStatement += " %s\n" % Line SectionList = [] SectionName = 'UserExtensions' UserId = UserExtension.GetUserID() if UserId: if '.' in UserId: UserId = '"' + UserId + '"' SectionName += '.' + UserId if UserExtension.GetIdentifier(): SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"' if not UserExtension.GetSupArchList(): SectionList.append(SectionName) else: for Arch in UserExtension.GetSupArchList(): SectionList.append(SectionName + '.' + Arch) SectionName = ', '.join(SectionList) SectionName = ''.join(['[', SectionName, ']\n']) Content += '\n' + SectionName + NewStatement SaveFileOnChange(ContainerFile, Content, False) if DistHeader.ReadOnly: os.chmod(ContainerFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) else: os.chmod( ContainerFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) return ContainerFile
def GenDefines(ModuleObject): # # generate [Defines] section # Content = '' NewSectionDict = {} for UserExtension in ModuleObject.GetUserExtensionList(): DefinesDict = UserExtension.GetDefinesDict() if not DefinesDict: continue for Statement in DefinesDict: SortedArch = DT.TAB_ARCH_COMMON if Statement.strip().startswith( DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE): pos = Statement.find(DT.TAB_VALUE_SPLIT) if pos == -1: pos = Statement.find(DT.TAB_EQUAL_SPLIT) Makefile = ConvertPath(Statement[pos + 1:].strip()) Statement = Statement[:pos + 1] + ' ' + Makefile if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [ Statement ] else: NewSectionDict[SortedArch] = [Statement] SpecialStatementList = [] # # Add INF_VERSION statement firstly # Statement = 'INF_VERSION = 0x00010017' SpecialStatementList.append(Statement) BaseName = ModuleObject.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = '%s = %s' % (DT.TAB_INF_DEFINES_BASE_NAME, BaseName) SpecialStatementList.append(Statement) Statement = '%s = %s' % (DT.TAB_INF_DEFINES_FILE_GUID, ModuleObject.GetGuid()) SpecialStatementList.append(Statement) Statement = '%s = %s' % (DT.TAB_INF_DEFINES_VERSION_STRING, ModuleObject.GetVersion()) SpecialStatementList.append(Statement) if ModuleObject.GetModuleType(): Statement = '%s = %s' % (DT.TAB_INF_DEFINES_MODULE_TYPE, ModuleObject.GetModuleType()) SpecialStatementList.append(Statement) if ModuleObject.GetPcdIsDriver(): Statement = '%s = %s' % (DT.TAB_INF_DEFINES_PCD_IS_DRIVER, ModuleObject.GetPcdIsDriver()) SpecialStatementList.append(Statement) if ModuleObject.GetUefiSpecificationVersion(): Statement = '%s = %s' % (DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION, \ ModuleObject.GetUefiSpecificationVersion()) SpecialStatementList.append(Statement) if ModuleObject.GetPiSpecificationVersion(): Statement = '%s = %s' % (DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION, ModuleObject.GetPiSpecificationVersion()) SpecialStatementList.append(Statement) for LibraryClass in ModuleObject.GetLibraryClassList(): if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES or \ LibraryClass.GetUsage() == DT.USAGE_ITEM_SOMETIMES_PRODUCES: Statement = '%s = %s' % (DT.TAB_INF_DEFINES_LIBRARY_CLASS, LibraryClass.GetLibraryClass()) if LibraryClass.GetSupModuleList(): Statement += '|' + DT.TAB_SPACE_SPLIT.join( l for l in LibraryClass.GetSupModuleList()) SpecialStatementList.append(Statement) for SpecItem in ModuleObject.GetSpecList(): Spec, Version = SpecItem Spec = ConvertSpec(Spec) Statement = '%s %s = %s' % (DT.TAB_INF_DEFINES_SPEC, Spec, Version) SpecialStatementList.append(Statement) ExternList = [] for Extern in ModuleObject.GetExternList(): ArchList = Extern.GetSupArchList() EntryPoint = Extern.GetEntryPoint() UnloadImage = Extern.GetUnloadImage() Constructor = Extern.GetConstructor() Destructor = Extern.GetDestructor() HelpStringList = Extern.GetHelpTextList() FFE = Extern.GetFeatureFlag() ExternList.append([ ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList ]) # # Add VALID_ARCHITECTURES information # ValidArchStatement = None if ModuleObject.SupArchList: ValidArchStatement = '# ' + '\n' ValidArchStatement += '# The following information is for reference only and not required by the build tools.\n' ValidArchStatement += '# ' + '\n' ValidArchStatement += '# VALID_ARCHITECTURES = %s' % (' '.join( ModuleObject.SupArchList)) + '\n' ValidArchStatement += '# ' + '\n' if DT.TAB_ARCH_COMMON not in NewSectionDict: NewSectionDict[DT.TAB_ARCH_COMMON] = [] NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[ DT.TAB_ARCH_COMMON] + SpecialStatementList GenMetaFileMisc.AddExternToDefineSec(NewSectionDict, DT.TAB_ARCH_COMMON, ExternList) if ValidArchStatement is not None: NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[ DT.TAB_ARCH_COMMON] + [ValidArchStatement] Content += GenSection('Defines', NewSectionDict) return Content
def InstallPackageContent(FromPath, ToPath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList, ReadOnly=False): if Dep: pass Package.FileList = [] if ToPath.startswith("\\") or ToPath.startswith("/"): ToPath = ToPath[1:] if not IsValidInstallPath(ToPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % ToPath) if FromPath.startswith("\\") or FromPath.startswith("/"): FromPath = FromPath[1:] if not IsValidInstallPath(FromPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FromPath) PackageFullPath = os.path.normpath(os.path.join(WorkspaceDir, ToPath)) for MiscFile in Package.GetMiscFileList(): for Item in MiscFile.GetFileList(): FileName = Item.GetURI() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FileName) FromFile = os.path.join(FromPath, FileName) Executable = Item.GetExecutable() ToFile = (os.path.join(PackageFullPath, ConvertPath(FileName))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable) if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) PackageIncludeArchList = [] for Item in Package.GetPackageIncludeFileList(): FileName = Item.GetFilePath() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FileName) FromFile = os.path.join(FromPath, FileName) ToFile = os.path.normpath( os.path.join(PackageFullPath, ConvertPath(FileName))) RetFile = ContentZipFile.UnpackFile(FromFile, ToFile) if RetFile == '': # # a non-exist path in Zipfile will return '', which means an include directory in our case # save the information for later DEC creation usage and also create the directory # PackageIncludeArchList.append( [Item.GetFilePath(), Item.GetSupArchList()]) CreateDirectory(ToFile) continue if ReadOnly: chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) else: chmod( ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) Package.SetIncludeArchList(PackageIncludeArchList) for Item in Package.GetStandardIncludeFileList(): FileName = Item.GetFilePath() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FileName) FromFile = os.path.join(FromPath, FileName) ToFile = os.path.normpath( os.path.join(PackageFullPath, ConvertPath(FileName))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) # # Update package # Package.SetPackagePath(Package.GetPackagePath().replace( FromPath, ToPath, 1)) Package.SetFullPath( os.path.normpath( os.path.join(PackageFullPath, ConvertPath(Package.GetName()) + '.dec'))) # # Install files in module # Module = None ModuleDict = Package.GetModuleDict() for ModuleGuid, ModuleVersion, ModuleName, ModulePath in ModuleDict: Module = ModuleDict[ModuleGuid, ModuleVersion, ModuleName, ModulePath] InstallModuleContent(FromPath, ToPath, ModulePath, Module, ContentZipFile, WorkspaceDir, ModuleList, Package, ReadOnly)
def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile, WorkspaceDir, ModuleList, Package=None, ReadOnly=False): if NewPath.startswith("\\") or NewPath.startswith("/"): NewPath = NewPath[1:] if not IsValidInstallPath(NewPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % NewPath) NewModuleFullPath = os.path.normpath( os.path.join(WorkspaceDir, NewPath, ConvertPath(ModulePath))) Module.SetFullPath( os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(Module.GetName()) + '.inf'))) Module.FileList = [] for MiscFile in Module.GetMiscFileList(): if not MiscFile: continue for Item in MiscFile.GetFileList(): File = Item.GetURI() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % File) FromFile = os.path.join(FromPath, ModulePath, File) Executable = Item.GetExecutable() ToFile = os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) for Item in Module.GetSourceFileList(): File = Item.GetSourceFile() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % File) FromFile = os.path.join(FromPath, ModulePath, File) ToFile = os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) for Item in Module.GetBinaryFileList(): FileNameList = Item.GetFileNameList() for FileName in FileNameList: File = FileName.GetFilename() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % File) FromFile = os.path.join(FromPath, ModulePath, File) ToFile = os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly, ModuleList)
def PackageToDec(Package): # # Init global information for the file # ContainerFile = Package.GetFullPath() Content = '' # # generate header comment section # Content += GenHeaderCommentSection(Package.GetAbstract(), \ Package.GetDescription(), \ Package.GetCopyright(), \ Package.GetLicense()) # # for each section, maintain a dict, sorted arch will be its key, #statement list will be its data # { 'Arch1 Arch2 Arch3': [statement1, statement2], # 'Arch1' : [statement1, statement3] # } # # # generate [Defines] section # NewSectionDict = {TAB_ARCH_COMMON: []} SpecialItemList = [] Statement = '%s = %s' % (TAB_DEC_DEFINES_DEC_SPECIFICATION, '0x00010017') SpecialItemList.append(Statement) BaseName = Package.GetBaseName() if BaseName.startswith('.') or BaseName.startswith('-'): BaseName = '_' + BaseName Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_NAME, BaseName) SpecialItemList.append(Statement) Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_VERSION, Package.GetVersion()) SpecialItemList.append(Statement) Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_GUID, Package.GetGuid()) SpecialItemList.append(Statement) for SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + SpecialItemList Content += GenSection('Defines', NewSectionDict) # # generate [Includes] section # NewSectionDict = {} IncludeArchList = Package.GetIncludeArchList() if IncludeArchList: for Path, ArchList in IncludeArchList: Statement = Path ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [ConvertPath(Statement)] else: NewSectionDict[SortedArch] = [ConvertPath(Statement)] Content += GenSection('Includes', NewSectionDict) Content = GenGuidProtocolPpi(Package, Content) # # generate [LibraryClasses] section # NewSectionDict = {} for LibraryClass in Package.GetLibraryClassList(): # # Generate generic comment # HelpTextList = LibraryClass.GetHelpTextList() HelpStr = _GetHelpStr(HelpTextList) if HelpStr: HelpStr = '@libraryclass ' + HelpStr CommentStr = GenGenericCommentF(HelpStr, 2) Statement = CommentStr Name = LibraryClass.GetLibraryClass() IncludeHeader = LibraryClass.GetIncludeHeader() Statement += Name + '|' + ConvertPath(IncludeHeader) # # generate tail comment # if LibraryClass.GetSupModuleList(): Statement += \ GenDecTailComment(LibraryClass.GetSupModuleList()) ArchList = LibraryClass.GetSupArchList() ArchList.sort() SortedArch = ' '.join(ArchList) if SortedArch in NewSectionDict: NewSectionDict[SortedArch] = \ NewSectionDict[SortedArch] + [Statement] else: NewSectionDict[SortedArch] = [Statement] Content += GenSection('LibraryClasses', NewSectionDict) Content = GenPcd(Package, Content) # # generate [UserExtensions] section # NewSectionDict = {} for UserExtension in Package.GetUserExtensionList(): Statement = UserExtension.GetStatement() if not Statement: continue SectionList = [] SectionName = 'UserExtensions' UserId = UserExtension.GetUserID() if UserId: if '.' in UserId: UserId = '"' + UserId + '"' SectionName += '.' + UserId if UserExtension.GetIdentifier(): SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"' if not UserExtension.GetSupArchList(): SectionList.append(SectionName) else: for Arch in UserExtension.GetSupArchList(): SectionList.append(SectionName + '.' + Arch) SectionName = ', '.join(SectionList) SectionName = ''.join(['[', SectionName, ']\n']) Content += '\n\n' + SectionName + Statement SaveFileOnChange(ContainerFile, Content, False) return ContainerFile