Check In tool source code based on Build tool project revision r1655.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8964 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4
2009-07-17 09:10:31 +00:00
parent 577e30cdb4
commit 30fdf1140b
532 changed files with 231447 additions and 32 deletions

View File

@@ -0,0 +1,66 @@
## @file
# Convert an SPD Package class object ot a DEC Package class object by filling
# some fields required by DEC file.
#
# Copyright (c) 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import os
from Common.MigrationUtilities import *
from LoadSpd import LoadSpd
from StoreDec import StoreDec
#The default DEC version number tool generates.
gDecVersion = "0x00010005"
## Add required version information.
#
# Add the default DEC specification version to Package class object.
#
# @param Package An input Package class object.
#
def AddPackageMiscVersion(Package):
PackageHeader = Package.Header
PackageHeader.DecSpecification = gDecVersion
## Add package include information.
#
# Adds the default "Include" folder to if that directory exists.
#
# @param Package An input Package class object.
#
def AddPackageInclude(Package):
PackageDir = os.path.dirname(Package.Header.FullPath)
DefaultIncludeDir = os.path.join(PackageDir, "Include")
if os.path.exists(DefaultIncludeDir):
Include = IncludeClass()
Include.FilePath = "Include"
Package.Includes.insert(0, Include)
## Convert SPD Package class object to DEC Package class object.
#
# Convert SPD Package class ojbect to DEC Package class object by filling in
# several information required by DEC file.
#
# @param Package An input Package class object.
#
def ConvertSpdPackageToDecPackage(Package):
AddPackageMiscVersion(Package)
AddPackageInclude(Package)
# This acts like the main() function for the script, unless it is 'import'ed
# into another script.
if __name__ == '__main__':
pass

View File

