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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_dir = '' |
| 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? |
| 120 |
115 for arch in archs: | 121 for arch in archs: |
116 # Extract environment variables for subprocesses. | 122 # Extract environment variables for subprocesses. |
117 args = _SetupScript(arch, win_sdk_path) | 123 args = _SetupScript(arch, win_sdk_path) |
118 args.extend(('&&', 'set')) | 124 args.extend(('&&', 'set')) |
119 popen = subprocess.Popen( | 125 popen = subprocess.Popen( |
120 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 126 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
121 variables, _ = popen.communicate() | 127 variables, _ = popen.communicate() |
122 env = _ExtractImportantEnvironment(variables) | 128 env = _ExtractImportantEnvironment(variables) |
123 env['PATH'] = runtime_dirs + ';' + env['PATH'] | 129 env['PATH'] = runtime_dirs + ';' + env['PATH'] |
124 | 130 |
| 131 if arch == cpu_arch: |
| 132 for path in env['PATH'].split(os.pathsep): |
| 133 if os.path.exists(os.path.join(path, 'cl.exe')): |
| 134 vc_bin_dir = os.path.realpath(path) |
| 135 break |
| 136 |
125 # TODO(scottmg|thakis|dpranke): Is there an equivalent to | 137 # TODO(scottmg|thakis|dpranke): Is there an equivalent to |
126 # msvs_system_include_dirs that we need to inject into INCLUDE here? | 138 # msvs_system_include_dirs that we need to inject into INCLUDE here? |
127 | 139 |
128 env_block = _FormatAsEnvironmentBlock(env) | 140 env_block = _FormatAsEnvironmentBlock(env) |
129 with open('environment.' + arch, 'wb') as f: | 141 with open('environment.' + arch, 'wb') as f: |
130 f.write(env_block) | 142 f.write(env_block) |
131 | 143 |
| 144 assert vc_bin_dir |
| 145 print 'vc_bin_dir = "%s"' % vc_bin_dir |
| 146 |
132 | 147 |
133 if __name__ == '__main__': | 148 if __name__ == '__main__': |
134 main() | 149 main() |
OLD | NEW |