| 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 # Copies the given "win tool" (which the toolchain uses to wrap compiler | 5 # Copies the given "win tool" (which the toolchain uses to wrap compiler |
| 6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on | 6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on |
| 7 # Windows to the build directory. | 7 # Windows to the build directory. |
| 8 # | 8 # |
| 9 # The arguments are the visual studio install location and the location of the | 9 # The arguments are the visual studio install location and the location of the |
| 10 # win tool. The script assumes that the root build directory is the current dir | 10 # win tool. The script assumes that the root build directory is the current dir |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 env = {} | 39 env = {} |
| 40 # This occasionally happens and leads to misleading SYSTEMROOT error messages | 40 # This occasionally happens and leads to misleading SYSTEMROOT error messages |
| 41 # if not caught here. | 41 # if not caught here. |
| 42 if output_of_set.count('=') == 0: | 42 if output_of_set.count('=') == 0: |
| 43 raise Exception('Invalid output_of_set. Value is:\n%s' % output_of_set) | 43 raise Exception('Invalid output_of_set. Value is:\n%s' % output_of_set) |
| 44 for line in output_of_set.splitlines(): | 44 for line in output_of_set.splitlines(): |
| 45 for envvar in envvars_to_save: | 45 for envvar in envvars_to_save: |
| 46 if re.match(envvar + '=', line.lower()): | 46 if re.match(envvar + '=', line.lower()): |
| 47 var, setting = line.split('=', 1) | 47 var, setting = line.split('=', 1) |
| 48 if envvar == 'path': | 48 if envvar == 'path': |
| 49 # Our own rules (for running gyp-win-tool) and other actions in | 49 # Our own rules and actions in Chromium rely on python being in the |
| 50 # Chromium rely on python being in the path. Add the path to this | 50 # path. Add the path to this python here so that if it's not in the |
| 51 # python here so that if it's not in the path when ninja is run | 51 # path when ninja is run later, python will still be found. |
| 52 # later, python will still be found. | |
| 53 setting = os.path.dirname(sys.executable) + os.pathsep + setting | 52 setting = os.path.dirname(sys.executable) + os.pathsep + setting |
| 54 env[var.upper()] = setting | 53 env[var.upper()] = setting |
| 55 break | 54 break |
| 56 if sys.platform in ('win32', 'cygwin'): | 55 if sys.platform in ('win32', 'cygwin'): |
| 57 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): | 56 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): |
| 58 if required not in env: | 57 if required not in env: |
| 59 raise Exception('Environment variable "%s" ' | 58 raise Exception('Environment variable "%s" ' |
| 60 'required to be set to valid path' % required) | 59 'required to be set to valid path' % required) |
| 61 return env | 60 return env |
| 62 | 61 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 Briefly this is a list of key=value\0, terminated by an additional \0. See | 139 Briefly this is a list of key=value\0, terminated by an additional \0. See |
| 141 CreateProcess documentation for more details.""" | 140 CreateProcess documentation for more details.""" |
| 142 block = '' | 141 block = '' |
| 143 nul = '\0' | 142 nul = '\0' |
| 144 for key, value in envvar_dict.iteritems(): | 143 for key, value in envvar_dict.iteritems(): |
| 145 block += key + '=' + value + nul | 144 block += key + '=' + value + nul |
| 146 block += nul | 145 block += nul |
| 147 return block | 146 return block |
| 148 | 147 |
| 149 | 148 |
| 150 def _CopyTool(source_path): | |
| 151 """Copies the given tool to the current directory, including a warning not | |
| 152 to edit it.""" | |
| 153 with open(source_path) as source_file: | |
| 154 tool_source = source_file.readlines() | |
| 155 | |
| 156 # Add header and write it out to the current directory (which should be the | |
| 157 # root build dir). Don't write the file if a matching file already exists | |
| 158 # because that causes a cascade of unnecessary rebuilds. | |
| 159 match = False | |
| 160 contents = ''.join([tool_source[0], | |
| 161 '# Generated by setup_toolchain.py do not edit.\n'] | |
| 162 + tool_source[1:]) | |
| 163 out_path = 'gyp-win-tool' | |
| 164 try: | |
| 165 with open(out_path, 'rb') as read_tool_file: | |
| 166 existing_contents = read_tool_file.read() | |
| 167 if existing_contents == contents: | |
| 168 match = True | |
| 169 except: | |
| 170 pass | |
| 171 if not match: | |
| 172 with open(out_path, 'wb') as write_tool_file: | |
| 173 write_tool_file.write(contents) | |
| 174 | |
| 175 | |
| 176 def main(): | 149 def main(): |
| 177 if len(sys.argv) != 7: | 150 if len(sys.argv) != 6: |
| 178 print('Usage setup_toolchain.py ' | 151 print('Usage setup_toolchain.py ' |
| 179 '<visual studio path> <win tool path> <win sdk path> ' | 152 '<visual studio path> <win sdk path> ' |
| 180 '<runtime dirs> <target_cpu> <include prefix>') | 153 '<runtime dirs> <target_cpu> <include prefix>') |
| 181 sys.exit(2) | 154 sys.exit(2) |
| 182 tool_source = sys.argv[2] | 155 win_sdk_path = sys.argv[2] |
| 183 win_sdk_path = sys.argv[3] | 156 runtime_dirs = sys.argv[3] |
| 184 runtime_dirs = sys.argv[4] | 157 target_cpu = sys.argv[4] |
| 185 target_cpu = sys.argv[5] | 158 include_prefix = sys.argv[5] |
| 186 include_prefix = sys.argv[6] | |
| 187 | |
| 188 _CopyTool(tool_source) | |
| 189 | 159 |
| 190 cpus = ('x86', 'x64') | 160 cpus = ('x86', 'x64') |
| 191 assert target_cpu in cpus | 161 assert target_cpu in cpus |
| 192 vc_bin_dir = '' | 162 vc_bin_dir = '' |
| 193 include = '' | 163 include = '' |
| 194 | 164 |
| 195 # TODO(scottmg|goma): Do we need an equivalent of | 165 # TODO(scottmg|goma): Do we need an equivalent of |
| 196 # ninja_use_custom_environment_files? | 166 # ninja_use_custom_environment_files? |
| 197 | 167 |
| 198 for cpu in cpus: | 168 for cpu in cpus: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 223 with open('environment.winrt_' + cpu, 'wb') as f: | 193 with open('environment.winrt_' + cpu, 'wb') as f: |
| 224 f.write(env_block) | 194 f.write(env_block) |
| 225 | 195 |
| 226 assert vc_bin_dir | 196 assert vc_bin_dir |
| 227 print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) | 197 print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) |
| 228 assert include | 198 assert include |
| 229 print 'include_flags = ' + gn_helpers.ToGNString(include) | 199 print 'include_flags = ' + gn_helpers.ToGNString(include) |
| 230 | 200 |
| 231 if __name__ == '__main__': | 201 if __name__ == '__main__': |
| 232 main() | 202 main() |
| OLD | NEW |