Skip to content

Commit

Permalink
BaseTools:Add [packages] section in dsc file
Browse files Browse the repository at this point in the history
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=2270

Currently a PCD (e.g. FeaturePCD) cannot be used in a conditional
statement in a DSC/FDF file without a module in the build referencing
the PCD package DEC file.

An example implementation that to support this is to allow a [Packages]
section in the DSC file to list additional package dependencies for PCD
references in the package DSC/FDF files.

this patch is going to  add the ability to have the [packages] section
defined in the DSC file

Cc: Liming Gao <[email protected]>
Cc: Bob Feng <[email protected]>
Signed-off-by: Zhiju.Fan <[email protected]>
Acked-by: Liming Gao <[email protected]>
Reviewed-by: Bob Feng <[email protected]>
  • Loading branch information
zhijufan authored and mergify[bot] committed Nov 20, 2019
1 parent 7607174 commit bf1ea93
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 7 deletions.
29 changes: 23 additions & 6 deletions BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,14 +462,31 @@ def MakeFileDir(self):
def BuildCommand(self):
return self.PlatformInfo.BuildCommand

## Get object list of all packages the module and its dependent libraries belong to
## Get Module package and Platform package
#
# @retval list The list of package object
#
@cached_property
def PackageList(self):
PkagList = []
if self.Module.Packages:
PkagList.extend(self.Module.Packages)
Platform = self.BuildDatabase[self.PlatformInfo.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
for Package in Platform.Packages:
if Package in PkagList:
continue
PkagList.append(Package)
return PkagList

## Get object list of all packages the module and its dependent libraries belong to and the Platform depends on
#
# @retval list The list of package object
#
@cached_property
def DerivedPackageList(self):
PackageList = []
for M in [self.Module] + self.DependentLibraryList:
PackageList.extend(self.PackageList)
for M in self.DependentLibraryList:
for Package in M.Packages:
if Package in PackageList:
continue
Expand Down Expand Up @@ -938,13 +955,13 @@ def FileTypes(self):
self.Targets
return self._FileTypes

## Get the list of package object the module depends on
## Get the list of package object the module depends on and the Platform depends on
#
# @retval list The package object list
#
@cached_property
def DependentPackageList(self):
return self.Module.Packages
return self.PackageList

## Return the list of auto-generated code file
#
Expand Down Expand Up @@ -1101,7 +1118,7 @@ def IncludePathList(self):
RetVal.append(self.MetaFile.Dir)
RetVal.append(self.DebugDir)

for Package in self.Module.Packages:
for Package in self.PackageList:
PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)
if PackageDir not in RetVal:
RetVal.append(PackageDir)
Expand All @@ -1125,7 +1142,7 @@ def IncludePathLength(self):
@cached_property
def PackageIncludePathList(self):
IncludesList = []
for Package in self.Module.Packages:
for Package in self.PackageList:
PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)
IncludesList = Package.Includes
if Package._PrivateIncludes:
Expand Down
1 change: 1 addition & 0 deletions BaseTools/Source/Python/AutoGen/PlatformAutoGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ def PackageList(self):
continue
ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]
RetVal.update(ModuleData.Packages)
RetVal.update(self.Platform.Packages)
return list(RetVal)

@cached_property
Expand Down
1 change: 1 addition & 0 deletions BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def PkgSet(self):
continue
ModuleData = self.BuildDatabase[ModuleFile, Arch, self.BuildTarget, self.ToolChain]
PkgSet.update(ModuleData.Packages)
PkgSet.update(Platform.Packages)
Pkgs[Arch] = list(PkgSet)
return Pkgs

Expand Down
1 change: 1 addition & 0 deletions BaseTools/Source/Python/Common/DataType.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@
PCDS_DYNAMICEX_VPD.upper(),
PCDS_DYNAMICEX_HII.upper(),
TAB_BUILD_OPTIONS.upper(),
TAB_PACKAGES.upper(),
TAB_INCLUDES.upper()}

#
Expand Down
23 changes: 22 additions & 1 deletion BaseTools/Source/Python/Workspace/DscBuildData.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,24 @@ def OverrideDuplicateModule(self):
self._RawData.DisableOverrideComponent(Components[(file_guid_str,str(ModuleFile))])
Components[(file_guid_str,str(ModuleFile))] = ModuleId
self._RawData._PostProcessed = False