@@ -0,0 +1,273 @@
## @file
# Open an SPD file and load all its contents to a PackageClass object.
#
# Copyright (c) 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import os
from Common.XmlRoutines import *
from Common.MigrationUtilities import *
from CommonDataClass.PackageClass import *
## Load a list of Package Cloned Records.
#
# Read an input Package XML DOM object and return a list of Cloned Records
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel ClonedRecords A list of Cloned Records loaded from XmlSpd.
#
def LoadPackageClonedRecords(XmlSpd):
XmlTag = "PackageSurfaceArea/PackageDefinitions/ClonedFrom/Cloned"
return map(LoadClonedRecord, XmlList(XmlSpd, XmlTag))
## Load Package Header.
#
# Read an input Package XML DOM object and return Package Header class object
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
# @param SpdFileName The file path of SPD File.
#
# @retvel PackageHeader A new Package Header object loaded from XmlSpd.
#
def LoadPackageHeader(XmlSpd, SpdFileName):
PackageHeader = PackageHeaderClass()
XmlTag = "PackageSurfaceArea/SpdHeader"
SpdHeader = XmlNode(XmlSpd, XmlTag)
SetIdentification(PackageHeader, SpdHeader, "PackageName", SpdFileName)
SetCommonHeader(PackageHeader, SpdHeader)
XmlTag = "PackageSurfaceArea/PackageDefinitions/ReadOnly"
if XmlElement(XmlSpd, XmlTag).lower() == "true":
PackageHeader.ReadOnly = True
XmlTag = "PackageSurfaceArea/PackageDefinitions/RePackage"
if XmlElement(XmlSpd, XmlTag).lower() == "true":
PackageHeader.RePackage = True
PackageHeader.ClonedFrom = LoadPackageClonedRecords(XmlSpd)
return PackageHeader
## Load a list of Package Library Classes.
#
# Read an input Package XML DOM object and return a list of Library Classes
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel LibraryClasses A list of Library Classes loaded from XmlSpd.
#
def LoadPackageLibraryClasses(XmlSpd):
XmlTag = "PackageSurfaceArea/LibraryClassDeclarations/LibraryClass"
return map(LoadLibraryClass, XmlList(XmlSpd, XmlTag))
## Load a new Package Industry Std Header class object.
#
# Read an input XML IndustryStdHeader DOM object and return an object of
# Industry Std Header contained in the DOM object.
#
# @param XmlIndustryStdHeader A child XML DOM object in Package XML DOM.
#
# @retvel PackageIndustryStdHeader A new Industry Std Header object created by XmlIndustryStdHeader.
#
def LoadPackageIndustryStdHeader(XmlIndustryStdHeader):
PackageIndustryStdHeader = PackageIndustryStdHeaderClass()
XmlTag = "Name"
Name = XmlAttribute(XmlIndustryStdHeader, XmlTag)
PackageIndustryStdHeader.Name = Name
XmlTag = "IndustryStdHeader/IncludeHeader"
IncludeHeader = XmlElement(XmlIndustryStdHeader, XmlTag)
PackageIndustryStdHeader.IncludeHeader = IncludeHeader
SetCommon(PackageIndustryStdHeader, XmlIndustryStdHeader)
return PackageIndustryStdHeader
## Load a list of Package Industry Std Headers.
#
# Read an input Package XML DOM object and return a list of Industry Std Headers
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel IndustryStdHeaders A list of Industry Std Headers loaded from XmlSpd.
#
def LoadPackageIndustryStdHeaders(XmlSpd):
XmlTag = "PackageSurfaceArea/IndustryStdIncludes/IndustryStdHeader"
return map(LoadPackageIndustryStdHeader, XmlList(XmlSpd, XmlTag))
## Load a list of Package Module Files.
#
# Read an input Package XML DOM object and return a list of Module Files
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel ModuleFiles A list of Module Files loaded from XmlSpd.
#
def LoadPackageModuleFiles(XmlSpd):
XmlTag = "PackageSurfaceArea/MsaFiles/Filename"
return XmlElementList(XmlSpd, XmlTag)
## Load a new Package Include Pkg Header class object.
#
# Read an input XML IncludePkgHeader DOM object and return an object of Include
# Package Header contained in the DOM object.
#
# @param XmlPackageIncludeHeader A child XML DOM object in Package XML DOM.
#
# @retvel PackageIncludePkgHeader A new Include Pkg Header object created by
# XmlPackageIncludeHeader.
#
def LoadPackageIncludePkgHeader(XmlPackageIncludeHeader):
PackageIncludeHeader = PackageIncludePkgHeaderClass()
IncludeHeader = XmlElementData(XmlPackageIncludeHeader)
PackageIncludeHeader.IncludeHeader = IncludeHeader
XmlTag = "ModuleType"
ModuleTypes = XmlAttribute(XmlPackageIncludeHeader, XmlTag)
PackageIncludeHeader.ModuleType = ModuleTypes.split()
return PackageIncludeHeader
## Load a list of Package Include Pkg Headers.
#
# Read an input Package XML DOM object and return a list of Include Pkg Headers
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel IncludePkgHeaders A list of Include Pkg Headers loaded from XmlSpd.
#
def LoadPackageIncludePkgHeaders(XmlSpd):
XmlTag = "PackageSurfaceArea/PackageHeaders/IncludePkgHeader"
return map(LoadPackageIncludePkgHeader, XmlList(XmlSpd, XmlTag))
## Load a list of Package Guid Declarations.
#
# Read an input Package XML DOM object and return a list of Guid Declarations
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel GuidDeclarations A list of Guid Declarations loaded from XmlSpd.
#
def LoadPackageGuidDeclarations(XmlSpd):
XmlTag = "PackageSurfaceArea/GuidDeclarations/Entry"
return map(LoadGuidProtocolPpiCommon, XmlList(XmlSpd, XmlTag))
## Load a list of Package Protocol Declarations.
#
# Read an input Package XML DOM object and return a list of Protocol Declarations
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel ProtocolDeclarations A list of Protocol Declarations loaded from XmlSpd.
#
def LoadPackageProtocolDeclarations(XmlSpd):
XmlTag = "PackageSurfaceArea/ProtocolDeclarations/Entry"
return map(LoadGuidProtocolPpiCommon, XmlList(XmlSpd, XmlTag))
## Load a list of Package Ppi Declarations.
#
# Read an input Package XML DOM object and return a list of Ppi Declarations
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel PpiDeclarations A list of Ppi Declarations loaded from XmlSpd.
#
def LoadPackagePpiDeclarations(XmlSpd):
XmlTag = "PackageSurfaceArea/PpiDeclarations/Entry"
return map(LoadGuidProtocolPpiCommon, XmlList(XmlSpd, XmlTag))
## Load a list of Package Pcd Declarations.
#
# Read an input Package XML DOM object and return a list of Pcd Declarations
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel PcdDeclarations A list of Pcd Declarations loaded from XmlSpd.
#
def LoadPackagePcdDeclarations(XmlSpd):
XmlTag = "PackageSurfaceArea/PcdDeclarations/PcdEntry"
return map(LoadPcd, XmlList(XmlSpd, XmlTag))
## Load a list of Package User Extensions.
#
# Read an input Package XML DOM object and return a list of User Extensions
# contained in the DOM object.
#
# @param XmlSpd An XML DOM object read from SPD file.
#
# @retvel UserExtensions A list of User Extensions loaded from XmlSpd.
#
def LoadPackageUserExtensions(XmlSpd):
XmlTag = "PackageSurfaceArea/UserExtensions"
return map(LoadUserExtensions, XmlList(XmlSpd, XmlTag))
## Load a new Package class object.
#
# Read an input SPD File and return a new Package class Object.
#
# @param SpdFileName An XML DOM object read from SPD file.
#
# @retvel Package A new Module class object loaded from SPD File.
#
def LoadSpd(SpdFileName):
XmlSpd = XmlParseFile(SpdFileName)
EdkLogger.verbose("Xml Object loaded for file %s" % SpdFileName)
Package = PackageClass()
Package.Header = LoadPackageHeader(XmlSpd, SpdFileName)
Package.LibraryClassDeclarations = LoadPackageLibraryClasses(XmlSpd)
Package.IndustryStdHeaders = LoadPackageIndustryStdHeaders(XmlSpd)
Package.ModuleFiles = LoadPackageModuleFiles(XmlSpd)
Package.PackageIncludePkgHeaders = LoadPackageIncludePkgHeaders(XmlSpd)
Package.GuidDeclarations = LoadPackageGuidDeclarations(XmlSpd)
Package.ProtocolDeclarations = LoadPackageProtocolDeclarations(XmlSpd)
Package.PpiDeclarations = LoadPackagePpiDeclarations(XmlSpd)
Package.PcdDeclarations = LoadPackagePcdDeclarations(XmlSpd)
Package.UserExtensions = LoadPackageUserExtensions(XmlSpd)
return Package
# This acts like the main() function for the script, unless it is 'import'ed
# into another script.
if __name__ == '__main__':
pass

