summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis <thakis@chromium.org>2016-02-15 10:18:01 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-15 18:19:25 +0000
commit44a40f8429c25eaf7bf8577cafbcf3a8df100840 (patch)
tree8f9c0f93695dd71d6b3c65dde0129645edb44d24
parent00c72f4350b045e1a7a588cf89ea6c2fa8192b1c (diff)
downloadchromium_src-44a40f8429c25eaf7bf8577cafbcf3a8df100840.zip
chromium_src-44a40f8429c25eaf7bf8577cafbcf3a8df100840.tar.gz
chromium_src-44a40f8429c25eaf7bf8577cafbcf3a8df100840.tar.bz2
vs toolchain: Move toolchain env computation into its own function.
Also replace a few ';'s with os.path.pathsep and a few \s with os.path.sep. No behavior change on Windows; the motivation is that this might make it possible to do this environment computation on non-Windows hosts too some day. BUG=495204 Review URL: https://codereview.chromium.org/1697023002 Cr-Commit-Position: refs/heads/master@{#375476}
-rw-r--r--build/toolchain/win/setup_toolchain.py34
-rwxr-xr-xbuild/vs_toolchain.py6
2 files changed, 23 insertions, 17 deletions
diff --git a/build/toolchain/win/setup_toolchain.py b/build/toolchain/win/setup_toolchain.py
index dcb09bb..1e20387 100644
--- a/build/toolchain/win/setup_toolchain.py
+++ b/build/toolchain/win/setup_toolchain.py
@@ -86,6 +86,19 @@ def _SetupScript(target_cpu, sdk_dir):
'amd64_x86' if target_cpu == 'x86' else 'amd64']
+def _LoadToolchainEnv(cpu, win_sdk_path):
+ """Returns a dictionary with environment variables that must be set while
+ running binaries from the toolchain (e.g. INCLUDE and PATH for cl.exe)."""
+ args = _SetupScript(cpu, win_sdk_path)
+ args.extend(('&&', 'set'))
+ popen = subprocess.Popen(
+ args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ variables, _ = popen.communicate()
+ if popen.returncode != 0:
+ raise Exception('"%s" failed with error %d' % (args, popen.returncode))
+ return _ExtractImportantEnvironment(variables)
+
+
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
@@ -134,15 +147,8 @@ def main():
for cpu in cpus:
# Extract environment variables for subprocesses.
- args = _SetupScript(cpu, win_sdk_path)
- args.extend(('&&', 'set'))
- popen = subprocess.Popen(
- args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
- variables, _ = popen.communicate()
- if popen.returncode != 0:
- raise Exception('"%s" failed with error %d' % (args, popen.returncode))
- env = _ExtractImportantEnvironment(variables)
- env['PATH'] = runtime_dirs + ';' + env['PATH']
+ env = _LoadToolchainEnv(cpu, win_sdk_path)
+ env['PATH'] = runtime_dirs + os.path.pathsep + env['PATH']
if cpu == target_cpu:
for path in env['PATH'].split(os.pathsep):
@@ -157,11 +163,11 @@ def main():
# version is used.
if win_sdk_path:
- additional_includes = ('{sdk_dir}\\Include\\10.0.10586.0\\shared;' +
- '{sdk_dir}\\Include\\10.0.10586.0\\um;' +
- '{sdk_dir}\\Include\\10.0.10586.0\\winrt;').format(
- sdk_dir=win_sdk_path)
- env['INCLUDE'] = additional_includes + env['INCLUDE']
+ additional_includes = [
+ os.path.join(win_sdk_path, 'Include', '10.0.10586.0', p)
+ for p in ['shared', 'um', 'winrt']]
+ additional_includes = os.path.pathsep.join(additional_includes)
+ env['INCLUDE'] = additional_includes + os.path.pathsep + env['INCLUDE']
env_block = _FormatAsEnvironmentBlock(env)
with open('environment.' + cpu, 'wb') as f:
f.write(env_block)
diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py
index 4399063..7c5c989 100755
--- a/build/vs_toolchain.py
+++ b/build/vs_toolchain.py
@@ -67,8 +67,8 @@ def SetEnvironmentAndGetRuntimeDllDirs():
os.environ['WINDOWSSDKDIR'] = win_sdk
os.environ['WDK_DIR'] = wdk
# Include the VS runtime in the PATH in case it's not machine-installed.
- runtime_path = ';'.join(vs_runtime_dll_dirs)
- os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
+ runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
+ os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
elif sys.platform == 'win32' and not depot_tools_win_toolchain:
if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
@@ -350,7 +350,7 @@ runtime_dirs = "%s"
os.environ['WINDOWSSDKDIR'],
GetVisualStudioVersion(),
os.environ.get('WDK_DIR', ''),
- ';'.join(runtime_dll_dirs or ['None']))
+ os.path.pathsep.join(runtime_dll_dirs or ['None']))
def main():