From 0ef1b2aacc89903e8d6281a411e0d7f93d97ad9c Mon Sep 17 00:00:00 2001 From: "scottmg@chromium.org" Date: Wed, 25 Apr 2012 18:22:38 +0000 Subject: [PATCH] Don't set up environment for ninja if the compiler is already available Previously when ninja.bat was run from a prompt that already had VS vars available, it was adding them a second time. Depending on what else the user had in the path, this could cause the path to become too long and so things at the end wouldn't be found. To avoid this, check if the compiler is available first, and don't run the environment set up in that case. R=maruel@chromium.org Review URL: https://chromiumcodereview.appspot.com/10222010 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@133940 0039d316-1c4b-4281-b951-d872f2087c98 --- ninja.bat | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ninja.bat b/ninja.bat index f436f668f..9782534a2 100644 --- a/ninja.bat +++ b/ninja.bat @@ -25,18 +25,33 @@ for %%A in (%*) do ( ) :done_dash_c +:: Try running the compiler. If it fails, then we assume we need to set up the +:: environment for the compiler. +:: TODO(scottmg): We should also try to detect if we have the right version +:: of the compiler too (i.e. If generation specified 2010, but we're running +:: from a 2008 command prompt). +cl 2>nul >nul +if not errorlevel 1 goto no_set_env + if not exist "%cd_path%\set_environment.bat" ( echo ninja.bat: set_environment.bat not found in '%cd_path%'. Is -C arg correct? goto :EOF ) call "%cd_path%\set_environment.bat" +:: Export only the path changes out of the script. +endlocal & set PATH=%PATH% & set INCLUDE=%INCLUDE% & set LIBPATH=%LIBPATH% & set LIB=%LIB% + +:: To pair with below when we don't skip this block. +setlocal + :: Add python to the path, many gyp rules assume it's there. :: Add ninja directory to the path (to find ninja and ninja-deplist-helper). -:: Then, export only the path changes out of the script so that next time we -:: just run ninja directly (otherwise, this script adds about 500-800ms to +:: Put it at the front so that ninja.exe is found before this wrapper so that +:: next time we just run it directly (otherwise, this script adds 500-800ms to :: ninja invocations). -endlocal & set PATH=%~dp0python_bin;%~dp0ninja-win;%PATH% & set INCLUDE=%INCLUDE% & set LIBPATH=%LIBPATH% & set LIB=%LIB% +:no_set_env +endlocal & set PATH=%~dp0python_bin;%~dp0ninja-win;%PATH% :: Now run the actual build. ninja.exe %*