X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FGenMake.py;h=4f85a93055abb6e09d6c988d269224b372d888e8;hb=7809492c10e8950a1b92581e6e87c6a4be069077;hp=a373507422403e6b40ba882ecab90364ae39b9c6;hpb=6fcd911c328648497960119569fa0849d52fbcfc;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
old mode 100644
new mode 100755
index a373507422..4f85a93055
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -2,17 +2,12 @@
# Create makefile for MS nmake and GNU make
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
#
## Import Modules
#
+from __future__ import absolute_import
import Common.LongFilePathOs as os
import sys
import string
@@ -22,13 +17,14 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.MultipleWorkspace import MultipleWorkspace as mws
from Common.BuildToolError import *
from Common.Misc import *
-from Common.String import *
-from BuildEngine import *
+from Common.StringUtils import *
+from .BuildEngine import *
import Common.GlobalData as GlobalData
from collections import OrderedDict
+from Common.DataType import TAB_COMPILER_MSFT
## Regular expression for finding header file inclusions
-gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)
+gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE)
## Regular expression for matching macro used in header file inclusion
gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE)
@@ -165,7 +161,7 @@ class BuildFile(object):
"gmake" : "include"
}
- _INC_FLAG_ = {"MSFT" : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I"}
+ _INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"}
## Constructor of BuildFile
#
@@ -433,9 +429,8 @@ cleanlib:
self.CommonFileDependency = []
self.FileListMacros = {}
self.ListFileMacros = {}
-
+ self.ObjTargetDict = OrderedDict()
self.FileCache = {}
- self.FileDependency = []
self.LibraryBuildCommandList = []
self.LibraryFileList = []
self.LibraryMakefileList = []
@@ -454,63 +449,58 @@ cleanlib:
self.FfsOutputFileList = []
# Compose a dict object containing information used to do replacement in template
- def _CreateTemplateDict(self):
+ @property
+ def _TemplateDict(self):
if self._FileType not in self._SEP_:
EdkLogger.error("build", PARAMETER_INVALID, "Invalid Makefile type [%s]" % self._FileType,
ExtraData="[%s]" % str(self._AutoGenObject))
+ MyAgo = self._AutoGenObject
Separator = self._SEP_[self._FileType]
# break build if no source files and binary files are found
- if len(self._AutoGenObject.SourceFileList) == 0 and len(self._AutoGenObject.BinaryFileList) == 0:
+ if len(MyAgo.SourceFileList) == 0 and len(MyAgo.BinaryFileList) == 0:
EdkLogger.error("build", AUTOGEN_ERROR, "No files to be built in module [%s, %s, %s]"
- % (self._AutoGenObject.BuildTarget, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch),
- ExtraData="[%s]" % str(self._AutoGenObject))
+ % (MyAgo.BuildTarget, MyAgo.ToolChain, MyAgo.Arch),
+ ExtraData="[%s]" % str(MyAgo))
# convert dependent libraries to build command
self.ProcessDependentLibrary()
- if len(self._AutoGenObject.Module.ModuleEntryPointList) > 0:
- ModuleEntryPoint = self._AutoGenObject.Module.ModuleEntryPointList[0]
+ if len(MyAgo.Module.ModuleEntryPointList) > 0:
+ ModuleEntryPoint = MyAgo.Module.ModuleEntryPointList[0]
else:
ModuleEntryPoint = "_ModuleEntryPoint"
- # Intel EBC compiler enforces EfiMain
- if self._AutoGenObject.AutoGenVersion < 0x00010005 and self._AutoGenObject.Arch == "EBC":
- ArchEntryPoint = "EfiMain"
- else:
- ArchEntryPoint = ModuleEntryPoint
+ ArchEntryPoint = ModuleEntryPoint
- if self._AutoGenObject.Arch == "EBC":
+ if MyAgo.Arch == "EBC":
# EBC compiler always use "EfiStart" as entry point. Only applies to EdkII modules
ImageEntryPoint = "EfiStart"
- elif self._AutoGenObject.AutoGenVersion < 0x00010005:
- # Edk modules use entry point specified in INF file
- ImageEntryPoint = ModuleEntryPoint
else:
# EdkII modules always use "_ModuleEntryPoint" as entry point
ImageEntryPoint = "_ModuleEntryPoint"
- for k, v in self._AutoGenObject.Module.Defines.iteritems():
- if k not in self._AutoGenObject.Macros:
- self._AutoGenObject.Macros[k] = v
+ for k, v in MyAgo.Module.Defines.items():
+ if k not in MyAgo.Macros:
+ MyAgo.Macros[k] = v
- if 'MODULE_ENTRY_POINT' not in self._AutoGenObject.Macros:
- self._AutoGenObject.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint
- if 'ARCH_ENTRY_POINT' not in self._AutoGenObject.Macros:
- self._AutoGenObject.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint
- if 'IMAGE_ENTRY_POINT' not in self._AutoGenObject.Macros:
- self._AutoGenObject.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint
+ if 'MODULE_ENTRY_POINT' not in MyAgo.Macros:
+ MyAgo.Macros['MODULE_ENTRY_POINT'] = ModuleEntryPoint
+ if 'ARCH_ENTRY_POINT' not in MyAgo.Macros:
+ MyAgo.Macros['ARCH_ENTRY_POINT'] = ArchEntryPoint
+ if 'IMAGE_ENTRY_POINT' not in MyAgo.Macros:
+ MyAgo.Macros['IMAGE_ENTRY_POINT'] = ImageEntryPoint
PCI_COMPRESS_Flag = False
- for k, v in self._AutoGenObject.Module.Defines.iteritems():
+ for k, v in MyAgo.Module.Defines.items():
if 'PCI_COMPRESS' == k and 'TRUE' == v:
PCI_COMPRESS_Flag = True
# tools definitions
ToolsDef = []
- IncPrefix = self._INC_FLAG_[self._AutoGenObject.ToolChainFamily]
- for Tool in self._AutoGenObject.BuildOption:
- for Attr in self._AutoGenObject.BuildOption[Tool]:
- Value = self._AutoGenObject.BuildOption[Tool][Attr]
+ IncPrefix = self._INC_FLAG_[MyAgo.ToolChainFamily]
+ for Tool in MyAgo.BuildOption:
+ for Attr in MyAgo.BuildOption[Tool]:
+ Value = MyAgo.BuildOption[Tool][Attr]
if Attr == "FAMILY":
continue
elif Attr == "PATH":
@@ -521,7 +511,10 @@ cleanlib:
continue
# Remove duplicated include path, if any
if Attr == "FLAGS":
- Value = RemoveDupOption(Value, IncPrefix, self._AutoGenObject.IncludePathList)
+ Value = RemoveDupOption(Value, IncPrefix, MyAgo.IncludePathList)
+ if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Tool == 'CC' and '/GM' in Value:
+ Value = Value.replace(' /MP', '')
+ MyAgo.BuildOption[Tool][Attr] = Value
if Tool == "OPTROM" and PCI_COMPRESS_Flag:
ValueList = Value.split()
if ValueList:
@@ -535,11 +528,11 @@ cleanlib:
# generate the Response file and Response flag
RespDict = self.CommandExceedLimit()
- RespFileList = os.path.join(self._AutoGenObject.OutputDir, 'respfilelist.txt')
+ RespFileList = os.path.join(MyAgo.OutputDir, 'respfilelist.txt')
if RespDict:
RespFileListContent = ''
for Resp in RespDict:
- RespFile = os.path.join(self._AutoGenObject.OutputDir, str(Resp).lower() + '.txt')
+ RespFile = os.path.join(MyAgo.OutputDir, str(Resp).lower() + '.txt')
StrList = RespDict[Resp].split(' ')
UnexpandMacro = []
NewStr = []
@@ -552,18 +545,18 @@ cleanlib:
NewRespStr = ' '.join(NewStr)
SaveFileOnChange(RespFile, NewRespStr, False)
ToolsDef.append("%s = %s" % (Resp, UnexpandMacroStr + ' @' + RespFile))
- RespFileListContent += '@' + RespFile + os.linesep
- RespFileListContent += NewRespStr + os.linesep
+ RespFileListContent += '@' + RespFile + TAB_LINE_BREAK
+ RespFileListContent += NewRespStr + TAB_LINE_BREAK
SaveFileOnChange(RespFileList, RespFileListContent, False)
else:
if os.path.exists(RespFileList):
os.remove(RespFileList)
# convert source files and binary files to build targets
- self.ResultFileList = [str(T.Target) for T in self._AutoGenObject.CodaTargetList]
- if len(self.ResultFileList) == 0 and len(self._AutoGenObject.SourceFileList) <> 0:
+ self.ResultFileList = [str(T.Target) for T in MyAgo.CodaTargetList]
+ if len(self.ResultFileList) == 0 and len(MyAgo.SourceFileList) != 0:
EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",
- ExtraData="[%s]" % str(self._AutoGenObject))
+ ExtraData="[%s]" % str(MyAgo))
self.ProcessBuildTargetList()
self.ParserGenerateFfsCmd()
@@ -582,7 +575,7 @@ cleanlib:
# INC_LIST is special
FileMacro = ""
IncludePathList = []
- for P in self._AutoGenObject.IncludePathList:
+ for P in MyAgo.IncludePathList:
IncludePathList.append(IncPrefix + self.PlaceMacro(P, self.Macros))
if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros:
self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(IncPrefix + P)
@@ -593,10 +586,28 @@ cleanlib:
}
)
FileMacroList.append(FileMacro)
+ # Add support when compiling .nasm source files
+ for File in self.FileCache.keys():
+ if not str(File).endswith('.nasm'):
+ continue
+ IncludePathList = []
+ for P in MyAgo.IncludePathList:
+ IncludePath = self._INC_FLAG_['NASM'] + self.PlaceMacro(P, self.Macros)
+ if IncludePath.endswith(os.sep):
+ IncludePath = IncludePath.rstrip(os.sep)
+ # When compiling .nasm files, need to add a literal backslash at each path
+ # To specify a literal backslash at the end of the line, precede it with a caret (^)
+ if P == MyAgo.IncludePathList[-1] and os.sep == '\\':
+ IncludePath = ''.join([IncludePath, '^', os.sep])
+ else:
+ IncludePath = os.path.join(IncludePath, '')
+ IncludePathList.append(IncludePath)
+ FileMacroList.append(self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", "source_file": IncludePathList}))
+ break
# Generate macros used to represent files containing list of input files
for ListFileMacro in self.ListFileMacros:
- ListFileName = os.path.join(self._AutoGenObject.OutputDir, "%s.lst" % ListFileMacro.lower()[:len(ListFileMacro) - 5])
+ ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % ListFileMacro.lower()[:len(ListFileMacro) - 5])
FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName))
SaveFileOnChange(
ListFileName,
@@ -604,11 +615,11 @@ cleanlib:
False
)
- # Edk modules need StrDefs.h for string ID
- #if self._AutoGenObject.AutoGenVersion < 0x00010005 and len(self._AutoGenObject.UnicodeFileList) > 0:
- # BcTargetList = ['strdefs']
- #else:
- # BcTargetList = []
+ # Generate objlist used to create .obj file
+ for Type in self.ObjTargetDict:
+ NewLine = ' '.join(list(self.ObjTargetDict[Type]))
+ FileMacroList.append("OBJLIST_%s = %s" % (list(self.ObjTargetDict.keys()).index(Type), NewLine))
+
BcTargetList = []
MakefileName = self._FILE_NAME_[self._FileType]
@@ -617,7 +628,7 @@ cleanlib:
Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join(D, MakefileName)}
LibraryMakeCommandList.append(Command)
- package_rel_dir = self._AutoGenObject.SourceDir
+ package_rel_dir = MyAgo.SourceDir
current_dir = self.Macros["WORKSPACE"]
found = False
while not found and os.sep in package_rel_dir:
@@ -639,35 +650,35 @@ cleanlib:
"platform_version" : self.PlatformInfo.Version,
"platform_relative_directory": self.PlatformInfo.SourceDir,
"platform_output_directory" : self.PlatformInfo.OutputDir,
- "ffs_output_directory" : self._AutoGenObject.Macros["FFS_OUTPUT_DIR"],
- "platform_dir" : self._AutoGenObject.Macros["PLATFORM_DIR"],
-
- "module_name" : self._AutoGenObject.Name,
- "module_guid" : self._AutoGenObject.Guid,
- "module_name_guid" : self._AutoGenObject._GetUniqueBaseName(),
- "module_version" : self._AutoGenObject.Version,
- "module_type" : self._AutoGenObject.ModuleType,
- "module_file" : self._AutoGenObject.MetaFile.Name,
- "module_file_base_name" : self._AutoGenObject.MetaFile.BaseName,
- "module_relative_directory" : self._AutoGenObject.SourceDir,
- "module_dir" : mws.join (self.Macros["WORKSPACE"], self._AutoGenObject.SourceDir),
+ "ffs_output_directory" : MyAgo.Macros["FFS_OUTPUT_DIR"],
+ "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],
+
+ "module_name" : MyAgo.Name,
+ "module_guid" : MyAgo.Guid,
+ "module_name_guid" : MyAgo.UniqueBaseName,
+ "module_version" : MyAgo.Version,
+ "module_type" : MyAgo.ModuleType,
+ "module_file" : MyAgo.MetaFile.Name,
+ "module_file_base_name" : MyAgo.MetaFile.BaseName,
+ "module_relative_directory" : MyAgo.SourceDir,
+ "module_dir" : mws.join (self.Macros["WORKSPACE"], MyAgo.SourceDir),
"package_relative_directory": package_rel_dir,
- "module_extra_defines" : ["%s = %s" % (k, v) for k, v in self._AutoGenObject.Module.Defines.iteritems()],
+ "module_extra_defines" : ["%s = %s" % (k, v) for k, v in MyAgo.Module.Defines.items()],
- "architecture" : self._AutoGenObject.Arch,
- "toolchain_tag" : self._AutoGenObject.ToolChain,
- "build_target" : self._AutoGenObject.BuildTarget,
+ "architecture" : MyAgo.Arch,
+ "toolchain_tag" : MyAgo.ToolChain,
+ "build_target" : MyAgo.BuildTarget,
"platform_build_directory" : self.PlatformInfo.BuildDir,
- "module_build_directory" : self._AutoGenObject.BuildDir,
- "module_output_directory" : self._AutoGenObject.OutputDir,
- "module_debug_directory" : self._AutoGenObject.DebugDir,
+ "module_build_directory" : MyAgo.BuildDir,
+ "module_output_directory" : MyAgo.OutputDir,
+ "module_debug_directory" : MyAgo.DebugDir,
"separator" : Separator,
"module_tool_definitions" : ToolsDef,
- "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),
- "shell_command" : self._SHELL_CMD_[self._FileType].values(),
+ "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
"module_entry_point" : ModuleEntryPoint,
"image_entry_point" : ImageEntryPoint,
@@ -698,7 +709,7 @@ cleanlib:
Src = self.ReplaceMacro(Src)
Dst = self.ReplaceMacro(Dst)
if Dst not in self.ResultFileList:
- self.ResultFileList.append('%s' % Dst)
+ self.ResultFileList.append(Dst)
if '%s :' %(Dst) not in self.BuildTargetList:
self.BuildTargetList.append("%s :" %(Dst))
self.BuildTargetList.append('\t' + self._CP_TEMPLATE_[self._FileType] %{'Src': Src, 'Dst': Dst})
@@ -707,7 +718,7 @@ cleanlib:
for index, Str in enumerate(FfsCmdList):
if '-o' == Str:
OutputFile = FfsCmdList[index + 1]
- if '-i' == Str:
+ if '-i' == Str or "-oi" == Str:
if DepsFileList == []:
DepsFileList = [FfsCmdList[index + 1]]
else:
@@ -716,7 +727,7 @@ cleanlib:
if DepsFileString == '':
continue
OutputFile = self.ReplaceMacro(OutputFile)
- self.ResultFileList.append('%s' % OutputFile)
+ self.ResultFileList.append(OutputFile)
DepsFileString = self.ReplaceMacro(DepsFileString)
self.BuildTargetList.append('%s : %s' % (OutputFile, DepsFileString))
CmdString = ' '.join(FfsCmdList).strip()
@@ -745,7 +756,7 @@ cleanlib:
if CmdName == 'Trim':
SecDepsFileList.append(os.path.join('$(DEBUG_DIR)', os.path.basename(OutputFile).replace('offset', 'efi')))
if OutputFile.endswith('.ui') or OutputFile.endswith('.ver'):
- SecDepsFileList.append(os.path.join('$(MODULE_DIR)','$(MODULE_FILE)'))
+ SecDepsFileList.append(os.path.join('$(MODULE_DIR)', '$(MODULE_FILE)'))
self.FfsOutputFileList.append((OutputFile, ' '.join(SecDepsFileList), SecCmdStr))
if len(SecDepsFileList) > 0:
self.ParseSecCmd(SecDepsFileList, CmdTuple)
@@ -797,14 +808,14 @@ cleanlib:
Tool = Flag
break
if Tool:
- if 'PATH' not in self._AutoGenObject._BuildOption[Tool]:
+ if 'PATH' not in self._AutoGenObject.BuildOption[Tool]:
EdkLogger.error("build", AUTOGEN_ERROR, "%s_PATH doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))
- SingleCommandLength += len(self._AutoGenObject._BuildOption[Tool]['PATH'])
+ SingleCommandLength += len(self._AutoGenObject.BuildOption[Tool]['PATH'])
for item in SingleCommandList[1:]:
if FlagDict[Tool]['Macro'] in item:
- if 'FLAGS' not in self._AutoGenObject._BuildOption[Tool]:
+ if 'FLAGS' not in self._AutoGenObject.BuildOption[Tool]:
EdkLogger.error("build", AUTOGEN_ERROR, "%s_FLAGS doesn't exist in %s ToolChain and %s Arch." %(Tool, self._AutoGenObject.ToolChain, self._AutoGenObject.Arch), ExtraData="[%s]" % str(self._AutoGenObject))
- Str = self._AutoGenObject._BuildOption[Tool]['FLAGS']
+ Str = self._AutoGenObject.BuildOption[Tool]['FLAGS']
for Option in self._AutoGenObject.BuildOption:
for Attr in self._AutoGenObject.BuildOption[Option]:
if Str.find(Option + '_' + Attr) != -1:
@@ -819,7 +830,7 @@ cleanlib:
break
SingleCommandLength += len(Str)
elif '$(INC)' in item:
- SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject._IncludePathList)
+ SingleCommandLength += self._AutoGenObject.IncludePathLength + len(IncPrefix) * len(self._AutoGenObject.IncludePathList)
elif item.find('$(') != -1:
Str = item
for Option in self._AutoGenObject.BuildOption:
@@ -845,7 +856,7 @@ cleanlib:
Key = Flag + '_RESP'
RespMacro = FlagDict[Flag]['Macro'].replace('FLAGS', 'RESP')
Value = self._AutoGenObject.BuildOption[Flag]['FLAGS']
- for inc in self._AutoGenObject._IncludePathList:
+ for inc in self._AutoGenObject.IncludePathList:
Value += ' ' + IncPrefix + inc
for Option in self._AutoGenObject.BuildOption:
for Attr in self._AutoGenObject.BuildOption[Option]:
@@ -867,7 +878,7 @@ cleanlib:
for Target in BuildTargets:
for i, SingleCommand in enumerate(BuildTargets[Target].Commands):
if FlagDict[Flag]['Macro'] in SingleCommand:
- BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)','').replace(FlagDict[Flag]['Macro'], RespMacro)
+ BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)', '').replace(FlagDict[Flag]['Macro'], RespMacro)
return RespDict
def ProcessBuildTargetList(self):
@@ -889,26 +900,90 @@ cleanlib:
if Item in SourceFileList:
SourceFileList.remove(Item)
- self.FileDependency = self.GetFileDependency(
+ FileDependencyDict = self.GetFileDependency(
SourceFileList,
ForceIncludedFile,
self._AutoGenObject.IncludePathList + self._AutoGenObject.BuildOptionIncPathList
)
+
+ self.DependencyHeaderFileSet = set()
+ if FileDependencyDict:
+ for Dependency in FileDependencyDict.values():
+ self.DependencyHeaderFileSet.update(set(Dependency))
+
+ # Get a set of unique package includes from MetaFile
+ parentMetaFileIncludes = set()
+ for aInclude in self._AutoGenObject.PackageIncludePathList:
+ aIncludeName = str(aInclude)
+ parentMetaFileIncludes.add(aIncludeName.lower())
+
+ # Check if header files are listed in metafile
+ # Get a set of unique module header source files from MetaFile
+ headerFilesInMetaFileSet = set()
+ for aFile in self._AutoGenObject.SourceFileList:
+ aFileName = str(aFile)
+ if not aFileName.endswith('.h'):
+ continue
+ headerFilesInMetaFileSet.add(aFileName.lower())
+
+ # Get a set of unique module autogen files
+ localAutoGenFileSet = set()
+ for aFile in self._AutoGenObject.AutoGenFileList:
+ localAutoGenFileSet.add(str(aFile).lower())
+
+ # Get a set of unique module dependency header files
+ # Exclude autogen files and files not in the source directory
+ # and files that are under the package include list
+ headerFileDependencySet = set()
+ localSourceDir = str(self._AutoGenObject.SourceDir).lower()
+ for Dependency in FileDependencyDict.values():
+ for aFile in Dependency:
+ aFileName = str(aFile).lower()
+ # Exclude non-header files
+ if not aFileName.endswith('.h'):
+ continue
+ # Exclude autogen files
+ if aFileName in localAutoGenFileSet:
+ continue
+ # Exclude include out of local scope
+ if localSourceDir not in aFileName:
+ continue
+ # Exclude files covered by package includes
+ pathNeeded = True
+ for aIncludePath in parentMetaFileIncludes:
+ if aIncludePath in aFileName:
+ pathNeeded = False
+ break
+ if not pathNeeded:
+ continue
+ # Keep the file to be checked
+ headerFileDependencySet.add(aFileName)
+
+ # Check if a module dependency header file is missing from the module's MetaFile
+ for aFile in headerFileDependencySet:
+ if aFile in headerFilesInMetaFileSet:
+ continue
+ if GlobalData.gUseHashCache:
+ GlobalData.gModuleBuildTracking[self._AutoGenObject] = 'FAIL_METAFILE'
+ EdkLogger.warn("build","Module MetaFile [Sources] is missing local header!",
+ ExtraData = "Local Header: " + aFile + " not found in " + self._AutoGenObject.MetaFile.Path
+ )
+
DepSet = None
- for File in self.FileDependency:
- if not self.FileDependency[File]:
- self.FileDependency[File] = ['$(FORCE_REBUILD)']
+ for File,Dependency in FileDependencyDict.items():
+ if not Dependency:
+ FileDependencyDict[File] = ['$(FORCE_REBUILD)']
continue
- self._AutoGenObject.AutoGenDepSet |= set(self.FileDependency[File])
+ self._AutoGenObject.AutoGenDepSet |= set(Dependency)
# skip non-C files
if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":
continue
elif DepSet is None:
- DepSet = set(self.FileDependency[File])
+ DepSet = set(Dependency)
else:
- DepSet &= set(self.FileDependency[File])
+ DepSet &= set(Dependency)
# in case nothing in SourceFileList
if DepSet is None:
DepSet = set()
@@ -918,15 +993,26 @@ cleanlib:
for File in DepSet:
self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))
- for File in self.FileDependency:
+ CmdSumDict = {}
+ CmdTargetDict = {}
+ CmdCppDict = {}
+ DependencyDict = FileDependencyDict.copy()
+ for File in FileDependencyDict:
# skip non-C files
if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":
continue
- NewDepSet = set(self.FileDependency[File])
+ NewDepSet = set(FileDependencyDict[File])
NewDepSet -= DepSet
- self.FileDependency[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)
+ FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)
+ DependencyDict[File] = list(NewDepSet)
# Convert target description object to target string in makefile
+ if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and TAB_C_CODE_FILE in self._AutoGenObject.Targets:
+ for T in self._AutoGenObject.Targets[TAB_C_CODE_FILE]:
+ NewFile = self.PlaceMacro(str(T), self.Macros)
+ if not self.ObjTargetDict.get(T.Target.SubDir):
+ self.ObjTargetDict[T.Target.SubDir] = set()
+ self.ObjTargetDict[T.Target.SubDir].add(NewFile)
for Type in self._AutoGenObject.Targets:
for T in self._AutoGenObject.Targets[Type]:
# Generate related macros if needed
@@ -938,39 +1024,95 @@ cleanlib:
self.ListFileMacros[T.IncListFileMacro] = []
Deps = []
+ CCodeDeps = []
# Add force-dependencies
for Dep in T.Dependencies:
Deps.append(self.PlaceMacro(str(Dep), self.Macros))
+ if Dep != '$(MAKE_FILE)':
+ CCodeDeps.append(self.PlaceMacro(str(Dep), self.Macros))
# Add inclusion-dependencies
- if len(T.Inputs) == 1 and T.Inputs[0] in self.FileDependency:
- for F in self.FileDependency[T.Inputs[0]]:
+ if len(T.Inputs) == 1 and T.Inputs[0] in FileDependencyDict:
+ for F in FileDependencyDict[T.Inputs[0]]:
Deps.append(self.PlaceMacro(str(F), self.Macros))
# Add source-dependencies
for F in T.Inputs:
NewFile = self.PlaceMacro(str(F), self.Macros)
# In order to use file list macro as dependency
if T.GenListFile:
- # gnu tools need forward slash path separater, even on Windows
+ # gnu tools need forward slash path separator, even on Windows
self.ListFileMacros[T.ListFileMacro].append(str(F).replace ('\\', '/'))
self.FileListMacros[T.FileListMacro].append(NewFile)
elif T.GenFileListMacro:
self.FileListMacros[T.FileListMacro].append(NewFile)
else:
Deps.append(NewFile)
-
+ for key in self.FileListMacros:
+ self.FileListMacros[key].sort()
# Use file list macro as dependency
if T.GenFileListMacro:
Deps.append("$(%s)" % T.FileListMacro)
if Type in [TAB_OBJECT_FILE, TAB_STATIC_LIBRARY]:
Deps.append("$(%s)" % T.ListFileMacro)
- TargetDict = {
- "target" : self.PlaceMacro(T.Target.Path, self.Macros),
- "cmd" : "\n\t".join(T.Commands),
- "deps" : Deps
- }
- self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))
-
+ if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE:
+ T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict)
+ TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": CCodeDeps}
+ CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST')
+ if T.Commands:
+ CmdLine = '%s%s' %(CmdLine, TAB_LINE_BREAK)
+ if CCodeDeps or CmdLine:
+ self.BuildTargetList.append(CmdLine)
+ else:
+ TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps}
+ self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))
+
+ def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict):
+ if not CmdSumDict:
+ for item in self._AutoGenObject.Targets[Type]:
+ CmdSumDict[item.Target.SubDir] = item.Target.BaseName
+ for CppPath in item.Inputs:
+ Path = self.PlaceMacro(CppPath.Path, self.Macros)
+ if CmdCppDict.get(item.Target.SubDir):
+ CmdCppDict[item.Target.SubDir].append(Path)
+ else:
+ CmdCppDict[item.Target.SubDir] = ['$(MAKE_FILE)', Path]
+ if CppPath.Path in DependencyDict:
+ for Temp in DependencyDict[CppPath.Path]:
+ try:
+ Path = self.PlaceMacro(Temp.Path, self.Macros)
+ except:
+ continue
+ if Path not in (self.CommonFileDependency + CmdCppDict[item.Target.SubDir]):
+ CmdCppDict[item.Target.SubDir].append(Path)
+ if T.Commands:
+ CommandList = T.Commands[:]
+ for Item in CommandList[:]:
+ SingleCommandList = Item.split()
+ if len(SingleCommandList) > 0 and self.CheckCCCmd(SingleCommandList):
+ for Temp in SingleCommandList:
+ if Temp.startswith('/Fo'):
+ CmdSign = '%s%s' % (Temp.rsplit(TAB_SLASH, 1)[0], TAB_SLASH)
+ break
+ else: continue
+ if CmdSign not in list(CmdTargetDict.keys()):
+ CmdTargetDict[CmdSign] = Item.replace(Temp, CmdSign)
+ else:
+ CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1])
+ Index = CommandList.index(Item)
+ CommandList.pop(Index)
+ if SingleCommandList[-1].endswith("%s%s.c" % (TAB_SLASH, CmdSumDict[CmdSign[3:].rsplit(TAB_SLASH, 1)[0]])):
+ Cpplist = CmdCppDict[T.Target.SubDir]
+ Cpplist.insert(0, '$(OBJLIST_%d): $(COMMON_DEPS)' % list(self.ObjTargetDict.keys()).index(T.Target.SubDir))
+ T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign])
+ else:
+ T.Commands.pop(Index)
+ return T, CmdSumDict, CmdTargetDict, CmdCppDict
+
+ def CheckCCCmd(self, CommandList):
+ for cmd in CommandList:
+ if '$(CC)' in cmd:
+ return True
+ return False
## For creating makefile targets for dependent libraries
def ProcessDependentLibrary(self):
for LibraryAutoGen in self._AutoGenObject.LibraryAutoGenList:
@@ -988,112 +1130,9 @@ cleanlib:
def GetFileDependency(self, FileList, ForceInculeList, SearchPathList):
Dependency = {}
for F in FileList:
- Dependency[F] = self.GetDependencyList(F, ForceInculeList, SearchPathList)
+ Dependency[F] = GetDependencyList(self._AutoGenObject, self.FileCache, F, ForceInculeList, SearchPathList)
return Dependency
- ## Find dependencies for one source file
- #
- # By searching recursively "#include" directive in file, find out all the
- # files needed by given source file. The dependecies will be only searched
- # in given search path list.
- #
- # @param File The source file
- # @param ForceInculeList The list of files which will be included forcely
- # @param SearchPathList The list of search path
- #
- # @retval list The list of files the given source file depends on
- #
- def GetDependencyList(self, File, ForceList, SearchPathList):
- EdkLogger.debug(EdkLogger.DEBUG_1, "Try to get dependency files for %s" % File)
- FileStack = [File] + ForceList
- DependencySet = set()
-
- if self._AutoGenObject.Arch not in gDependencyDatabase:
- gDependencyDatabase[self._AutoGenObject.Arch] = {}
- DepDb = gDependencyDatabase[self._AutoGenObject.Arch]
-
- while len(FileStack) > 0:
- F = FileStack.pop()
-
- FullPathDependList = []
- if F in self.FileCache:
- for CacheFile in self.FileCache[F]:
- FullPathDependList.append(CacheFile)
- if CacheFile not in DependencySet:
- FileStack.append(CacheFile)
- DependencySet.update(FullPathDependList)
- continue
-
- CurrentFileDependencyList = []
- if F in DepDb:
- CurrentFileDependencyList = DepDb[F]
- else:
- try:
- Fd = open(F.Path, 'r')
- except BaseException, X:
- EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))
-
- FileContent = Fd.read()
- Fd.close()
- if len(FileContent) == 0:
- continue
-
- if FileContent[0] == 0xff or FileContent[0] == 0xfe:
- FileContent = unicode(FileContent, "utf-16")
- IncludedFileList = gIncludePattern.findall(FileContent)
-
- for Inc in IncludedFileList:
- Inc = Inc.strip()
- # if there's macro used to reference header file, expand it
- HeaderList = gMacroPattern.findall(Inc)
- if len(HeaderList) == 1 and len(HeaderList[0]) == 2:
- HeaderType = HeaderList[0][0]
- HeaderKey = HeaderList[0][1]
- if HeaderType in gIncludeMacroConversion:
- Inc = gIncludeMacroConversion[HeaderType] % {"HeaderKey" : HeaderKey}
- else:
- # not known macro used in #include, always build the file by
- # returning a empty dependency
- self.FileCache[File] = []
- return []
- Inc = os.path.normpath(Inc)
- CurrentFileDependencyList.append(Inc)
- DepDb[F] = CurrentFileDependencyList
-
- CurrentFilePath = F.Dir
- PathList = [CurrentFilePath] + SearchPathList
- for Inc in CurrentFileDependencyList:
- for SearchPath in PathList:
- FilePath = os.path.join(SearchPath, Inc)
- if FilePath in gIsFileMap:
- if not gIsFileMap[FilePath]:
- continue
- # If isfile is called too many times, the performance is slow down.
- elif not os.path.isfile(FilePath):
- gIsFileMap[FilePath] = False
- continue
- else:
- gIsFileMap[FilePath] = True
- FilePath = PathClass(FilePath)
- FullPathDependList.append(FilePath)
- if FilePath not in DependencySet:
- FileStack.append(FilePath)
- break
- else:
- EdkLogger.debug(EdkLogger.DEBUG_9, "%s included by %s was not found "\
- "in any given path:\n\t%s" % (Inc, F, "\n\t".join(SearchPathList)))
-
- self.FileCache[F] = FullPathDependList
- DependencySet.update(FullPathDependList)
-
- DependencySet.update(ForceList)
- if File in DependencySet:
- DependencySet.remove(File)
- DependencyList = list(DependencySet) # remove duplicate ones
-
- return DependencyList
-
- _TemplateDict = property(_CreateTemplateDict)
## CustomMakefile class
#
@@ -1203,34 +1242,36 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
self.IntermediateDirectoryList = ["$(DEBUG_DIR)", "$(OUTPUT_DIR)"]
# Compose a dict object containing information used to do replacement in template
- def _CreateTemplateDict(self):
+ @property
+ def _TemplateDict(self):
Separator = self._SEP_[self._FileType]
- if self._FileType not in self._AutoGenObject.CustomMakefile:
+ MyAgo = self._AutoGenObject
+ if self._FileType not in MyAgo.CustomMakefile:
EdkLogger.error('build', OPTION_NOT_SUPPORTED, "No custom makefile for %s" % self._FileType,
- ExtraData="[%s]" % str(self._AutoGenObject))
+ ExtraData="[%s]" % str(MyAgo))
MakefilePath = mws.join(
- self._AutoGenObject.WorkspaceDir,
- self._AutoGenObject.CustomMakefile[self._FileType]
+ MyAgo.WorkspaceDir,
+ MyAgo.CustomMakefile[self._FileType]
)
try:
CustomMakefile = open(MakefilePath, 'r').read()
except:
- EdkLogger.error('build', FILE_OPEN_FAILURE, File=str(self._AutoGenObject),
- ExtraData=self._AutoGenObject.CustomMakefile[self._FileType])
+ EdkLogger.error('build', FILE_OPEN_FAILURE, File=str(MyAgo),
+ ExtraData=MyAgo.CustomMakefile[self._FileType])
# tools definitions
ToolsDef = []
- for Tool in self._AutoGenObject.BuildOption:
+ for Tool in MyAgo.BuildOption:
# Don't generate MAKE_FLAGS in makefile. It's put in environment variable.
if Tool == "MAKE":
continue
- for Attr in self._AutoGenObject.BuildOption[Tool]:
+ for Attr in MyAgo.BuildOption[Tool]:
if Attr == "FAMILY":
continue
elif Attr == "PATH":
- ToolsDef.append("%s = %s" % (Tool, self._AutoGenObject.BuildOption[Tool][Attr]))
+ ToolsDef.append("%s = %s" % (Tool, MyAgo.BuildOption[Tool][Attr]))
else:
- ToolsDef.append("%s_%s = %s" % (Tool, Attr, self._AutoGenObject.BuildOption[Tool][Attr]))
+ ToolsDef.append("%s_%s = %s" % (Tool, Attr, MyAgo.BuildOption[Tool][Attr]))
ToolsDef.append("")
MakefileName = self._FILE_NAME_[self._FileType]
@@ -1242,32 +1283,32 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
"platform_version" : self.PlatformInfo.Version,
"platform_relative_directory": self.PlatformInfo.SourceDir,
"platform_output_directory" : self.PlatformInfo.OutputDir,
- "platform_dir" : self._AutoGenObject.Macros["PLATFORM_DIR"],
-
- "module_name" : self._AutoGenObject.Name,
- "module_guid" : self._AutoGenObject.Guid,
- "module_name_guid" : self._AutoGenObject._GetUniqueBaseName(),
- "module_version" : self._AutoGenObject.Version,
- "module_type" : self._AutoGenObject.ModuleType,
- "module_file" : self._AutoGenObject.MetaFile,
- "module_file_base_name" : self._AutoGenObject.MetaFile.BaseName,
- "module_relative_directory" : self._AutoGenObject.SourceDir,
- "module_dir" : mws.join (self._AutoGenObject.WorkspaceDir, self._AutoGenObject.SourceDir),
-
- "architecture" : self._AutoGenObject.Arch,
- "toolchain_tag" : self._AutoGenObject.ToolChain,
- "build_target" : self._AutoGenObject.BuildTarget,
+ "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],
+
+ "module_name" : MyAgo.Name,
+ "module_guid" : MyAgo.Guid,
+ "module_name_guid" : MyAgo.UniqueBaseName,
+ "module_version" : MyAgo.Version,
+ "module_type" : MyAgo.ModuleType,
+ "module_file" : MyAgo.MetaFile,
+ "module_file_base_name" : MyAgo.MetaFile.BaseName,
+ "module_relative_directory" : MyAgo.SourceDir,
+ "module_dir" : mws.join (MyAgo.WorkspaceDir, MyAgo.SourceDir),
+
+ "architecture" : MyAgo.Arch,
+ "toolchain_tag" : MyAgo.ToolChain,
+ "build_target" : MyAgo.BuildTarget,
"platform_build_directory" : self.PlatformInfo.BuildDir,
- "module_build_directory" : self._AutoGenObject.BuildDir,
- "module_output_directory" : self._AutoGenObject.OutputDir,
- "module_debug_directory" : self._AutoGenObject.DebugDir,
+ "module_build_directory" : MyAgo.BuildDir,
+ "module_output_directory" : MyAgo.OutputDir,
+ "module_debug_directory" : MyAgo.DebugDir,
"separator" : Separator,
"module_tool_definitions" : ToolsDef,
- "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),
- "shell_command" : self._SHELL_CMD_[self._FileType].values(),
+ "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
"create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),
"custom_makefile_content" : CustomMakefile
@@ -1275,8 +1316,6 @@ ${BEGIN}\t-@${create_directory_command}\n${END}\
return MakefileTemplateDict
- _TemplateDict = property(_CreateTemplateDict)
-
## PlatformMakefile class
#
# This class encapsules makefie and its generation for platform. It uses
@@ -1393,13 +1432,14 @@ cleanlib:
self.LibraryMakeCommandList = []
# Compose a dict object containing information used to do replacement in template
- def _CreateTemplateDict(self):
+ @property
+ def _TemplateDict(self):
Separator = self._SEP_[self._FileType]
- PlatformInfo = self._AutoGenObject
- if "MAKE" not in PlatformInfo.ToolDefinition or "PATH" not in PlatformInfo.ToolDefinition["MAKE"]:
+ MyAgo = self._AutoGenObject
+ if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:
EdkLogger.error("build", OPTION_MISSING, "No MAKE command defined. Please check your tools_def.txt!",
- ExtraData="[%s]" % str(self._AutoGenObject))
+ ExtraData="[%s]" % str(MyAgo))
self.IntermediateDirectoryList = ["$(BUILD_DIR)"]
self.ModuleBuildDirectoryList = self.GetModuleBuildDirectoryList()
@@ -1409,7 +1449,7 @@ cleanlib:
LibraryMakefileList = []
LibraryMakeCommandList = []
for D in self.LibraryBuildDirectoryList:
- D = self.PlaceMacro(D, {"BUILD_DIR":PlatformInfo.BuildDir})
+ D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})
Makefile = os.path.join(D, MakefileName)
Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}
LibraryMakefileList.append(Makefile)
@@ -1419,7 +1459,7 @@ cleanlib:
ModuleMakefileList = []
ModuleMakeCommandList = []
for D in self.ModuleBuildDirectoryList:
- D = self.PlaceMacro(D, {"BUILD_DIR":PlatformInfo.BuildDir})
+ D = self.PlaceMacro(D, {"BUILD_DIR":MyAgo.BuildDir})
Makefile = os.path.join(D, MakefileName)
Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":Makefile}
ModuleMakefileList.append(Makefile)
@@ -1428,23 +1468,23 @@ cleanlib:
MakefileTemplateDict = {
"makefile_header" : self._FILE_HEADER_[self._FileType],
"makefile_path" : os.path.join("$(BUILD_DIR)", MakefileName),
- "make_path" : PlatformInfo.ToolDefinition["MAKE"]["PATH"],
+ "make_path" : MyAgo.ToolDefinition["MAKE"]["PATH"],
"makefile_name" : MakefileName,
- "platform_name" : PlatformInfo.Name,
- "platform_guid" : PlatformInfo.Guid,
- "platform_version" : PlatformInfo.Version,
- "platform_file" : self._AutoGenObject.MetaFile,
- "platform_relative_directory": PlatformInfo.SourceDir,
- "platform_output_directory" : PlatformInfo.OutputDir,
- "platform_build_directory" : PlatformInfo.BuildDir,
- "platform_dir" : self._AutoGenObject.Macros["PLATFORM_DIR"],
-
- "toolchain_tag" : PlatformInfo.ToolChain,
- "build_target" : PlatformInfo.BuildTarget,
- "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),
- "shell_command" : self._SHELL_CMD_[self._FileType].values(),
- "build_architecture_list" : self._AutoGenObject.Arch,
- "architecture" : self._AutoGenObject.Arch,
+ "platform_name" : MyAgo.Name,
+ "platform_guid" : MyAgo.Guid,
+ "platform_version" : MyAgo.Version,
+ "platform_file" : MyAgo.MetaFile,
+ "platform_relative_directory": MyAgo.SourceDir,
+ "platform_output_directory" : MyAgo.OutputDir,
+ "platform_build_directory" : MyAgo.BuildDir,
+ "platform_dir" : MyAgo.Macros["PLATFORM_DIR"],
+
+ "toolchain_tag" : MyAgo.ToolChain,
+ "build_target" : MyAgo.BuildTarget,
+ "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
+ "build_architecture_list" : MyAgo.Arch,
+ "architecture" : MyAgo.Arch,
"separator" : Separator,
"create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),
"cleanall_command" : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList),
@@ -1478,8 +1518,6 @@ cleanlib:
DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))
return DirList
- _TemplateDict = property(_CreateTemplateDict)
-
## TopLevelMakefile class
#
# This class encapsules makefie and its generation for entrance makefile. It
@@ -1499,32 +1537,29 @@ class TopLevelMakefile(BuildFile):
self.IntermediateDirectoryList = []
# Compose a dict object containing information used to do replacement in template
- def _CreateTemplateDict(self):
+ @property
+ def _TemplateDict(self):
Separator = self._SEP_[self._FileType]
# any platform autogen object is ok because we just need common information
- PlatformInfo = self._AutoGenObject
+ MyAgo = self._AutoGenObject
- if "MAKE" not in PlatformInfo.ToolDefinition or "PATH" not in PlatformInfo.ToolDefinition["MAKE"]:
+ if "MAKE" not in MyAgo.ToolDefinition or "PATH" not in MyAgo.ToolDefinition["MAKE"]:
EdkLogger.error("build", OPTION_MISSING, "No MAKE command defined. Please check your tools_def.txt!",
- ExtraData="[%s]" % str(self._AutoGenObject))
+ ExtraData="[%s]" % str(MyAgo))
- for Arch in PlatformInfo.ArchList:
+ for Arch in MyAgo.ArchList:
self.IntermediateDirectoryList.append(Separator.join(["$(BUILD_DIR)", Arch]))
self.IntermediateDirectoryList.append("$(FV_DIR)")
# TRICK: for not generating GenFds call in makefile if no FDF file
MacroList = []
- if PlatformInfo.FdfFile is not None and PlatformInfo.FdfFile != "":
- FdfFileList = [PlatformInfo.FdfFile]
+ if MyAgo.FdfFile is not None and MyAgo.FdfFile != "":
+ FdfFileList = [MyAgo.FdfFile]
# macros passed to GenFds
- MacroList.append('"%s=%s"' % ("EFI_SOURCE", GlobalData.gEfiSource.replace('\\', '\\\\')))
- MacroList.append('"%s=%s"' % ("EDK_SOURCE", GlobalData.gEdkSource.replace('\\', '\\\\')))
MacroDict = {}
MacroDict.update(GlobalData.gGlobalDefines)
MacroDict.update(GlobalData.gCommandLineDefines)
- MacroDict.pop("EFI_SOURCE", "dummy")
- MacroDict.pop("EDK_SOURCE", "dummy")
for MacroName in MacroDict:
if MacroDict[MacroName] != "":
MacroList.append('"%s=%s"' % (MacroName, MacroDict[MacroName].replace('\\', '\\\\')))
@@ -1545,8 +1580,8 @@ class TopLevelMakefile(BuildFile):
if GlobalData.gCaseInsensitive:
ExtraOption += " -c"
- if GlobalData.gEnableGenfdsMultiThread:
- ExtraOption += " --genfds-multi-thread"
+ if not GlobalData.gEnableGenfdsMultiThread:
+ ExtraOption += " --no-genfds-multi-thread"
if GlobalData.gIgnoreSource:
ExtraOption += " --ignore-sources"
@@ -1562,35 +1597,35 @@ class TopLevelMakefile(BuildFile):
MakefileName = self._FILE_NAME_[self._FileType]
SubBuildCommandList = []
- for A in PlatformInfo.ArchList:
+ for A in MyAgo.ArchList:
Command = self._MAKE_TEMPLATE_[self._FileType] % {"file":os.path.join("$(BUILD_DIR)", A, MakefileName)}
SubBuildCommandList.append(Command)
MakefileTemplateDict = {
"makefile_header" : self._FILE_HEADER_[self._FileType],
"makefile_path" : os.path.join("$(BUILD_DIR)", MakefileName),
- "make_path" : PlatformInfo.ToolDefinition["MAKE"]["PATH"],
- "platform_name" : PlatformInfo.Name,
- "platform_guid" : PlatformInfo.Guid,
- "platform_version" : PlatformInfo.Version,
- "platform_build_directory" : PlatformInfo.BuildDir,
+ "make_path" : MyAgo.ToolDefinition["MAKE"]["PATH"],
+ "platform_name" : MyAgo.Name,
+ "platform_guid" : MyAgo.Guid,
+ "platform_version" : MyAgo.Version,
+ "platform_build_directory" : MyAgo.BuildDir,
"conf_directory" : GlobalData.gConfDirectory,
- "toolchain_tag" : PlatformInfo.ToolChain,
- "build_target" : PlatformInfo.BuildTarget,
- "shell_command_code" : self._SHELL_CMD_[self._FileType].keys(),
- "shell_command" : self._SHELL_CMD_[self._FileType].values(),
- 'arch' : list(PlatformInfo.ArchList),
- "build_architecture_list" : ','.join(PlatformInfo.ArchList),
+ "toolchain_tag" : MyAgo.ToolChain,
+ "build_target" : MyAgo.BuildTarget,
+ "shell_command_code" : list(self._SHELL_CMD_[self._FileType].keys()),
+ "shell_command" : list(self._SHELL_CMD_[self._FileType].values()),
+ 'arch' : list(MyAgo.ArchList),
+ "build_architecture_list" : ','.join(MyAgo.ArchList),
"separator" : Separator,
"create_directory_command" : self.GetCreateDirectoryCommand(self.IntermediateDirectoryList),
"cleanall_command" : self.GetRemoveDirectoryCommand(self.IntermediateDirectoryList),
"sub_build_command" : SubBuildCommandList,
"fdf_file" : FdfFileList,
- "active_platform" : str(PlatformInfo),
- "fd" : PlatformInfo.FdTargetList,
- "fv" : PlatformInfo.FvTargetList,
- "cap" : PlatformInfo.CapTargetList,
+ "active_platform" : str(MyAgo),
+ "fd" : MyAgo.FdTargetList,
+ "fv" : MyAgo.FvTargetList,
+ "cap" : MyAgo.CapTargetList,
"extra_options" : ExtraOption,
"macro" : MacroList,
}
@@ -1619,9 +1654,112 @@ class TopLevelMakefile(BuildFile):
DirList.append(os.path.join(self._AutoGenObject.BuildDir, LibraryAutoGen.BuildDir))
return DirList
- _TemplateDict = property(_CreateTemplateDict)
+## Find dependencies for one source file
+#
+# By searching recursively "#include" directive in file, find out all the
+# files needed by given source file. The dependencies will be only searched
+# in given search path list.
+#
+# @param File The source file
+# @param ForceInculeList The list of files which will be included forcely
+# @param SearchPathList The list of search path
+#
+# @retval list The list of files the given source file depends on
+#
+def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList):
+ EdkLogger.debug(EdkLogger.DEBUG_1, "Try to get dependency files for %s" % File)
+ FileStack = [File] + ForceList
+ DependencySet = set()
+
+ if AutoGenObject.Arch not in gDependencyDatabase:
+ gDependencyDatabase[AutoGenObject.Arch] = {}
+ DepDb = gDependencyDatabase[AutoGenObject.Arch]
+
+ while len(FileStack) > 0:
+ F = FileStack.pop()
+
+ FullPathDependList = []
+ if F in FileCache:
+ for CacheFile in FileCache[F]:
+ FullPathDependList.append(CacheFile)
+ if CacheFile not in DependencySet:
+ FileStack.append(CacheFile)
+ DependencySet.update(FullPathDependList)
+ continue
+
+ CurrentFileDependencyList = []
+ if F in DepDb:
+ CurrentFileDependencyList = DepDb[F]
+ else:
+ try:
+ Fd = open(F.Path, 'rb')
+ FileContent = Fd.read()
+ Fd.close()
+ except BaseException as X:
+ EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))
+ if len(FileContent) == 0:
+ continue
+ try:
+ if FileContent[0] == 0xff or FileContent[0] == 0xfe:
+ FileContent = FileContent.decode('utf-16')
+ else:
+ FileContent = FileContent.decode()
+ except:
+ # The file is not txt file. for example .mcb file
+ continue
+ IncludedFileList = gIncludePattern.findall(FileContent)
+
+ for Inc in IncludedFileList:
+ Inc = Inc.strip()
+ # if there's macro used to reference header file, expand it
+ HeaderList = gMacroPattern.findall(Inc)
+ if len(HeaderList) == 1 and len(HeaderList[0]) == 2:
+ HeaderType = HeaderList[0][0]
+ HeaderKey = HeaderList[0][1]
+ if HeaderType in gIncludeMacroConversion:
+ Inc = gIncludeMacroConversion[HeaderType] % {"HeaderKey" : HeaderKey}
+ else:
+ # not known macro used in #include, always build the file by
+ # returning a empty dependency
+ FileCache[File] = []
+ return []
+ Inc = os.path.normpath(Inc)
+ CurrentFileDependencyList.append(Inc)
+ DepDb[F] = CurrentFileDependencyList
+
+ CurrentFilePath = F.Dir
+ PathList = [CurrentFilePath] + SearchPathList
+ for Inc in CurrentFileDependencyList:
+ for SearchPath in PathList:
+ FilePath = os.path.join(SearchPath, Inc)
+ if FilePath in gIsFileMap:
+ if not gIsFileMap[FilePath]:
+ continue
+ # If isfile is called too many times, the performance is slow down.
+ elif not os.path.isfile(FilePath):
+ gIsFileMap[FilePath] = False
+ continue
+ else:
+ gIsFileMap[FilePath] = True
+ FilePath = PathClass(FilePath)
+ FullPathDependList.append(FilePath)
+ if FilePath not in DependencySet:
+ FileStack.append(FilePath)
+ break
+ else:
+ EdkLogger.debug(EdkLogger.DEBUG_9, "%s included by %s was not found "\
+ "in any given path:\n\t%s" % (Inc, F, "\n\t".join(SearchPathList)))
+
+ FileCache[F] = FullPathDependList
+ DependencySet.update(FullPathDependList)
+
+ DependencySet.update(ForceList)
+ if File in DependencySet:
+ DependencySet.remove(File)
+ DependencyList = list(DependencySet) # remove duplicate ones
+
+ return DependencyList
# This acts like the main() function for the script, unless it is 'import'ed into another script.
if __name__ == '__main__':
- pass
-
+ pass
\ No newline at end of file