## Retrieve packages this Platform depends on
@cached_property
def Packages(self):
RetVal = set()
RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch]
Macros = self._Macros
for Record in RecordList:
File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
# check the file validation
ErrorCode, ErrorInfo = File.Validate('.dec')
if ErrorCode != 0:
LineNo = Record[-1]
EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
# parse this package now. we need it to get protocol/ppi/guid value
RetVal.add(self._Bdb[File, self._Arch, self._Target, self._Toolchain])
return RetVal

## Retrieve [Components] section information
@property
def Modules(self):
Expand Down Expand Up @@ -896,7 +914,8 @@ def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo):
continue
ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
PkgSet.update(ModuleData.Packages)

if self.Packages:
PkgSet.update(self.Packages)
self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain, PkgSet)
self._GuidDict.update(GlobalData.gPlatformPcds)

Expand Down Expand Up @@ -3320,6 +3339,8 @@ def DecPcds(self):
continue
ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
PkgSet.update(ModuleData.Packages)
if self.Packages:
PkgSet.update(self.Packages)
self._DecPcds, self._GuidDict = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain, PkgSet)
self._GuidDict.update(GlobalData.gPlatformPcds)
return self._DecPcds
14 changes: 14 additions & 0 deletions BaseTools/Source/Python/Workspace/MetaFileParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def __init__(self, FilePath, FileType, Arch, Table, Owner= -1, From= -1):
self.MetaFile = FilePath
self._FileDir = self.MetaFile.Dir
self._Defines = {}
self._Packages = []
self._FileLocalMacros = {}
self._SectionsMacroDict = defaultdict(dict)

Expand Down Expand Up @@ -352,6 +353,13 @@ def _SectionHeaderParser(self):
# If the section information is needed later, it should be stored in database
self._ValueList[0] = self._SectionName

## [packages] section parser
@ParseMacro
def _PackageParser(self):
self._CurrentLine = CleanString(self._CurrentLine)
self._Packages.append(self._CurrentLine)
self._ValueList[0] = self._CurrentLine

## [defines] section parser
@ParseMacro
def _DefineParser(self):
Expand Down Expand Up @@ -849,6 +857,7 @@ class DscParser(MetaFileParser):
TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,
TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,
TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,
TAB_PACKAGES.upper() : MODEL_META_DATA_PACKAGE,
TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,
TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,
TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,
Expand Down Expand Up @@ -1340,6 +1349,7 @@ def _PostProcess(self):
MODEL_META_DATA_DEFINE : self.__ProcessDefine,
MODEL_META_DATA_GLOBAL_DEFINE : self.__ProcessDefine,
MODEL_META_DATA_INCLUDE : self.__ProcessDirective,
MODEL_META_DATA_PACKAGE : self.__ProcessPackages,
MODEL_META_DATA_CONDITIONAL_STATEMENT_IF : self.__ProcessDirective,
MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE : self.__ProcessDirective,
MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF : self.__ProcessDirective,
Expand Down Expand Up @@ -1643,6 +1653,9 @@ def __ProcessDirective(self):
self._ValueList = None
self._ContentIndex -= 1

def __ProcessPackages(self):
self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros)

def __ProcessSkuId(self):
self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=True)
for Value in self._ValueList]
Expand Down Expand Up @@ -1721,6 +1734,7 @@ def DisableOverrideComponent(self,module_id):
MODEL_META_DATA_COMPONENT : _ComponentParser,
MODEL_META_DATA_BUILD_OPTION : _BuildOptionParser,
MODEL_UNKNOWN : MetaFileParser._Skip,
MODEL_META_DATA_PACKAGE : MetaFileParser._PackageParser,
MODEL_META_DATA_USER_EXTENSION : MetaFileParser._SkipUserExtension,
MODEL_META_DATA_SECTION_HEADER : MetaFileParser._SectionHeaderParser,
MODEL_META_DATA_SUBSECTION_HEADER : _SubsectionHeaderParser,
Expand Down
2 changes: 2 additions & 0 deletions BaseTools/Source/Python/Workspace/WorkspaceCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __missing__(self, key):
#
def GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain):
PkgSet = set()
if Platform.Packages:
PkgSet.update(Platform.Packages)
for ModuleFile in Platform.Modules:
Data = BuildDatabase[ModuleFile, Arch, Target, Toolchain]
PkgSet.update(Data.Packages)
Expand Down
4 changes: 4 additions & 0 deletions BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def GetPackageList(self, Platform, Arch, TargetName, ToolChainTag):
for Package in LibObj.Packages:
if Package not in PackageList:
PackageList.append(Package)
for Package in Pa.Packages:
if Package in PackageList:
continue
PackageList.append(Package)

return PackageList

Expand Down

0 comments on commit bf1ea93

Please sign in to comment.