Specify VS toolchain by command-line argument.

This lets the builders pass it in via gclient_vars. Once this lands,
I'll make the builders fill it in, at which point we can remove the
magic 'env' value and the logic in the recipe.

Change-Id: Idfc4db3e4cdecf62eacbb2925fd545e1a76b2c79
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/45624
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/util/bot/DEPS b/util/bot/DEPS
index c87de22..b1f9d80 100644
--- a/util/bot/DEPS
+++ b/util/bot/DEPS
@@ -19,6 +19,7 @@
   'checkout_sde': False,
   'checkout_nasm': False,
   'checkout_libcxx': False,
+  'vs_version': 'env',
 
   'android_sdk_platform-tools_version': 'Jxtur3_L9RzY4q79K-AwIahwFW4oi5uYVD5URx9h62wC',
 }
@@ -171,6 +172,7 @@
     'action': [ 'python',
                 'boringssl/util/bot/vs_toolchain.py',
                 'update',
+                Var('vs_version'),
     ],
   },
   {
diff --git a/util/bot/vs_toolchain.py b/util/bot/vs_toolchain.py
index 6e94df3..c15df49 100644
--- a/util/bot/vs_toolchain.py
+++ b/util/bot/vs_toolchain.py
@@ -13,10 +13,6 @@
 json_data_file = os.path.join(script_dir, 'win_toolchain.json')
 
 
-# Use MSVS2015 as the default toolchain.
-CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015'
-
-
 def SetEnvironmentForCPU(cpu):
   """Sets the environment to build with the selected toolchain for |cpu|."""
   with open(json_data_file, 'r') as tempf:
@@ -62,35 +58,30 @@
   raise Exception("depot_tools not found!")
 
 
-def GetVisualStudioVersion():
-  """Return GYP_MSVS_VERSION of Visual Studio.
-  """
-  # TODO(davidben): Replace this with a command-line argument. The depot_tools
-  # script no longer needs this environment variable.
-  return os.environ.get('GYP_MSVS_VERSION', CURRENT_DEFAULT_TOOLCHAIN_VERSION)
-
-
-def _GetDesiredVsToolchainHashes():
+def _GetDesiredVsToolchainHashes(version):
   """Load a list of SHA1s corresponding to the toolchains that we want installed
   to build with."""
-  env_version = GetVisualStudioVersion()
-  if env_version == '2015':
+  if version == '2015':
     # Update 3 final with 10.0.15063.468 SDK and no vctip.exe.
     return ['f53e4598951162bad6330f7a167486c7ae5db1e5']
-  if env_version == '2017':
+  if version == '2017':
     # VS 2017 Update 9 (15.9.12) with 10.0.18362 SDK, 10.0.17763 version of
     # Debuggers, and 10.0.17134 version of d3dcompiler_47.dll, with ARM64
     # libraries.
     return ['418b3076791776573a815eb298c8aa590307af63']
-  raise Exception('Unsupported VS version %s' % env_version)
+  raise Exception('Unsupported VS version %s' % version)
 
 
-def Update():
+def Update(version):
   """Requests an update of the toolchain to the specific hashes we have at
   this revision. The update outputs a .json of the various configuration
   information required to pass to vs_env.py which we use in
   |SetEnvironmentForCPU()|.
   """
+  # TODO(davidben): Once the builders specify the toolchain version directly,
+  # remove this and replace the default in DEPS from 'env' to '2015'.
+  if version == 'env':
+    version = os.environ.get('GYP_MSVS_VERSION', '2015')
   depot_tools_path = FindDepotTools()
   get_toolchain_args = [
       sys.executable,
@@ -98,7 +89,7 @@
                   'win_toolchain',
                   'get_toolchain_if_necessary.py'),
       '--output-json', json_data_file,
-    ] + _GetDesiredVsToolchainHashes()
+    ] + _GetDesiredVsToolchainHashes(version)
   subprocess.check_call(get_toolchain_args)
   return 0