X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2Fbuild%2Fbuild.py;h=b5b969e876d2d4f526c0517e8025e7e3b1cc304a;hb=fd2d74007bfae2bcc6da47457189ed9b7cdd106d;hp=36bb1fecf7e570143d11e0ac9f9c6568e13ba9b3;hpb=9eb87141eca12b1f15afa4b769af04d1395891c6;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py index 36bb1fecf7..b5b969e876 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -2,7 +2,8 @@ # build a platform or a module # # Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
+# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -16,33 +17,33 @@ ## # Import Modules # +from __future__ import print_function import Common.LongFilePathOs as os import re -import StringIO +from io import BytesIO import sys import glob import time import platform import traceback import encodings.ascii -import itertools import multiprocessing from struct import * from threading import * +import threading from optparse import OptionParser from subprocess import * from Common import Misc as Utils from Common.LongFilePathSupport import OpenLongFilePath as open -from Common.LongFilePathSupport import LongFilePath -from Common.TargetTxtClassObject import * -from Common.ToolDefClassObject import * +from Common.TargetTxtClassObject import TargetTxtClassObject +from Common.ToolDefClassObject import ToolDefClassObject from Common.DataType import * from Common.BuildVersion import gBUILD_VERSION from AutoGen.AutoGen import * from Common.BuildToolError import * -from Workspace.WorkspaceDatabase import * +from Workspace.WorkspaceDatabase import WorkspaceDatabase from Common.MultipleWorkspace import MultipleWorkspace as mws from BuildReport import BuildReport @@ -51,14 +52,14 @@ from PatchPcdValue.PatchPcdValue import * import Common.EdkLogger import Common.GlobalData as GlobalData -from GenFds.GenFds import GenFds +from GenFds.GenFds import GenFds, GenFdsApi -from collections import OrderedDict,defaultdict +from collections import OrderedDict, defaultdict # Version and Copyright VersionNumber = "0.60" + ' ' + gBUILD_VERSION __version__ = "%prog Version " + VersionNumber -__copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation All rights reserved." +__copyright__ = "Copyright (c) 2007 - 2018, Intel Corporation All rights reserved." ## standard targets of build command gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run'] @@ -76,7 +77,7 @@ TmpTableDict = {} # Otherwise, False is returned # def IsToolInPath(tool): - if os.environ.has_key('PATHEXT'): + if 'PATHEXT' in os.environ: extns = os.environ['PATHEXT'].split(os.path.pathsep) else: extns = ('',) @@ -105,81 +106,25 @@ def CheckEnvVariable(): WorkspaceDir = os.path.normcase(os.path.normpath(os.environ["WORKSPACE"])) if not os.path.exists(WorkspaceDir): - EdkLogger.error("build", FILE_NOT_FOUND, "WORKSPACE doesn't exist", ExtraData="%s" % WorkspaceDir) + EdkLogger.error("build", FILE_NOT_FOUND, "WORKSPACE doesn't exist", ExtraData=WorkspaceDir) elif ' ' in WorkspaceDir: EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in WORKSPACE path", ExtraData=WorkspaceDir) os.environ["WORKSPACE"] = WorkspaceDir - + # set multiple workspace PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(WorkspaceDir, PackagesPath) if mws.PACKAGES_PATH: for Path in mws.PACKAGES_PATH: if not os.path.exists(Path): - EdkLogger.error("build", FILE_NOT_FOUND, "One Path in PACKAGES_PATH doesn't exist", ExtraData="%s" % Path) + EdkLogger.error("build", FILE_NOT_FOUND, "One Path in PACKAGES_PATH doesn't exist", ExtraData=Path) elif ' ' in Path: EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in PACKAGES_PATH", ExtraData=Path) - # - # Check EFI_SOURCE (Edk build convention). EDK_SOURCE will always point to ECP - # - if "ECP_SOURCE" not in os.environ: - os.environ["ECP_SOURCE"] = mws.join(WorkspaceDir, GlobalData.gEdkCompatibilityPkg) - if "EFI_SOURCE" not in os.environ: - os.environ["EFI_SOURCE"] = os.environ["ECP_SOURCE"] - if "EDK_SOURCE" not in os.environ: - os.environ["EDK_SOURCE"] = os.environ["ECP_SOURCE"] - - # - # Unify case of characters on case-insensitive systems - # - EfiSourceDir = os.path.normcase(os.path.normpath(os.environ["EFI_SOURCE"])) - EdkSourceDir = os.path.normcase(os.path.normpath(os.environ["EDK_SOURCE"])) - EcpSourceDir = os.path.normcase(os.path.normpath(os.environ["ECP_SOURCE"])) - os.environ["EFI_SOURCE"] = EfiSourceDir - os.environ["EDK_SOURCE"] = EdkSourceDir - os.environ["ECP_SOURCE"] = EcpSourceDir os.environ["EDK_TOOLS_PATH"] = os.path.normcase(os.environ["EDK_TOOLS_PATH"]) - if not os.path.exists(EcpSourceDir): - EdkLogger.verbose("ECP_SOURCE = %s doesn't exist. Edk modules could not be built." % EcpSourceDir) - elif ' ' in EcpSourceDir: - EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in ECP_SOURCE path", - ExtraData=EcpSourceDir) - if not os.path.exists(EdkSourceDir): - if EdkSourceDir == EcpSourceDir: - EdkLogger.verbose("EDK_SOURCE = %s doesn't exist. Edk modules could not be built." % EdkSourceDir) - else: - EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE does not exist", - ExtraData=EdkSourceDir) - elif ' ' in EdkSourceDir: - EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in EDK_SOURCE path", - ExtraData=EdkSourceDir) - if not os.path.exists(EfiSourceDir): - if EfiSourceDir == EcpSourceDir: - EdkLogger.verbose("EFI_SOURCE = %s doesn't exist. Edk modules could not be built." % EfiSourceDir) - else: - EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE does not exist", - ExtraData=EfiSourceDir) - elif ' ' in EfiSourceDir: - EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in EFI_SOURCE path", - ExtraData=EfiSourceDir) - - # check those variables on single workspace case - if not PackagesPath: - # change absolute path to relative path to WORKSPACE - if EfiSourceDir.upper().find(WorkspaceDir.upper()) != 0: - EdkLogger.error("build", PARAMETER_INVALID, "EFI_SOURCE is not under WORKSPACE", - ExtraData="WORKSPACE = %s\n EFI_SOURCE = %s" % (WorkspaceDir, EfiSourceDir)) - if EdkSourceDir.upper().find(WorkspaceDir.upper()) != 0: - EdkLogger.error("build", PARAMETER_INVALID, "EDK_SOURCE is not under WORKSPACE", - ExtraData="WORKSPACE = %s\n EDK_SOURCE = %s" % (WorkspaceDir, EdkSourceDir)) - if EcpSourceDir.upper().find(WorkspaceDir.upper()) != 0: - EdkLogger.error("build", PARAMETER_INVALID, "ECP_SOURCE is not under WORKSPACE", - ExtraData="WORKSPACE = %s\n ECP_SOURCE = %s" % (WorkspaceDir, EcpSourceDir)) - # check EDK_TOOLS_PATH if "EDK_TOOLS_PATH" not in os.environ: EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found", @@ -191,16 +136,10 @@ def CheckEnvVariable(): ExtraData="PATH") GlobalData.gWorkspace = WorkspaceDir - GlobalData.gEfiSource = EfiSourceDir - GlobalData.gEdkSource = EdkSourceDir - GlobalData.gEcpSource = EcpSourceDir GlobalData.gGlobalDefines["WORKSPACE"] = WorkspaceDir - GlobalData.gGlobalDefines["EFI_SOURCE"] = EfiSourceDir - GlobalData.gGlobalDefines["EDK_SOURCE"] = EdkSourceDir - GlobalData.gGlobalDefines["ECP_SOURCE"] = EcpSourceDir GlobalData.gGlobalDefines["EDK_TOOLS_PATH"] = os.environ["EDK_TOOLS_PATH"] - + ## Get normalized file path # # Convert the path to be local format, and remove the WORKSPACE path at the @@ -265,7 +204,7 @@ def LaunchCommand(Command, WorkingDir): # if working directory doesn't exist, Popen() will raise an exception if not os.path.isdir(WorkingDir): EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=WorkingDir) - + # Command is used as the first Argument in following Popen(). # It could be a string or sequence. We find that if command is a string in following Popen(), # ubuntu may fail with an error message that the command is not found. @@ -304,7 +243,7 @@ def LaunchCommand(Command, WorkingDir): if EndOfProcedure is not None: EndOfProcedure.set() if Proc is None: - if type(Command) != type(""): + if not isinstance(Command, type("")): Command = " ".join(Command) EdkLogger.error("build", COMMAND_FAILURE, "Failed to start command", ExtraData="%s [%s]" % (Command, WorkingDir)) @@ -315,7 +254,7 @@ def LaunchCommand(Command, WorkingDir): # check the return code of the program if Proc.returncode != 0: - if type(Command) != type(""): + if not isinstance(Command, type("")): Command = " ".join(Command) # print out the Response file and its content when make failure RespFile = os.path.join(WorkingDir, 'OUTPUT', 'respfilelist.txt') @@ -377,7 +316,8 @@ class BuildUnit: # @param Other The other BuildUnit object compared to # def __eq__(self, Other): - return Other is not None and self.BuildObject == Other.BuildObject \ + return Other and self.BuildObject == Other.BuildObject \ + and Other.BuildObject \ and self.BuildObject.Arch == Other.BuildObject.Arch ## hash() method @@ -524,7 +464,7 @@ class BuildTask: BuildTask._Thread.acquire(True) # start a new build thread - Bo,Bt = BuildTask._ReadyQueue.popitem() + Bo, Bt = BuildTask._ReadyQueue.popitem() # move into running queue BuildTask._RunningQueueLock.acquire() @@ -544,10 +484,10 @@ class BuildTask: # while not BuildTask._ErrorFlag.isSet() and \ while len(BuildTask._RunningQueue) > 0: EdkLogger.verbose("Waiting for thread ending...(%d)" % len(BuildTask._RunningQueue)) - EdkLogger.debug(EdkLogger.DEBUG_8, "Threads [%s]" % ", ".join([Th.getName() for Th in threading.enumerate()])) + EdkLogger.debug(EdkLogger.DEBUG_8, "Threads [%s]" % ", ".join(Th.getName() for Th in threading.enumerate())) # avoid tense loop time.sleep(0.1) - except BaseException, X: + except BaseException as X: # # TRICK: hide the output of threads left runing, so that the user can # catch the error message easily @@ -724,7 +664,7 @@ class PeImageInfo(): self.OutputDir = OutputDir self.DebugDir = DebugDir self.Image = ImageClass - self.Image.Size = (self.Image.Size / 0x1000 + 1) * 0x1000 + self.Image.Size = (self.Image.Size // 0x1000 + 1) * 0x1000 ## The class implementing the EDK2 build process # @@ -825,10 +765,7 @@ class Build(): GlobalData.gConfDirectory = ConfDirectoryPath GlobalData.gDatabasePath = os.path.normpath(os.path.join(ConfDirectoryPath, GlobalData.gDatabasePath)) - if BuildOptions.DisableCache: - self.Db = WorkspaceDatabase(":memory:") - else: - self.Db = WorkspaceDatabase(GlobalData.gDatabasePath, self.Reparse) + self.Db = WorkspaceDatabase() self.BuildDatabase = self.Db.BuildObject self.Platform = None self.ToolChainFamily = None @@ -838,7 +775,7 @@ class Build(): self.HashSkipModules = [] self.Db_Flag = False self.LaunchPrebuildFlag = False - self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory,'.cache', '.PlatformBuild') + self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory, '.cache', '.PlatformBuild') if BuildOptions.CommandLength: GlobalData.gCommandMaxLength = BuildOptions.CommandLength @@ -847,16 +784,19 @@ class Build(): # print current build environment and configuration EdkLogger.quiet("%-16s = %s" % ("WORKSPACE", os.environ["WORKSPACE"])) if "PACKAGES_PATH" in os.environ: - # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env. + # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env. EdkLogger.quiet("%-16s = %s" % ("PACKAGES_PATH", os.path.normcase(os.path.normpath(os.environ["PACKAGES_PATH"])))) - EdkLogger.quiet("%-16s = %s" % ("ECP_SOURCE", os.environ["ECP_SOURCE"])) - EdkLogger.quiet("%-16s = %s" % ("EDK_SOURCE", os.environ["EDK_SOURCE"])) - EdkLogger.quiet("%-16s = %s" % ("EFI_SOURCE", os.environ["EFI_SOURCE"])) EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"])) if "EDK_TOOLS_BIN" in os.environ: - # Print the same path style with WORKSPACE env. + # Print the same path style with WORKSPACE env. EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"])))) EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", GlobalData.gConfDirectory)) + if "PYTHON3_ENABLE" in os.environ: + PYTHON3_ENABLE = os.environ["PYTHON3_ENABLE"] + if PYTHON3_ENABLE != "TRUE": + PYTHON3_ENABLE = "FALSE" + EdkLogger.quiet("%-16s = %s" % ("PYTHON3_ENABLE", PYTHON3_ENABLE)) + EdkLogger.quiet("%-16s = %s" % ("PYTHON", os.environ["PYTHON"])) self.InitPreBuild() self.InitPostBuild() if self.Prebuild: @@ -885,7 +825,7 @@ class Build(): if os.path.isfile(BuildConfigurationFile) == True: StatusCode = self.TargetTxt.LoadTargetTxtFile(BuildConfigurationFile) - ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF] + ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF] if ToolDefinitionFile == '': ToolDefinitionFile = gToolsDefinition ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile)) @@ -898,16 +838,16 @@ class Build(): # if no ARCH given in command line, get it from target.txt if not self.ArchList: - self.ArchList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET_ARCH] + self.ArchList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH] self.ArchList = tuple(self.ArchList) # if no build target given in command line, get it from target.txt if not self.BuildTargetList: - self.BuildTargetList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET] + self.BuildTargetList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET] # if no tool chain given in command line, get it from target.txt if not self.ToolChainList: - self.ToolChainList = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG] + self.ToolChainList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_TAG] if self.ToolChainList is None or len(self.ToolChainList) == 0: EdkLogger.error("build", RESOURCE_NOT_AVAILABLE, ExtraData="No toolchain given. Don't know how to build.\n") @@ -931,13 +871,13 @@ class Build(): if TAB_TOD_DEFINES_FAMILY not in ToolDefinition or Tool not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \ or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool]: EdkLogger.warn("build", "No tool chain family found in configuration for %s. Default to MSFT." % Tool) - ToolChainFamily.append("MSFT") + ToolChainFamily.append(TAB_COMPILER_MSFT) else: ToolChainFamily.append(ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool]) self.ToolChainFamily = ToolChainFamily if self.ThreadNumber is None: - self.ThreadNumber = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER] + self.ThreadNumber = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER] if self.ThreadNumber == '': self.ThreadNumber = 0 else: @@ -950,7 +890,7 @@ class Build(): self.ThreadNumber = 1 if not self.PlatformFile: - PlatformFile = self.TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM] + PlatformFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_ACTIVE_PLATFORM] if not PlatformFile: # Try to find one in current directory WorkingDirectory = os.getcwd() @@ -981,9 +921,6 @@ class Build(): if ErrorCode != 0: EdkLogger.error("build", ErrorCode, ExtraData=ErrorInfo) - # create metafile database - if not self.Db_Flag: - self.Db.InitDatabase() def InitPreBuild(self): self.LoadConfiguration() @@ -1002,9 +939,8 @@ class Build(): if 'PREBUILD' in GlobalData.gCommandLineDefines: self.Prebuild = GlobalData.gCommandLineDefines.get('PREBUILD') else: - self.Db.InitDatabase() self.Db_Flag = True - Platform = self.Db._MapPlatform(str(self.PlatformFile)) + Platform = self.Db.MapPlatform(str(self.PlatformFile)) self.Prebuild = str(Platform.Prebuild) if self.Prebuild: PrebuildList = [] @@ -1043,7 +979,7 @@ class Build(): if 'POSTBUILD' in GlobalData.gCommandLineDefines: self.Postbuild = GlobalData.gCommandLineDefines.get('POSTBUILD') else: - Platform = self.Db._MapPlatform(str(self.PlatformFile)) + Platform = self.Db.MapPlatform(str(self.PlatformFile)) self.Postbuild = str(Platform.Postbuild) if self.Postbuild: PostbuildList = [] @@ -1131,7 +1067,7 @@ class Build(): # and preserve them for the rest of the main build step, because the child process environment will # evaporate as soon as it exits, we cannot get it in build step. # - PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory,'.cache','.PrebuildEnv') + PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory, '.cache', '.PrebuildEnv') if os.path.isfile(PrebuildEnvFile): os.remove(PrebuildEnvFile) if os.path.isfile(self.PlatformBuildPath): @@ -1171,9 +1107,8 @@ class Build(): f = open(PrebuildEnvFile) envs = f.readlines() f.close() - envs = itertools.imap(lambda l: l.split('=',1), envs) - envs = itertools.ifilter(lambda l: len(l) == 2, envs) - envs = itertools.imap(lambda l: [i.strip() for i in l], envs) + envs = [l.split("=", 1) for l in envs ] + envs = [[I.strip() for I in item] for item in envs if len(item) == 2] os.environ.update(dict(envs)) EdkLogger.info("\n- Prebuild Done -\n") @@ -1323,7 +1258,7 @@ class Build(): try: #os.rmdir(AutoGenObject.BuildDir) RemoveDirectory(AutoGenObject.BuildDir, True) - except WindowsError, X: + except WindowsError as X: EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X)) return True @@ -1390,7 +1325,8 @@ class Build(): # genfds if Target == 'fds': - LaunchCommand(AutoGenObject.GenFdsCommand, AutoGenObject.MakeFileDir) + if GenFdsApi(AutoGenObject.GenFdsCommandDict, self.Db): + EdkLogger.error("build", COMMAND_FAILURE) return True # run @@ -1413,7 +1349,7 @@ class Build(): try: #os.rmdir(AutoGenObject.BuildDir) RemoveDirectory(AutoGenObject.BuildDir, True) - except WindowsError, X: + except WindowsError as X: EdkLogger.error("build", FILE_DELETE_FAILURE, ExtraData=str(X)) return True @@ -1467,11 +1403,7 @@ class Build(): Name = StrList[1] RelativeAddress = int (StrList[2], 16) - OrigImageBaseAddress FunctionList.append ((Name, RelativeAddress)) - if ModuleInfo.Arch == 'IPF' and Name.endswith('_ModuleEntryPoint'): - # - # Get the real entry point address for IPF image. - # - ModuleInfo.Image.EntryPoint = RelativeAddress + ImageMap.close() # # Add general information. @@ -1542,7 +1474,7 @@ class Build(): GuidString = MatchGuid.group() if GuidString.upper() in ModuleList: Line = Line.replace(GuidString, ModuleList[GuidString.upper()].Name) - MapBuffer.write('%s' % (Line)) + MapBuffer.write(Line) # # Add the debug image full path. # @@ -1569,9 +1501,6 @@ class Build(): RtSize = 0 # reserve 4K size in SMRAM to make SMM module address not from 0. SmmSize = 0x1000 - IsIpfPlatform = False - if 'IPF' in self.ArchList: - IsIpfPlatform = True for ModuleGuid in ModuleList: Module = ModuleList[ModuleGuid] GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (Module.MetaFile, Module.Arch, Module.ToolChain, Module.BuildTarget) @@ -1587,22 +1516,19 @@ class Build(): if not ImageClass.IsValid: EdkLogger.error("build", FILE_PARSE_FAILURE, ExtraData=ImageClass.ErrorInfo) ImageInfo = PeImageInfo(Module.Name, Module.Guid, Module.Arch, Module.OutputDir, Module.DebugDir, ImageClass) - if Module.ModuleType in ['PEI_CORE', 'PEIM', 'COMBINED_PEIM_DRIVER', 'PIC_PEIM', 'RELOCATABLE_PEIM', 'DXE_CORE']: + if Module.ModuleType in [SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM, EDK_COMPONENT_TYPE_COMBINED_PEIM_DRIVER, EDK_COMPONENT_TYPE_PIC_PEIM, EDK_COMPONENT_TYPE_RELOCATABLE_PEIM, SUP_MODULE_DXE_CORE]: PeiModuleList[Module.MetaFile] = ImageInfo PeiSize += ImageInfo.Image.Size - elif Module.ModuleType in ['BS_DRIVER', 'DXE_DRIVER', 'UEFI_DRIVER']: + elif Module.ModuleType in [EDK_COMPONENT_TYPE_BS_DRIVER, SUP_MODULE_DXE_DRIVER, SUP_MODULE_UEFI_DRIVER]: BtModuleList[Module.MetaFile] = ImageInfo BtSize += ImageInfo.Image.Size - elif Module.ModuleType in ['DXE_RUNTIME_DRIVER', 'RT_DRIVER', 'DXE_SAL_DRIVER', 'SAL_RT_DRIVER']: + elif Module.ModuleType in [SUP_MODULE_DXE_RUNTIME_DRIVER, EDK_COMPONENT_TYPE_RT_DRIVER, SUP_MODULE_DXE_SAL_DRIVER, EDK_COMPONENT_TYPE_SAL_RT_DRIVER]: RtModuleList[Module.MetaFile] = ImageInfo - #IPF runtime driver needs to be at 2 page alignment. - if IsIpfPlatform and ImageInfo.Image.Size % 0x2000 != 0: - ImageInfo.Image.Size = (ImageInfo.Image.Size / 0x2000 + 1) * 0x2000 RtSize += ImageInfo.Image.Size - elif Module.ModuleType in ['SMM_CORE', 'DXE_SMM_DRIVER', 'MM_STANDALONE', 'MM_CORE_STANDALONE']: + elif Module.ModuleType in [SUP_MODULE_SMM_CORE, SUP_MODULE_DXE_SMM_DRIVER, SUP_MODULE_MM_STANDALONE, SUP_MODULE_MM_CORE_STANDALONE]: SmmModuleList[Module.MetaFile] = ImageInfo SmmSize += ImageInfo.Image.Size - if Module.ModuleType == 'DXE_SMM_DRIVER': + if Module.ModuleType == SUP_MODULE_DXE_SMM_DRIVER: PiSpecVersion = Module.Module.Specification.get('PI_SPECIFICATION_VERSION', '0x00000000') # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver. if int(PiSpecVersion, 16) < 0x0001000A: @@ -1616,12 +1542,12 @@ class Build(): if OutputImageFile != '': ModuleIsPatch = False for Pcd in Module.ModulePcdList: - if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_LIST: + if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET: ModuleIsPatch = True break if not ModuleIsPatch: for Pcd in Module.LibraryPcdList: - if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_LIST: + if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE and Pcd.TokenCName in TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SET: ModuleIsPatch = True break @@ -1644,10 +1570,6 @@ class Build(): TopMemoryAddress = self.LoadFixAddress if TopMemoryAddress < RtSize + BtSize + PeiSize: EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is too low to load driver") - # Make IPF runtime driver at 2 page alignment. - if IsIpfPlatform: - ReservedRuntimeMemorySize = TopMemoryAddress % 0x2000 - RtSize = RtSize + ReservedRuntimeMemorySize # # Patch FixAddress related PCDs into EFI image @@ -1666,21 +1588,21 @@ class Build(): for PcdInfo in PcdTable: ReturnValue = 0 if PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE: - ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize / 0x1000)) + ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_PEI_PAGE_SIZE_DATA_TYPE, str (PeiSize // 0x1000)) elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE: - ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize / 0x1000)) + ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_DXE_PAGE_SIZE_DATA_TYPE, str (BtSize // 0x1000)) elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE: - ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize / 0x1000)) + ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_RUNTIME_PAGE_SIZE_DATA_TYPE, str (RtSize // 0x1000)) elif PcdInfo[0] == TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE and len (SmmModuleList) > 0: - ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize / 0x1000)) + ReturnValue, ErrorInfo = PatchBinaryFile (EfiImage, PcdInfo[1], TAB_PCDS_PATCHABLE_LOAD_FIX_ADDRESS_SMM_PAGE_SIZE_DATA_TYPE, str (SmmSize // 0x1000)) if ReturnValue != 0: EdkLogger.error("build", PARAMETER_INVALID, "Patch PCD value failed", ExtraData=ErrorInfo) - MapBuffer.write('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize / 0x1000)) - MapBuffer.write('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize / 0x1000)) - MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize / 0x1000)) + MapBuffer.write('PEI_CODE_PAGE_NUMBER = 0x%x\n' % (PeiSize // 0x1000)) + MapBuffer.write('BOOT_CODE_PAGE_NUMBER = 0x%x\n' % (BtSize // 0x1000)) + MapBuffer.write('RUNTIME_CODE_PAGE_NUMBER = 0x%x\n' % (RtSize // 0x1000)) if len (SmmModuleList) > 0: - MapBuffer.write('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize / 0x1000)) + MapBuffer.write('SMM_CODE_PAGE_NUMBER = 0x%x\n' % (SmmSize // 0x1000)) PeiBaseAddr = TopMemoryAddress - RtSize - BtSize BtBaseAddr = TopMemoryAddress - RtSize @@ -1780,7 +1702,7 @@ class Build(): if not Ma.IsLibrary: ModuleList[Ma.Guid.upper()] = Ma - MapBuffer = StringIO('') + MapBuffer = BytesIO('') if self.LoadFixAddress != 0: # # Rebase module to the preferred memory address before GenFds @@ -1938,7 +1860,7 @@ class Build(): if not Ma.IsLibrary: ModuleList[Ma.Guid.upper()] = Ma - MapBuffer = StringIO('') + MapBuffer = BytesIO('') if self.LoadFixAddress != 0: # # Rebase module to the preferred memory address before GenFds @@ -1960,7 +1882,7 @@ class Build(): self._SaveMapFile (MapBuffer, Wa) def _GenFfsCmd(self): - # convert dictionary of Cmd:(Inf,Arch) + # convert dictionary of Cmd:(Inf,Arch) # to a new dictionary of (Inf,Arch):Cmd,Cmd,Cmd... CmdSetDict = defaultdict(set) GenFfsDict = GenFds.GenFfsMakefile('', GlobalData.gFdfParser, self, self.ArchList, GlobalData) @@ -2032,7 +1954,7 @@ class Build(): for Module in ModuleList: # Get ModuleAutoGen object to generate C code file and makefile Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile) - + if Ma is None: continue if Ma.CanSkipbyHash(): @@ -2081,13 +2003,7 @@ class Build(): self.MakeTime += int(round((time.time() - MakeStart))) MakeContiue = time.time() - # - # Save temp tables to a TmpTableDict. - # - for Key in Wa.BuildDatabase._CACHE_: - if Wa.BuildDatabase._CACHE_[Key]._RawData and Wa.BuildDatabase._CACHE_[Key]._RawData._Table and Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Table: - if TemporaryTablePattern.match(Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Table): - TmpTableDict[Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Table] = Wa.BuildDatabase._CACHE_[Key]._RawData._Table.Cur + # # # All modules have been put in build tasks queue. Tell task scheduler @@ -2125,7 +2041,7 @@ class Build(): # # Rebase module to the preferred memory address before GenFds # - MapBuffer = StringIO('') + MapBuffer = BytesIO('') if self.LoadFixAddress != 0: self._CollectModuleMapBuffer(MapBuffer, ModuleList) @@ -2134,7 +2050,8 @@ class Build(): # Generate FD image if there's a FDF file found # GenFdsStart = time.time() - LaunchCommand(Wa.GenFdsCommand, os.getcwd()) + if GenFdsApi(Wa.GenFdsCommandDict, self.Db): + EdkLogger.error("build", COMMAND_FAILURE) # # Create MAP file for all platform FVs after GenFds. @@ -2177,7 +2094,7 @@ class Build(): # Look through the tool definitions for GUIDed tools guidAttribs = [] - for (attrib, value) in self.ToolDef.ToolsDefTxtDictionary.iteritems(): + for (attrib, value) in self.ToolDef.ToolsDefTxtDictionary.items(): if attrib.upper().endswith('_GUID'): split = attrib.split('_') thisPrefix = '_'.join(split[0:3]) + '_' @@ -2194,7 +2111,7 @@ class Build(): toolsFile = os.path.join(FvDir, 'GuidedSectionTools.txt') toolsFile = open(toolsFile, 'wt') for guidedSectionTool in guidAttribs: - print >> toolsFile, ' '.join(guidedSectionTool) + print(' '.join(guidedSectionTool), file=toolsFile) toolsFile.close() ## Returns the full path of the tool. @@ -2229,7 +2146,6 @@ class Build(): self._BuildModule() if self.Target == 'cleanall': - self.Db.Close() RemoveDirectory(os.path.dirname(GlobalData.gDatabasePath), True) def CreateAsBuiltInf(self): @@ -2243,31 +2159,11 @@ class Build(): def Relinquish(self): OldLogLevel = EdkLogger.GetLevel() EdkLogger.SetLevel(EdkLogger.ERROR) - #self.DumpBuildData() Utils.Progressor.Abort() if self.SpawnMode == True: BuildTask.Abort() EdkLogger.SetLevel(OldLogLevel) - def DumpBuildData(self): - CacheDirectory = os.path.dirname(GlobalData.gDatabasePath) - Utils.CreateDirectory(CacheDirectory) - Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache")) - Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase")) - - def RestoreBuildData(self): - FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gFileTimeStampCache") - if Utils.gFileTimeStampCache == {} and os.path.isfile(FilePath): - Utils.gFileTimeStampCache = Utils.DataRestore(FilePath) - if Utils.gFileTimeStampCache is None: - Utils.gFileTimeStampCache = {} - - FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gDependencyDatabase") - if Utils.gDependencyDatabase == {} and os.path.isfile(FilePath): - Utils.gDependencyDatabase = Utils.DataRestore(FilePath) - if Utils.gDependencyDatabase is None: - Utils.gDependencyDatabase = {} - def ParseDefines(DefineList=[]): DefineDict = {} if DefineList is not None: @@ -2313,8 +2209,8 @@ def LogBuildTime(Time): # def MyOptionParser(): Parser = OptionParser(description=__copyright__, version=__version__, prog="build.exe", usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]") - Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'IPF', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch", - help="ARCHS is one of list: IA32, X64, IPF, ARM, AARCH64 or EBC, which overrides target.txt's TARGET_ARCH definition. To specify more archs, please repeat this option.") + Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch", + help="ARCHS is one of list: IA32, X64, ARM, AARCH64 or EBC, which overrides target.txt's TARGET_ARCH definition. To specify more archs, please repeat this option.") Parser.add_option("-p", "--platform", action="callback", type="string", dest="PlatformFile", callback=SingleCheckCallback, help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.") Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback, @@ -2356,7 +2252,7 @@ def MyOptionParser(): Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".") Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.") - Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD','LIBRARY','FLASH','DEPEX','BUILD_FLAGS','FIXED_ADDRESS','HASH','EXECUTION_ORDER'], dest="ReportType", default=[], + Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', 'FIXED_ADDRESS', 'HASH', 'EXECUTION_ORDER'], dest="ReportType", default=[], help="Flags that control the type of build report to generate. Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, HASH, EXECUTION_ORDER]. "\ "To specify more than one flag, repeat this option on the command line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, HASH, BUILD_FLAGS, FIXED_ADDRESS]") Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag", @@ -2490,23 +2386,19 @@ def Main(): GlobalData.gCommandLineDefines['ARCH'] = ' '.join(MyBuild.ArchList) if not (MyBuild.LaunchPrebuildFlag and os.path.exists(MyBuild.PlatformBuildPath)): MyBuild.Launch() - # Drop temp tables to avoid database locked. - for TmpTableName in TmpTableDict: - SqlCommand = """drop table IF EXISTS %s""" % TmpTableName - TmpTableDict[TmpTableName].execute(SqlCommand) - #MyBuild.DumpBuildData() + # # All job done, no error found and no exception raised # BuildError = False - except FatalError, X: + except FatalError as X: if MyBuild is not None: # for multi-thread build exits safely MyBuild.Relinquish() if Option is not None and Option.debug is not None: EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc()) ReturnCode = X.args[0] - except Warning, X: + except Warning as X: # error from Fdf parser if MyBuild is not None: # for multi-thread build exits safely @@ -2565,7 +2457,7 @@ def Main(): if MyBuild is not None: if not BuildError: MyBuild.BuildReport.GenerateReport(BuildDurationStr, LogBuildTime(MyBuild.AutoGenTime), LogBuildTime(MyBuild.MakeTime), LogBuildTime(MyBuild.GenFdsTime)) - MyBuild.Db.Close() + EdkLogger.SetLevel(EdkLogger.QUIET) EdkLogger.quiet("\n- %s -" % Conclusion) EdkLogger.quiet(time.strftime("Build end time: %H:%M:%S, %b.%d %Y", time.localtime()))