| 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_cpu, sdk_dir): |
| 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_cpu| should be either |
| 61 # 'x86' or 'x64'. | 61 # 'x86' or 'x64'. |
| 62 assert target_arch in ('x86', 'x64') | 62 assert target_cpu 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_cpu] |
| 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(os.environ['GYP_MSVS_OVERRIDE_PATH'], | 70 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], |
| 71 'VC/vcvarsall.bat')), | 71 'VC/vcvarsall.bat')), |
| 72 'amd64_x86' if target_arch == 'x86' else 'amd64'] | 72 'amd64_x86' if target_cpu == 'x86' else 'amd64'] |
| 73 | 73 |
| 74 | 74 |
| 75 def _FormatAsEnvironmentBlock(envvar_dict): | 75 def _FormatAsEnvironmentBlock(envvar_dict): |
| 76 """Format as an 'environment block' directly suitable for CreateProcess. | 76 """Format as an 'environment block' directly suitable for CreateProcess. |
| 77 Briefly this is a list of key=value\0, terminated by an additional \0. See | 77 Briefly this is a list of key=value\0, terminated by an additional \0. See |
| 78 CreateProcess documentation for more details.""" | 78 CreateProcess documentation for more details.""" |
| 79 block = '' | 79 block = '' |
| 80 nul = '\0' | 80 nul = '\0' |
| 81 for key, value in envvar_dict.iteritems(): | 81 for key, value in envvar_dict.iteritems(): |
| 82 block += key + '=' + value + nul | 82 block += key + '=' + value + nul |
| (...skipping 12 matching lines...) Expand all Loading... |
| 95 with open("gyp-win-tool", 'w') as tool_file: | 95 with open("gyp-win-tool", 'w') as tool_file: |
| 96 tool_file.write(''.join([tool_source[0], | 96 tool_file.write(''.join([tool_source[0], |
| 97 '# Generated by setup_toolchain.py do not edit.\n'] | 97 '# Generated by setup_toolchain.py do not edit.\n'] |
| 98 + tool_source[1:])) | 98 + tool_source[1:])) |
| 99 | 99 |
| 100 | 100 |
| 101 def main(): | 101 def main(): |
| 102 if len(sys.argv) != 6: | 102 if len(sys.argv) != 6: |
| 103 print('Usage setup_toolchain.py ' | 103 print('Usage setup_toolchain.py ' |
| 104 '<visual studio path> <win tool path> <win sdk path> ' | 104 '<visual studio path> <win tool path> <win sdk path> ' |
| 105 '<runtime dirs> <cpu_arch>') | 105 '<runtime dirs> <target_cpu>') |
| 106 sys.exit(2) | 106 sys.exit(2) |
| 107 vs_path = sys.argv[1] | 107 vs_path = sys.argv[1] |
| 108 tool_source = sys.argv[2] | 108 tool_source = sys.argv[2] |
| 109 win_sdk_path = sys.argv[3] | 109 win_sdk_path = sys.argv[3] |
| 110 runtime_dirs = sys.argv[4] | 110 runtime_dirs = sys.argv[4] |
| 111 cpu_arch = sys.argv[5] | 111 target_cpu = sys.argv[5] |
| 112 | 112 |
| 113 _CopyTool(tool_source) | 113 _CopyTool(tool_source) |
| 114 | 114 |
| 115 archs = ('x86', 'x64') | 115 cpus = ('x86', 'x64') |
| 116 assert cpu_arch in archs | 116 assert target_cpu in cpus |
| 117 vc_bin_dir = '' | 117 vc_bin_dir = '' |
| 118 | 118 |
| 119 # TODO(scottmg|goma): Do we need an equivalent of | 119 # TODO(scottmg|goma): Do we need an equivalent of |
| 120 # ninja_use_custom_environment_files? | 120 # ninja_use_custom_environment_files? |
| 121 | 121 |
| 122 for arch in archs: | 122 for cpu in cpus: |
| 123 # Extract environment variables for subprocesses. | 123 # Extract environment variables for subprocesses. |
| 124 args = _SetupScript(arch, win_sdk_path) | 124 args = _SetupScript(cpu, win_sdk_path) |
| 125 args.extend(('&&', 'set')) | 125 args.extend(('&&', 'set')) |
| 126 popen = subprocess.Popen( | 126 popen = subprocess.Popen( |
| 127 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 127 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 128 variables, _ = popen.communicate() | 128 variables, _ = popen.communicate() |
| 129 env = _ExtractImportantEnvironment(variables) | 129 env = _ExtractImportantEnvironment(variables) |
| 130 env['PATH'] = runtime_dirs + ';' + env['PATH'] | 130 env['PATH'] = runtime_dirs + ';' + env['PATH'] |
| 131 | 131 |
| 132 if arch == cpu_arch: | 132 if cpu == target_cpu: |
| 133 for path in env['PATH'].split(os.pathsep): | 133 for path in env['PATH'].split(os.pathsep): |
| 134 if os.path.exists(os.path.join(path, 'cl.exe')): | 134 if os.path.exists(os.path.join(path, 'cl.exe')): |
| 135 vc_bin_dir = os.path.realpath(path) | 135 vc_bin_dir = os.path.realpath(path) |
| 136 break | 136 break |
| 137 | 137 |
| 138 # The Windows SDK include directories must be first. They both have a sal.h, | 138 # The Windows SDK include directories must be first. They both have a sal.h, |
| 139 # and the SDK one is newer and the SDK uses some newer features from it not | 139 # and the SDK one is newer and the SDK uses some newer features from it not |
| 140 # present in the Visual Studio one. | 140 # present in the Visual Studio one. |
| 141 | 141 |
| 142 if win_sdk_path: | 142 if win_sdk_path: |
| 143 additional_includes = ('{sdk_dir}\\Include\\shared;' + | 143 additional_includes = ('{sdk_dir}\\Include\\shared;' + |
| 144 '{sdk_dir}\\Include\\um;' + | 144 '{sdk_dir}\\Include\\um;' + |
| 145 '{sdk_dir}\\Include\\winrt;').format( | 145 '{sdk_dir}\\Include\\winrt;').format( |
| 146 sdk_dir=win_sdk_path) | 146 sdk_dir=win_sdk_path) |
| 147 env['INCLUDE'] = additional_includes + env['INCLUDE'] | 147 env['INCLUDE'] = additional_includes + env['INCLUDE'] |
| 148 env_block = _FormatAsEnvironmentBlock(env) | 148 env_block = _FormatAsEnvironmentBlock(env) |
| 149 with open('environment.' + arch, 'wb') as f: | 149 with open('environment.' + cpu, 'wb') as f: |
| 150 f.write(env_block) | 150 f.write(env_block) |
| 151 | 151 |
| 152 assert vc_bin_dir | 152 assert vc_bin_dir |
| 153 print 'vc_bin_dir = "%s"' % vc_bin_dir | 153 print 'vc_bin_dir = "%s"' % vc_bin_dir |
| 154 | 154 |
| 155 | 155 |
| 156 if __name__ == '__main__': | 156 if __name__ == '__main__': |
| 157 main() | 157 main() |
| OLD | NEW |