## @file
# Generate AutoGen.h, AutoGen.c and *.depex files
#
# Copyright (c) 2007 - 2011, 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
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
## Import Modules
#
import os
import re
import copy
import GenC
import GenMake
import GenDepex
from StrGather import *
from Common.BuildToolError import *
from Workspace.BuildClassObject import *
## Regular expression for splitting Dependency Expression stirng into tokens
## Mapping Makefile type
## Build rule configuration file
## Build rule default version
## default file name for AutoGen
#
# Template string to generic AsBuilt INF
#
# ${module_name}
#
# DO NOT EDIT
# FILE auto-generated Binary INF
#
##
[Defines]
INF_VERSION = 0x00010016
BASE_NAME = ${module_name}
FILE_GUID = ${module_guid}
MODULE_TYPE = ${module_module_type}
VERSION_STRING = ${module_version_string}${BEGIN}
UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}
[Packages]${BEGIN}
${package_item}${END}
[Binaries.${module_arch}]${BEGIN}
${binary_item}${END}
[PcdEx]${BEGIN}
${pcd_item}${END}
## @AsBuilt${BEGIN}
## ${flags_item}${END}
""")
## Base class for AutoGen
#
# This class just implements the cache mechanism of AutoGen objects.
#
# database to maintain the objects of xxxAutoGen
## Factory method
#
# @param Class class object of real AutoGen class
# (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
# @param Workspace Workspace directory or WorkspaceAutoGen object
# @param MetaFile The path of meta file
# @param Target Build target
# @param Toolchain Tool chain name
# @param Arch Target arch
# @param *args The specific class related parameters
# @param **kwargs The specific class related dict parameters
#
# check if the object has been created
# call real constructor
return None
else:
return AutoGenObject
## hash() operator
#
# The file path of platform file will be used to represent hash value of this object
#
# @retval int Hash value of the file path of platform file
#
## str() operator
#
# The file path of platform file will be used to represent this object
#
# @retval string String of platform file path
#
## "==" operator
## Workspace AutoGen class
#
# This class is used mainly to control the whole platform build for different
# architecture. This class will generate top level makefile.
#
## Real constructor of WorkspaceAutoGen
#
# This method behaves the same as __init__ except that it needs explicit invoke
# (in super class's __new__ method)
#
# @param WorkspaceDir Root directory of workspace
# @param ActivePlatform Meta-file of active platform
# @param Target Build target
# @param Toolchain Tool chain name
# @param ArchList List of architecture of current build
# @param MetaFileDb Database containing meta-files
# @param BuildConfig Configuration of build
# @param ToolDefinition Tool chain definitions
# @param FlashDefinitionFile File of flash definition
# @param Fds FD list to be generated
# @param Fvs FV list to be generated
# @param Caps Capsule list to be generated
# @param SkuId SKU id from command line
#
BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,
Progress=None, BuildModule=None):
if Fds is None:
Fds = []
if Fvs is None:
Fvs = []
if Caps is None:
Caps = []
self.AutoGenObjectList = []
# there's many relative directory operations, so ...
#
# Merge Arch
#
else:
if not ArchList:
# Validate build target
ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"
# Validate SKU ID
ExtraData="SKU-ID [%s] is not supported by the platform. [Valid SKU-ID: %s]"
# parse FDF file to get PCDs in it, if any
if BuildModule:
if Progress:
#
# Mark now build in AutoGen Phase
#
"No such an FV in FDF file: %s" % fvname)
else:
PcdSet = {}
ModuleList = []
self.FdfProfile = None
if self.FdTargetList:
EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))
self.FdTargetList = []
if self.FvTargetList:
EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))
self.FvTargetList = []
if self.CapTargetList:
EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))
self.CapTargetList = []
# apply SKU and inject PCDs from Flash Definition file
DecPcds = {}
'build',
)
#
# Explicitly collect platform's dynamic PCDs
#
#
# Check PCDs token value conflict in each DEC file.
#
#
# Check PCD type and definition between DSC and DEC
#
self._MakeFileDir = None
self._BuildCommand = None
return True
## _CheckDuplicateInFV() method
#
# The check base on the file GUID;
#
_GuidDict = {}
#
# Get INF file GUID
#
if InfFoundFlag:
break
break
else:
"Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,
#
# Some INF files not have entity in DSC file.
#
if not InfFoundFlag:
#
# Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
# BuildObject from one of AutoGenObjectList is enough.
#
InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]
else:
"Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,
#
# If the NameGuid reference a PCD name.
# The style must match: PCD(xxxx.yyy)
#
#
# Replace the PCD value.
#
if not PcdFoundFlag:
#
# First convert from CFormatGuid to GUID string
#
if not _PcdGuidString:
#
# Then try Byte array.
#
if not _PcdGuidString:
#
# Not Byte array or CFormat GUID, raise error.
#
break
else:
"Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,
else:
#
# Two raw file GUID conflict.
#
"Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,
PcdTypeList = [
"FixedAtBuild", "PatchableInModule", "FeatureFlag",
"Dynamic", #"DynamicHii", "DynamicVpd",
"DynamicEx", # "DynamicExHii", "DynamicExVpd"
]
# This dict store PCDs which are not used by any modules with specified arches
# Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
# If no PCD type, this PCD comes from FDF
if not PcdType:
continue
# Try to remove Hii and Vpd suffix
PcdType = "DynamicEx"
PcdType = "Dynamic"
# VBox: Don't know exactly what the logic here should be, because Pcds may appear in several
# sections (see MdePkg.dec and MdeModulePkg.dec for examples), in which case we'll bum
# out here since only one of them will be according to the .dsc file, usually.
# Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
for Type in PcdTypeList:
'build',
"Type [%s] of PCD [%s.%s] in DSC file (%s) doesn't match the type [%s] defined in DEC file (%s)." \
ExtraData=None
)
#return -
if not KeyFound: # VBox: was 'else:' - see above.
'build',
"The PCD was not specified by any INF module in the platform for the given architecture.\n"
"\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
ExtraData=None
)
## Return the directory to store FV files
## Return the directory to store all intermediate and final files built
## Return the build output directory platform specifies
## Return platform name
## Return meta-file GUID
## Return platform version
## Return paths of tools
## Return directory of platform makefile
#
# @retval string Makefile directory
#
if self._MakeFileDir == None:
return self._MakeFileDir
## Return build command string
#
# @retval string Build command string
#
if self._BuildCommand == None:
# BuildCommand should be all the same. So just get one from platform AutoGen
return self._BuildCommand
## Check the PCDs token value conflict in each DEC file.
#
# Will cause build break and raise error message while two PCDs conflict.
#
# @return None
#
Count = 0
#
# Make sure in the same token space the TokenValue should be unique
#
else:
break;
#
# Sort same token value PCD list with TokenGuid and TokenCName
#
SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s"%(x.TokenSpaceGuidCName, x.TokenCName), "%s.%s"%(y.TokenSpaceGuidCName, y.TokenCName)))
if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):
'build',
"The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
% (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),
ExtraData=None
)
Count += 1
PcdList.sort(lambda x, y: cmp("%s.%s"%(x.TokenSpaceGuidCName, x.TokenCName), "%s.%s"%(y.TokenSpaceGuidCName, y.TokenCName)))
Count = 0
#
# Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
#
if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (Item.TokenValue != ItemNext.TokenValue):
'build',
"The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
ExtraData=None
)
Count += 1
## Create makefile for the platform and modules in it
#
# @param CreateDepsMakeFile Flag indicating if the makefile for
# modules will be created as well
#
# create makefile for platform
else:
## Create autogen code for platform and modules
#
# Since there's no autogen code for platform, this method will do nothing
# if CreateModuleCodeFile is set to False.
#
# @param CreateDepsCodeFile Flag indicating if creating module's
# autogen code file or not
#
if not CreateDepsCodeFile:
return
## Create AsBuilt INF file the platform
#
return
## AutoGen class for platform
#
# PlatformAutoGen class will process the original information in platform
# file in order to generate makefile for platform.
#
#
# Used to store all PCDs for both PEI and DXE phase, in order to generate
# correct PCD database
#
_DynaPcdList_ = []
_NonDynaPcdList_ = []
#
# The priority list while override build option
#
"0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
"0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
"0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
"0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
"0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
"0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
"0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
"0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
"0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
"0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
"0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
"0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
"0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
"0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
"0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
## The real constructor of PlatformAutoGen
#
# This method is not supposed to be called by users of PlatformAutoGen. It's
# only used by factory method __new__() to do real initialization work for an
# object of PlatformAutoGen
#
# @param Workspace WorkspaceAutoGen object
# @param PlatformFile Platform file (DSC file)
# @param Target Build target (DEBUG, RELEASE)
# @param Toolchain Name of tool chain
# @param Arch arch of the platform supports
#
self.SourceOverrideDir = None
self.AllPcdList = []
self._BuildRule = None
self._SourceDir = None
self._OutputDir = None
self._MakeFileDir = None
self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
self._ToolDefinitions = None
self._ToolChainFamily = None
self._BuildRuleFamily = None
self._PackageList = None
self._ModuleAutoGenList = None
self._LibraryAutoGenList = None
self._BuildCommand = None
return True
## Create autogen code for platform and modules
#
# Since there's no autogen code for platform, this method will do nothing
# if CreateModuleCodeFile is set to False.
#
# @param CreateModuleCodeFile Flag indicating if creating module's
# autogen code file or not
#
# only module has code to be greated, so do nothing if CreateModuleCodeFile is False
return
# don't do this twice
## Create makefile for the platform and mdoules in it
#
# @param CreateModuleMakeFile Flag indicating if the makefile for
# modules will be created as well
#
# no need to create makefile for the platform more than once
return
# create makefile for platform
else:
## Collect dynamic PCDs
#
# Gather dynamic PCDs list from each module and their settings from platform
# This interface should be invoked explicitly when platform action is created.
#
# for gathering error information
self._GuidValue = {}
#GuidValue.update(M.Guids)
# make sure that the "VOID*" kind of datum has MaxDatumSize set
NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))
#
# it should be stored in Pcd PEI database, If a dynamic only
# used by DXE module, it should be stored in DXE PCD database.
# The default Phase is DXE
#
# overwrite any the same PCD existing, if Phase is PEI
# print out error information and break the build, if error found
ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
#
# Sort dynamic PCD list to:
# 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
# try to be put header of dynamicd List
# 2) If PCD is HII type, the PCD item should be put after unicode type PCD
#
# The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
#
UnicodePcdArray = []
HiiPcdArray = []
OtherPcdArray = []
VpdPcdDict = {}
# just pick the a value to determine whether is unicode string type
# if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
# if found HII type PCD then insert to right of UnicodeIndex
else:
#
# Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
#
for PcdKey in PlatformPcds:
#
# Fix the optional data of VPD PCD.
#
Pcd.MaxDatumSize = None
else:
ExtraData="\n\tPCD: %s.%s format incorrect in DSC: %s\n\t\t\n"
# if the offset of a VPD is *, then it need to be fixed up by third party tool.
"Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")
#
# Fix the PCDs define in VPD PCD section that never referenced by module.
# An example is PCD for signature usage.
#
for DscPcd in PlatformPcds:
# This PCD has been referenced by module
# Not found, it should be signature
if not FoundFlag :
# just pick the a value to determine whether is unicode string type
# Need to iterate DEC pcd information to get the value & datumtype
# Print warning message to let the developer make a determine.
ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \
# Only fix the value while no value provided in DSC file.
# if the offset of a VPD is *, then it need to be fixed up by third party tool.
"Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))
try:
except:
# retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
BPDGToolName = None
EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)
break
# Call third party GUID BPDG tool.
if BPDGToolName != None:
else:
EdkLogger.error("Build", FILE_NOT_FOUND, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")
# Process VPD map file generated by third party BPDG tool
# Fixup "*" offset
# just pick the a value to determine whether is unicode string type
else:
EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)
# Delete the DynamicPcdList At the last time enter into this function
del self._DynamicPcdList[:]
## Return the platform build data object
## Return platform name
## Return the meta file GUID
## Return the platform version
## Return the FDF file name
else:
## Return the build output directory platform specifies
## Return the directory to store all intermediate and final files built
)
else:
)
## Return directory of platform makefile
#
# @retval string Makefile directory
#
if self._MakeFileDir == None:
return self._MakeFileDir
## Return build command string
#
# @retval string Build command string
#
if self._BuildCommand == None:
self._BuildCommand = []
if NewOption != '':
return self._BuildCommand
## Get tool chain definition
#
# Get each tool defition for given tool chain from tools_def.txt and platform
#
if self._ToolDefinitions == None:
self._ToolDefinitions = {}
DllPathList = set()
for Def in ToolDefinition:
continue
# don't record the DLL
if Attr == "DLL":
continue
ToolsDef = ''
MakePath = ''
MakeFlags = ''
# check if override is indicated
else:
if Attr == "PATH":
# Don't put MAKE definition in the file
if Tool == "MAKE":
else:
elif Attr != "DLL":
# Don't put MAKE definition in the file
if Tool == "MAKE":
if Attr == "FLAGS":
else:
ToolsDef += "\n"
for DllPath in DllPathList:
return self._ToolDefinitions
## Return the paths of tools
if self._ToolDefFile == None:
return self._ToolDefFile
## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
if self._ToolChainFamily == None:
if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \
else:
return self._ToolChainFamily
if self._BuildRuleFamily == None:
if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \
else:
return self._BuildRuleFamily
## Return the build options specific for all modules in this platform
if self._BuildOption == None:
return self._BuildOption
## Return the build options specific for EDK modules in this platform
if self._EdkBuildOption == None:
return self._EdkBuildOption
## Return the build options specific for EDKII modules in this platform
if self._EdkIIBuildOption == None:
return self._EdkIIBuildOption
## Parse build_rule.txt in $(WORKSPACE)/Conf/build_rule.txt
#
# @retval BuildRule object
#
if self._BuildRule == None:
BuildRuleFile = None
if BuildRuleFile in [None, '']:
else:
# If Build Rule's version is less than the version number required by the tools, halting the build.
ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\
return self._BuildRule
## Summarize the packages used by modules in this platform
if self._PackageList == None:
# VBox: The order of the package list is (or was) relevant to one or more
# loops, so don't use set.update() but the slower manual updating.
if False: # Original - undefined update order.
else: # VBox - always update by appending new dependencies.
self._PackageList = []
return self._PackageList
## Get list of non-dynamic PCDs
if self._NonDynamicPcdList == None:
return self._NonDynamicPcdList
## Get list of dynamic PCDs
if self._DynamicPcdList == None:
return self._DynamicPcdList
## Generate Token Number for all PCD
if self._PcdTokenNumber == None:
TokenNumber = 1
#
# Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
# Such as:
#
# Dynamic PCD:
# TokenNumber 0 ~ 10
# DynamicEx PCD:
# TokeNumber 11 ~ 20
#
EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
TokenNumber += 1
EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
TokenNumber += 1
EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
TokenNumber += 1
EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
TokenNumber += 1
TokenNumber += 1
return self._PcdTokenNumber
self._ModuleAutoGenList = []
self._LibraryAutoGenList = []
Ma = ModuleAutoGen(
)
## Summarize ModuleAutoGen objects of all modules to be built for this platform
if self._ModuleAutoGenList == None:
return self._ModuleAutoGenList
## Summarize ModuleAutoGen objects of all libraries to be built for this platform
if self._LibraryAutoGenList == None:
return self._LibraryAutoGenList
## Test if a module is supported by the platform
#
# An error will be raised directly if the module or its arch is not supported
# by the platform or current configuration
#
## Resolve the library classes in a module to library instances
#
# This method will not only resolve library classes but also sort the library
# instances according to the dependency-ship.
#
# @param Module The module from which the library classes will be resolved
#
# @retval library_list List of library instances sorted
#
# for overridding library instances with module specific setting
# add forced library instances (specified under LibraryClasses sections)
#
# If a module has a MODULE_TYPE of USER_DEFINED,
# do not link in NULL library class instances from the global [LibraryClasses.*] sections.
#
if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
# add forced library instances (specified in module overrides)
# EdkII module
Constructor = []
ConsumedByList = sdict()
LibraryInstance = sdict()
M = LibraryConsumerList.pop()
for LibraryClassName in M.LibraryClasses:
if LibraryClassName not in LibraryInstance:
# override library instance for this module
else:
"Instance of library class [%s] is not found" % LibraryClassName,
# for those forced library instance (NULL library), add a fake library class
elif LibraryModule.LibraryClass == None \
or (ModuleType != 'USER_DEFINED'
# only USER_DEFINED can link against any library instance despite of its SupModList
"Module type [%s] is not supported by library instance [%s]" \
else:
if LibraryModule == None:
continue
if LibraryModule not in ConsumedByList:
ConsumedByList[LibraryModule] = []
# don't add current module itself to consumer list
if M != Module:
if M in ConsumedByList[LibraryModule]:
continue
#
# Initialize the sorted output list to the empty set
#
SortedLibraryList = []
#
# Q <- Set of all nodes with no incoming edges
#
LibraryList = [] #LibraryInstance.values()
Q = []
for LibraryClassName in LibraryInstance:
if ConsumedByList[M] == []:
Q.append(M)
#
# start the DAG algorithm
#
while True:
while Q == [] and EdgeRemoved:
# for each node Item with a Constructor
for Item in LibraryList:
if Item not in Constructor:
continue
# for each Node without a constructor with an edge e from Item to Node
if Node in Constructor:
continue
# remove edge e from the graph if Node has no constructor
if ConsumedByList[Item] == []:
# insert Item into Q
break
if Q != []:
break
# DAG is done if there's no more incoming edge for all nodes
if Q == []:
break
# remove node from Q
# output Node
# for each node Item with an edge e from Node to Item do
for Item in LibraryList:
continue
# remove edge e from the graph
if ConsumedByList[Item] != []:
continue
# insert Item into Q, if Item has no other incoming edges
#
# if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
#
for Item in LibraryList:
if Item not in SortedLibraryList:
#
# Build the list of constructor and destructir names
# The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
#
return SortedLibraryList
## Override PCD setting (type, value, ...)
#
# @param ToPcd The PCD to be overrided
# @param FromPcd The PCD overrideing from
#
#
# in case there's PCDs coming from FDF file, which have no type given.
# at this point, ToPcd.Type has the type found from dependent
# package
#
if FromPcd != None:
ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
# check the validation of datum
if not IsValid:
if Value in [None, '']:
else:
# apply default SKU for dynamic PCDS if specified one is not available
else:
SkuName = 'DEFAULT'
ToPcd.SkuInfoList = {
SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)
}
## Apply PCD setting defined platform to a module
#
# @param Module The module from which the PCD setting will be overrided
#
# @retval PCD_list The list PCDs with settings from platform
#
# for each PCD in module
# find out the PCD setting in platform
else:
PcdInPlatform = None
# then override the settings if any
# resolve the VariableGuid value
if Sku.VariableGuidValue == None:
'build',
)
# override PCD settings with module specific setting
## Resolve library names to library modules
#
# (for Edk.x modules)
#
# @param Module The module from which the library names will be resolved
#
# @retval library_list The list of library modules
#
# "CompilerStub" is a must for Edk modules
LibraryList = []
M = LibraryConsumerList.pop()
for LibraryName in M.Libraries:
if Library == None:
break
if Library == None:
continue
if Library not in LibraryList:
return LibraryList
## Calculate the priority value of the build option
#
# @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
#
# @retval Value Priority value based on the priority list.
#
PriorityValue = 0x11111
if Target == "*":
PriorityValue &= 0x01111
if ToolChain == "*":
PriorityValue &= 0x10111
if Arch == "*":
PriorityValue &= 0x11011
if CommandType == "*":
PriorityValue &= 0x11101
if Attr == "*":
PriorityValue &= 0x11110
## Expand * in build option key
#
# @param Options Options to be expanded
#
# @retval options Options expanded
#
BuildOptions = {}
OverrideList = {}
#
# Construct a list contain the build options which need override.
#
#
# Key[0] -- tool family
# Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
#
#
# Use the highest priority value.
#
#
# Compare two Key, if one is included by another, choose the higher priority one
#
else:
# Check Module style is EDK or EDKII.
# Only append build option for the matched style module.
continue
continue
# if tool chain family doesn't match, skip it
continue
continue
# expand any wildcard
if Tool not in BuildOptions:
BuildOptions[Tool] = {}
else:
# append options for the same tool
# Build Option Family has been checked, which need't to be checked again for family.
if FamilyMatch or FamilyIsNull:
return BuildOptions
# Check Module style is EDK or EDKII.
# Only append build option for the matched style module.
continue
continue
# if tool chain family doesn't match, skip it
continue
# option has been added before
continue
# expand any wildcard
if Tool not in BuildOptions:
BuildOptions[Tool] = {}
else:
# append options for the same tool
return BuildOptions
## Append build options in platform to a module
#
# @param Module The module to which the build options will be appened
#
# @retval options The options appended with build options in platform
#
# Get the different options for the different style module
else:
else:
AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + self.ToolDefinition.keys())
BuildOptions = {}
if Tool not in BuildOptions:
BuildOptions[Tool] = {}
continue
# check if override is indicated
else:
#
# Override UNI flag only for EDK module.
#
if 'BUILD' not in BuildOptions:
BuildOptions['BUILD'] = {}
return BuildOptions
PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
## ModuleAutoGen class
#
# This class encapsules the AutoGen behaviors for the build tools. In addition to
# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
# to the [depex] section in module's inf file.
#
## The real constructor of ModuleAutoGen
#
# This method is not supposed to be called by users of ModuleAutoGen. It's
# only used by factory method __new__() to do real initialization work for an
# object of ModuleAutoGen
#
# @param Workspace EdkIIWorkspaceBuild object
# @param ModuleFile The path of module file
# @param Target Build target (DEBUG, RELEASE)
# @param Toolchain Name of tool chain
# @param Arch The arch the module supports
# @param PlatformFile Platform meta-file
#
# check if this module is employed by active platform
return False
self.SourceOverrideDir = None
# use overrided path defined in DSC file
self._ModuleType = None
self._ComponentType = None
self._PcdIsDriver = None
self._AutoGenVersion = None
self._LibraryFlag = None
self._CustomMakefile = None
self._OutputDir = None
self._MakeFileDir = None
self._IncludePathList = None
self._AutoGenFileList = None
self._UnicodeFileList = None
self._SourceFileList = None
self._ObjectFileList = None
self._BinaryFileList = None
self._DependentPackageList = None
self._DependentLibraryList = None
self._LibraryAutoGenList = None
self._DerivedPackageList = None
self._ModulePcdList = None
self._LibraryPcdList = None
self._ProtocolList = None
self._DepexList = None
self._DepexExpressionList = None
self._BuildOption = None
self._BuildOptionIncPathList = None
self._BuildTargets = None
self._IntroBuildTargetList = None
self._FinalBuildTargetList = None
self._FileTypes = None
self._BuildRules = None
return True
# Macros could be used in build_rule.txt (also Makefile)
## Return the module build data object
self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
## Return the module name
## Return the module DxsFile if exist
## Return the module SourceOverridePath
## Return the module meta-file GUID
## Return the module version
## Return the module type
## Return the component type (for Edk.x style of module)
## Return the build type
## Return the PCD_IS_DRIVER setting
## Return the autogen version, i.e. module meta-file version
## Check if the module is library or not
if self._LibraryFlag == None:
else:
return self._LibraryFlag
## Return the directory to store intermediate files of the module
)
## Return the directory to store the intermediate object files of the mdoule
if self._OutputDir == None:
return self._OutputDir
## Return the directory to store auto-gened source files of the mdoule
## Return the path of custom file
if self._CustomMakefile == None:
self._CustomMakefile = {}
if Type in gMakeTypeMap:
else:
MakeType = 'nmake'
if self.SourceOverrideDir != None:
else:
return self._CustomMakefile
## Return the directory of the makefile
#
# @retval string The directory string of module's makefile
#
## Return build command string
#
# @retval string Build command string
#
## Get object list of all packages the module and its dependent libraries belong to
#
# @retval list The list of package object
#
PackageList = []
if Package in PackageList:
continue
return PackageList
## Merge dependency expression
#
# @retval list The token list of the dependency expression after parsed
#
if self._DepexList == None:
self._DepexList = {}
return self._DepexList
#
# Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
#
if DepexList != []:
if Inherited:
break
return self._DepexList
## Merge dependency expression
#
# @retval list The token list of the dependency expression after parsed
#
if self._DepexExpressionList == None:
self._DepexExpressionList = {}
return self._DepexExpressionList
#
# Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
#
if DepexExpressionList != '':
DepexExpressionList += ' AND '
DepexExpressionList += '('
DepexExpressionList += D
DepexExpressionList += ')'
if Inherited:
break
return self._DepexExpressionList
## Return the list of specification version required for the module
#
# @retval list The list of specification defined in module file
#
## Tool option for the module build
#
# @param PlatformInfo The object of PlatformBuildInfo
# @retval dict The dict containing valid options
#
if self._BuildOption == None:
return self._BuildOption
## Get include path list from tool option for the module build
#
# @retval list The include path list
#
if self._BuildOptionIncPathList == None:
#
# Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
# is the former use /I , the Latter used -I to specify include directories
#
else:
#
# New ToolChainFamily, don't known whether there is option to specify include directories
#
return self._BuildOptionIncPathList
Attr = 'FLAGS'
try:
except KeyError:
FlagOption = ''
else:
#
# RVCT may specify a list of directory seperated by commas
#
IncPathList = []
#
# EDK II modules must not reference header files outside of the packages they depend on or
# within the module's directory tree. Report error if violation.
#
for Path in IncPathList:
if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):
ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)
return self._BuildOptionIncPathList
## Return a list of files which can be built from source
#
# What kind of files can be built is determined by build rules in
# $(WORKSPACE)/Conf/build_rule.txt and toolchain family.
#
if self._SourceFileList == None:
self._SourceFileList = []
# match tool chain
continue
# match tool chain family
"The file [%s] must be built by tools of [%s], " \
"but current toolchain family is [%s]" \
continue
# add the file path into search path list for file including
return self._SourceFileList
## Return the list of unicode files
if self._UnicodeFileList == None:
else:
self._UnicodeFileList = []
return self._UnicodeFileList
## Return a list of files which can be built from binary
#
# "Build" binary files are just to copy them to build directory.
#
# @retval list The list of files which can be built later
#
if self._BinaryFileList == None:
self._BinaryFileList = []
continue
return self._BinaryFileList
if self._BuildRules == None:
BuildRules = {}
#first try getting build rule by BuildRuleFamily
if not RuleObject:
# build type is always module type, but ...
#second try getting build rule by ToolChainFamily
if not RuleObject:
if not RuleObject:
# build type is always module type, but ...
if not RuleObject:
continue
return self._BuildRules
if self._BuildTargets == None:
self._BuildTargets = {}
self._FileTypes = {}
LastTarget = None
RuleChain = []
SourceList = [File]
Index = 0
if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:
# Skip all files that are not binary libraries
continue
else:
# stop at no more rules
if LastTarget:
break
# stop at STATIC_LIBRARY for library
if LastTarget:
break
if not Target:
if LastTarget:
break
# Only do build for target with outputs
# to avoid cyclic rule
break
if self._BuildTargets == None:
self._BuildTargets = {}
self._FileTypes = {}
#TRICK: call _GetSourceFileList to apply build rule for source files
if self.SourceFileList:
pass
#TRICK: call _GetBinaryFileList to apply build rule for binary files
if self.BinaryFileList:
pass
return self._BuildTargets
return self._IntroBuildTargetList
return self._FinalBuildTargetList
return self._FileTypes
## Get the list of package object the module depends on
#
# @retval list The package object list
#
## Return the list of auto-generated code file
#
# @retval list The list of auto-generated file
#
if self._AutoGenFileList == None:
self._AutoGenFileList = {}
if UniStringBinBuffer != None:
return self._AutoGenFileList
## Return the list of library modules explicitly or implicityly used by this module
if self._DependentLibraryList == None:
# only merge library classes and PCD for non-library module
else:
else:
return self._DependentLibraryList
## Get the list of PCDs from current module
#
# @retval list The list of PCD
#
if self._ModulePcdList == None:
# apply PCD settings from platform
return self._ModulePcdList
## Get the list of PCDs from dependent libraries
#
# @retval list The list of PCD
#
if self._LibraryPcdList == None:
# get PCDs from dependent libraries
# skip duplicated PCDs
continue
# apply PCD settings from platform
else:
self._LibraryPcdList = []
return self._LibraryPcdList
## Get the GUID value mapping
#
# @retval dict The mapping between GUID cname and its value
#
## Get the protocol value mapping
#
# @retval dict The mapping between protocol cname and its value
#
if self._ProtocolList == None:
return self._ProtocolList
## Get the PPI value mapping
#
# @retval dict The mapping between PPI cname and its value
#
## Get the list of include search path
#
# @retval list The list path
#
if self._IncludePathList == None:
self._IncludePathList = []
# for Edk modules
# Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
else:
return self._IncludePathList
## Create AsBuilt INF file the module
#
return
# Skip the following code for EDK I inf
return
# Skip the following code for libraries
return
# Skip the following code for modules with no source files
return
# Skip the following code for modules without any binary files
return
### TODO: How to handles mixed source and binary modules
# Find all DynamicEx PCDs used by this module and dependent libraries
# Also find all packages that the DynamicEx PCDs depend on
Pcds = []
Packages = []
ModuleType = 'DXE_DRIVER'
AsBuiltInfDict = {
'module_module_type' : ModuleType,
'module_uefi_specification_version' : [],
'module_pi_specification_version' : [],
'binary_item' : [],
'pcd_item' : [],
'flags_item' : []
}
AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]
AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]
else:
else:
else:
if self.DepexGenerated:
AsBuiltInfDict['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip())]
## Create makefile for the module and its dependent libraries
#
# @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
# dependent libraries will be created
#
return
else:
else:
## Create autogen code for the module and its dependent libraries
#
# @param CreateLibraryCodeFile Flag indicating if or not the code of
# dependent libraries will be created
#
return
AutoGenList = []
IgoredAutoGenList = []
#Ignore Edk AutoGen.c
continue
else:
# Skip the following code for EDK I inf
return
# Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
continue
else:
if IgoredAutoGenList == []:
elif AutoGenList == []:
else:
return AutoGenList
## Summarize the ModuleAutoGen objects of all libraries used by this module
if self._LibraryAutoGenList == None:
self._LibraryAutoGenList = []
La = ModuleAutoGen(
)
return self._LibraryAutoGenList
# This acts like the main() function for the script, unless it is 'import'ed into another script.
if __name__ == '__main__':
pass