##\r
# Import Modules\r
#\r
+from __future__ import print_function\r
import Common.LongFilePathOs as os\r
import re\r
-import StringIO\r
+from io import BytesIO\r
import sys\r
import glob\r
import time\r
import Common.GlobalData as GlobalData\r
from GenFds.GenFds import GenFds\r
\r
-from collections import OrderedDict,defaultdict\r
+from collections import OrderedDict, defaultdict\r
\r
# Version and Copyright\r
VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
__version__ = "%prog Version " + VersionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2017, Intel Corporation All rights reserved."\r
+__copyright__ = "Copyright (c) 2007 - 2018, Intel Corporation All rights reserved."\r
\r
## standard targets of build command\r
gSupportedTarget = ['all', 'genc', 'genmake', 'modules', 'libraries', 'fds', 'clean', 'cleanall', 'cleanlib', 'run']\r
# Otherwise, False is returned\r
#\r
def IsToolInPath(tool):\r
- if os.environ.has_key('PATHEXT'):\r
+ if 'PATHEXT' in os.environ:\r
extns = os.environ['PATHEXT'].split(os.path.pathsep)\r
else:\r
extns = ('',)\r
EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in WORKSPACE path",\r
ExtraData=WorkspaceDir)\r
os.environ["WORKSPACE"] = WorkspaceDir\r
- \r
+\r
# set multiple workspace\r
PackagesPath = os.getenv("PACKAGES_PATH")\r
mws.setWs(WorkspaceDir, PackagesPath)\r
GlobalData.gGlobalDefines["EDK_SOURCE"] = EdkSourceDir\r
GlobalData.gGlobalDefines["ECP_SOURCE"] = EcpSourceDir\r
GlobalData.gGlobalDefines["EDK_TOOLS_PATH"] = os.environ["EDK_TOOLS_PATH"]\r
- \r
+\r
## Get normalized file path\r
#\r
# Convert the path to be local format, and remove the WORKSPACE path at the\r
# if working directory doesn't exist, Popen() will raise an exception\r
if not os.path.isdir(WorkingDir):\r
EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=WorkingDir)\r
- \r
+\r
# Command is used as the first Argument in following Popen().\r
# It could be a string or sequence. We find that if command is a string in following Popen(),\r
# ubuntu may fail with an error message that the command is not found.\r
if EndOfProcedure is not None:\r
EndOfProcedure.set()\r
if Proc is None:\r
- if type(Command) != type(""):\r
+ if not isinstance(Command, type("")):\r
Command = " ".join(Command)\r
EdkLogger.error("build", COMMAND_FAILURE, "Failed to start command", ExtraData="%s [%s]" % (Command, WorkingDir))\r
\r
\r
# check the return code of the program\r
if Proc.returncode != 0:\r
- if type(Command) != type(""):\r
+ if not isinstance(Command, type("")):\r
Command = " ".join(Command)\r
# print out the Response file and its content when make failure\r
RespFile = os.path.join(WorkingDir, 'OUTPUT', 'respfilelist.txt')\r
BuildTask._Thread.acquire(True)\r
\r
# start a new build thread\r
- Bo,Bt = BuildTask._ReadyQueue.popitem()\r
+ Bo, Bt = BuildTask._ReadyQueue.popitem()\r
\r
# move into running queue\r
BuildTask._RunningQueueLock.acquire()\r
self.HashSkipModules = []\r
self.Db_Flag = False\r
self.LaunchPrebuildFlag = False\r
- self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory,'.cache', '.PlatformBuild')\r
+ self.PlatformBuildPath = os.path.join(GlobalData.gConfDirectory, '.cache', '.PlatformBuild')\r
if BuildOptions.CommandLength:\r
GlobalData.gCommandMaxLength = BuildOptions.CommandLength\r
\r
# print current build environment and configuration\r
EdkLogger.quiet("%-16s = %s" % ("WORKSPACE", os.environ["WORKSPACE"]))\r
if "PACKAGES_PATH" in os.environ:\r
- # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env. \r
+ # WORKSPACE env has been converted before. Print the same path style with WORKSPACE env.\r
EdkLogger.quiet("%-16s = %s" % ("PACKAGES_PATH", os.path.normcase(os.path.normpath(os.environ["PACKAGES_PATH"]))))\r
EdkLogger.quiet("%-16s = %s" % ("ECP_SOURCE", os.environ["ECP_SOURCE"]))\r
EdkLogger.quiet("%-16s = %s" % ("EDK_SOURCE", os.environ["EDK_SOURCE"]))\r
EdkLogger.quiet("%-16s = %s" % ("EFI_SOURCE", os.environ["EFI_SOURCE"]))\r
EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_PATH", os.environ["EDK_TOOLS_PATH"]))\r
if "EDK_TOOLS_BIN" in os.environ:\r
- # Print the same path style with WORKSPACE env. \r
+ # Print the same path style with WORKSPACE env.\r
EdkLogger.quiet("%-16s = %s" % ("EDK_TOOLS_BIN", os.path.normcase(os.path.normpath(os.environ["EDK_TOOLS_BIN"]))))\r
EdkLogger.quiet("%-16s = %s" % ("CONF_PATH", GlobalData.gConfDirectory))\r
self.InitPreBuild()\r
if TAB_TOD_DEFINES_FAMILY not in ToolDefinition or Tool not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool]:\r
EdkLogger.warn("build", "No tool chain family found in configuration for %s. Default to MSFT." % Tool)\r
- ToolChainFamily.append("MSFT")\r
+ ToolChainFamily.append(TAB_COMPILER_MSFT)\r
else:\r
ToolChainFamily.append(ToolDefinition[TAB_TOD_DEFINES_FAMILY][Tool])\r
self.ToolChainFamily = ToolChainFamily\r
# and preserve them for the rest of the main build step, because the child process environment will\r
# evaporate as soon as it exits, we cannot get it in build step.\r
#\r
- PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory,'.cache','.PrebuildEnv')\r
+ PrebuildEnvFile = os.path.join(GlobalData.gConfDirectory, '.cache', '.PrebuildEnv')\r
if os.path.isfile(PrebuildEnvFile):\r
os.remove(PrebuildEnvFile)\r
if os.path.isfile(self.PlatformBuildPath):\r
f = open(PrebuildEnvFile)\r
envs = f.readlines()\r
f.close()\r
- envs = itertools.imap(lambda l: l.split('=',1), envs)\r
+ envs = itertools.imap(lambda l: l.split('=', 1), envs)\r
envs = itertools.ifilter(lambda l: len(l) == 2, envs)\r
envs = itertools.imap(lambda l: [i.strip() for i in l], envs)\r
os.environ.update(dict(envs))\r
if not Ma.IsLibrary:\r
ModuleList[Ma.Guid.upper()] = Ma\r
\r
- MapBuffer = StringIO('')\r
+ MapBuffer = BytesIO('')\r
if self.LoadFixAddress != 0:\r
#\r
# Rebase module to the preferred memory address before GenFds\r
if not Ma.IsLibrary:\r
ModuleList[Ma.Guid.upper()] = Ma\r
\r
- MapBuffer = StringIO('')\r
+ MapBuffer = BytesIO('')\r
if self.LoadFixAddress != 0:\r
#\r
# Rebase module to the preferred memory address before GenFds\r
self._SaveMapFile (MapBuffer, Wa)\r
\r
def _GenFfsCmd(self):\r
- # convert dictionary of Cmd:(Inf,Arch) \r
+ # convert dictionary of Cmd:(Inf,Arch)\r
# to a new dictionary of (Inf,Arch):Cmd,Cmd,Cmd...\r
CmdSetDict = defaultdict(set)\r
GenFfsDict = GenFds.GenFfsMakefile('', GlobalData.gFdfParser, self, self.ArchList, GlobalData)\r
for Module in ModuleList:\r
# Get ModuleAutoGen object to generate C code file and makefile\r
Ma = ModuleAutoGen(Wa, Module, BuildTarget, ToolChain, Arch, self.PlatformFile)\r
- \r
+\r
if Ma is None:\r
continue\r
if Ma.CanSkipbyHash():\r
#\r
# Rebase module to the preferred memory address before GenFds\r
#\r
- MapBuffer = StringIO('')\r
+ MapBuffer = BytesIO('')\r
if self.LoadFixAddress != 0:\r
self._CollectModuleMapBuffer(MapBuffer, ModuleList)\r
\r
toolsFile = os.path.join(FvDir, 'GuidedSectionTools.txt')\r
toolsFile = open(toolsFile, 'wt')\r
for guidedSectionTool in guidAttribs:\r
- print >> toolsFile, ' '.join(guidedSectionTool)\r
+ print(' '.join(guidedSectionTool), file=toolsFile)\r
toolsFile.close()\r
\r
## Returns the full path of the tool.\r
Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")\r
\r
Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.")\r
- 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=[],\r
+ 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=[],\r
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]. "\\r
"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]")\r
Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",\r