View File

@@ -0,0 +1,46 @@
## @file
# Convert an XML-based SPD file to a text-based DEC file.
#
# Copyright (c) 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import sys
from Common.MigrationUtilities import *
from LoadSpd import LoadSpd
from StoreDec import StoreDec
from ConvertPackage import ConvertSpdPackageToDecPackage
## Entrance method
#
# This method mainly dispatch specific methods per the command line options.
# If no error found, return zero value so the caller of this tool can know
# if it's executed successfully or not.
#
# @retval 0 Tool was successful.
# @retval 1 Tool failed.
#
def Main():
try:
Options, InputFile = MigrationOptionParser("SPD", "DEC", "%prog")
Package = LoadSpd(InputFile)
ConvertSpdPackageToDecPackage(Package)
StoreDec(Options.OutputFile, Package)
return 0
except Exception, e:
print e
return 1
if __name__ == '__main__':
sys.exit(Main())

View File

@@ -0,0 +1,247 @@
## @file
# Store a Package class object to a DEC file.
#
# Copyright (c) 2007, Intel Corporation
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import os
from Common.MigrationUtilities import *
from LoadSpd import LoadSpd
from CommonDataClass.PackageClass import *
## Store Defines section.
#
# Write [Defines] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Defines section.
# @param Package An input Package class object.
#
def StorePackageDefinesSection(DecFile, Package):
DefinesTupleList = []
DefinesTupleList.append(("DEC_VERSION", Package.Header.DecSpecification))
DefinesTupleList.append(("PACKAGE_NAME", Package.Header.Name))
DefinesTupleList.append(("PACKAGE_GUID", Package.Header.Guid))
StoreDefinesSection(DecFile, DefinesTupleList)
## Return a Package Include Class Item.
#
# Read the input Include class object and return one Include Class Item.
#
# @param Include An input Include class object.
#
# @retval IncludeClassItem A Package Include Class Item.
#
def GetPackageIncludeClassItem(Include):
return Include.FilePath
## Store Includes section.
#
# Write [Includes] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Includes section.
# @param Package An input Package class object.
#
def StorePackageIncludesSection(DecFile, Package):
Includes = Package.Includes
Section = GetSection("Includes", GetPackageIncludeClassItem, Includes)
StoreTextFile(DecFile, Section)
## Return a Package Library Class Item.
#
# Read the input LibraryClass class object and return one Library Class Item.
#
# @param LibraryClass An input LibraryClass class object.
#
# @retval LibraryClassItem A Package Library Class Item.
#
def GetPackageLibraryClassItem(LibraryClass):
return "|".join((LibraryClass.LibraryClass, LibraryClass.IncludeHeader))
## Store Library Classes section.
#
# Write [LibraryClasses] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Library Classes
# section.
# @param Package An input Package class object.
#
def StorePackageLibraryClassesSection(DecFile, Package):
LibraryClasses = Package.LibraryClassDeclarations
Section = GetSection("LibraryClasses", GetPackageLibraryClassItem, LibraryClasses)
StoreTextFile(DecFile, Section)
## Return a Package Guid Declaration Item.
#
# Read the input Guid class object and return one line of Guid Declaration Item.
#
# @param Guid An input Guid class object.
#
# @retval GuidDeclarationItem A Package Guid Declaration Item.
#
def GetPackageGuidDeclarationItem(Guid):
GuidCName = Guid.CName
GuidValue = Guid.Guid.replace("-", "")
GuidValueList = [GuidValue[0:8]]
GuidValueList += [GuidValue[i : i + 4] for i in range(8, 16, 4)]
GuidValueList += [GuidValue[i : i + 2] for i in range(16, 32, 2)]
GuidCFormat = "{0x%s" + ", 0x%s" * 2 + ", {0x%s" + ", 0x%s" * 7 + "}}"
GuidCValue = GuidCFormat % tuple(GuidValueList)
return "%-30s = %s" % (GuidCName, GuidCValue)
## Store Protocols section.
#
# Write [Protocols] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Protocols section.
# @param Package An input Package class object.
#
def StorePackageProtocolsSection(DecFile, Package):
Protocols = Package.ProtocolDeclarations
Section = GetSection("Protocols", GetPackageGuidDeclarationItem, Protocols)
StoreTextFile(DecFile, Section)
## Store Ppis section.
#
# Write [Ppis] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Ppis section.
# @param Package An input Package class object.
#
def StorePackagePpisSection(DecFile, Package):
Ppis = Package.PpiDeclarations
Section = GetSection("Ppis", GetPackageGuidDeclarationItem, Ppis)
StoreTextFile(DecFile, Section)
## Store Guids section.
#
# Write [Guids] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Guids section.
# @param Package An input Package class object.
#
def StorePackageGuidsSection(DecFile, Package):
Guids = Package.GuidDeclarations
Section = GetSection("Guids", GetPackageGuidDeclarationItem, Guids)
StoreTextFile(DecFile, Section)
## Return a Package Pcd Item.
#
# Read the input Pcd class object and return one line of Pcd Item.
#
# @param Pcd An input Pcd class object.
#
# @retval PcdItem A Package Pcd Item.
#
def GetPackagePcdItem(Pcd):
PcdPair = "%s.%s" % (Pcd.TokenSpaceGuidCName, Pcd.CName)
DatumType = Pcd.DatumType
DefaultValue = Pcd.DefaultValue
Token = Pcd.Token
PcdList = [PcdPair, DefaultValue, DatumType, Token]
return "|".join(PcdList)
## DEC Pcd Section Name dictionary indexed by PCD Item Type.
mDecPcdSectionNameDict = {
"FEATURE_FLAG" : "PcdsFeatureFlag",
"FIXED_AT_BUILD" : "PcdsFixedAtBuild",
"PATCHABLE_IN_MODULE" : "PcdsPatchableInModule",
"DYNAMIC" : "PcdsDynamic",
"DYNAMIC_EX" : "PcdsDynamicEx"
}
## Store Pcds section.
#
# Write [Pcds*] section to the DecFile based on Package class object.
# Different CPU architectures are specified in the subsection if possible.
#
# @param DecFile The output DEC file to store the Pcds section.
# @param Package An input Package class object.
#
def StorePackagePcdsSection(DecFile, Package):
PcdsDict = {}
for Pcd in Package.PcdDeclarations:
for PcdItemType in Pcd.ValidUsage:
PcdSectionName = mDecPcdSectionNameDict.get(PcdItemType)
if PcdSectionName:
PcdsDict.setdefault(PcdSectionName, []).append(Pcd)
else:
EdkLogger.info("Unknown Pcd Item Type: %s" % PcdItemType)
Section = ""
for PcdSectionName in PcdsDict:
Pcds = PcdsDict[PcdSectionName]
Section += GetSection(PcdSectionName, GetPackagePcdItem, Pcds)
StoreTextFile(DecFile, Section)
## Store User Extensions section.
#
# Write [UserExtensions] section to the DecFile based on Package class object.
#
# @param DecFile The output DEC file to store the User Extensions section.
# @param Package An input Package class object.
#
def StorePackageUserExtensionsSection(DecFile, Package):
Section = "".join(map(GetUserExtensions, Package.UserExtensions))
StoreTextFile(DecFile, Section)
## Store a Package class object to a new DEC file.
#
# Read an input Package class object and ave the contents to a new DEC file.
#
# @param DecFileName The output DEC file.
# @param Package An input Package class object.
#
def StoreDec(DecFileName, Package):
DecFile = open(DecFileName, "w+")
EdkLogger.info("Save file to %s" % DecFileName)
StoreHeader(DecFile, Package.Header)
StorePackageDefinesSection(DecFile, Package)
StorePackageIncludesSection(DecFile, Package)
StorePackageLibraryClassesSection(DecFile, Package)
StorePackageProtocolsSection(DecFile, Package)
StorePackagePpisSection(DecFile, Package)
StorePackageGuidsSection(DecFile, Package)
StorePackagePcdsSection(DecFile, Package)
StorePackageUserExtensionsSection(DecFile, Package)
DecFile.close()
# This acts like the main() function for the script, unless it is 'import'ed
# into another script.
if __name__ == '__main__':
pass