| 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 |
| 11 """ | 11 """ |
| 12 Copies the given "win tool" (which the toolchain uses to wrap compiler | 12 Copies the given "win tool" (which the toolchain uses to wrap compiler |
| 13 invocations) and the environment blocks for the 32-bit and 64-bit builds on | 13 invocations) and the environment blocks for the 32-bit and 64-bit builds on |
| 14 Windows to the build directory. | 14 Windows to the build directory. |
| 15 | 15 |
| 16 The arguments are the visual studio install location and the location of the | 16 The arguments are the visual studio install location and the location of the |
| 17 win tool. The script assumes that the root build directory is the current dir | 17 win tool. The script assumes that the root build directory is the current dir |
| 18 and the files will be written to the current directory. | 18 and the files will be written to the current directory. |
| 19 """ | 19 """ |
| 20 | 20 |
| 21 | 21 |
| 22 def ExtractImportantEnvironment(): | 22 def ExtractImportantEnvironment(): |
| 23 """Extracts environment variables required for the toolchain from the | 23 """Extracts environment variables required for the toolchain from the |
| 24 current environment.""" | 24 current environment.""" |
| 25 envvars_to_save = ( | 25 envvars_to_save = ( |
| 26 'goma_.*', # TODO(scottmg): This is ugly, but needed for goma. | 26 'goma_.*', # TODO(scottmg): This is ugly, but needed for goma. |
| 27 'Path', | 27 'path', |
| 28 'PATHEXT', | 28 'pathext', |
| 29 'SystemRoot', | 29 'systemroot', |
| 30 'TEMP', | 30 'temp', |
| 31 'TMP', | 31 'tmp', |
| 32 ) | 32 ) |
| 33 result = {} | 33 result = {} |
| 34 for envvar in envvars_to_save: | 34 for envvar in envvars_to_save: |
| 35 if envvar in os.environ: | 35 if envvar in os.environ: |
| 36 if envvar == 'Path': | 36 envvar = envvar.lower() |
| 37 if envvar == 'path': |
| 37 # Our own rules (for running gyp-win-tool) and other actions in | 38 # Our own rules (for running gyp-win-tool) and other actions in |
| 38 # Chromium rely on python being in the path. Add the path to this | 39 # Chromium rely on python being in the path. Add the path to this |
| 39 # python here so that if it's not in the path when ninja is run | 40 # python here so that if it's not in the path when ninja is run |
| 40 # later, python will still be found. | 41 # later, python will still be found. |
| 41 result[envvar.upper()] = os.path.dirname(sys.executable) + \ | 42 result[envvar.upper()] = os.path.dirname(sys.executable) + \ |
| 42 os.pathsep + os.environ[envvar] | 43 os.pathsep + os.environ[envvar] |
| 43 else: | 44 else: |
| 44 result[envvar.upper()] = os.environ[envvar] | 45 result[envvar.upper()] = os.environ[envvar] |
| 45 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): | 46 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): |
| 46 if required not in result: | 47 if required not in result: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 with open(source_path) as source_file: | 68 with open(source_path) as source_file: |
| 68 tool_source = source_file.readlines() | 69 tool_source = source_file.readlines() |
| 69 | 70 |
| 70 # Add header and write it out to the current directory (which should be the | 71 # Add header and write it out to the current directory (which should be the |
| 71 # root build dir). | 72 # root build dir). |
| 72 with open("gyp-win-tool", 'w') as tool_file: | 73 with open("gyp-win-tool", 'w') as tool_file: |
| 73 tool_file.write(''.join([tool_source[0], | 74 tool_file.write(''.join([tool_source[0], |
| 74 '# Generated by setup_toolchain.py do not edit.\n'] | 75 '# Generated by setup_toolchain.py do not edit.\n'] |
| 75 + tool_source[1:])) | 76 + tool_source[1:])) |
| 76 | 77 |
| 77 if len(sys.argv) != 3: | 78 if len(sys.argv) != 4: |
| 78 print 'Usage setup_toolchain.py <visual studio path> <win tool path>' | 79 print('Usage setup_toolchain.py ' |
| 80 '<visual studio path> <win tool path> <win sdk path>') |
| 79 sys.exit(2) | 81 sys.exit(2) |
| 80 vs_path = sys.argv[1] | 82 vs_path = sys.argv[1] |
| 81 tool_source = sys.argv[2] | 83 tool_source = sys.argv[2] |
| 84 win_sdk_path = sys.argv[3] |
| 82 | 85 |
| 83 CopyTool(tool_source) | 86 CopyTool(tool_source) |
| 84 | 87 |
| 85 important_env_vars = ExtractImportantEnvironment() | 88 important_env_vars = ExtractImportantEnvironment() |
| 86 path = important_env_vars["PATH"].split(";") | 89 path = important_env_vars["PATH"].split(";") |
| 87 | 90 |
| 88 # Add 32-bit compiler path to the beginning and write the block. | 91 # Add 32-bit compiler path to the beginning and write the block. |
| 89 path32 = [os.path.join(vs_path, "VC\\BIN")] + path | 92 path32 = [os.path.join(vs_path, "VC\\BIN")] + \ |
| 93 [os.path.join(win_sdk_path, "bin\\x86")] + \ |
| 94 path |
| 90 important_env_vars["PATH"] = ";".join(path32) | 95 important_env_vars["PATH"] = ";".join(path32) |
| 91 environ = FormatAsEnvironmentBlock(important_env_vars) | 96 environ = FormatAsEnvironmentBlock(important_env_vars) |
| 92 with open('environment.x86', 'wb') as env_file: | 97 with open('environment.x86', 'wb') as env_file: |
| 93 env_file.write(environ) | 98 env_file.write(environ) |
| 94 | 99 |
| 95 # Add 64-bit compiler path to the beginning and write the block. | 100 # Add 64-bit compiler path to the beginning and write the block. |
| 96 path64 = [os.path.join(vs_path, "VC\\BIN\\amd64")] + path | 101 path64 = [os.path.join(vs_path, "VC\\BIN\\amd64")] + \ |
| 102 [os.path.join(win_sdk_path, "bin\\x64")] + \ |
| 103 path |
| 97 important_env_vars["PATH"] = ";".join(path64) | 104 important_env_vars["PATH"] = ";".join(path64) |
| 98 environ = FormatAsEnvironmentBlock(important_env_vars) | 105 environ = FormatAsEnvironmentBlock(important_env_vars) |
| 99 with open('environment.x64', 'wb') as env_file: | 106 with open('environment.x64', 'wb') as env_file: |
| 100 env_file.write(environ) | 107 env_file.write(environ) |
| OLD | NEW |