summaryrefslogtreecommitdiff
path: root/BaseTools/Scripts
diff options
context:
space:
mode:
authorlhauch <larry.hauch@intel.com>2014-08-21 16:41:41 +0000
committerlhauch <lhauch@6f19259b-4bc3-4df7-8a09-765794883524>2014-08-21 16:41:41 +0000
commitbd63012c73486e306a90bc28805d8914b70c8859 (patch)
tree5d9e0577341214ee404598b538d556c472f835ac /BaseTools/Scripts
parent66c6d4d67ed870e9135c05a1f4deb03843c9faec (diff)
downloadedk2-platforms-bd63012c73486e306a90bc28805d8914b70c8859.tar.xz
Adding files for proposed replacement for edksetup.bat.
This changes includes new scripts that breaks out some of the functionality in edksetup.bat and eliminates calling the toolsetup.bat file in BaseTools directory. Edk2Setup.bat is to be used for testing. If no bugs are reported by the end of September, 2014, the file will be renamed to edksetup.bat. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: lhauch <larry.hauch@intel.com> Reviewed-by: Gao, Liming <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15867 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Scripts')
-rw-r--r--BaseTools/Scripts/SetVisualStudio.bat103
-rw-r--r--BaseTools/Scripts/ShowEnvironment.bat207
-rw-r--r--BaseTools/Scripts/UpdateBuildVersions.py400
3 files changed, 710 insertions, 0 deletions
diff --git a/BaseTools/Scripts/SetVisualStudio.bat b/BaseTools/Scripts/SetVisualStudio.bat
new file mode 100644
index 0000000000..a302a83596
--- /dev/null
+++ b/BaseTools/Scripts/SetVisualStudio.bat
@@ -0,0 +1,103 @@
+@REM @file
+@REM Windows batch file to set up the Microsoft Visual Studio environment
+@REM
+@REM This script is used to set up one of the Microsoft Visual Studio
+@REM environments, VS2008x86, VS2010x86, VS2012x86 or VS2013x86 for
+@REM building the Nt32Pkg/Nt32Pkg.dsc emulation environment to run on
+@REM an X64 version of Windows.
+@REM The system environment variables in this script are set by the
+@rem Edk2Setup.bat script (that will be renamed to edksetup.bat).
+@REM
+@REM This script can also be used to build the Win32 binaries
+@REM
+@REM Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+@REM This program and the accompanying materials
+@REM are licensed and made available under the terms and conditions of the BSD License
+@REM which accompanies this distribution. The full text of the license may be found at
+@REM http://opensource.org/licenses/bsd-license.php
+@REM
+@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+@REM
+@echo off
+@if defined NT32_X64 @goto CheckLatest
+@if "%REBUILD_TOOLS%"=="TRUE" @goto RebuildTools
+
+:CheckLatest
+echo.
+@if defined VS120COMNTOOLS (
+ @set "COMMONTOOLSx64=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\x86_amd64"
+ @goto SetVs
+)
+
+@if defined VS110COMNTOOLS (
+ @set "COMMONTOOLSx64=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"
+ @goto SetVs
+)
+
+@if defined VS100COMNTOOLS (
+ @set "COMMONTOOLSx64=C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64"
+ @goto SetVs
+)
+
+@if defined VS90COMNTOOLS (
+ @set "COMMONTOOLSx64=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\x86_amd64"
+ @goto SetVs
+)
+@echo.
+@echo No version of Microsoft Visual Studio was found on this system
+@echo.
+@exit /B 1
+
+@REM Set up the X64 environment for building Nt32Pkg/Nt32Pkg.dsc to run on an X64 platform
+:SetVs
+if exist "%COMMONTOOLSx64%\vcvarsx86_amd64.bat" (
+ @call "%COMMONTOOLSx64%\vcvarsx86_amd64.bat"
+ @if errorlevel 1 (
+ @echo. ERROR setting Microsoft Visual Studio %1
+ @set COMMONTOOLSx64=
+ @exit /B 1
+ )
+)
+if not exist "%COMMONTOOLSx64%\vcvarsx86_amd64.bat" (
+ @echo ERROR : This script does not exist: "%COMMONTOOLSx64%\vcvarsx86_amd64.bat"
+ @set COMMONTOOLSx64=
+ @exit /B 1
+)
+@set COMMONTOOLSx64=
+@goto End
+
+:RebuildTools
+@call python "%WORKSPACE%\BaseTools\Scripts\UpdateBuildVersions.py"
+@set "BIN_DIR=%EDK_TOOLS_PATH%\Bin\Win32"
+if not exist "%BIN_DIR%" @mkdir "%BIN_DIR%"
+@echo Removing temporary and binary files
+@cd "%BASE_TOOLS_PATH%"
+@call nmake cleanall
+@echo Rebuilding the EDK II BaseTools
+@cd "%BASE_TOOLS_PATH%\Source\C"
+@call nmake -nologo -a -f Makefile
+@if errorlevel 1 (
+@echo Error building the C-based BaseTools
+@cd "%WORKSPACE%"
+@exit /B1
+)
+@cd %BASE_TOOLS_PATH%\Source\Python
+@call nmake -nologo -a -f Makefile
+@if errorlevel 1 (
+@echo Error building the Python-based BaseTools
+@cd %WORKSPACE%
+@exit /B1
+)
+@cd %WORKSPACE%
+
+@goto End
+
+:VersionNotFound
+@echo.
+@echo This Microsoft Visual Studio version is in not installed on this system: %1
+@echo.
+@exit /B 1
+
+:End
+@exit /B 0
diff --git a/BaseTools/Scripts/ShowEnvironment.bat b/BaseTools/Scripts/ShowEnvironment.bat
new file mode 100644
index 0000000000..c4613e1170
--- /dev/null
+++ b/BaseTools/Scripts/ShowEnvironment.bat
@@ -0,0 +1,207 @@
+@REM @file
+@REM Windows batch file to display the Windows environment
+@REM
+@REM This script will be used to show the current EDK II build environment.
+@REM it may be called by the Edk2Setup.bat (that will be renamed to edksetup.bat) or
+@REM run as stand-alone application.
+@REM
+@REM Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+@REM This program and the accompanying materials
+@REM are licensed and made available under the terms and conditions of the BSD License
+@REM which accompanies this distribution. The full text of the license may be found at
+@REM http://opensource.org/licenses/bsd-license.php
+@REM
+@REM THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+@REM WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+@REM
+@echo off
+@set SE_SVN_REVISION=$Revision: 8 $
+@set SE_VERSION=0.7.0.
+@if "%SCRIPT%"=="EDKSETUP_BAT" goto SkipCmdlineArgumentCheck
+
+:parse_cmd_line
+@if /I "%1"=="-h" @goto Usage
+@if /I "%1"=="--help" @goto Usage
+@if /I "%1"=="/?" @goto Usage
+@if /I "%1"=="-v" @goto Version
+@if /I "%1"=="--version" @goto Version
+
+:Usage
+@echo Usage: ShowEnvironment.bat [Options]
+@echo Copyright(c) 2014, Intel Corporation. All rights reserved.
+@echo.
+@echo Options:
+@echo --help, -h Print this help screen and exit
+@echo --version, -v Print this tool's version and exit
+@echo.
+@goto End
+
+:Version
+@echo ShowEnvironment.bat Version: %SE_VERSION%%SE_SVN_REVISION:~11,-1%
+@echo Copyright(c) 2014, Intel Corporation. All rights reserved.
+
+:SkipCmdlineArgumentCheck
+if defined SRC_CONF @goto SetEnv
+
+@echo.
+@echo #############################################################################
+@if defined WORKSPACE @echo WORKSPACE = %WORKSPACE%
+@if not defined WORKSPACE @echo WORKSPACE = Not Set
+@if defined EDK_TOOLS_PATH @echo EDK_TOOLS_PATH = %EDK_TOOLS_PATH%
+@if not defined EDK_TOOLS_PATH @echo EDK_TOOLS_PATH = Not Set
+@if defined BASE_TOOLS_PATH @echo BASE_TOOLS_PATH = %BASE_TOOLS_PATH%
+@if defined PYTHON_FREEZER_PATH @echo PYTHON_FREEZER_PATH = %PYTHON_FREEZER_PATH%
+@if "%NT32PKG%"=="TRUE" (
+ @echo.
+ @echo NOTE: Please configure your build to use the following TOOL_CHAIN_TAG
+ @echo when building NT32Pkg/Nt32Pkg.dsc
+ @if defined VCINSTALLDIR @call :CheckVsVer
+ @set TEST_VS=
+)
+@if defined HIDE_PATH goto End
+
+
+@echo ############################## PATH #########################################
+@setlocal DisableDelayedExpansion
+@set "var=%PATH%"
+@set "var=%var:"=""%"
+@set "var=%var:^=^^%"
+@set "var=%var:&=^&%"
+@set "var=%var:|=^|%"
+@set "var=%var:<=^<%"
+@set "var=%var:>=^>%"
+@set "var=%var:;=^;^;%"
+@set var=%var:""="%
+@set "var=%var:"=""Q%"
+@set "var=%var:;;="S"S%"
+@set "var=%var:^;^;=;%"
+@set "var=%var:""="%"
+@setlocal EnableDelayedExpansion
+@set "var=!var:"Q=!"
+@for %%a in ("!var:"S"S=";"!") do (
+ @if "!!"=="" endlocal
+ @if %%a neq "" echo %%~a
+)
+@goto End
+
+:CheckVsVer
+@set "TEST_VS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2008x86
+ @goto :EOF
+)
+@set "TEST_VS=C:\Program Files\Microsoft Visual Studio 9.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2008
+ @goto :EOF
+)
+
+@set "TEST_VS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2010x86
+ @goto :EOF
+)
+@set "TEST_VS=C:\Program Files\Microsoft Visual Studio 10.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2010
+ @goto :EOF
+)
+
+@set "TEST_VS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2012x86
+ @goto :EOF
+)
+@set "TEST_VS=C:\Program Files\Microsoft Visual Studio 11.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2012
+ @goto :EOF
+)
+
+@set "TEST_VS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2013x86
+ @goto :EOF
+)
+@set "TEST_VS=C:\Program Files\Microsoft Visual Studio 12.0\"
+@if "%VSINSTALLDIR%"=="%TEST_VS%" (
+ @echo TOOL_CHAIN_TAG = VS2013
+ @goto :EOF
+)
+@goto :EOF
+
+:SetEnv
+@set FIRST_COPY=FALSE
+@set MISSING_TARGET_TEMPLATE=FALSE
+@set MISSING_TOOLS_DEF_TEMPLATE=FALSE
+@set MISSING_BUILD_RULE_TEMPLATE=FALSE
+@if not exist "%SRC_CONF%\target.template" @set MISSING_TARGET_TEMPLATE=TRUE
+@if not exist "%SRC_CONF%\tools_def.template" @set MISSING_TOOLS_DEF_TEMPLATE=TRUE
+@if not exist "%SRC_CONF%\build_rule.template" @set MISSING_BUILD_RULE_TEMPLATE=TRUE
+
+@if not exist "%WORKSPACE%\Conf\target.txt" (
+ @if "%MISSING_TARGET_TEMPLATE%"=="TRUE" @goto MissingTemplates
+ @echo copying ... target.template to %WORKSPACE%\Conf\target.txt
+ @copy /Y "%SRC_CONF%\target.template" "%WORKSPACE%\Conf\target.txt" > nul
+ @set FIRST_COPY=TRUE
+)
+@if not exist "%WORKSPACE%\Conf\tools_def.txt" (
+ @if "%MISSING_TOOLS_DEF_TEMPLATE%"=="TRUE" @goto MissingTemplates
+ @echo copying ... tools_def.template to %WORKSPACE%\Conf\tools_def.txt
+ @copy /Y "%SRC_CONF%\tools_def.template" "%WORKSPACE%\Conf\tools_def.txt" > nul
+ @set FIRST_COPY=TRUE
+)
+@if not exist "%WORKSPACE%\Conf\build_rule.txt" (
+ @if "%MISSING_BUILD_RULE_TEMPLATE%"=="TRUE" @goto MissingTemplates
+ @echo copying ... build_rule.template to %WORKSPACE%\Conf\build_rule.txt
+ @copy /Y "%SRC_CONF%\build_rule.template" "%WORKSPACE%\Conf\build_rule.txt" > nul
+ @set FIRST_COPY=TRUE
+)
+
+@if "%FIRST_COPY%"=="TRUE" @goto End
+@if not "%RECONFIG%"=="TRUE" @goto End
+
+@if "%RECONFIG%"=="TRUE" (
+ @echo.
+ @echo Over-writing the files in the WORKSPACE\Conf directory
+ @echo using the default template files
+ @echo.
+ @if "%MISSING_TARGET_TEMPLATE%"=="TRUE" @goto MissingTemplates
+ @echo over-write ... target.template to %WORKSPACE%\Conf\target.txt
+ @copy /Y "%SRC_CONF%\target.template" "%WORKSPACE%\Conf\target.txt" > nul
+
+ @if "%MISSING_TOOLS_DEF_TEMPLATE%"=="TRUE" @goto MissingTemplates
+ @echo over-write ... tools_def.template to %WORKSPACE%\Conf\tools_def.txt
+ @copy /Y "%SRC_CONF%\tools_def.template" "%WORKSPACE%\Conf\tools_def.txt" > nul
+
+ @if "%MISSING_BUILD_RULE_TEMPLATE%"=="TRUE" @goto MissingTemplates
+ @echo over-write ... build_rule.template to %WORKSPACE%\Conf\build_rule.txt
+ @copy /Y "%SRC_CONF%\build_rule.template" "%WORKSPACE%\Conf\build_rule.txt" > nul
+ @goto End
+)
+
+:MissingTemplates
+@echo.
+@if "%RECONFIG%"=="TRUE" @echo ERROR : Reconfig failed
+@if "%MISSING_TARGET_TEMPLATE%"=="TRUE" @echo ERROR : Unable to locate: "%SRC_CONF%\target.template"
+@if "%MISSING_TOOLS_DEF_TEMPLATE%"=="TRUE" @echo ERROR : Unable to locate: "%SRC_CONF%\tools_def.template"
+@if "%MISSING_BUILD_RULE_TEMPLATE%"=="TRUE" @echo ERROR : Unable to locate: "%SRC_CONF%\build_rule.template"
+@echo.
+@set MISSING_TARGET_TEMPLATE=
+@set MISSING_TOOLS_DEF_TEMPLATE=
+@set MISSING_BUILD_RULE_TEMPLATE=
+@set FIRST_COPY=
+@set SE_VERSION=
+@set SE_SVN_REVISION=
+@if not "%SCRIPT%"=="EDKSETUP_BAT" @echo on
+exit /B 1
+
+:End
+@set MISSING_TARGET_TEMPLATE=
+@set MISSING_TOOLS_DEF_TEMPLATE=
+@set MISSING_BUILD_RULE_TEMPLATE=
+@set FIRST_COPY=
+@set SE_VERSION=
+@set SE_SVN_REVISION=
+@if not "%SCRIPT%"=="EDKSETUP_BAT" @echo on
+exit /B 0
diff --git a/BaseTools/Scripts/UpdateBuildVersions.py b/BaseTools/Scripts/UpdateBuildVersions.py
new file mode 100644
index 0000000000..e9c069724e
--- /dev/null
+++ b/BaseTools/Scripts/UpdateBuildVersions.py
@@ -0,0 +1,400 @@
+## @file
+# Update build revisions of the tools when performing a developer build
+#
+# This script will modife the C/Include/Common/BuildVersion.h file and the two
+# Python scripts, Python/Common/BuildVersion.py and Python/UPT/BuildVersion.py.
+# If SVN is available, the tool will obtain the current checked out version of
+# the source tree for including the the --version commands.
+
+# Copyright (c) 2014, 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
+# 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.
+##
+""" This program will update the BuildVersion.py and BuildVersion.h files used to set a tool's version value """
+from __future__ import absolute_import
+
+import os
+import shlex
+import subprocess
+import sys
+
+from argparse import ArgumentParser, SUPPRESS
+from tempfile import NamedTemporaryFile
+from types import IntType, ListType
+
+
+SYS_ENV_ERR = "ERROR : %s system environment variable must be set prior to running this tool.\n"
+
+__execname__ = "UpdateBuildVersions.py"
+SVN_REVISION = "$Revision: 3 $"
+SVN_REVISION = SVN_REVISION.replace("$Revision:", "").replace("$", "").strip()
+__copyright__ = "Copyright (c) 2014, Intel Corporation. All rights reserved."
+VERSION_NUMBER = "0.7.0"
+__version__ = "Version %s.%s" % (VERSION_NUMBER, SVN_REVISION)
+
+
+def ParseOptions():
+ """
+ Parse the command-line options.
+ The options for this tool will be passed along to the MkBinPkg tool.
+ """
+ parser = ArgumentParser(
+ usage=("%s [options]" % __execname__),
+ description=__copyright__,
+ conflict_handler='resolve')
+
+ # Standard Tool Options
+ parser.add_argument("--version", action="version",
+ version=__execname__ + " " + __version__)
+ parser.add_argument("-s", "--silent", action="store_true",
+ dest="silent",
+ help="All output will be disabled, pass/fail determined by the exit code")
+ parser.add_argument("-v", "--verbose", action="store_true",
+ dest="verbose",
+ help="Enable verbose output")
+ # Tool specific options
+ parser.add_argument("--revert", action="store_true",
+ dest="REVERT", default=False,
+ help="Revert the BuildVersion files only")
+ parser.add_argument("--svn-test", action="store_true",
+ dest="TEST_SVN", default=False,
+ help="Test if the svn command is available")
+ parser.add_argument("--svnFlag", action="store_true",
+ dest="HAVE_SVN", default=False,
+ help=SUPPRESS)
+
+ return(parser.parse_args())
+
+
+def ShellCommandResults(CmdLine, Opt):
+ """ Execute the comand, returning the output content """
+ file_list = NamedTemporaryFile(delete=False)
+ filename = file_list.name
+ Results = []
+
+ returnValue = 0
+ try:
+ subprocess.check_call(args=shlex.split(CmdLine), stderr=subprocess.STDOUT, stdout=file_list)
+ except subprocess.CalledProcessError as err_val:
+ file_list.close()
+ if not Opt.silent:
+ sys.stderr.write("ERROR : %d : %s\n" % (err_val.returncode, err_val.__str__()))
+ if os.path.exists(filename):
+ sys.stderr.write(" : Partial results may be in this file: %s\n" % filename)
+ sys.stderr.flush()
+ returnValue = err_val.returncode
+
+ except IOError as (errno, strerror):
+ file_list.close()
+ if not Opt.silent:
+ sys.stderr.write("I/O ERROR : %s : %s\n" % (str(errno), strerror))
+ sys.stderr.write("ERROR : this command failed : %s\n" % CmdLine)
+ if os.path.exists(filename):
+ sys.stderr.write(" : Partial results may be in this file: %s\n" % filename)
+ sys.stderr.flush()
+ returnValue = errno
+
+ except OSError as (errno, strerror):
+ file_list.close()
+ if not Opt.silent:
+ sys.stderr.write("OS ERROR : %s : %s\n" % (str(errno), strerror))
+ sys.stderr.write("ERROR : this command failed : %s\n" % CmdLine)
+ if os.path.exists(filename):
+ sys.stderr.write(" : Partial results may be in this file: %s\n" % filename)
+ sys.stderr.flush()
+ returnValue = errno
+
+ except KeyboardInterrupt:
+ file_list.close()
+ if not Opt.silent:
+ sys.stderr.write("ERROR : Command terminated by user : %s\n" % CmdLine)
+ if os.path.exists(filename):
+ sys.stderr.write(" : Partial results may be in this file: %s\n" % filename)
+ sys.stderr.flush()
+ returnValue = 1
+
+ finally:
+ if not file_list.closed:
+ file_list.flush()
+ os.fsync(file_list.fileno())
+ file_list.close()
+
+ if os.path.exists(filename):
+ fd_ = open(filename, 'r')
+ Results = fd_.readlines()
+ fd_.close()
+ os.unlink(filename)
+
+ if returnValue > 0:
+ return returnValue
+
+ return Results
+
+
+def UpdateBuildVersionPython(Rev, UserModified, opts):
+ """ This routine will update the BuildVersion.h files in the C source tree """
+ for SubDir in ["Common", "UPT"]:
+ PyPath = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source", "Python", SubDir)
+ BuildVersionPy = os.path.join(PyPath, "BuildVersion.py")
+ fd_ = open(os.path.normpath(BuildVersionPy), 'r')
+ contents = fd_.readlines()
+ fd_.close()
+ if opts.HAVE_SVN is False:
+ BuildVersionOrig = os.path.join(PyPath, "orig_BuildVersion.py")
+ fd_ = open (BuildVersionOrig, 'w')
+ for line in contents:
+ fd_.write(line)
+ fd_.flush()
+ fd_.close()
+ new_content = []
+ for line in contents:
+ if line.strip().startswith("gBUILD_VERSION"):
+ new_line = "gBUILD_VERSION = \"Developer Build based on Revision: %s\"" % Rev
+ if UserModified:
+ new_line = "gBUILD_VERSION = \"Developer Build based on Revision: %s with Modified Sources\"" % Rev
+ new_content.append(new_line)
+ continue
+ new_content.append(line)
+
+ fd_ = open(os.path.normpath(BuildVersionPy), 'w')
+ for line in new_content:
+ fd_.write(line)
+ fd_.close()
+
+
+def UpdateBuildVersionH(Rev, UserModified, opts):
+ """ This routine will update the BuildVersion.h files in the C source tree """
+ CPath = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source", "C", "Include", "Common")
+ BuildVersionH = os.path.join(CPath, "BuildVersion.h")
+ fd_ = open(os.path.normpath(BuildVersionH), 'r')
+ contents = fd_.readlines()
+ fd_.close()
+ if opts.HAVE_SVN is False:
+ BuildVersionOrig = os.path.join(CPath, "orig_BuildVersion.h")
+ fd_ = open(BuildVersionOrig, 'w')
+ for line in contents:
+ fd_.write(line)
+ fd_.flush()
+ fd_.close()
+
+ new_content = []
+ for line in contents:
+ if line.strip().startswith("#define"):
+ new_line = "#define __BUILD_VERSION \"Developer Build based on Revision: %s\"" % Rev
+ if UserModified:
+ new_line = "#define __BUILD_VERSION \"Developer Build based on Revision: %s with Modified Sources\"" % \
+ Rev
+ new_content.append(new_line)
+ continue
+ new_content.append(line)
+
+ fd_ = open(os.path.normpath(BuildVersionH), 'w')
+ for line in new_content:
+ fd_.write(line)
+ fd_.close()
+
+
+def RevertCmd(Filename, Opt):
+ """ This is the shell command that does the SVN revert """
+ CmdLine = "svn revert %s" % Filename.replace("\\", "/").strip()
+ try:
+ subprocess.check_output(args=shlex.split(CmdLine))
+ except subprocess.CalledProcessError as err_val:
+ if not Opt.silent:
+ sys.stderr.write("Subprocess ERROR : %s\n" % err_val)
+ sys.stderr.flush()
+
+ except IOError as (errno, strerror):
+ if not Opt.silent:
+ sys.stderr.write("I/O ERROR : %d : %s\n" % (str(errno), strerror))
+ sys.stderr.write("ERROR : this command failed : %s\n" % CmdLine)
+ sys.stderr.flush()
+
+ except OSError as (errno, strerror):
+ if not Opt.silent:
+ sys.stderr.write("OS ERROR : %d : %s\n" % (str(errno), strerror))
+ sys.stderr.write("ERROR : this command failed : %s\n" % CmdLine)
+ sys.stderr.flush()
+
+ except KeyboardInterrupt:
+ if not Opt.silent:
+ sys.stderr.write("ERROR : Command terminated by user : %s\n" % CmdLine)
+ sys.stderr.flush()
+
+ if Opt.verbose:
+ sys.stdout.write("Reverted this file: %s\n" % Filename)
+ sys.stdout.flush()
+
+
+def GetSvnRevision(opts):
+ """ Get the current revision of the BaseTools/Source tree, and check if any of the files have been modified """
+ Revision = "Unknown"
+ Modified = False
+
+ if opts.HAVE_SVN is False:
+ sys.stderr.write("WARNING: the svn command-line tool is not available.\n")
+ return (Revision, Modified)
+
+ SrcPath = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source")
+ # Check if there are modified files.
+ Cwd = os.getcwd()
+ os.chdir(SrcPath)
+
+ StatusCmd = "svn st -v --depth infinity --non-interactive"
+ contents = ShellCommandResults(StatusCmd, opts)
+ os.chdir(Cwd)
+ if type(contents) is ListType:
+ for line in contents:
+ if line.startswith("M "):
+ Modified = True
+ break
+
+ # Get the repository revision of BaseTools/Source
+ InfoCmd = "svn info %s" % SrcPath.replace("\\", "/").strip()
+ Revision = 0
+ contents = ShellCommandResults(InfoCmd, opts)
+ if type(contents) is IntType:
+ return 0, Modified
+ for line in contents:
+ line = line.strip()
+ if line.startswith("Revision:"):
+ Revision = line.replace("Revision:", "").strip()
+ break
+
+ return (Revision, Modified)
+
+
+def CheckSvn(opts):
+ """
+ This routine will return True if an svn --version command succeeds, or False if it fails.
+ If it failed, SVN is not available.
+ """
+ OriginalSilent = opts.silent
+ opts.silent = True
+ VerCmd = "svn --version"
+ contents = ShellCommandResults(VerCmd, opts)
+ opts.silent = OriginalSilent
+ if type(contents) is IntType:
+ if opts.verbose:
+ sys.stdout.write("SVN does not appear to be available.\n")
+ sys.stdout.flush()
+ return False
+
+ if opts.verbose:
+ sys.stdout.write("Found %s" % contents[0])
+ sys.stdout.flush()
+ return True
+
+
+def CopyOrig(Src, Dest, Opt):
+ """ Overwrite the Dest File with the Src File content """
+ try:
+ fd_ = open(Src, 'r')
+ contents = fd_.readlines()
+ fd_.close()
+ fd_ = open(Dest, 'w')
+ for line in contents:
+ fd_.write(line)
+ fd_.flush()
+ fd_.close()
+ except IOError:
+ if not Opt.silent:
+ sys.stderr.write("Unable to restore this file: %s\n" % Dest)
+ sys.stderr.flush()
+ return 1
+
+ os.remove(Src)
+ if Opt.verbose:
+ sys.stdout.write("Restored this file: %s\n" % Src)
+ sys.stdout.flush()
+
+ return 0
+
+
+def CheckOriginals(Opts):
+ """
+ If SVN was not available, then the tools may have made copies of the original BuildVersion.* files using
+ orig_BuildVersion.* for the name. If they exist, replace the existing BuildVersion.* file with the corresponding
+ orig_BuildVersion.* file.
+ Returns 0 if this succeeds, or 1 if the copy function fails. It will also return 0 if the orig_BuildVersion.* file
+ does not exist.
+ """
+ CPath = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source", "C", "Include", "Common")
+ BuildVersionH = os.path.join(CPath, "BuildVersion.h")
+ OrigBuildVersionH = os.path.join(CPath, "orig_BuildVersion.h")
+ if not os.path.exists(OrigBuildVersionH):
+ return 0
+ if CopyOrig(OrigBuildVersionH, BuildVersionH, Opts):
+ return 1
+ for SubDir in ["Common", "UPT"]:
+ PyPath = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source", "Python", SubDir)
+ BuildVersionPy = os.path.join(PyPath, "BuildVersion.h")
+ OrigBuildVersionPy = os.path.join(PyPath, "orig_BuildVersion.h")
+ if not os.path.exists(OrigBuildVersionPy):
+ return 0
+ if CopyOrig(OrigBuildVersionPy, BuildVersionPy, Opts):
+ return 1
+
+ return 0
+
+
+def RevertBuildVersionFiles(opts):
+ """
+ This routine will attempt to perform an SVN --revert on each of the BuildVersion.* files
+ """
+ if not opts.HAVE_SVN:
+ if CheckOriginals(opts):
+ return 1
+ return 0
+ # SVN is available
+ BuildVersionH = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source", "C", "Include", "Common", "BuildVersion.h")
+ RevertCmd(BuildVersionH, opts)
+ for SubDir in ["Common", "UPT"]:
+ BuildVersionPy = os.path.join(os.environ['BASE_TOOLS_PATH'], "Source", "Python", SubDir, "BuildVersion.py")
+ RevertCmd(BuildVersionPy, opts)
+
+def UpdateRevisionFiles():
+ """ Main routine that will update the BuildVersion.py and BuildVersion.h files."""
+ options = ParseOptions()
+ # Check the working environment
+ if "WORKSPACE" not in os.environ.keys():
+ sys.stderr.write(SYS_ENV_ERR % 'WORKSPACE')
+ return 1
+ if 'BASE_TOOLS_PATH' not in os.environ.keys():
+ sys.stderr.write(SYS_ENV_ERR % 'BASE_TOOLS_PATH')
+ return 1
+ if not os.path.exists(os.environ['BASE_TOOLS_PATH']):
+ sys.stderr.write("Unable to locate the %s directory." % os.environ['BASE_TOOLS_PATH'])
+ return 1
+
+
+ options.HAVE_SVN = CheckSvn(options)
+ if options.TEST_SVN:
+ return (not options.HAVE_SVN)
+ # done processing the option, now use the option.HAVE_SVN as a flag. True = Have it, False = Don't have it.
+ if options.REVERT:
+ # Just revert the tools an exit
+ RevertBuildVersionFiles(options)
+ else:
+ # Revert any changes in the BuildVersion.* files before setting them again.
+ RevertBuildVersionFiles(options)
+ Revision, Modified = GetSvnRevision(options)
+ if options.verbose:
+ sys.stdout.write("Revision: %s is Modified: %s\n" % (Revision, Modified))
+ sys.stdout.flush()
+ UpdateBuildVersionH(Revision, Modified, options)
+ UpdateBuildVersionPython(Revision, Modified, options)
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(UpdateRevisionFiles())
+
+