OLD | NEW |
---|---|
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import errno | 5 import errno |
6 import os | 6 import os |
7 import re | 7 import re |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 setting = os.path.dirname(sys.executable) + os.pathsep + setting | 46 setting = os.path.dirname(sys.executable) + os.pathsep + setting |
47 env[var.upper()] = setting | 47 env[var.upper()] = setting |
48 break | 48 break |
49 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): | 49 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): |
50 if required not in env: | 50 if required not in env: |
51 raise Exception('Environment variable "%s" ' | 51 raise Exception('Environment variable "%s" ' |
52 'required to be set to valid path' % required) | 52 'required to be set to valid path' % required) |
53 return env | 53 return env |
54 | 54 |
55 | 55 |
56 def _SetupScript(target_arch, sdk_dir): | 56 def _SetupScript(target_arch, sdk_dir, vc_bin_subdir): |
57 """Returns a command (with arguments) to be used to set up the | 57 """Returns a command (with arguments) to be used to set up the |
58 environment.""" | 58 environment.""" |
59 # Check if we are running in the SDK command line environment and use | 59 # Check if we are running in the SDK command line environment and use |
60 # the setup script from the SDK if so. |target_arch| should be either | 60 # the setup script from the SDK if so. |target_arch| should be either |
61 # 'x86' or 'x64'. | 61 # 'x86' or 'x64'. |
62 assert target_arch in ('x86', 'x64') | 62 assert target_arch in ('x86', 'x64') |
63 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir: | 63 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir: |
64 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), | 64 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), |
65 '/' + target_arch] | 65 '/' + target_arch] |
66 else: | 66 else: |
67 # We only support x64-hosted tools. | 67 # We only support x64-hosted tools. |
68 # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual | 68 # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual |
69 # Studio install location from registry. | 69 # Studio install location from registry. |
70 return [os.path.normpath(os.path.join(FIND_VS_IN_REG, 'VC/vcvarsall.bat')), | 70 return [os.path.normpath(os.path.join(FIND_VS_IN_REG, 'VC/vcvarsall.bat')), |
71 'amd64_x86' if target_arch == 'x86' else 'amd64'] | 71 vc_bin_subdir] |
72 | 72 |
73 | 73 |
74 def _FormatAsEnvironmentBlock(envvar_dict): | 74 def _FormatAsEnvironmentBlock(envvar_dict): |
75 """Format as an 'environment block' directly suitable for CreateProcess. | 75 """Format as an 'environment block' directly suitable for CreateProcess. |
76 Briefly this is a list of key=value\0, terminated by an additional \0. See | 76 Briefly this is a list of key=value\0, terminated by an additional \0. See |
77 CreateProcess documentation for more details.""" | 77 CreateProcess documentation for more details.""" |
78 block = '' | 78 block = '' |
79 nul = '\0' | 79 nul = '\0' |
80 for key, value in envvar_dict.iteritems(): | 80 for key, value in envvar_dict.iteritems(): |
81 block += key + '=' + value + nul | 81 block += key + '=' + value + nul |
82 block += nul | 82 block += nul |
83 return block | 83 return block |
84 | 84 |
85 | 85 |
86 def _CopyTool(source_path): | 86 def _CopyTool(source_path): |
87 """Copies the given tool to the current directory, including a warning not | 87 """Copies the given tool to the current directory, including a warning not |
88 to edit it.""" | 88 to edit it.""" |
89 with open(source_path) as source_file: | 89 with open(source_path) as source_file: |
90 tool_source = source_file.readlines() | 90 tool_source = source_file.readlines() |
91 | 91 |
92 # Add header and write it out to the current directory (which should be the | 92 # Add header and write it out to the current directory (which should be the |
93 # root build dir). | 93 # root build dir). |
94 with open("gyp-win-tool", 'w') as tool_file: | 94 with open("gyp-win-tool", 'w') as tool_file: |
95 tool_file.write(''.join([tool_source[0], | 95 tool_file.write(''.join([tool_source[0], |
96 '# Generated by setup_toolchain.py do not edit.\n'] | 96 '# Generated by setup_toolchain.py do not edit.\n'] |
97 + tool_source[1:])) | 97 + tool_source[1:])) |
98 | 98 |
99 | 99 |
100 def main(): | 100 def main(): |
101 if len(sys.argv) != 5: | 101 if len(sys.argv) != 6: |
102 print('Usage setup_toolchain.py ' | 102 print('Usage setup_toolchain.py ' |
103 '<visual studio path> <win tool path> <win sdk path> <runtime dirs>') | 103 '<visual studio path> <win tool path> <win sdk path> ' |
104 '<runtime dirs> <cpu_arch>') | |
104 sys.exit(2) | 105 sys.exit(2) |
105 vs_path = sys.argv[1] | 106 vs_path = sys.argv[1] |
106 tool_source = sys.argv[2] | 107 tool_source = sys.argv[2] |
107 win_sdk_path = sys.argv[3] | 108 win_sdk_path = sys.argv[3] |
108 runtime_dirs = sys.argv[4] | 109 runtime_dirs = sys.argv[4] |
110 cpu_arch = sys.argv[5] | |
109 | 111 |
110 _CopyTool(tool_source) | 112 _CopyTool(tool_source) |
111 | 113 |
112 archs = ('x86', 'x64') | 114 archs = ('x86', 'x64') |
115 assert cpu_arch in archs | |
116 vc_bin_subdir = 'amd64_x86' if cpu_arch == 'x86' else 'amd64' | |
scottmg
2014/11/21 22:26:59
i guess that's ok :) at least it's all in this scr
| |
117 | |
113 # TODO(scottmg|goma): Do we need an equivalent of | 118 # TODO(scottmg|goma): Do we need an equivalent of |
114 # ninja_use_custom_environment_files? | 119 # ninja_use_custom_environment_files? |
115 for arch in archs: | 120 for arch in archs: |
116 # Extract environment variables for subprocesses. | 121 # Extract environment variables for subprocesses. |
117 args = _SetupScript(arch, win_sdk_path) | 122 args = _SetupScript(arch, win_sdk_path, vc_bin_subdir) |
118 args.extend(('&&', 'set')) | 123 args.extend(('&&', 'set')) |
119 popen = subprocess.Popen( | 124 popen = subprocess.Popen( |
120 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 125 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
121 variables, _ = popen.communicate() | 126 variables, _ = popen.communicate() |
122 env = _ExtractImportantEnvironment(variables) | 127 env = _ExtractImportantEnvironment(variables) |
123 env['PATH'] = runtime_dirs + ';' + env['PATH'] | 128 env['PATH'] = runtime_dirs + ';' + env['PATH'] |
124 | 129 |
125 # TODO(scottmg|thakis|dpranke): Is there an equivalent to | 130 # TODO(scottmg|thakis|dpranke): Is there an equivalent to |
126 # msvs_system_include_dirs that we need to inject into INCLUDE here? | 131 # msvs_system_include_dirs that we need to inject into INCLUDE here? |
127 | 132 |
128 env_block = _FormatAsEnvironmentBlock(env) | 133 env_block = _FormatAsEnvironmentBlock(env) |
129 with open('environment.' + arch, 'wb') as f: | 134 with open('environment.' + arch, 'wb') as f: |
130 f.write(env_block) | 135 f.write(env_block) |
131 | 136 |
137 print 'vc_bin_dir = "%s"' % os.path.join(vs_path, 'VC', 'bin', vc_bin_subdir) | |
138 | |
132 | 139 |
133 if __name__ == '__main__': | 140 if __name__ == '__main__': |
134 main() | 141 main() |
OLD | NEW |