Revision: 15896
http://sourceforge.net/p/edk2/code/15896
Author: hchen30
Date: 2014-08-26 05:58:02 +0000 (Tue, 26 Aug 2014)
Log Message:
-----------
This patch is going to:
1. Add a recovery mode for UPT failure
2. Add UNI file support
3. Add binary file header support
4. Add support for PCD error message
5. Add support for replace
6. Format generated INF/DEC files
7. Update dependency check
8. Other minor fixes
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <[email protected]>
Reviewed-by: Gao, Liming <[email protected]>
Modified Paths:
--------------
trunk/edk2/BaseTools/Source/Python/UPT/Core/DependencyRules.py
trunk/edk2/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
trunk/edk2/BaseTools/Source/Python/UPT/Core/IpiDb.py
trunk/edk2/BaseTools/Source/Python/UPT/Core/PackageFile.py
trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenMetaFileMisc.py
trunk/edk2/BaseTools/Source/Python/UPT/InstallPkg.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/CommentGenerating.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/CommentParsing.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/DataType.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/ExpressionValidate.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/GlobalData.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/Misc.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/ParserValidate.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/Parsing.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/String.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/Xml/XmlRoutines.py
trunk/edk2/BaseTools/Source/Python/UPT/Logger/StringTable.py
trunk/edk2/BaseTools/Source/Python/UPT/MkPkg.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/POM/CommonObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/POM/ModuleObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/POM/PackageObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/Parser/InfBinaryObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/Parser/InfBuildOptionObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/Parser/InfDefineObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/Parser/InfGuidObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/Parser/InfLibraryClassesObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Object/Parser/InfPcdObject.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/DecParser.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfLibrarySectionParser.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfParser.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfPcdSectionParser.py
trunk/edk2/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py
trunk/edk2/BaseTools/Source/Python/UPT/PomAdapter/DecPomAlignment.py
trunk/edk2/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignment.py
trunk/edk2/BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py
trunk/edk2/BaseTools/Source/Python/UPT/RmPkg.py
trunk/edk2/BaseTools/Source/Python/UPT/UPT.py
trunk/edk2/BaseTools/Source/Python/UPT/UnitTest/CommentGeneratingUnitTest.py
trunk/edk2/BaseTools/Source/Python/UPT/UnitTest/CommentParsingUnitTest.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/CommonXml.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/IniToXml.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/ModuleSurfaceAreaXml.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/PackageSurfaceAreaXml.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/PcdXml.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/XmlParser.py
trunk/edk2/BaseTools/Source/Python/UPT/Xml/XmlParserMisc.py
Added Paths:
-----------
trunk/edk2/BaseTools/Source/Python/UPT/Core/FileHook.py
trunk/edk2/BaseTools/Source/Python/UPT/InventoryWs.py
trunk/edk2/BaseTools/Source/Python/UPT/Library/UniClassObject.py
trunk/edk2/BaseTools/Source/Python/UPT/ReplacePkg.py
Modified: trunk/edk2/BaseTools/Source/Python/UPT/Core/DependencyRules.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Core/DependencyRules.py
2014-08-26 05:30:49 UTC (rev 15895)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Core/DependencyRules.py
2014-08-26 05:58:02 UTC (rev 15896)
@@ -1,7 +1,7 @@
## @file
# This file is for installed package information database operations
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -20,14 +20,14 @@
##
# Import Modules
#
-from os import getenv
-from os import environ
from os.path import dirname
import Logger.Log as Logger
from Logger import StringTable as ST
from Library.Parsing import GetWorkspacePackage
from Library.Parsing import GetWorkspaceModule
+from Library.Misc import GetRelativePath
+from Library import GlobalData
from PomAdapter.InfPomAlignment import InfPomAlignment
from Logger.ToolError import FatalError
from Logger.ToolError import EDK1_INF_ERROR
@@ -36,12 +36,10 @@
DEPEX_CHECK_PACKAGE_NOT_FOUND, DEPEX_CHECK_DP_NOT_FOUND) = (0, 1, 2, 3)
-## IpiDb
+## DependencyRules
#
-# This class represents the installed package information database
-# Add/Remove/Get installed distribution package information here.
+# This class represents the dependency rule check mechanism
#
-#
# @param object: Inherited from object class
#
class DependencyRules(object):
@@ -49,15 +47,17 @@
self.IpiDb = Datab
self.WsPkgList = GetWorkspacePackage()
self.WsModuleList = GetWorkspaceModule()
-
- ## Check whether a module exists in current workspace.
+ self.PkgsToBeDepend = []
+
+ ## Check whether a module exists by checking the Guid+Version+Name+Path
combination
#
# @param Guid: Guid of a module
# @param Version: Version of a module
+ # @param Name: Name of a module
+ # @param Path: Path of a module
+ # @return: True if module existed, else False
#
- def CheckModuleExists(self, Guid, Version, Name, Path,
ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ def CheckModuleExists(self, Guid, Version, Name, Path):
Logger.Verbose(ST.MSG_CHECK_MODULE_EXIST)
ModuleList = self.IpiDb.GetModInPackage(Guid, Version, Name, Path)
ModuleList.extend(self.IpiDb.GetStandaloneModule(Guid, Version, Name,
Path))
@@ -67,15 +67,14 @@
else:
return False
- ## Check whether a module depex satisfied by current workspace or dist.
+ ## Check whether a module depex satisfied.
#
# @param ModuleObj: A module object
- # @param DpObj: A depex object
+ # @param DpObj: A distribution object
+ # @return: True if module depex satisfied
+ # False else
#
- def CheckModuleDepexSatisfied(self, ModuleObj, DpObj=None, \
- ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ def CheckModuleDepexSatisfied(self, ModuleObj, DpObj=None):
Logger.Verbose(ST.MSG_CHECK_MODULE_DEPEX_START)
Result = True
Dep = None
@@ -114,97 +113,122 @@
Dep.GetVersion()))
return Result
- ## Check whether a package exists in current workspace.
+ ## Check whether a package exists in a package list specified by
PkgsToBeDepend.
#
# @param Guid: Guid of a package
# @param Version: Version of a package
+ # @return: True if package exist
+ # False else
#
def CheckPackageExists(self, Guid, Version):
Logger.Verbose(ST.MSG_CHECK_PACKAGE_START)
- for (PkgName, PkgGuid, PkgVer, PkgPath) in self.WsPkgList:
- if PkgName or PkgPath:
- pass
+ Found = False
+ for (PkgGuid, PkgVer) in self.PkgsToBeDepend:
if (PkgGuid == Guid):
#
# if version is not empty and not equal, then not match
#
if Version and (PkgVer != Version):
- return False
+ Found = False
+ break
else:
- return True
+ Found = True
+ break
else:
- return False
-
+ Found = False
+
Logger.Verbose(ST.MSG_CHECK_PACKAGE_FINISH)
+ return Found
- ## Check whether a package depex satisfied by current workspace.
+ ## Check whether a package depex satisfied.
#
# @param PkgObj: A package object
- # @param DpObj: A package depex object
+ # @param DpObj: A distribution object
+ # @return: True if package depex satisified
+ # False else
#
- def CheckPackageDepexSatisfied(self, PkgObj, DpObj=None, \
- ReturnCode=DEPEX_CHECK_SUCCESS):
-
+ def CheckPackageDepexSatisfied(self, PkgObj, DpObj=None):
ModuleDict = PkgObj.GetModuleDict()
for ModKey in ModuleDict.keys():
ModObj = ModuleDict[ModKey]
- if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):
+ if self.CheckModuleDepexSatisfied(ModObj, DpObj):
continue
else:
return False
return True
- ## Check whether a DP exists in current workspace.
+ ## Check whether a DP exists.
#
- # @param Guid: Guid of a module
- # @param Version: Version of a module
- #
- def CheckDpExists(self, Guid, Version, ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ # @param Guid: Guid of a Distribution
+ # @param Version: Version of a Distribution
+ # @return: True if Distribution exist
+ # False else
+ def CheckDpExists(self, Guid, Version):
Logger.Verbose(ST.MSG_CHECK_DP_START)
DpList = self.IpiDb.GetDp(Guid, Version)
if len(DpList) > 0:
- return True
+ Found = True
else:
- return False
-
- Logger.Verbose(ST.MSG_CHECK_DP_FINISH)
-
+ Found = False
+
+ Logger.Verbose(ST.MSG_CHECK_DP_FINISH)
+ return Found
+
+ ## Check whether a DP depex satisfied by current workspace for Install
+ #
+ # @param DpObj: A distribution object
+ # @return: True if distribution depex satisfied
+ # False else
+ #
+ def CheckInstallDpDepexSatisfied(self, DpObj):
+ self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in
self.WsPkgList]
+ return self.CheckDpDepexSatisfied(DpObj)
+
+ ## Check whether a DP depex satisfied by current workspace
+ # (excluding the original distribution's packages to be replaced) for
Replace
+ #
+ # @param DpObj: A distribution object
+ # @param OrigDpGuid: The original distribution's Guid
+ # @param OrigDpVersion: The original distribution's Version
+ #
+ def ReplaceCheckNewDpDepex(self, DpObj, OrigDpGuid, OrigDpVersion):
+ self.PkgsToBeDepend = [(PkgInfo[1], PkgInfo[2]) for PkgInfo in
self.WsPkgList]
+ OrigDpPackageList = self.IpiDb.GetPackageListFromDp(OrigDpGuid,
OrigDpVersion)
+ for OrigPkgInfo in OrigDpPackageList:
+ Guid, Version = OrigPkgInfo[0], OrigPkgInfo[1]
+ if (Guid, Version) in self.PkgsToBeDepend:
+ self.PkgsToBeDepend.remove((Guid, Version))
+ return self.CheckDpDepexSatisfied(DpObj)
+
## Check whether a DP depex satisfied by current workspace.
#
- # @param DpObj: Depex object
- # @param ReturnCode: ReturnCode
+ # @param DpObj: A distribution object
#
- def CheckDpDepexSatisfied(self, DpObj, ReturnCode=DEPEX_CHECK_SUCCESS):
-
+ def CheckDpDepexSatisfied(self, DpObj):
for PkgKey in DpObj.PackageSurfaceArea.keys():
PkgObj = DpObj.PackageSurfaceArea[PkgKey]
- if self.CheckPackageDepexSatisfied(PkgObj, DpObj, ReturnCode):
+ if self.CheckPackageDepexSatisfied(PkgObj, DpObj):
continue
else:
return False
for ModKey in DpObj.ModuleSurfaceArea.keys():
ModObj = DpObj.ModuleSurfaceArea[ModKey]
- if self.CheckModuleDepexSatisfied(ModObj, DpObj, ReturnCode):
+ if self.CheckModuleDepexSatisfied(ModObj, DpObj):
continue
else:
return False
return True
- ## Check whether a DP depex satisfied by current workspace. Return False
- # if Can not remove (there is dependency), True else
+ ## Check whether a DP could be removed from current workspace.
#
# @param DpGuid: File's guid
# @param DpVersion: File's version
- # @param ReturnCode: ReturnCode
- #
- def CheckDpDepexForRemove(self, DpGuid, DpVersion, \
- ReturnCode=DEPEX_CHECK_SUCCESS):
- if ReturnCode:
- pass
+ # @retval Removable: True if distribution could be removed, False Else
+ # @retval DependModuleList: the list of modules that make distribution can
not be removed
+ #
+ def CheckDpDepexForRemove(self, DpGuid, DpVersion):
Removable = True
DependModuleList = []
WsModuleList = self.WsModuleList
@@ -223,15 +247,14 @@
# List of item (PkgGuid, PkgVersion, InstallPath)
DpPackageList = self.IpiDb.GetPackageListFromDp(DpGuid, DpVersion)
DpPackagePathList = []
- WorkSP = environ["WORKSPACE"]
+ WorkSP = GlobalData.gWORKSPACE
for (PkgName, PkgGuid, PkgVersion, DecFile) in self.WsPkgList:
if PkgName:
pass
DecPath = dirname(DecFile)
if DecPath.find(WorkSP) > -1:
- InstallPath = DecPath[DecPath.find(WorkSP) + len(WorkSP) + 1:]
- DecFileRelaPath = \
- DecFile[DecFile.find(WorkSP) + len(WorkSP) + 1:]
+ InstallPath = GetRelativePath(DecPath,WorkSP)
+ DecFileRelaPath = GetRelativePath(DecFile,WorkSP)
else:
InstallPath = DecPath
DecFileRelaPath = DecFile
@@ -251,43 +274,135 @@
# check modules to see if has dependency on package of current DP
#
for Module in WsModuleList:
- if (CheckModuleDependFromInf(Module, DpPackagePathList)):
+ if (not VerifyRemoveModuleDep(Module, DpPackagePathList)):
Removable = False
DependModuleList.append(Module)
return (Removable, DependModuleList)
+ ## Check whether a DP could be replaced by a distribution containing
NewDpPkgList
+ # from current workspace.
+ #
+ # @param OrigDpGuid: original Dp's Guid
+ # @param OrigDpVersion: original Dp's version
+ # @param NewDpPkgList: a list of package information (Guid, Version) in
new Dp
+ # @retval Replaceable: True if distribution could be replaced, False Else
+ # @retval DependModuleList: the list of modules that make distribution can
not be replaced
+ #
+ def CheckDpDepexForReplace(self, OrigDpGuid, OrigDpVersion, NewDpPkgList):
+ Replaceable = True
+ DependModuleList = []
+ WsModuleList = self.WsModuleList
+ #
+ # remove modules that included in current DP
+ # List of item (FilePath)
+ DpModuleList = self.IpiDb.GetDpModuleList(OrigDpGuid, OrigDpVersion)
+ for Module in DpModuleList:
+ if Module in WsModuleList:
+ WsModuleList.remove(Module)
+ else:
+ Logger.Warn("UPT\n",
+ ST.ERR_MODULE_NOT_INSTALLED % Module)
+
+ OtherPkgList = NewDpPkgList
+ #
+ # get packages in current Dp and find the install path
+ # List of item (PkgGuid, PkgVersion, InstallPath)
+ DpPackageList = self.IpiDb.GetPackageListFromDp(OrigDpGuid,
OrigDpVersion)
+ DpPackagePathList = []
+ WorkSP = GlobalData.gWORKSPACE
+ for (PkgName, PkgGuid, PkgVersion, DecFile) in self.WsPkgList:
+ if PkgName:
+ pass
+ DecPath = dirname(DecFile)
+ if DecPath.find(WorkSP) > -1:
+ InstallPath = GetRelativePath(DecPath,WorkSP)
+ DecFileRelaPath = GetRelativePath(DecFile,WorkSP)
+ else:
+ InstallPath = DecPath
+ DecFileRelaPath = DecFile
+
+ if (PkgGuid, PkgVersion, InstallPath) in DpPackageList:
+ DpPackagePathList.append(DecFileRelaPath)
+ DpPackageList.remove((PkgGuid, PkgVersion, InstallPath))
+ else:
+ OtherPkgList.append((PkgGuid, PkgVersion))
+
+ #
+ # the left items in DpPackageList are the packages that installed but
not found anymore
+ #
+ for (PkgGuid, PkgVersion, InstallPath) in DpPackageList:
+ Logger.Warn("UPT",
+ ST.WARN_INSTALLED_PACKAGE_NOT_FOUND%(PkgGuid,
PkgVersion, InstallPath))
+
+ #
+ # check modules to see if it can be satisfied by package not belong to
removed DP
+ #
+ for Module in WsModuleList:
+ if (not VerifyReplaceModuleDep(Module, DpPackagePathList,
OtherPkgList)):
+ Replaceable = False
+ DependModuleList.append(Module)
+ return (Replaceable, DependModuleList)
+
+
## check whether module depends on packages in DpPackagePathList, return True
# if found, False else
#
# @param Path: a module path
# @param DpPackagePathList: a list of Package Paths
+# @retval: False: module depends on package in DpPackagePathList
+# True: module doesn't depend on package in DpPackagePathList
#
-def CheckModuleDependFromInf(Path, DpPackagePathList):
+def VerifyRemoveModuleDep(Path, DpPackagePathList):
+ WorkSP = GlobalData.gWORKSPACE
- #
- # use InfParser to parse inf, then get the information for now,
- # later on, may consider only parse to get the package dependency info
- # (Need to take care how to deal wit Macros)
- #
- WorkSP = getenv('WORKSPACE')
-
try:
PomAli = InfPomAlignment(Path, WorkSP, Skip=True)
for Item in PomAli.GetPackageDependencyList():
if Item.GetPackageFilePath() in DpPackagePathList:
Logger.Info(ST.MSG_MODULE_DEPEND_ON % (Path,
Item.GetPackageFilePath()))
- return True
+ return False
else:
- return False
+ return True
except FatalError, ErrCode:
if ErrCode.message == EDK1_INF_ERROR:
Logger.Warn("UPT",
ST.WRN_EDK1_INF_FOUND%Path)
- return False
+ return True
else:
- return False
-
+ return True
+## check whether module depends on packages in DpPackagePathList and can not
be satisfied by OtherPkgList
+#
+# @param Path: a module path
+# @param DpPackagePathList: a list of Package Paths
+# @param OtherPkgList: a list of Package Information (Guid, Version)
+# @retval: False: module depends on package in DpPackagePathList and can not
be satisfied by OtherPkgList
+# True: either module doesn't depend on DpPackagePathList or module
depends on DpPackagePathList
+# but can be satisfied by OtherPkgList
+#
+def VerifyReplaceModuleDep(Path, DpPackagePathList, OtherPkgList):
+ WorkSP = GlobalData.gWORKSPACE
+
+ try:
+ PomAli = InfPomAlignment(Path, WorkSP, Skip=True)
+ for Item in PomAli.GetPackageDependencyList():
+ if Item.GetPackageFilePath() in DpPackagePathList:
+ Guid, Version = Item.GetGuid(), Item.GetVersion()
+ if (Guid, Version) not in OtherPkgList:
+ Logger.Info(ST.MSG_MODULE_DEPEND_ON % (Path,
Item.GetPackageFilePath()))
+ return False
+ else:
+ return True
+ except FatalError, ErrCode:
+ if ErrCode.message == EDK1_INF_ERROR:
+ Logger.Warn("UPT",
+ ST.WRN_EDK1_INF_FOUND%Path)
+ return True
+ else:
+ return True
+
+
+
Modified:
trunk/edk2/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
2014-08-26 05:30:49 UTC (rev 15895)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Core/DistributionPackageClass.py
2014-08-26 05:58:02 UTC (rev 15896)
@@ -1,7 +1,7 @@
## @file
# This file is used to define a class object to describe a distribution package
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -195,6 +195,7 @@
#
def GetDistributionFileList(self):
MetaDataFileList = []
+ SkipModulesUniList = []
for Guid, Version, Path in self.PackageSurfaceArea:
Package = self.PackageSurfaceArea[Guid, Version, Path]
@@ -206,7 +207,15 @@
SearchPath =
os.path.normpath(os.path.join(os.path.dirname(FullPath), IncludePath))
AddPath = os.path.normpath(os.path.join(PackagePath,
IncludePath))
self.FileList += GetNonMetaDataFiles(SearchPath, ['CVS',
'.svn'], False, AddPath)
-
+ #
+ # Add the miscellaneous files on DEC file
+ #
+ for MiscFileObj in Package.GetMiscFileList():
+ for FileObj in MiscFileObj.GetFileList():
+ MiscFileFullPath =
os.path.normpath(os.path.join(os.path.dirname(FullPath), FileObj.GetURI()))
+ if MiscFileFullPath not in self.FileList:
+ self.FileList.append(MiscFileFullPath)
+
Module = None
ModuleDict = Package.GetModuleDict()
for Guid, Version, Name, Path in ModuleDict:
@@ -215,15 +224,43 @@
FullPath = Module.GetFullPath()
PkgRelPath = os.path.normpath(os.path.join(PackagePath,
ModulePath))
MetaDataFileList.append(Path)
- self.FileList +=
GetNonMetaDataFiles(os.path.dirname(FullPath), ['CVS', '.svn'], False,
PkgRelPath)
-
+ SkipList = ['CVS', '.svn']
+ NonMetaDataFileList = []
+ if Module.UniFileClassObject:
+ for UniFile in Module.UniFileClassObject.IncFileList:
+ OriPath = os.path.normpath(os.path.dirname(FullPath))
+ UniFilePath =
os.path.normpath(os.path.join(PkgRelPath, UniFile.Path[len(OriPath) + 1:]))
+ if UniFilePath not in SkipModulesUniList:
+ SkipModulesUniList.append(UniFilePath)
+ for IncludeFile in
Module.UniFileClassObject.IncludePathList:
+ if IncludeFile not in SkipModulesUniList:
+ SkipModulesUniList.append(IncludeFile)
+ NonMetaDataFileList =
GetNonMetaDataFiles(os.path.dirname(FullPath), SkipList, False, PkgRelPath)
+ for NonMetaDataFile in NonMetaDataFileList:
+ if NonMetaDataFile not in self.FileList:
+ self.FileList.append(NonMetaDataFile)
for Guid, Version, Name, Path in self.ModuleSurfaceArea:
Module = self.ModuleSurfaceArea[Guid, Version, Name, Path]
ModulePath = Module.GetModulePath()
FullPath = Module.GetFullPath()
MetaDataFileList.append(Path)
- self.FileList += GetNonMetaDataFiles(os.path.dirname(FullPath),
['CVS', '.svn'], False, ModulePath)
-
+ SkipList = ['CVS', '.svn']
+ NonMetaDataFileList = []
+ if Module.UniFileClassObject:
+ for UniFile in Module.UniFileClassObject.IncFileList:
+ OriPath = os.path.normpath(os.path.dirname(FullPath))
+ UniFilePath = os.path.normpath(os.path.join(ModulePath,
UniFile.Path[len(OriPath) + 1:]))
+ if UniFilePath not in SkipModulesUniList:
+ SkipModulesUniList.append(UniFilePath)
+ NonMetaDataFileList =
GetNonMetaDataFiles(os.path.dirname(FullPath), SkipList, False, ModulePath)
+ for NonMetaDataFile in NonMetaDataFileList:
+ if NonMetaDataFile not in self.FileList:
+ self.FileList.append(NonMetaDataFile)
+
+ for SkipModuleUni in SkipModulesUniList:
+ if SkipModuleUni in self.FileList:
+ self.FileList.remove(SkipModuleUni)
+
return self.FileList, MetaDataFileList
Added: trunk/edk2/BaseTools/Source/Python/UPT/Core/FileHook.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Core/FileHook.py
(rev 0)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Core/FileHook.py 2014-08-26
05:58:02 UTC (rev 15896)
@@ -0,0 +1,199 @@
+## @file
+# This file hooks file and directory creation and removal
+#
+# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+#
+# 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.
+#
+
+'''
+File hook
+'''
+
+import os
+import stat
+import time
+import zipfile
+from time import sleep
+from Library import GlobalData
+
+__built_in_remove__ = os.remove
+__built_in_mkdir__ = os.mkdir
+__built_in_rmdir__ = os.rmdir
+__built_in_chmod__ = os.chmod
+__built_in_open__ = open
+
+_RMFILE = 0
+_MKFILE = 1
+_RMDIR = 2
+_MKDIR = 3
+_CHMOD = 4
+
+gBACKUPFILE = 'file.backup'
+gEXCEPTION_LIST = ['Conf'+os.sep+'DistributionPackageDatabase.db', '.tmp',
gBACKUPFILE]
+
+class _PathInfo:
+ def __init__(self, action, path, mode=-1):
+ self.action = action
+ self.path = path
+ self.mode = mode
+
+class RecoverMgr:
+ def __init__(self, workspace):
+ self.rlist = []
+ self.zip = None
+ self.workspace = os.path.normpath(workspace)
+ self.backupfile = gBACKUPFILE
+ self.zipfile = os.path.join(self.workspace, gBACKUPFILE)
+
+ def _createzip(self):
+ if self.zip:
+ return
+ self.zip = zipfile.ZipFile(self.zipfile, 'w', zipfile.ZIP_DEFLATED)
+
+ def _save(self, tmp, path):
+ if not self._tryhook(path):
+ return
+ self.rlist.append(_PathInfo(tmp, path))
+
+ def bkrmfile(self, path):
+ arc = self._tryhook(path)
+ if arc and os.path.isfile(path):
+ self._createzip()
+ self.zip.write(path, arc.encode('utf_8'))
+ sta = os.stat(path)
+ oldmode = stat.S_IMODE(sta.st_mode)
+ self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
+ self.rlist.append(_PathInfo(_RMFILE, path))
+ __built_in_remove__(path)
+
+ def bkmkfile(self, path, mode, bufsize):
+ if not os.path.exists(path):
+ self._save(_MKFILE, path)
+ return __built_in_open__(path, mode, bufsize)
+
+ def bkrmdir(self, path):
+ if os.path.exists(path):
+ sta = os.stat(path)
+ oldmode = stat.S_IMODE(sta.st_mode)
+ self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
+ self._save(_RMDIR, path)
+ __built_in_rmdir__(path)
+
+ def bkmkdir(self, path, mode):
+ if not os.path.exists(path):
+ self._save(_MKDIR, path)
+ __built_in_mkdir__(path, mode)
+
+ def bkchmod(self, path, mode):
+ if self._tryhook(path) and os.path.exists(path):
+ sta = os.stat(path)
+ oldmode = stat.S_IMODE(sta.st_mode)
+ self.rlist.append(_PathInfo(_CHMOD, path, oldmode))
+ __built_in_chmod__(path, mode)
+
+ def rollback(self):
+ if self.zip:
+ self.zip.close()
+ self.zip = None
+ index = len(self.rlist) - 1
+ while index >= 0:
+ item = self.rlist[index]
+ exist = os.path.exists(item.path)
+ if item.action == _MKFILE and exist:
+ #if not os.access(item.path, os.W_OK):
+ # os.chmod(item.path, S_IWUSR)
+ __built_in_remove__(item.path)
+ elif item.action == _RMFILE and not exist:
+ if not self.zip:
+ self.zip = zipfile.ZipFile(self.zipfile, 'r',
zipfile.ZIP_DEFLATED)
+ arcname = os.path.normpath(item.path)
+ arcname = arcname[len(self.workspace)+1:].encode('utf_8')
+ if os.sep != "/" and os.sep in arcname:
+ arcname = arcname.replace(os.sep, '/')
+ mtime = self.zip.getinfo(arcname).date_time
+ content = self.zip.read(arcname)
+ filep = __built_in_open__(item.path, "wb")
+ filep.write(content)
+ filep.close()
+ intime = time.mktime(mtime + (0, 0, 0))
+ os.utime(item.path, (intime, intime))
+ elif item.action == _MKDIR and exist:
+ while True:
+ try:
+ __built_in_rmdir__(item.path)
+ break
+ except IOError:
+ # Sleep a short time and try again
+ # The anti-virus software may delay the file removal
in this directory
+ sleep(0.1)
+ elif item.action == _RMDIR and not exist:
+ __built_in_mkdir__(item.path)
+ elif item.action == _CHMOD and exist:
+ try:
+ __built_in_chmod__(item.path, item.mode)
+ except EnvironmentError:
+ pass
+ index -= 1
+ self.commit()
+
+ def commit(self):
+ if self.zip:
+ self.zip.close()
+ __built_in_remove__(self.zipfile)
+
+ # Check if path needs to be hooked
+ def _tryhook(self, path):
+ path = os.path.normpath(path)
+ works = self.workspace if str(self.workspace).endswith(os.sep) else
(self.workspace + os.sep)
+ if not path.startswith(works):
+ return ''
+ for exceptdir in gEXCEPTION_LIST:
+ full = os.path.join(self.workspace, exceptdir)
+ if full == path or path.startswith(full + os.sep) or
os.path.split(full)[0] == path:
+ return ''
+ return path[len(self.workspace)+1:]
+
+def _hookrm(path):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkrmfile(path)
+ else:
+ __built_in_remove__(path)
+
+def _hookmkdir(path, mode=0777):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkmkdir(path, mode)
+ else:
+ __built_in_mkdir__(path, mode)
+
+def _hookrmdir(path):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkrmdir(path)
+ else:
+ __built_in_rmdir__(path)
+
+def _hookmkfile(path, mode='r', bufsize=-1):
+ if GlobalData.gRECOVERMGR:
+ return GlobalData.gRECOVERMGR.bkmkfile(path, mode, bufsize)
+ return __built_in_open__(path, mode, bufsize)
+
+def _hookchmod(path, mode):
+ if GlobalData.gRECOVERMGR:
+ GlobalData.gRECOVERMGR.bkchmod(path, mode)
+ else:
+ __built_in_chmod__(path, mode)
+
+def SetRecoverMgr(mgr):
+ GlobalData.gRECOVERMGR = mgr
+
+os.remove = _hookrm
+os.mkdir = _hookmkdir
+os.rmdir = _hookrmdir
+os.chmod = _hookchmod
+__FileHookOpen__ = _hookmkfile
Modified: trunk/edk2/BaseTools/Source/Python/UPT/Core/IpiDb.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Core/IpiDb.py 2014-08-26
05:30:49 UTC (rev 15895)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Core/IpiDb.py 2014-08-26
05:58:02 UTC (rev 15896)
@@ -1,7 +1,7 @@
## @file
# This file is for installed package information database operations
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -27,6 +27,7 @@
from Logger import StringTable as ST
from Logger.ToolError import UPT_ALREADY_RUNNING_ERROR
from Logger.ToolError import UPT_DB_UPDATE_ERROR
+import platform as pf
## IpiDb
#
@@ -39,7 +40,7 @@
#
#
class IpiDatabase(object):
- def __init__(self, DbPath):
+ def __init__(self, DbPath, Workspace):
Dir = os.path.dirname(DbPath)
if not os.path.isdir(Dir):
os.mkdir(Dir)
@@ -54,6 +55,7 @@
self.ModDepexTable = 'ModDepexInfo'
self.DpFileListTable = 'DpFileListInfo'
self.DummyTable = 'Dummy'
+ self.Workspace = os.path.normpath(Workspace)
## Initialize build database
#
@@ -156,6 +158,12 @@
Logger.Verbose(ST.MSG_INIT_IPI_FINISH)
+ def RollBack(self):
+ self.Conn.rollback()
+
+ def Commit(self):
+ self.Conn.commit()
+
## Add a distribution install information from DpObj
#
# @param DpObj:
@@ -222,7 +230,6 @@
self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \
NewDpPkgFileName, DpPkgFileName, RePackage)
- self.Conn.commit()
except sqlite3.IntegrityError, DetailMsg:
Logger.Error("UPT",
UPT_DB_UPDATE_ERROR,
@@ -266,7 +273,13 @@
# @param Path: A Md5Sum
#
def _AddDpFilePathList(self, DpGuid, DpVersion, Path, Md5Sum):
-
+ Path = os.path.normpath(Path)
+ if pf.system() == 'Windows':
+ if Path.startswith(self.Workspace):
+ Path = Path[len(self.Workspace):]
+ else:
+ if Path.startswith(self.Workspace + os.sep):
+ Path = Path[len(self.Workspace)+1:]
SqlCommand = """insert into %s values('%s', '%s', '%s', '%s')""" % \
(self.DpFileListTable, Path, DpGuid, DpVersion, Md5Sum)
@@ -320,6 +333,11 @@
if PkgVersion == None or len(PkgVersion.strip()) == 0:
PkgVersion = 'N/A'
+
+ if os.name == 'posix':
+ Path = Path.replace('\\', os.sep)
+ else:
+ Path = Path.replace('/', os.sep)
#
# Add module from package information to DB.
@@ -378,6 +396,11 @@
if DepexVersion == None or len(DepexVersion.strip()) == 0:
DepexVersion = 'N/A'
+
+ if os.name == 'posix':
+ Path = Path.replace('\\', os.sep)
+ else:
+ Path = Path.replace('/', os.sep)
#
# Add module depex information to DB.
@@ -478,7 +501,7 @@
(self.DpTable, DpGuid, DpVersion)
self.Cur.execute(SqlCommand)
- self.Conn.commit()
+ #self.Conn.commit()
## Get a list of distribution install information.
#
@@ -554,7 +577,7 @@
for Result in self.Cur:
Path = Result[0]
Md5Sum = Result[3]
- PathList.append((Path, Md5Sum))
+ PathList.append((os.path.join(self.Workspace, Path), Md5Sum))
return PathList
@@ -824,7 +847,7 @@
self.Cur.execute(SqlCommand)
for ModuleInfo in self.Cur:
FilePath = ModuleInfo[0]
- ModList.append(FilePath)
+ ModList.append(os.path.join(self.Workspace, FilePath))
return ModList
@@ -844,7 +867,7 @@
ModuleVersion = '%s' and InstallPath ='%s'
""" % (self.ModDepexTable, Guid, Version, Path)
self.Cur.execute(SqlCommand)
- self.Conn.commit()
+
DepexList = []
for DepInfo in self.Cur:
@@ -853,7 +876,25 @@
DepexList.append((DepexGuid, DepexVersion))
return DepexList
-
+
+ ## Inventory the distribution installed to current workspace
+ #
+ # Inventory the distribution installed to current workspace
+ #
+ def InventoryDistInstalled(self):
+ SqlCommand = """select * from %s """ % (self.DpTable)
+ self.Cur.execute(SqlCommand)
+
+ DpInfoList = []
+ for Result in self.Cur:
+ DpGuid = Result[0]
+ DpVersion = Result[1]
+ DpAliasName = Result[3]
+ DpFileName = Result[4]
+ DpInfoList.append((DpGuid, DpVersion, DpFileName, DpAliasName))
+
+ return DpInfoList
+
## Close entire database
#
# Close the connection and cursor
Modified: trunk/edk2/BaseTools/Source/Python/UPT/Core/PackageFile.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Core/PackageFile.py 2014-08-26
05:30:49 UTC (rev 15895)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Core/PackageFile.py 2014-08-26
05:58:02 UTC (rev 15896)
@@ -2,7 +2,7 @@
#
# PackageFile class represents the zip file of a distribution package.
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -36,9 +36,9 @@
from Logger import StringTable as ST
from Library.Misc import CreateDirectory
from Library.Misc import RemoveDirectory
+from Core.FileHook import __FileHookOpen__
-
class PackageFile:
def __init__(self, FileName, Mode="r"):
self._FileName = FileName
@@ -96,7 +96,7 @@
## Extract the file
#
# @param Which: the source path
- # @param To: the destination path
+ # @param ToDest: the destination path
#
def Extract(self, Which, ToDest):
Which = os.path.normpath(Which)
@@ -116,7 +116,8 @@
Logger.Warn("PackagingTool", \
ST.WRN_FILE_NOT_OVERWRITTEN % ToDest)
return
- ToFile = open(ToDest, "wb")
+ else:
+ ToFile = __FileHookOpen__(ToDest, 'wb')
except BaseException, Xstr:
Logger.Error("PackagingTool", FILE_OPEN_FAILURE,
ExtraData="%s (%s)" % (ToDest, str(Xstr)))
@@ -234,6 +235,8 @@
#
def PackData(self, Data, ArcName):
try:
+ if os.path.splitext(ArcName)[1].lower() == '.pkg':
+ Data = Data.encode('utf_8')
self._ZipFile.writestr(ArcName, Data)
except BaseException, Xstr:
Logger.Error("PackagingTool", FILE_COMPRESS_FAILURE,
Modified: trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
2014-08-26 05:30:49 UTC (rev 15895)
+++ trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenDecFile.py
2014-08-26 05:58:02 UTC (rev 15896)
@@ -2,7 +2,7 @@
#
# This file contained the logical of transfer package object to DEC files.
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -16,7 +16,11 @@
'''
GenDEC
'''
-
+import os
+import stat
+import codecs
+import md5
+from Core.FileHook import __FileHookOpen__
from Library.Parsing import GenSection
from Library.CommentGenerating import GenHeaderCommentSection
from Library.CommentGenerating import GenGenericCommentF
@@ -25,15 +29,42 @@
from Library.Misc import GuidStringToGuidStructureString
from Library.Misc import SaveFileOnChange
from Library.Misc import ConvertPath
+from Library.Misc import GetLocalValue
from Library.DataType import TAB_SPACE_SPLIT
from Library.DataType import TAB_COMMA_SPLIT
+from Library.DataType import END_OF_LINE
from Library.DataType import TAB_ARCH_COMMON
+from Library.DataType import TAB_VALUE_SPLIT
+from Library.DataType import TAB_COMMENT_SPLIT
+from Library.DataType import TAB_PCD_VALIDRANGE
+from Library.DataType import TAB_PCD_VALIDLIST
+from Library.DataType import TAB_PCD_EXPRESSION
from Library.DataType import TAB_DEC_DEFINES_DEC_SPECIFICATION
from Library.DataType import TAB_DEC_DEFINES_PACKAGE_NAME
from Library.DataType import TAB_DEC_DEFINES_PACKAGE_GUID
from Library.DataType import TAB_DEC_DEFINES_PACKAGE_VERSION
+from Library.DataType import TAB_DEC_DEFINES_PKG_UNI_FILE
+from Library.DataType import TAB_DEC_PACKAGE_ABSTRACT
+from Library.DataType import TAB_DEC_PACKAGE_DESCRIPTION
+from Library.DataType import TAB_DEC_BINARY_ABSTRACT
+from Library.DataType import TAB_DEC_BINARY_DESCRIPTION
+from Library.DataType import TAB_LANGUAGE_EN_X
+from Library.DataType import TAB_BINARY_HEADER_USERID
+from Library.DataType import TAB_BINARY_HEADER_IDENTIFIER
+from Library.DataType import TAB_COMMENT_EDK1_SPLIT
+from Library.DataType import TAB_ENCODING_UTF16LE
+from Library.DataType import TAB_CAPHEX_START
+from Library.DataType import TAB_HEX_START
+from Library.DataType import TAB_UNDERLINE_SPLIT
+from Library.DataType import TAB_STR_TOKENERR
+from Library.DataType import TAB_STR_TOKENCNAME
+from Library.DataType import TAB_PCD_ERROR_SECTION_COMMENT
+from Library.DataType import TAB_PCD_ERROR
+from Library.DataType import TAB_SECTION_START
+from Library.DataType import TAB_SECTION_END
+from Library.DataType import TAB_SPLIT
+from Library.UniClassObject import FormatUniEntry
-
def GenPcd(Package, Content):
#
# generate [Pcd] section
@@ -47,12 +78,16 @@
HelpTextList = Pcd.GetHelpTextList()
HelpStr = _GetHelpStr(HelpTextList)
CommentStr = GenGenericCommentF(HelpStr, 2)
-
+
+ PromptList = Pcd.GetPromptList()
+ PromptStr = _GetHelpStr(PromptList)
+ CommentStr += GenGenericCommentF(PromptStr.strip(), 1, True)
+
PcdErrList = Pcd.GetPcdErrorsList()
- if PcdErrList:
- CommentStr += GenPcdErrComment(PcdErrList[0])
+ for PcdErr in PcdErrList:
+ CommentStr += GenPcdErrComment(PcdErr)
Statement = CommentStr
-
+
CName = Pcd.GetCName()
TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()
DefaultValue = Pcd.GetDefaultValue()
@@ -96,16 +131,62 @@
NewSectionDict[SortedArch] = [Statement]
for ValidUsage in ValidUsageDict:
- Content += GenSection(ValidUsage, ValidUsageDict[ValidUsage])
+ Content += GenSection(ValidUsage, ValidUsageDict[ValidUsage], True,
True)
return Content
+def GenPcdErrorMsgSection(Package, Content):
+ if not Package.PcdErrorCommentDict:
+ return Content
+
+ #
+ # Generate '# [Error.<TokenSpcCName>]' section
+ #
+ Content += END_OF_LINE + END_OF_LINE
+ SectionComment = TAB_COMMENT_SPLIT + END_OF_LINE
+ SectionComment += TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT +
TAB_PCD_ERROR_SECTION_COMMENT + END_OF_LINE
+ SectionComment += TAB_COMMENT_SPLIT + END_OF_LINE
+ TokenSpcCNameList = []
+
+ #
+ # Get TokenSpcCName list in PcdErrorCommentDict in Package object
+ #
+ for (TokenSpcCName, ErrorNumber) in Package.PcdErrorCommentDict:
+ if TokenSpcCName not in TokenSpcCNameList:
+ TokenSpcCNameList.append(TokenSpcCName)
+
+ for TokenSpcCNameItem in TokenSpcCNameList:
+ SectionName = TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT + TAB_SECTION_START
+ TAB_PCD_ERROR + \
+ TAB_SPLIT + TokenSpcCNameItem + TAB_SECTION_END +
END_OF_LINE
+ Content += SectionComment
+ Content += SectionName
+ for (TokenSpcCName, ErrorNumber) in Package.PcdErrorCommentDict:
+ if TokenSpcCNameItem == TokenSpcCName:
+ PcdErrorMsg =
GetLocalValue(Package.PcdErrorCommentDict[(TokenSpcCName, ErrorNumber)])
+ SectionItem = TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT +
TAB_SPACE_SPLIT + \
+ ErrorNumber + TAB_SPACE_SPLIT + TAB_VALUE_SPLIT
+ TAB_SPACE_SPLIT + \
+ PcdErrorMsg + END_OF_LINE
+ Content += SectionItem
+
+ Content += TAB_COMMENT_SPLIT
+ return Content
+
def GenGuidProtocolPpi(Package, Content):
#
# generate [Guids] section
#
NewSectionDict = {}
+
+ LeftOffset = 46
+ # Get the line offset need
+ # If the real one < the min one, use the min one
+ # else use the real one
for Guid in Package.GetGuidList():
+ if len(Guid.GetCName()) > LeftOffset:
+ LeftOffset = len(Guid.GetCName())
+
+ # Generate
+ for Guid in Package.GetGuidList():
#
# Generate generic comment
#
@@ -116,7 +197,7 @@
Statement = CommentStr
CName = Guid.GetCName()
Value = GuidStringToGuidStructureString(Guid.GetGuid())
- Statement += CName + ' = ' + Value
+ Statement += CName.ljust(LeftOffset) + ' = ' + Value
#
# generate tail comment
#
@@ -131,13 +212,21 @@
else:
NewSectionDict[SortedArch] = [Statement]
- Content += GenSection('Guids', NewSectionDict)
+ Content += GenSection('Guids', NewSectionDict, True, True)
#
# generate [Protocols] section
#
NewSectionDict = {}
+ LeftOffset = 46
+ # Get the line offset need
+ # If the real one < the min one, use the min one
+ # else use the real one
for Protocol in Package.GetProtocolList():
+ if len(Protocol.GetCName()) > LeftOffset:
+ LeftOffset = len(Protocol.GetCName())
+
+ for Protocol in Package.GetProtocolList():
#
# Generate generic comment
#
@@ -148,7 +237,7 @@
Statement = CommentStr
CName = Protocol.GetCName()
Value = GuidStringToGuidStructureString(Protocol.GetGuid())
- Statement += CName + ' = ' + Value
+ Statement += CName.ljust(LeftOffset) + ' = ' + Value
#
# generate tail comment
@@ -164,13 +253,21 @@
else:
NewSectionDict[SortedArch] = [Statement]
- Content += GenSection('Protocols', NewSectionDict)
+ Content += GenSection('Protocols', NewSectionDict, True, True)
#
# generate [Ppis] section
#
NewSectionDict = {}
+ LeftOffset = 46
+ # Get the line offset need
+ # If the real one < the min one, use the min one
+ # else use the real one
for Ppi in Package.GetPpiList():
+ if len(Ppi.GetCName()) > LeftOffset:
+ LeftOffset = len(Ppi.GetCName())
+
+ for Ppi in Package.GetPpiList():
#
# Generate generic comment
#
@@ -181,7 +278,7 @@
Statement = CommentStr
CName = Ppi.GetCName()
Value = GuidStringToGuidStructureString(Ppi.GetGuid())
- Statement += CName + ' = ' + Value
+ Statement += CName.ljust(LeftOffset) + ' = ' + Value
#
# generate tail comment
@@ -197,7 +294,7 @@
else:
NewSectionDict[SortedArch] = [Statement]
- Content += GenSection('Ppis', NewSectionDict)
+ Content += GenSection('Ppis', NewSectionDict, True, True)
return Content
@@ -207,22 +304,78 @@
#
# @param Package: A Package
#
-def PackageToDec(Package):
+def PackageToDec(Package, DistHeader = None):
#
# Init global information for the file
#
ContainerFile = Package.GetFullPath()
Content = ''
+
#
- # generate header comment section
+ # Generate file header
#
- Content += GenHeaderCommentSection(Package.GetAbstract(), \
- Package.GetDescription(), \
- Package.GetCopyright(), \
- Package.GetLicense())
-
+ 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)
+
+ #
+ # 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],
@@ -233,21 +386,29 @@
#
# generate [Defines] section
#
+ LeftOffset = 31
NewSectionDict = {TAB_ARCH_COMMON : []}
SpecialItemList = []
- Statement = '%s = %s' % (TAB_DEC_DEFINES_DEC_SPECIFICATION, '0x00010017')
+ 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 = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_NAME, BaseName)
+ Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_NAME).ljust(LeftOffset) +
u'= %s' % BaseName
SpecialItemList.append(Statement)
- Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_VERSION,
Package.GetVersion())
+
+ Statement = (u'%s ' % TAB_DEC_DEFINES_PACKAGE_VERSION).ljust(LeftOffset) +
u'= %s' % Package.GetVersion()
SpecialItemList.append(Statement)
- Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_GUID, Package.GetGuid())
- 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
@@ -269,8 +430,11 @@
else:
NewSectionDict[SortedArch] = [ConvertPath(Statement)]
- Content += GenSection('Includes', NewSectionDict)
+ Content += GenSection('Includes', NewSectionDict)
+ #
+ # generate [guids][protocols][ppis] sections
+ #
Content = GenGuidProtocolPpi(Package, Content)
#
@@ -284,8 +448,8 @@
HelpTextList = LibraryClass.GetHelpTextList()
HelpStr = _GetHelpStr(HelpTextList)
if HelpStr:
- HelpStr = '@libraryclass ' + HelpStr
- CommentStr = GenGenericCommentF(HelpStr, 2)
+ HelpStr = '@libraryclass' + HelpStr
+ CommentStr = GenGenericCommentF(HelpStr, 2, False, True)
Statement = CommentStr
Name = LibraryClass.GetLibraryClass()
@@ -306,18 +470,31 @@
else:
NewSectionDict[SortedArch] = [Statement]
- Content += GenSection('LibraryClasses', NewSectionDict)
+ 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
Statement = UserExtension.GetStatement()
if not Statement:
continue
+ else:
+ LineList = Statement.split('\n')
+ NewStatement = ""
+ for Line in LineList:
+ NewStatement += " %s\n" % Line
SectionList = []
SectionName = 'UserExtensions'
@@ -335,11 +512,147 @@
SectionList.append(SectionName + '.' + Arch)
SectionName = ', '.join(SectionList)
SectionName = ''.join(['[', SectionName, ']\n'])
- Content += '\n\n' + SectionName + Statement
+ 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
+## GenPackageUNIEncodeFile
+# GenPackageUNIEncodeFile, default is a UCS-2LE encode file
+#
+def GenPackageUNIEncodeFile(PackageObject, UniFileHeader = '',
Encoding=TAB_ENCODING_UTF16LE):
+ GenUNIFlag = False
+ OnlyLANGUAGE_EN_X = True
+ BinaryAbstract = []
+ BinaryDescription = []
+ #
+ # If more than one language code is used for any element that would be
present in the PACKAGE_UNI_FILE,
+ # then the PACKAGE_UNI_FILE must be created.
+ #
+ for (Key, Value) in PackageObject.GetAbstract() +
PackageObject.GetDescription():
+ if Key == TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+
+ for UserExtension in PackageObject.GetUserExtensionList():
+ if UserExtension.GetUserID() == TAB_BINARY_HEADER_USERID \
+ and UserExtension.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER:
+ for (Key, Value) in UserExtension.GetBinaryAbstract():
+ if Key == TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+ BinaryAbstract.append((Key, Value))
+
+ for (Key, Value) in UserExtension.GetBinaryDescription():
+ if Key == TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+ BinaryDescription.append((Key, Value))
+
+ for Pcd in PackageObject.GetPcdList():
+ for TxtObj in Pcd.GetPromptList() + Pcd.GetHelpTextList():
+ if TxtObj.GetLang() == TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+
+ for PcdError in Pcd.GetPcdErrorsList():
+ if PcdError.GetErrorNumber().startswith('0x') or
PcdError.GetErrorNumber().startswith('0X'):
+ for (Key, Value) in PcdError.GetErrorMessageList():
+ if Key == TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+ if not GenUNIFlag:
+ return
+ elif OnlyLANGUAGE_EN_X:
+ return
+ else:
+ PackageObject.UNIFlag = True
+
+ if not os.path.exists(os.path.dirname(PackageObject.GetFullPath())):
+ os.makedirs(os.path.dirname(PackageObject.GetFullPath()))
+ ContainerFile =
os.path.normpath(os.path.join(os.path.dirname(PackageObject.GetFullPath()),
+ (PackageObject.GetBaseName()
+ '.uni')))
+
+ Content = UniFileHeader + os.linesep
+ Content += os.linesep
+
+ Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_ABSTRACT,
PackageObject.GetAbstract(), ContainerFile) \
+ + os.linesep
+
+ Content += FormatUniEntry('#string ' + TAB_DEC_PACKAGE_DESCRIPTION,
PackageObject.GetDescription(), ContainerFile) \
+ + os.linesep
+
+ Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_ABSTRACT,
BinaryAbstract, ContainerFile) \
+ + os.linesep
+
+ Content += FormatUniEntry('#string ' + TAB_DEC_BINARY_DESCRIPTION,
BinaryDescription, ContainerFile) \
+ + os.linesep
+
+ PromptGenList = []
+ HelpTextGenList = []
+ for Pcd in PackageObject.GetPcdList():
+ # Generate Prompt for each Pcd
+ PcdPromptStrName = '#string ' + 'STR_' + Pcd.GetTokenSpaceGuidCName()
+ '_' + Pcd.GetCName() + '_PROMPT '
+ TokenValueList = []
+ for TxtObj in Pcd.GetPromptList():
+ Lang = TxtObj.GetLang()
+ PromptStr = TxtObj.GetString()
+ #
+ # Avoid generating the same PROMPT entry more than one time.
+ #
+ if (PcdPromptStrName, Lang) not in PromptGenList:
+ TokenValueList.append((Lang, PromptStr))
+ PromptGenList.append((PcdPromptStrName, Lang))
+ PromptString = FormatUniEntry(PcdPromptStrName, TokenValueList,
ContainerFile) + os.linesep
+ if PromptString not in Content:
+ Content += PromptString
+
+ # Generate Help String for each Pcd
+ PcdHelpStrName = '#string ' + 'STR_' + Pcd.GetTokenSpaceGuidCName() +
'_' + Pcd.GetCName() + '_HELP '
+ TokenValueList = []
+ for TxtObj in Pcd.GetHelpTextList():
+ Lang = TxtObj.GetLang()
+ HelpStr = TxtObj.GetString()
+ #
+ # Avoid generating the same HELP entry more than one time.
+ #
+ if (PcdHelpStrName, Lang) not in HelpTextGenList:
+ TokenValueList.append((Lang, HelpStr))
+ HelpTextGenList.append((PcdHelpStrName, Lang))
+ HelpTextString = FormatUniEntry(PcdHelpStrName, TokenValueList,
ContainerFile) + os.linesep
+ if HelpTextString not in Content:
+ Content += HelpTextString
+
+ # Generate PcdError for each Pcd if ErrorNo exist.
+ for PcdError in Pcd.GetPcdErrorsList():
+ ErrorNo = PcdError.GetErrorNumber()
+ if ErrorNo.startswith(TAB_HEX_START) or
ErrorNo.startswith(TAB_CAPHEX_START):
+ PcdErrStrName = '#string ' + TAB_STR_TOKENCNAME +
TAB_UNDERLINE_SPLIT + Pcd.GetTokenSpaceGuidCName() \
+ + TAB_UNDERLINE_SPLIT + TAB_STR_TOKENERR \
+ + TAB_UNDERLINE_SPLIT + ErrorNo[2:]
+ PcdErrString = FormatUniEntry(PcdErrStrName,
PcdError.GetErrorMessageList(), ContainerFile) + os.linesep
+ if PcdErrString not in Content:
+ Content += PcdErrString
+
+ File = codecs.open(ContainerFile, 'w', Encoding)
+ File.write(u'\uFEFF' + Content)
+ File.stream.close()
+ Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())
+ Md5Sum = Md5Sigature.hexdigest()
+ if (ContainerFile, Md5Sum) not in PackageObject.FileList:
+ PackageObject.FileList.append((ContainerFile, Md5Sum))
+
+ return ContainerFile
+
## GenPcdErrComment
#
# @param PcdErrObject: PcdErrorObject
@@ -347,21 +660,30 @@
# @retval CommentStr: Generated comment lines, with prefix "#"
#
def GenPcdErrComment (PcdErrObject):
- EndOfLine = "\n"
+ CommentStr = ''
+ ErrorCode = PcdErrObject.GetErrorNumber()
ValidValueRange = PcdErrObject.GetValidValueRange()
if ValidValueRange:
- CommentStr = "# @ValidRange " + ValidValueRange + EndOfLine
+ CommentStr = TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT + TAB_PCD_VALIDRANGE
+ TAB_SPACE_SPLIT
+ if ErrorCode:
+ CommentStr += ErrorCode + TAB_SPACE_SPLIT + TAB_VALUE_SPLIT +
TAB_SPACE_SPLIT
+ CommentStr += ValidValueRange + END_OF_LINE
ValidValue = PcdErrObject.GetValidValue()
if ValidValue:
ValidValueList = \
[Value for Value in ValidValue.split(TAB_SPACE_SPLIT) if Value]
- CommentStr = \
- "# @ValidList " + TAB_COMMA_SPLIT.join(ValidValueList) + EndOfLine
+ CommentStr = TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT + TAB_PCD_VALIDLIST +
TAB_SPACE_SPLIT
+ if ErrorCode:
+ CommentStr += ErrorCode + TAB_SPACE_SPLIT + TAB_VALUE_SPLIT +
TAB_SPACE_SPLIT
+ CommentStr += TAB_COMMA_SPLIT.join(ValidValueList) + END_OF_LINE
Expression = PcdErrObject.GetExpression()
if Expression:
- CommentStr = "# @Expression " + Expression + EndOfLine
+ CommentStr = TAB_COMMENT_SPLIT + TAB_SPACE_SPLIT + TAB_PCD_EXPRESSION
+ TAB_SPACE_SPLIT
+ if ErrorCode:
+ CommentStr += ErrorCode + TAB_SPACE_SPLIT + TAB_VALUE_SPLIT +
TAB_SPACE_SPLIT
+ CommentStr += Expression + END_OF_LINE
return CommentStr
Modified: trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
2014-08-26 05:30:49 UTC (rev 15895)
+++ trunk/edk2/BaseTools/Source/Python/UPT/GenMetaFile/GenInfFile.py
2014-08-26 05:58:02 UTC (rev 15896)
@@ -2,7 +2,7 @@
#
# This file contained the logical of transfer package object to INF files.
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -15,16 +15,22 @@
'''
GenInf
'''
-from os import getenv
+import os
+import stat
+import codecs
+import md5
+from Core.FileHook import __FileHookOpen__
from Library.String import GetSplitValueList
from Library.Parsing import GenSection
from Library.Parsing import GetWorkspacePackage
-from Library.Parsing import ConvertArchForInstall
+from Library.Parsing import ConvertArchForInstall
from Library.Misc import SaveFileOnChange
from Library.Misc import IsAllModuleList
from Library.Misc import Sdict
from Library.Misc import ConvertPath
from Library.Misc import ConvertSpec
+from Library.Misc import GetRelativePath
+from Library.Misc import GetLocalValue
from Library.CommentGenerating import GenHeaderCommentSection
from Library.CommentGenerating import GenGenericCommentF
from Library.CommentGenerating import _GetHelpStr
@@ -34,37 +40,114 @@
import Logger.Log as Logger
from Library import DataType as DT
from GenMetaFile import GenMetaFileMisc
+from Library.UniClassObject import FormatUniEntry
+
## Transfer Module Object to Inf files
#
# Transfer all contents of a standard Module Object to an Inf file
# @param ModuleObject: A Module Object
#
-def ModuleToInf(ModuleObject):
- if not GlobalData.gWSPKG_LIST:
+def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):
+ if not GlobalData.gWSPKG_LIST:
GlobalData.gWSPKG_LIST = GetWorkspacePackage()
-
#
# Init global information for the file
#
ContainerFile = ModuleObject.GetFullPath()
+
Content = ''
#
- # generate header comment section
+ # Generate file header, If any Abstract, Description, Copyright or License
XML elements are missing,
+ # should 1) use the Abstract, Description, Copyright or License from the
PackageSurfaceArea.Header elements
+ # that the module belongs to, or 2) if this is a stand-alone module that
is not included in a PackageSurfaceArea,
+ # use the abstract, description, copyright or license from the
DistributionPackage.Header elements.
+ #
+ ModuleAbstract = GetLocalValue(ModuleObject.GetAbstract())
+ if not ModuleAbstract and PackageObject:
+ ModuleAbstract = GetLocalValue(PackageObject.GetAbstract())
+ if not ModuleAbstract and DistHeader:
+ ModuleAbstract = GetLocalValue(DistHeader.GetAbstract())
+ ModuleDescription = GetLocalValue(ModuleObject.GetDescription())
+ if not ModuleDescription and PackageObject:
+ ModuleDescription = GetLocalValue(PackageObject.GetDescription())
+ if not ModuleDescription and DistHeader:
+ ModuleDescription = GetLocalValue(DistHeader.GetDescription())
+ ModuleCopyright = ''
+ for (Lang, Copyright) in ModuleObject.GetCopyright():
+ if Lang:
+ pass
+ ModuleCopyright = Copyright
+ if not ModuleCopyright and PackageObject:
+ for (Lang, Copyright) in PackageObject.GetCopyright():
+ if Lang:
+ pass
+ ModuleCopyright = Copyright
+ if not ModuleCopyright and DistHeader:
+ for (Lang, Copyright) in DistHeader.GetCopyright():
+ if Lang:
+ pass
+ ModuleCopyright = Copyright
+ ModuleLicense = ''
+ for (Lang, License) in ModuleObject.GetLicense():
+ if Lang:
+ pass
+ ModuleLicense = License
+ if not ModuleLicense and PackageObject:
+ for (Lang, License) in PackageObject.GetLicense():
+ if Lang:
+ pass
+ ModuleLicense = License
+ if not ModuleLicense and DistHeader:
+ for (Lang, License) in DistHeader.GetLicense():
+ if Lang:
+ pass
+ ModuleLicense = License
+
+ #
+ # Generate header comment section of INF file
#
- Content += GenHeaderCommentSection(ModuleObject.GetAbstract(),
- ModuleObject.GetDescription(),
- ModuleObject.GetCopyright(),
- ModuleObject.GetLicense())
-
+ Content += GenHeaderCommentSection(ModuleAbstract,
+ ModuleDescription,
+ ModuleCopyright,
+ ModuleLicense)
+
#
+ # Generate Binary Header
+ #
+ for UserExtension in ModuleObject.GetUserExtensionList():
+ if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \
+ and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:
+ ModuleBinaryAbstract =
GetLocalValue(UserExtension.GetBinaryAbstract())
+ ModuleBinaryDescription =
GetLocalValue(UserExtension.GetBinaryDescription())
+ ModuleBinaryCopyright = ''
+ ModuleBinaryLicense = ''
+ for (Lang, Copyright) in UserExtension.GetBinaryCopyright():
+ ModuleBinaryCopyright = Copyright
+ for (Lang, License) in UserExtension.GetBinaryLicense():
+ ModuleBinaryLicense = License
+ if ModuleBinaryAbstract and ModuleBinaryDescription and \
+ ModuleBinaryCopyright and ModuleBinaryLicense:
+ Content += GenHeaderCommentSection(ModuleBinaryAbstract,
+ ModuleBinaryDescription,
+ ModuleBinaryCopyright,
+ ModuleBinaryLicense,
+ True)
+
+ #
+ # Generate MODULE_UNI_FILE for module
+ #
+ FileHeader = GenHeaderCommentSection(ModuleAbstract, ModuleDescription,
ModuleCopyright, ModuleLicense, False, \
+ DT.TAB_COMMENT_EDK1_SPLIT)
+ GenModuleUNIEncodeFile(ModuleObject, FileHeader)
+
+ #
# Judge whether the INF file is an AsBuild INF.
#
if ModuleObject.BinaryModule:
GlobalData.gIS_BINARY_INF = True
else:
GlobalData.gIS_BINARY_INF = False
-
#
# for each section, maintain a dict, sorted arch will be its key,
# statement list will be its data
@@ -72,8 +155,6 @@
# 'Arch1' : [statement1, statement3]
# }
#
-
- #
# Gen section contents
#
Content += GenDefines(ModuleObject)
@@ -82,36 +163,110 @@
Content += GenPackages(ModuleObject)
Content += GenPcdSections(ModuleObject)
Content += GenSources(ModuleObject)
- Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True)
- Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False)
- Content += GenGuidSections(ModuleObject.GetGuidList())
+ Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True)
+ Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False)
+ Content += GenGuidSections(ModuleObject.GetGuidList())
Content += GenBinaries(ModuleObject)
Content += GenDepex(ModuleObject)
- Content += GenUserExtensions(ModuleObject)
-
+ Content += GenUserExtensions(ModuleObject)
if ModuleObject.GetEventList() or ModuleObject.GetBootModeList() or
ModuleObject.GetHobList():
- Content += '\n\n'
+ Content += '\n'
#
# generate [Event], [BootMode], [Hob] section
#
- Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event')
+ Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event')
Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode')
Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob')
-
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
+## GenModuleUNIEncodeFile
+# GenModuleUNIEncodeFile, default is a UCS-2LE encode file
+#
+def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='',
Encoding=DT.TAB_ENCODING_UTF16LE):
+ GenUNIFlag = False
+ OnlyLANGUAGE_EN_X = True
+ BinaryAbstract = []
+ BinaryDescription = []
+ #
+ # If more than one language code is used for any element that would be
present in the MODULE_UNI_FILE,
+ # then the MODULE_UNI_FILE must be created.
+ #
+ for (Key, Value) in ModuleObject.GetAbstract() +
ModuleObject.GetDescription():
+ if Key == DT.TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+
+ for UserExtension in ModuleObject.GetUserExtensionList():
+ if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \
+ and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:
+ for (Key, Value) in UserExtension.GetBinaryAbstract():
+ if Key == DT.TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+ BinaryAbstract.append((Key, Value))
+ for (Key, Value) in UserExtension.GetBinaryDescription():
+ if Key == DT.TAB_LANGUAGE_EN_X:
+ GenUNIFlag = True
+ else:
+ OnlyLANGUAGE_EN_X = False
+ BinaryDescription.append((Key, Value))
+
+
+ if not GenUNIFlag:
+ return
+ elif OnlyLANGUAGE_EN_X:
+ return
+ else:
+ ModuleObject.UNIFlag = True
+ ContainerFile =
os.path.normpath(os.path.join(os.path.dirname(ModuleObject.GetFullPath()),
+ (ModuleObject.GetBaseName()
+ '.uni')))
+ if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):
+ os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))
+
+ Content = UniFileHeader + os.linesep
+ Content += DT.END_OF_LINE
+
+ Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT,
ModuleObject.GetAbstract(), ContainerFile) + os.linesep
+
+ Content += FormatUniEntry('#string ' + DT.TAB_INF_DESCRIPTION,
ModuleObject.GetDescription(), ContainerFile) \
+ + os.linesep
+
+ BinaryAbstractString = FormatUniEntry('#string ' +
DT.TAB_INF_BINARY_ABSTRACT, BinaryAbstract, ContainerFile)
+ if BinaryAbstractString:
+ Content += BinaryAbstractString + os.linesep
+
+ BinaryDescriptionString = FormatUniEntry('#string ' +
DT.TAB_INF_BINARY_DESCRIPTION, BinaryDescription, \
+ ContainerFile)
+ if BinaryDescriptionString:
+ Content += BinaryDescriptionString + os.linesep
+
+ if not os.path.exists(ContainerFile):
+ File = codecs.open(ContainerFile, 'wb', Encoding)
+ File.write(u'\uFEFF' + Content)
+ File.stream.close()
+ Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())
+ Md5Sum = Md5Sigature.hexdigest()
+ if (ContainerFile, Md5Sum) not in ModuleObject.FileList:
+ ModuleObject.FileList.append((ContainerFile, Md5Sum))
+
+ return ContainerFile
def GenDefines(ModuleObject):
#
# generate [Defines] section
#
- Content = ''
- NewSectionDict = {}
+ 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):
@@ -123,52 +278,79 @@
if SortedArch in NewSectionDict:
NewSectionDict[SortedArch] = NewSectionDict[SortedArch] +
[Statement]
else:
- NewSectionDict[SortedArch] = [Statement]
-
+ NewSectionDict[SortedArch] = [Statement]
SpecialStatementList = []
-
#
# Add INF_VERSION statement firstly
#
- Statement = 'INF_VERSION = 0x00010017'
+
+ LeftOffset = 31
+ # TAB_INF_DEFINES_INF_VERSION
+ Statement = (u'%s ' % DT.TAB_INF_DEFINES_INF_VERSION).ljust(LeftOffset) +
u'= %s' % '0x00010017'
SpecialStatementList.append(Statement)
+ # BaseName
BaseName = ModuleObject.GetBaseName()
if BaseName.startswith('.') or BaseName.startswith('-'):
BaseName = '_' + BaseName
- Statement = '%s = %s' % (DT.TAB_INF_DEFINES_BASE_NAME, BaseName)
+ Statement = (u'%s ' % DT.TAB_INF_DEFINES_BASE_NAME).ljust(LeftOffset) +
u'= %s' % BaseName
SpecialStatementList.append(Statement)
- Statement = '%s = %s' % (DT.TAB_INF_DEFINES_FILE_GUID,
ModuleObject.GetGuid())
+
+ # TAB_INF_DEFINES_FILE_GUID
+ Statement = (u'%s ' % DT.TAB_INF_DEFINES_FILE_GUID).ljust(LeftOffset) +
u'= %s' % ModuleObject.GetGuid()
SpecialStatementList.append(Statement)
- Statement = '%s = %s' % (DT.TAB_INF_DEFINES_VERSION_STRING,
ModuleObject.GetVersion())
+
+ # TAB_INF_DEFINES_VERSION_STRING
+ Statement = (u'%s ' % DT.TAB_INF_DEFINES_VERSION_STRING).ljust(LeftOffset)
+ u'= %s' % ModuleObject.GetVersion()
SpecialStatementList.append(Statement)
-
+
+ # TAB_INF_DEFINES_VERSION_STRING
+ if ModuleObject.UNIFlag:
+ Statement = (u'%s ' %
DT.TAB_INF_DEFINES_MODULE_UNI_FILE).ljust(LeftOffset) + \
+ u'= %s' % ModuleObject.GetBaseName() + '.uni'
+ SpecialStatementList.append(Statement)
+
+ # TAB_INF_DEFINES_MODULE_TYPE
if ModuleObject.GetModuleType():
- Statement = '%s = %s' % (DT.TAB_INF_DEFINES_MODULE_TYPE,
ModuleObject.GetModuleType())
+ Statement = (u'%s ' %
DT.TAB_INF_DEFINES_MODULE_TYPE).ljust(LeftOffset) + u'= %s' %
ModuleObject.GetModuleType()
SpecialStatementList.append(Statement)
+
+ # TAB_INF_DEFINES_PCD_IS_DRIVER
if ModuleObject.GetPcdIsDriver():
- Statement = '%s = %s' % (DT.TAB_INF_DEFINES_PCD_IS_DRIVER,
ModuleObject.GetPcdIsDriver())
+ Statement = (u'%s ' %
DT.TAB_INF_DEFINES_PCD_IS_DRIVER).ljust(LeftOffset) + \
+ u'= %s' % ModuleObject.GetPcdIsDriver()
SpecialStatementList.append(Statement)
+
+ # TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
if ModuleObject.GetUefiSpecificationVersion():
- Statement = '%s = %s' %
(DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION, \
- ModuleObject.GetUefiSpecificationVersion())
+ Statement = (u'%s ' %
DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION).ljust(LeftOffset) + \
+ u'= %s' % ModuleObject.GetUefiSpecificationVersion()
SpecialStatementList.append(Statement)
+
+ # TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
if ModuleObject.GetPiSpecificationVersion():
- Statement = '%s = %s' % (DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION,
ModuleObject.GetPiSpecificationVersion())
- SpecialStatementList.append(Statement)
+ Statement = (u'%s ' %
DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION).ljust(LeftOffset) + \
+ u'= %s' % ModuleObject.GetPiSpecificationVersion()
+ SpecialStatementList.append(Statement)
+
+ # LibraryClass
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())
+ Statement = (u'%s ' %
DT.TAB_INF_DEFINES_LIBRARY_CLASS).ljust(LeftOffset) + \
+ u'= %s' % LibraryClass.GetLibraryClass()
if LibraryClass.GetSupModuleList():
Statement += '|' + DT.TAB_SPACE_SPLIT.join(l for l in
LibraryClass.GetSupModuleList())
SpecialStatementList.append(Statement)
+
+ # Spec Item
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)
-
+
+ # Extern
ExternList = []
for Extern in ModuleObject.GetExternList():
ArchList = Extern.GetSupArchList()
@@ -179,27 +361,23 @@
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 = '\n' + '# ' + '\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'
-
+ ValidArchStatement += '# '
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 GenLibraryClasses(ModuleObject):
@@ -223,17 +401,16 @@
FFE = LibraryClass.GetFeatureFlag()
Statement += Name
if FFE:
- Statement += '|' + FFE
+ Statement += '|' + FFE
ModuleList = LibraryClass.GetSupModuleList()
ArchList = LibraryClass.GetSupArchList()
for Index in xrange(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index])
ArchList.sort()
SortedArch = ' '.join(ArchList)
-
KeyList = []
if not ModuleList or IsAllModuleList(ModuleList):
- KeyList = [SortedArch]
+ KeyList = [SortedArch]
else:
ModuleString = DT.TAB_VALUE_SPLIT.join(l for l in ModuleList)
if not ArchList:
@@ -241,7 +418,6 @@
KeyList = [SortedArch + '.' + ModuleString]
else:
KeyList = [Arch + '.' + ModuleString for Arch in ArchList]
-
for Key in KeyList:
if Key in NewSectionDict:
NewSectionDict[Key] = NewSectionDict[Key] + [Statement]
@@ -254,9 +430,10 @@
if not BinaryFile.AsBuiltList:
continue
for LibraryItem in BinaryFile.AsBuiltList[0].LibraryInstancesList:
- Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' +
LibraryItem.Version
+ Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' +
LibraryItem.Version
+
if len(BinaryFile.SupArchList) == 0:
- if LibraryClassDict.has_key('COMMON'):
+ if LibraryClassDict.has_key('COMMON') and Statement not in
LibraryClassDict['COMMON']:
LibraryClassDict['COMMON'].append(Statement)
else:
LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']
@@ -264,13 +441,15 @@
else:
for Arch in BinaryFile.SupArchList:
if LibraryClassDict.has_key(Arch):
- LibraryClassDict[Arch].append(Statement)
+ if Statement not in LibraryClassDict[Arch]:
+ LibraryClassDict[Arch].append(Statement)
+ else:
+ continue
else:
LibraryClassDict[Arch] = ['## @LIB_INSTANCES']
LibraryClassDict[Arch].append(Statement)
-
Content += GenSection('LibraryClasses', LibraryClassDict)
-
+
return Content
def GenPackages(ModuleObject):
@@ -279,7 +458,7 @@
# generate [Packages] section
#
NewSectionDict = Sdict()
- WorkspaceDir = getenv('WORKSPACE')
+ WorkspaceDir = GlobalData.gWORKSPACE
for PackageDependency in ModuleObject.GetPackageDependencyList():
#
# Generate generic comment
@@ -288,11 +467,12 @@
HelpText = PackageDependency.GetHelpText()
if HelpText:
HelpStr = HelpText.GetString()
- CommentStr = GenGenericCommentF(HelpStr)
+ CommentStr = GenGenericCommentF(HelpStr)
Statement = CommentStr
Guid = PackageDependency.GetGuid()
Version = PackageDependency.GetVersion()
FFE = PackageDependency.GetFeatureFlag()
+ Path = ''
#
# find package path/name
#
@@ -304,20 +484,18 @@
#
# get relative path
#
- RelaPath = Path[Path.upper().find(WorkspaceDir.upper()) +
len(WorkspaceDir) + 1:]
+ RelaPath = GetRelativePath(Path, WorkspaceDir)
Statement += RelaPath.replace('\\', '/')
if FFE:
- Statement += '|' + FFE
+ Statement += '|' + FFE
ArchList = PackageDependency.GetSupArchList()
ArchList.sort()
SortedArch = ' '.join(ArchList)
if SortedArch in NewSectionDict:
NewSectionDict[SortedArch] = NewSectionDict[SortedArch] +
[Statement]
else:
- NewSectionDict[SortedArch] = [Statement]
-
+ NewSectionDict[SortedArch] = [Statement]
Content += GenSection('Packages', NewSectionDict)
-
return Content
def GenSources(ModuleObject):
@@ -326,23 +504,20 @@
#
Content = ''
NewSectionDict = {}
-
- for Source in ModuleObject.GetSourceFileList():
+ for Source in ModuleObject.GetSourceFileList():
SourceFile = Source.GetSourceFile()
Family = Source.GetFamily()
FeatureFlag = Source.GetFeatureFlag()
SupArchList = Source.GetSupArchList()
SupArchList.sort()
- SortedArch = ' '.join(SupArchList)
-
+ 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)
- Content += GenSection('Sources', NewSectionDict)
-
return Content
def GenDepex(ModuleObject):
@@ -359,7 +534,6 @@
SupModList = Depex.GetModuleType()
Expression = Depex.GetDepex()
Statement = CommentStr + Expression
-
SupArchList.sort()
KeyList = []
if not SupArchList:
@@ -370,17 +544,14 @@
for ModuleType in SupModList:
for Arch in SupArchList:
KeyList.append(ConvertArchForInstall(Arch) + '.' +
ModuleType)
-
for Key in KeyList:
if Key in NewSectionDict:
NewSectionDict[Key] = NewSectionDict[Key] + [Statement]
else:
NewSectionDict[Key] = [Statement]
-
Content += GenSection('Depex', NewSectionDict, False)
return Content
-
## GenUserExtensions
#
# GenUserExtensions
@@ -388,17 +559,18 @@
def GenUserExtensions(ModuleObject):
NewSectionDict = {}
for UserExtension in ModuleObject.GetUserExtensionList():
+ if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID and \
+ UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:
+ continue
if UserExtension.GetIdentifier() == 'Depex':
continue
Statement = UserExtension.GetStatement()
if not Statement:
continue
-
ArchList = UserExtension.GetSupArchList()
for Index in xrange(0, len(ArchList)):
ArchList[Index] = ConvertArchForInstall(ArchList[Index])
ArchList.sort()
-
KeyList = []
CommonPreFix = ''
if UserExtension.GetUserID():
@@ -410,17 +582,16 @@
if ArchList:
KeyList = [CommonPreFix + '.' + Arch for Arch in ArchList]
else:
- KeyList = [CommonPreFix]
-
+ KeyList = [CommonPreFix]
for Key in KeyList:
if Key in NewSectionDict:
NewSectionDict[Key] = NewSectionDict[Key] + [Statement]
else:
NewSectionDict[Key] = [Statement]
Content = GenSection('UserExtensions', NewSectionDict, False)
-
+
return Content
-
+
# GenSourceStatement
#
# @param SourceFile: string of source file path/name
@@ -432,23 +603,21 @@
#
# @retval Statement: The generated statement for source
#
-def GenSourceStatement(SourceFile, Family, FeatureFlag, TagName=None,
+def GenSourceStatement(SourceFile, Family, FeatureFlag, TagName=None,
ToolCode=None, HelpStr=None):
Statement = ''
if HelpStr:
- Statement += GenGenericCommentF(HelpStr)
+ Statement += GenGenericCommentF(HelpStr)
#
# format of SourceFile|Family|TagName|ToolCode|FeatureFlag
#
Statement += SourceFile
-
if TagName == None:
TagName = ''
if ToolCode == None:
ToolCode = ''
if HelpStr == None:
HelpStr = ''
-
if FeatureFlag:
Statement += '|' + Family + '|' + TagName + '|' + ToolCode + '|' +
FeatureFlag
elif ToolCode:
@@ -457,7 +626,6 @@
Statement += '|' + Family + '|' + TagName
elif Family:
Statement += '|' + Family
-
return Statement
# GenBinaryStatement
@@ -466,7 +634,7 @@
# @param Value: (Target, Family, TagName, Comment)
#
#
-def GenBinaryStatement(Key, Value):
+def GenBinaryStatement(Key, Value, SubTypeGuidValue=None):
(FileName, FileType, FFE, SortedArch) = Key
if SortedArch:
pass
@@ -477,14 +645,14 @@
Family = ''
TagName = ''
Comment = ''
-
if Comment:
Statement = GenGenericCommentF(Comment)
else:
Statement = ''
-
- Statement += FileType + '|' + FileName
-
+ if FileType == 'SUBTYPE_GUID' and SubTypeGuidValue:
+ Statement += FileType + '|' + SubTypeGuidValue + '|' + FileName
+ else:
+ Statement += FileType + '|' + FileName
if FileType in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST:
if FFE:
Statement += '|' + Target + '|' + FFE
@@ -499,9 +667,7 @@
Statement += '|' + Target + '|' + Family
elif Target:
Statement += '|' + Target
-
return Statement
-
## GenGuidSections
#
# @param GuidObjList: List of GuidObject
@@ -511,26 +677,21 @@
#
# generate [Guids] section
#
- Content = ''
+ Content = ''
GuidDict = Sdict()
-
for Guid in GuidObjList:
HelpTextList = Guid.GetHelpTextList()
HelpStr = _GetHelpStr(HelpTextList)
-
CName = Guid.GetCName()
FFE = Guid.GetFeatureFlag()
Statement = CName
if FFE:
Statement += '|' + FFE
-
Usage = Guid.GetUsage()
GuidType = Guid.GetGuidTypeList()[0]
VariableName = Guid.GetVariableName()
-
#
- # we need to differentiate the generic comment and usage comment
- # as multiple generic comment need to be put at first
+ # Differentiate the generic comment and usage comment as multiple
generic comment need to be put at first
#
if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:
# generate list of generic comment
@@ -543,17 +704,15 @@
Comment = ' # ' + Comment
else:
Comment = ''
-
if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:
- Comment = '## ' + Usage + Comment
+ Comment = '## ' + Usage + ' ## GUID ' + Comment
elif GuidType == 'Variable':
Comment = '## ' + Usage + ' ## ' + GuidType + ':' +
VariableName + Comment
else:
Comment = '## ' + Usage + ' ## ' + GuidType + Comment
-
+
if Comment:
Comment += '\n'
-
#
# merge duplicate items
#
@@ -562,18 +721,15 @@
SortedArch = ' '.join(ArchList)
if (Statement, SortedArch) in GuidDict:
PreviousComment = GuidDict[Statement, SortedArch]
- Comment = PreviousComment + Comment
+ Comment = PreviousComment + Comment
GuidDict[Statement, SortedArch] = Comment
-
-
- NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict)
-
+ NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict, 'INF_GUID')
#
# generate the section contents
#
if NewSectionDict:
Content = GenSection('Guids', NewSectionDict)
-
+
return Content
## GenProtocolPPiSections
@@ -587,19 +743,15 @@
for Object in ObjList:
HelpTextList = Object.GetHelpTextList()
HelpStr = _GetHelpStr(HelpTextList)
-
CName = Object.GetCName()
FFE = Object.GetFeatureFlag()
Statement = CName
if FFE:
Statement += '|' + FFE
-
Usage = Object.GetUsage()
Notify = Object.GetNotify()
-
#
- # we need to differentiate the generic comment and usage comment
- # as consecutive generic comment need to be put together
+ # Differentiate the generic comment and usage comment as consecutive
generic comment need to be put together
#
if Usage == DT.ITEM_UNDEFINED and Notify == '':
# generate list of generic comment
@@ -612,7 +764,6 @@
Comment = ' # ' + Comment
else:
Comment = ''
-
if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == '':
Comment = ''
else:
@@ -620,10 +771,8 @@
Comment = '## ' + Usage + ' ## ' + 'NOTIFY' + Comment
else:
Comment = '## ' + Usage + Comment
-
if Comment:
Comment += '\n'
-
#
# merge duplicate items
#
@@ -634,9 +783,7 @@
PreviousComment = Dict[Statement, SortedArch]
Comment = PreviousComment + Comment
Dict[Statement, SortedArch] = Comment
-
- NewSectionDict = GenMetaFileMisc.TransferDict(Dict)
-
+ NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL')
#
# generate the section contents
#
@@ -645,7 +792,7 @@
Content = GenSection('Protocols', NewSectionDict)
else:
Content = GenSection('Ppis', NewSectionDict)
-
+
return Content
## GenPcdSections
@@ -662,7 +809,6 @@
for Pcd in ModuleObject.GetPcdList():
HelpTextList = Pcd.GetHelpTextList()
HelpStr = _GetHelpStr(HelpTextList)
-
Statement = ''
CName = Pcd.GetCName()
TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()
@@ -673,7 +819,6 @@
else:
Dict = Sdict()
ItemTypeDict[ItemType] = Dict
-
FFE = Pcd.GetFeatureFlag()
Statement += TokenSpaceGuidCName + '.' + CName
if DefaultValue:
@@ -682,18 +827,14 @@
Statement += '|' + FFE
elif FFE:
Statement += '||' + FFE
-
#
# Generate comment
#
Usage = Pcd.GetValidUsage()
-
- #
# if FeatureFlag Pcd, then assume all Usage is CONSUMES
- #
if ItemType == DT.TAB_INF_FEATURE_PCD:
Usage = DT.USAGE_ITEM_CONSUMES
- if Usage == DT.ITEM_UNDEFINED or (ItemType ==
DT.TAB_INF_FEATURE_PCD):
+ if Usage == DT.ITEM_UNDEFINED:
# generate list of generic comment
Comment = GenGenericCommentF(HelpStr)
else:
@@ -704,12 +845,9 @@
Comment = ' # ' + Comment
else:
Comment = ''
-
Comment = '## ' + Usage + Comment
-
if Comment:
Comment += '\n'
-
#
# Merge duplicate entries
#
@@ -719,15 +857,11 @@
if (Statement, SortedArch) in Dict:
PreviousComment = Dict[Statement, SortedArch]
Comment = PreviousComment + Comment
- Dict[Statement, SortedArch] = Comment
-
+ Dict[Statement, SortedArch] = Comment
for ItemType in ItemTypeDict:
- #
# First we need to transfer the Dict to use SortedArch as key
- #
Dict = ItemTypeDict[ItemType]
- NewSectionDict = GenMetaFileMisc.TransferDict(Dict)
-
+ NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PCD')
if NewSectionDict:
Content += GenSection(ItemType, NewSectionDict)
#
@@ -736,7 +870,7 @@
else:
Content += GenAsBuiltPacthPcdSections(ModuleObject)
Content += GenAsBuiltPcdExSections(ModuleObject)
-
+
return Content
## GenPcdSections
@@ -746,8 +880,8 @@
PatchPcdDict = {}
for BinaryFile in ModuleObject.GetBinaryFileList():
if not BinaryFile.AsBuiltList:
- continue
- for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList:
+ continue
+ for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList:
TokenSpaceName = ''
PcdCName = PatchPcd.CName
PcdValue = PatchPcd.DefaultValue
@@ -758,31 +892,38 @@
HelpString = ''
for HelpStringItem in HelpTextList:
for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):
- HelpString += '# ' + HelpLine + '\n'
-
- TokenSpaceName, PcdCName =
GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,
-
TokenSpaceGuidValue,
+ HelpString += '## ' + HelpLine + '\n'
+ TokenSpaceName, PcdCName =
GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,
+
TokenSpaceGuidValue,
Token)
- if TokenSpaceName == '' or PcdCName == '':
- Logger.Error("Upt",
+ if TokenSpaceName == '' or PcdCName == '':
+ Logger.Error("Upt",
ToolError.RESOURCE_NOT_AVAILABLE,
-
ST.ERR_INSTALL_FILE_DEC_FILE_ERROR%(TokenSpaceGuidValue, Token),
- File=ModuleObject.GetFullPath())
- Statement = HelpString[:-3] + TokenSpaceName + '.' + PcdCName + '
| ' + PcdValue + ' | ' + PcdOffset
-
- if len(BinaryFile.SupArchList) == 0:
- if PatchPcdDict.has_key('COMMON'):
- PatchPcdDict['COMMON'].append(Statement)
+ ST.ERR_INSTALL_FILE_DEC_FILE_ERROR %
(TokenSpaceGuidValue, Token),
+ File=ModuleObject.GetFullPath())
+ Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' +
PcdValue + ' | ' + \
+ PcdOffset + DT.TAB_SPACE_SPLIT
+ #
+ # Use binary file's Arch to be Pcd's Arch
+ #
+ ArchList = []
+ FileNameObjList = BinaryFile.GetFileNameList()
+ if FileNameObjList:
+ ArchList = FileNameObjList[0].GetSupArchList()
+ if len(ArchList) == 0:
+ if PatchPcdDict.has_key(DT.TAB_ARCH_COMMON):
+ if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:
+ PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)
else:
- PatchPcdDict['COMMON'] = [Statement]
+ PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]
else:
- for Arch in BinaryFile.SupArchList:
+ for Arch in ArchList:
if PatchPcdDict.has_key(Arch):
- PatchPcdDict[Arch].append(Statement)
+ if Statement not in PatchPcdDict[Arch]:
+ PatchPcdDict[Arch].append(Statement)
else:
PatchPcdDict[Arch] = [Statement]
- return GenSection('PatchPcd', PatchPcdDict)
-
+ return GenSection(DT.TAB_INF_PATCH_PCD, PatchPcdDict)
## GenPcdSections
#
#
@@ -790,42 +931,49 @@
PcdExDict = {}
for BinaryFile in ModuleObject.GetBinaryFileList():
if not BinaryFile.AsBuiltList:
- continue
+ continue
for PcdExItem in BinaryFile.AsBuiltList[0].PcdExValueList:
TokenSpaceName = ''
PcdCName = PcdExItem.CName
- PcdValue = PcdExItem.DefaultValue
TokenSpaceGuidValue = PcdExItem.TokenSpaceGuidValue
Token = PcdExItem.Token
HelpTextList = PcdExItem.HelpTextList
HelpString = ''
for HelpStringItem in HelpTextList:
for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):
- HelpString += '# ' + HelpLine + '\n'
- TokenSpaceName, PcdCName =
GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,
+ HelpString += '## ' + HelpLine + '\n'
+ TokenSpaceName, PcdCName =
GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,
TokenSpaceGuidValue, Token)
-
- if TokenSpaceName == '' or PcdCName == '':
+ if TokenSpaceName == '' or PcdCName == '':
Logger.Error("Upt",
ToolError.RESOURCE_NOT_AVAILABLE,
-
ST.ERR_INSTALL_FILE_DEC_FILE_ERROR%(TokenSpaceGuidValue, Token),
- File=ModuleObject.GetFullPath())
-
- Statement = HelpString[:-3] + TokenSpaceName + '.' + PcdCName + '
| ' + PcdValue
-
- if len(BinaryFile.SupArchList) == 0:
+ ST.ERR_INSTALL_FILE_DEC_FILE_ERROR %
(TokenSpaceGuidValue, Token),
+ File=ModuleObject.GetFullPath())
+
+ Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName
+ DT.TAB_SPACE_SPLIT
+
+ #
+ # Use binary file's Arch to be Pcd's Arch
+ #
+ ArchList = []
+ FileNameObjList = BinaryFile.GetFileNameList()
+ if FileNameObjList:
+ ArchList = FileNameObjList[0].GetSupArchList()
+
+ if len(ArchList) == 0:
if PcdExDict.has_key('COMMON'):
PcdExDict['COMMON'].append(Statement)
else:
PcdExDict['COMMON'] = [Statement]
else:
- for Arch in BinaryFile.SupArchList:
+ for Arch in ArchList:
if PcdExDict.has_key(Arch):
- PcdExDict[Arch].append(Statement)
+ if Statement not in PcdExDict[Arch]:
+ PcdExDict[Arch].append(Statement)
else:
PcdExDict[Arch] = [Statement]
return GenSection('PcdEx', PcdExDict)
-
+
## GenSpecialSections
# generate special sections for Event/BootMode/Hob
#
@@ -843,7 +991,6 @@
HelpTextList = Obj.GetHelpTextList()
HelpStr = _GetHelpStr(HelpTextList)
CommentStr = GenGenericCommentF(HelpStr)
-
if SectionName == 'Hob':
Type = Obj.GetHobType()
elif SectionName == 'Event':
@@ -852,25 +999,20 @@
Type = Obj.GetSupportedBootModes()
else:
assert(SectionName)
-
Usage = Obj.GetUsage()
Statement = ' ' + Type + ' ## ' + Usage
-
if CommentStr in ['#\n', '#\n#\n']:
CommentStr = '#\n#\n#\n'
#
- # the first head comment line should start with '##\n',
- # if it starts with '#\n', then add one '#'
+ # the first head comment line should start with '##\n', if it starts
with '#\n', then add one '#'
# else add '##\n' to meet the format defined in INF spec
#
if CommentStr.startswith('#\n'):
CommentStr = '#' + CommentStr
elif CommentStr:
CommentStr = '##\n' + CommentStr
-
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits