| 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 and actions in Chromium rely on python being in the | 49 # Our own rules (for running gyp-win-tool) and other actions in |
| 50 # path. Add the path to this python here so that if it's not in the | 50 # Chromium rely on python being in the path. Add the path to this |
| 51 # path when ninja is run later, python will still be found. | 51 # python here so that if it's not in the path when ninja is run |
| 52 # later, python will still be found. |
| 52 setting = os.path.dirname(sys.executable) + os.pathsep + setting | 53 setting = os.path.dirname(sys.executable) + os.pathsep + setting |
| 53 env[var.upper()] = setting | 54 env[var.upper()] = setting |
| 54 break | 55 break |
| 55 if sys.platform in ('win32', 'cygwin'): | 56 if sys.platform in ('win32', 'cygwin'): |
| 56 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): | 57 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): |
| 57 if required not in env: | 58 if required not in env: |
| 58 raise Exception('Environment variable "%s" ' | 59 raise Exception('Environment variable "%s" ' |
| 59 'required to be set to valid path' % required) | 60 'required to be set to valid path' % required) |
| 60 return env | 61 return env |
| 61 | 62 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 Briefly this is a list of key=value\0, terminated by an additional \0. See | 140 Briefly this is a list of key=value\0, terminated by an additional \0. See |
| 140 CreateProcess documentation for more details.""" | 141 CreateProcess documentation for more details.""" |
| 141 block = '' | 142 block = '' |
| 142 nul = '\0' | 143 nul = '\0' |
| 143 for key, value in envvar_dict.iteritems(): | 144 for key, value in envvar_dict.iteritems(): |
| 144 block += key + '=' + value + nul | 145 block += key + '=' + value + nul |
| 145 block += nul | 146 block += nul |
| 146 return block | 147 return block |
| 147 | 148 |
| 148 | 149 |
| 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 |
| 149 def main(): | 176 def main(): |
| 150 if len(sys.argv) != 6: | 177 if len(sys.argv) != 7: |
| 151 print('Usage setup_toolchain.py ' | 178 print('Usage setup_toolchain.py ' |
| 152 '<visual studio path> <win sdk path> ' | 179 '<visual studio path> <win tool path> <win sdk path> ' |
| 153 '<runtime dirs> <target_cpu> <include prefix>') | 180 '<runtime dirs> <target_cpu> <include prefix>') |
| 154 sys.exit(2) | 181 sys.exit(2) |
| 155 win_sdk_path = sys.argv[2] | 182 tool_source = sys.argv[2] |
| 156 runtime_dirs = sys.argv[3] | 183 win_sdk_path = sys.argv[3] |
| 157 target_cpu = sys.argv[4] | 184 runtime_dirs = sys.argv[4] |
| 158 include_prefix = sys.argv[5] | 185 target_cpu = sys.argv[5] |
| 186 include_prefix = sys.argv[6] |
| 187 |
| 188 _CopyTool(tool_source) |
| 159 | 189 |
| 160 cpus = ('x86', 'x64') | 190 cpus = ('x86', 'x64') |
| 161 assert target_cpu in cpus | 191 assert target_cpu in cpus |
| 162 vc_bin_dir = '' | 192 vc_bin_dir = '' |
| 163 include = '' | 193 include = '' |
| 164 | 194 |
| 165 # TODO(scottmg|goma): Do we need an equivalent of | 195 # TODO(scottmg|goma): Do we need an equivalent of |
| 166 # ninja_use_custom_environment_files? | 196 # ninja_use_custom_environment_files? |
| 167 | 197 |
| 168 for cpu in cpus: | 198 for cpu in cpus: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 193 with open('environment.winrt_' + cpu, 'wb') as f: | 223 with open('environment.winrt_' + cpu, 'wb') as f: |
| 194 f.write(env_block) | 224 f.write(env_block) |
| 195 | 225 |
| 196 assert vc_bin_dir | 226 assert vc_bin_dir |
| 197 print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) | 227 print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) |
| 198 assert include | 228 assert include |
| 199 print 'include_flags = ' + gn_helpers.ToGNString(include) | 229 print 'include_flags = ' + gn_helpers.ToGNString(include) |
| 200 | 230 |
| 201 if __name__ == '__main__': | 231 if __name__ == '__main__': |
| 202 main() | 232 main() |
| OLD | NEW |