summaryrefslogtreecommitdiffstats
path: root/build/toolchain
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 18:46:44 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 18:46:44 +0000
commit033ab11494b2500c9f3d65e49b8cdfe324ddbeb6 (patch)
treef38a02fbaad1f035d6b282228f433860aa1da61d /build/toolchain
parentc29da3489695f28871e041f76a8c97ef40d0cf89 (diff)
downloadchromium_src-033ab11494b2500c9f3d65e49b8cdfe324ddbeb6.zip
chromium_src-033ab11494b2500c9f3d65e49b8cdfe324ddbeb6.tar.gz
chromium_src-033ab11494b2500c9f3d65e49b8cdfe324ddbeb6.tar.bz2
GN: Autodetect Visual Studio versions
This searches the local system for Visual Studio versions like GYP. It enables specifically requesting one version, as well as overriding the directory like GYP. BUG= R=scottmg@chromium.org Review URL: https://codereview.chromium.org/126073005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/toolchain')
-rw-r--r--build/toolchain/win/BUILD.gn24
-rw-r--r--build/toolchain/win/setup_toolchain.py75
2 files changed, 35 insertions, 64 deletions
diff --git a/build/toolchain/win/BUILD.gn b/build/toolchain/win/BUILD.gn
index ceb0ca8..b567745 100644
--- a/build/toolchain/win/BUILD.gn
+++ b/build/toolchain/win/BUILD.gn
@@ -7,23 +7,17 @@ import("//build/toolchain/goma.gni")
# Should only be running on Windows.
assert(is_win)
+import("//build/config/win/visual_studio_version.gni")
+
# Setup the Visual Studio state.
#
-# Its argument is the location to write the environment files.
-# It will write "environment.x86" and "environment.x64" to this directory,
-# and return a list to us.
-#
-# The list contains the include path as its only element. (I'm expecting to
-# add more so it's currently a list inside a list.)
-#exec_script("get_msvc_config.py",
- # [relative_root_output_dir],
- # "value")
-
-# This will save the environment block and and copy the gyp-win-tool to the
-# build directory. We pass in the source file of the win tool.
-gyp_win_tool_source =
- rebase_path("//tools/gyp/pylib/gyp/win_tool.py", ".", root_build_dir)
-exec_script("setup_toolchain.py", [ gyp_win_tool_source ], "value")
+# Its arguments are the VS path and the compiler wrapper tool. It will write
+# "environment.x86" and "environment.x64" to the build directory and return a
+# list to us.
+gyp_win_tool_path = rebase_path("//tools/gyp/pylib/gyp/win_tool.py", ".",
+ root_build_dir)
+exec_script("setup_toolchain.py", [ visual_studio_path, gyp_win_tool_path ],
+ "string")
stamp_command = "$python_path gyp-win-tool stamp \$out"
copy_command = "$python_path gyp-win-tool recursive-mirror \$in \$out"
diff --git a/build/toolchain/win/setup_toolchain.py b/build/toolchain/win/setup_toolchain.py
index 162c2e1..bceafd1 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)