From: Dandan Bi Date: Wed, 12 Jun 2019 03:28:46 +0000 (+0800) Subject: Edk2Setup: Support different VS tool chain setup X-Git-Tag: edk2-stable201908~332 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=6759212fa69d5d266c2854ea6de44bfd3f7e370b Edk2Setup: Support different VS tool chain setup REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1693 This patch is to update edksetup with additional option: VS2017 VS2015 VS2013 VS2012 to setup different VS environment. And will report error if the specified VS tool is not installed. For VS2017, also consider the case that only VS2017 build tool is installed. Cc: Bob Feng Cc: Liming Gao Signed-off-by: Dandan Bi Reviewed-by: Bob Feng Reviewed-by: Liming Gao --- diff --git a/BaseTools/get_vsvars.bat b/BaseTools/get_vsvars.bat index 9b5e9d24fc..9f3759b2a9 100644 --- a/BaseTools/get_vsvars.bat +++ b/BaseTools/get_vsvars.bat @@ -8,7 +8,12 @@ @echo off -goto :main +set SCRIPT_ERROR=0 +if "%1"=="" goto main +if /I "%1"=="VS2017" goto VS2017Vars +if /I "%1"=="VS2015" goto VS2015Vars +if /I "%1"=="VS2013" goto VS2013Vars +if /I "%1"=="VS2012" goto VS2012Vars :set_vsvars for /f "usebackq tokens=1* delims=: " %%i in (`%*`) do ( @@ -26,6 +31,10 @@ if defined VCINSTALLDIR goto :EOF goto :EOF +:ToolNotInstall +set SCRIPT_ERROR=1 +goto :EOF + REM NOTE: This file will find the most recent Visual Studio installation REM apparent from the environment. REM To use an older version, modify your environment set up. @@ -33,11 +42,32 @@ REM (Or invoke the relevant vsvars32 file beforehand). :main if defined VCINSTALLDIR goto :done - if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" call :set_vsvars "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" - if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" call :set_vsvars "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" - if defined VS140COMNTOOLS call :read_vsvars "%VS140COMNTOOLS%" - if defined VS120COMNTOOLS call :read_vsvars "%VS120COMNTOOLS%" - if defined VS110COMNTOOLS call :read_vsvars "%VS110COMNTOOLS%" + :VS2017Vars + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" ( + call :set_vsvars "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools + ) else ( + call :set_vsvars "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" + ) + ) + if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( + if exist "%ProgramFiles%\Microsoft Visual Studio\2017\BuildTools" ( + call :set_vsvars "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools + ) else ( + call :set_vsvars "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" + ) + ) + if /I "%1"=="VS2017" goto ToolNotInstall + + :VS2015Vars + if defined VS140COMNTOOLS (call :read_vsvars "%VS140COMNTOOLS%") else (if /I "%1"=="VS2015" goto ToolNotInstall) + + :VS2013Vars + if defined VS120COMNTOOLS ( call :read_vsvars "%VS120COMNTOOLS%") else (if /I "%1"=="VS2013" goto ToolNotInstall) + + :VS2012Vars + if defined VS110COMNTOOLS (call :read_vsvars "%VS110COMNTOOLS%") else (if /I "%1"=="VS2012" goto ToolNotInstall) + if defined VS100COMNTOOLS call :read_vsvars "%VS100COMNTOOLS%" if defined VS90COMNTOOLS call :read_vsvars "%VS90COMNTOOLS%" if defined VS80COMNTOOLS call :read_vsvars "%VS80COMNTOOLS%" diff --git a/BaseTools/set_vsprefix_envs.bat b/BaseTools/set_vsprefix_envs.bat index 95f30f7aef..81686f5b63 100644 --- a/BaseTools/set_vsprefix_envs.bat +++ b/BaseTools/set_vsprefix_envs.bat @@ -10,6 +10,18 @@ @echo off pushd . +set SCRIPT_ERROR=0 +goto main + +:ToolNotInstall +set SCRIPT_ERROR=1 +goto :EOF + +:main +if /I "%1"=="VS2017" goto SetVS2017 +if /I "%1"=="VS2015" goto SetVS2015 +if /I "%1"=="VS2013" goto SetVS2013 +if /I "%1"=="VS2012" goto SetVS2012 if defined VS71COMNTOOLS ( if not defined VS2003_PREFIX ( @@ -47,6 +59,7 @@ if defined VS100COMNTOOLS ( ) ) +:SetVS2012 if defined VS110COMNTOOLS ( if not defined VS2012_PREFIX ( set "VS2012_PREFIX=%VS110COMNTOOLS:~0,-14%" @@ -57,8 +70,12 @@ if defined VS110COMNTOOLS ( if not defined WINSDK71x86_PREFIX ( set "WINSDK71x86_PREFIX=c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\" ) +) else ( + if /I "%1"=="VS2012" goto ToolNotInstall ) +if /I "%1"=="VS2012" goto SetWinDDK +:SetVS2013 if defined VS120COMNTOOLS ( if not defined VS2013_PREFIX ( set "VS2013_PREFIX=%VS120COMNTOOLS:~0,-14%" @@ -69,8 +86,12 @@ if defined VS120COMNTOOLS ( if not defined WINSDK8x86_PREFIX ( set "WINSDK8x86_PREFIX=c:\Program Files (x86)\Windows Kits\8.0\bin\" ) +) else ( + if /I "%1"=="VS2013" goto ToolNotInstall ) +if /I "%1"=="VS2013" goto SetWinDDK +:SetVS2015 if defined VS140COMNTOOLS ( if not defined VS2015_PREFIX ( set "VS2015_PREFIX=%VS140COMNTOOLS:~0,-14%" @@ -81,19 +102,35 @@ if defined VS140COMNTOOLS ( if not defined WINSDK81x86_PREFIX ( set "WINSDK81x86_PREFIX=c:\Program Files (x86)\Windows Kits\8.1\bin\" ) +) else ( + if /I "%1"=="VS2015" goto ToolNotInstall ) +if /I "%1"=="VS2015" goto SetWinDDK -@REM set VS2017 +:SetVS2017 if not defined VS150COMNTOOLS ( if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" ( - for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"`) do ( - if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" ( + for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools`) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) + ) else ( + for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"`) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) ) ) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" ( - for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"`) do ( - if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + if exist "%ProgramFiles%\Microsoft Visual Studio\2017\BuildTools" ( + for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools`) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) + ) else ( + for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"`) do ( + if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat" + ) ) ) else ( + if /I "%1"=="VS2017" goto ToolNotInstall goto SetWinDDK ) ) diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat index 999f3b3984..395694fa09 100755 --- a/BaseTools/toolsetup.bat +++ b/BaseTools/toolsetup.bat @@ -11,6 +11,7 @@ @echo off pushd . +set SCRIPT_ERROR=0 @REM ############################################################## @REM # You should not have to modify anything below this line @@ -41,6 +42,30 @@ if /I "%1"=="/?" goto Usage set FORCE_REBUILD=TRUE goto loop ) + if /I "%1"=="VS2017" ( + shift + set VS2017=TRUE + set VSTool=VS2017 + goto loop + ) + if /I "%1"=="VS2015" ( + shift + set VS2015=TRUE + set VSTool=VS2015 + goto loop + ) + if /I "%1"=="VS2013" ( + shift + set VS2013=TRUE + set VSTool=VS2013 + goto loop + ) + if /I "%1"=="VS2012" ( + shift + set VS2012=TRUE + set VSTool=VS2012 + goto loop + ) if "%1"=="" goto setup_workspace if exist %1 ( if not defined BASE_TOOLS_PATH ( @@ -151,7 +176,27 @@ IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" ( @echo. goto end ) -call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat +if defined VS2017 ( + call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017 +) else if defined VS2015 ( + call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2015 + call %EDK_TOOLS_PATH%\get_vsvars.bat VS2015 +) else if defined VS2013 ( + call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2013 + call %EDK_TOOLS_PATH%\get_vsvars.bat VS2013 +) else if defined VS2012 ( + call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2012 + call %EDK_TOOLS_PATH%\get_vsvars.bat VS2012 +) else ( + call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat + call %EDK_TOOLS_PATH%\get_vsvars.bat +) +if %SCRIPT_ERROR% NEQ 0 ( + @echo. + @echo !!! ERROR !!! %VSTool% is not installed !!! + @echo. + goto end +) if not defined CONF_PATH ( set CONF_PATH=%WORKSPACE%\Conf @@ -365,7 +410,7 @@ goto end goto end ) ) - call "%EDK_TOOLS_PATH%\get_vsvars.bat" + if not defined VCINSTALLDIR ( @echo. @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!! @@ -399,7 +444,7 @@ goto end :Usage @echo. - echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]]" + echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2017] [VS2015] [VS2013] [VS2012]" @echo. @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path. @echo edk_tools_path EDK_TOOLS_PATH will be set to this path. @@ -408,11 +453,20 @@ goto end @echo ForceRebuild If sources are available, rebuild all tools regardless of @echo whether they have been updated or not. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt. + @echo VS2012 Set the env for VS2012 build. + @echo VS2013 Set the env for VS2013 build. + @echo VS2015 Set the env for VS2015 build. + @echo VS2017 Set the env for VS2017 build. @echo. :end set REBUILD= set FORCE_REBUILD= set RECONFIG= +set VS2017= +set VS2015= +set VS2013= +set VS2012= +set VSTool= popd diff --git a/edksetup.bat b/edksetup.bat index d607e2ebea..5f6028deff 100755 --- a/edksetup.bat +++ b/edksetup.bat @@ -133,15 +133,23 @@ if defined CYGWIN_HOME ( :cygwin_done if /I "%1"=="Rebuild" shift if /I "%1"=="ForceRebuild" shift +if /I "%1"=="VS2017" shift +if /I "%1"=="VS2015" shift +if /I "%1"=="VS2013" shift +if /I "%1"=="VS2012" shift if "%1"=="" goto end :Usage @echo. - @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild]" + @echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [VS2017] [VS2015] [VS2013] [VS2012]" @echo. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt. @echo Rebuild Perform incremental rebuild of BaseTools binaries. @echo ForceRebuild Force a full rebuild of BaseTools binaries. + @echo VS2012 Set the env for VS2012 build. + @echo VS2013 Set the env for VS2013 build. + @echo VS2015 Set the env for VS2015 build. + @echo VS2017 Set the env for VS2017 build. @echo. @echo Note that target.template, tools_def.template and build_rules.template @echo will only be copied to target.txt, tools_def.txt and build_rule.txt