Index: build/vs_toolchain.py |
diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py |
index 247703b8654094dd91eb4767eff3593eaa5561e7..4b925f0799f2ade1abbb97834b44ebdddc591a85 100644 |
--- a/build/vs_toolchain.py |
+++ b/build/vs_toolchain.py |
@@ -8,7 +8,6 @@ import pipes |
import shutil |
import subprocess |
import sys |
-import tempfile |
script_dir = os.path.dirname(os.path.realpath(__file__)) |
@@ -16,46 +15,23 @@ chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
sys.path.insert(1, os.path.join(chrome_src, 'tools')) |
sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
+json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
import gyp |
-def GetDesiredVsToolchainHashes(): |
- """Load a list of SHA1s corresponding to the toolchains that we want installed |
- to build with.""" |
- sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') |
- with open(sha1path, 'rb') as f: |
- return f.read().strip().splitlines() |
- |
- |
-def DownloadVsToolchain(): |
- """Download the Visual Studio toolchain on Windows. |
- |
- If on Windows, request that depot_tools install/update the automatic |
- toolchain, and then use it (unless opted-out) and return a tuple containing |
- the x64 and x86 paths. Otherwise return None. |
+def SetEnvironmentAndGetRuntimeDllDirs(): |
+ """Sets up os.environ to use the depot_tools VS toolchain with gyp, and |
+ returns the location of the VS runtime DLLs so they can be copied into |
+ the output directory after gyp generation. |
""" |
vs2013_runtime_dll_dirs = None |
depot_tools_win_toolchain = \ |
bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: |
- import find_depot_tools |
- depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
- temp_handle, data_file = tempfile.mkstemp(suffix='.json') |
- os.close(temp_handle) |
- get_toolchain_args = [ |
- sys.executable, |
- os.path.join(depot_tools_path, |
- 'win_toolchain', |
- 'get_toolchain_if_necessary.py'), |
- '--output-json', data_file, |
- ] + GetDesiredVsToolchainHashes() |
- subprocess.check_call(get_toolchain_args) |
- |
- with open(data_file, 'r') as tempf: |
+ with open(json_data_file, 'r') as tempf: |
toolchain_data = json.load(tempf) |
- os.unlink(data_file) |
toolchain = toolchain_data['path'] |
version = toolchain_data['version'] |
@@ -132,18 +108,58 @@ def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') |
+def _GetDesiredVsToolchainHashes(): |
+ """Load a list of SHA1s corresponding to the toolchains that we want installed |
+ to build with.""" |
+ sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') |
+ with open(sha1path, 'rb') as f: |
+ return f.read().strip().splitlines() |
+ |
+ |
+def Update(): |
+ """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 gyp which we use in |GetToolchainDir()|. |
+ """ |
+ depot_tools_win_toolchain = \ |
+ bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
+ if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: |
+ import find_depot_tools |
+ depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
+ json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
+ get_toolchain_args = [ |
+ sys.executable, |
+ os.path.join(depot_tools_path, |
+ 'win_toolchain', |
+ 'get_toolchain_if_necessary.py'), |
+ '--output-json', json_data_file, |
+ ] + _GetDesiredVsToolchainHashes() |
+ subprocess.check_call(get_toolchain_args) |
+ |
+ return 0 |
+ |
+ |
+def GetToolchainDir(): |
+ """Gets location information about the current toolchain (must have been |
+ previously updated by 'update').""" |
+ SetEnvironmentAndGetRuntimeDllDirs() |
+ print '["%s", "%s"]' % ( |
+ os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['WINDOWSSDKDIR']) |
+ |
+ |
def main(): |
- if len(sys.argv) < 2: |
- print >>sys.stderr, 'Expected either "get_toolchain_dir" or "copy_dlls"' |
+ if not sys.platform.startswith(('win32', 'cygwin')): |
+ return 0 |
+ commands = { |
+ 'update': Update, |
+ 'get_toolchain_dir': GetToolchainDir, |
+ # TODO(scottmg): Add copy_dlls for GN builds (gyp_chromium calls |
+ # CopyVsRuntimeDlls via import, currently). |
+ } |
+ if len(sys.argv) < 2 or sys.argv[1] not in commands: |
+ print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
return 1 |
- if sys.argv[1] == 'get_toolchain_dir': |
- DownloadVsToolchain() |
- print '["%s", "%s"]' % ( |
- os.environ['GYP_MSVS_OVERRIDE_PATH'], os.environ['WINDOWSSDKDIR']) |
- else: |
- print >>sys.stderr, 'TODO: not implemented "%s"' % sys.argv[1] |
- return 1 |
- return 0 |
+ return commands[sys.argv[1]]() |
if __name__ == '__main__': |