Index: build/toolchain/win/setup_toolchain.py |
diff --git a/build/toolchain/win/setup_toolchain.py b/build/toolchain/win/setup_toolchain.py |
index 162c2e16cef6cbd5609ad9b02c39229b5c83ecd7..bceafd121be44b6c0c2271ea8c40462937493fd7 100644 |
--- a/build/toolchain/win/setup_toolchain.py |
+++ b/build/toolchain/win/setup_toolchain.py |
@@ -2,10 +2,23 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import errno |
import os |
import re |
+import subprocess |
import sys |
+""" |
+Copies the given "win tool" (which the toolchain uses to wrap compiler |
+invocations) and the environment blocks for the 32-bit and 64-bit builds on |
+Windows to the build directory. |
+ |
+The arguments are the visual studio install location and the location of the |
+win tool. The script assumes that the root build directory is the current dir |
+and the files will be written to the current directory. |
+""" |
+ |
+ |
def ExtractImportantEnvironment(): |
"""Extracts environment variables required for the toolchain from the |
current environment.""" |
@@ -36,48 +49,6 @@ def ExtractImportantEnvironment(): |
return result |
-# VC setup will add a path like this in 32-bit mode: |
-# c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN |
-# And this in 64-bit mode: |
-# c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64 |
-# Note that in 64-bit it's duplicated but the 64-bit one comes first. |
-# |
-# What we get as the path when running this will depend on which VS setup |
-# script you've run. The following two functions try to do this. |
- |
-# For 32-bit compiles remove anything that ends in "\VC\WIN\amd64". |
-def FixupPath32(path): |
- find_64 = re.compile("VC\\\\BIN\\\\amd64\\\\*$", flags=re.IGNORECASE) |
- |
- for i in range(len(path)): |
- if find_64.search(path[i]): |
- # Found 32-bit path, insert the 64-bit one immediately before it. |
- dir_64 = path[i].rstrip("\\") |
- dir_64 = dir_64[:len(dir_64) - 6] # Trim off "\amd64". |
- path[i] = dir_64 |
- break |
- return path |
- |
-# For 64-bit compiles, append anything ending in "\VC\BIN" with "\amd64" as |
-# long as that thing isn't already in the list, and append it immediately |
-# before the non-amd64-one. |
-def FixupPath64(path): |
- find_32 = re.compile("VC\\\\BIN\\\\*$", flags=re.IGNORECASE) |
- |
- for i in range(len(path)): |
- if find_32.search(path[i]): |
- # Found 32-bit path, insert the 64-bit one immediately before it. |
- dir_32 = path[i] |
- if dir_32[len(dir_32) - 1] == '\\': |
- dir_64 = dir_32 + "amd64" |
- else: |
- dir_64 = dir_32 + "\\amd64" |
- path.insert(i, dir_64) |
- break |
- |
- return path |
- |
- |
def FormatAsEnvironmentBlock(envvar_dict): |
"""Format as an 'environment block' directly suitable for CreateProcess. |
Briefly this is a list of key=value\0, terminated by an additional \0. See |
@@ -89,6 +60,7 @@ def FormatAsEnvironmentBlock(envvar_dict): |
block += nul |
return block |
+ |
def CopyTool(source_path): |
"""Copies the given tool to the current directory, including a warning not |
to edit it.""" |
@@ -102,22 +74,27 @@ def CopyTool(source_path): |
'# Generated by setup_toolchain.py do not edit.\n'] |
+ tool_source[1:])) |
+if len(sys.argv) != 3: |
+ print 'Usage setup_toolchain.py <visual studio path> <win tool path>' |
+ sys.exit(2) |
+vs_path = sys.argv[1] |
+tool_source = sys.argv[2] |
-# Find the tool source, it's the first argument, and copy it. |
-if len(sys.argv) != 2: |
- print "Need one argument (win_tool source path)." |
- sys.exit(1) |
-CopyTool(sys.argv[1]) |
+CopyTool(tool_source) |
important_env_vars = ExtractImportantEnvironment() |
path = important_env_vars["PATH"].split(";") |
-important_env_vars["PATH"] = ";".join(FixupPath32(path)) |
+# Add 32-bit compiler path to the beginning and write the block. |
+path32 = [os.path.join(vs_path, "VC\\BIN")] + path |
+important_env_vars["PATH"] = ";".join(path32) |
environ = FormatAsEnvironmentBlock(important_env_vars) |
with open('environment.x86', 'wb') as env_file: |
env_file.write(environ) |
-important_env_vars["PATH"] = ";".join(FixupPath64(path)) |
+# Add 64-bit compiler path to the beginning and write the block. |
+path64 = [os.path.join(vs_path, "VC\\BIN\\amd64")] + path |
+important_env_vars["PATH"] = ";".join(path64) |
environ = FormatAsEnvironmentBlock(important_env_vars) |
with open('environment.x64', 'wb') as env_file: |
env_file.write(environ) |