From 2a622f20ee62c279073e59cf0b283de2aa5534ce Mon Sep 17 00:00:00 2001 From: Dan Jacques Date: Thu, 1 Jun 2017 11:37:36 -0700 Subject: [PATCH] [win_toolchain] Allow toolchain dir override. Currently, the Windows toolchain is installed in a subdirectory under "depot_tools". Allow this installation destination to be overridden, either by flag (useful for testing) or via environment variable (to be used in Chromium recipe). BUG=chromium:727917 TEST=local - Ran explicitly w/ flag, seems to work. - Ran via Chromium's "vs_toolchain" with and without environment variable override, seems to install correctly. Change-Id: I6b33832d7f099796e23da0548949073c70a17788 Reviewed-on: https://chromium-review.googlesource.com/521663 Reviewed-by: Robbie Iannucci Reviewed-by: Scott Graham Commit-Queue: Robbie Iannucci --- win_toolchain/get_toolchain_if_necessary.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/win_toolchain/get_toolchain_if_necessary.py b/win_toolchain/get_toolchain_if_necessary.py index df04b0646..5d06efc51 100755 --- a/win_toolchain/get_toolchain_if_necessary.py +++ b/win_toolchain/get_toolchain_if_necessary.py @@ -38,6 +38,10 @@ import tempfile import time import zipfile +# Environment variable that, if set, specifies the default Visual Studio +# toolchain root directory to use. +ENV_TOOLCHAIN_ROOT = 'DEPOT_TOOLS_WIN_TOOLCHAIN_ROOT' + # winreg isn't natively available under CygWin if sys.platform == "win32": try: @@ -394,6 +398,9 @@ def main(): help='write information about toolchain to FILE') parser.add_option('--force', action='store_true', help='force script to run on non-Windows hosts') + parser.add_option('--toolchain-dir', + default=os.getenv(ENV_TOOLCHAIN_ROOT, BASEDIR), + help='directory to install toolchain into') options, args = parser.parse_args() if not (sys.platform.startswith(('cygwin', 'win32')) or options.force): @@ -415,14 +422,18 @@ def main(): sys.exit('Desired hash is required.') desired_hash = args[0] + # Create our toolchain destination and "chdir" to it. + toolchain_dir = os.path.abspath(options.toolchain_dir) + if not os.path.isdir(toolchain_dir): + os.makedirs(toolchain_dir) + os.chdir(toolchain_dir) + # Move to depot_tools\win_toolchain where we'll store our files, and where # the downloader script is. - os.chdir(os.path.normpath(os.path.join(BASEDIR))) - toolchain_dir = '.' if os.environ.get('GYP_MSVS_VERSION') == '2013': - target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) + target_dir = 'vs2013_files' else: - target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs_files')) + target_dir = 'vs_files' if not os.path.isdir(target_dir): os.mkdir(target_dir) toolchain_target_dir = os.path.join(target_dir, desired_hash)