OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Common utilities for all buildbot scripts that specifically don't rely | 5 """Common utilities for all buildbot scripts that specifically don't rely |
6 on having a full chromium checkout. | 6 on having a full chromium checkout. |
7 """ | 7 """ |
8 | 8 |
9 import os | 9 import os |
10 import subprocess | 10 import subprocess |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 sys.stderr.write(str(msg) + '\n') | 51 sys.stderr.write(str(msg) + '\n') |
52 sys.exit(1) | 52 sys.exit(1) |
53 | 53 |
54 | 54 |
55 def Trace(msg): | 55 def Trace(msg): |
56 if verbose: | 56 if verbose: |
57 sys.stderr.write(str(msg) + '\n') | 57 sys.stderr.write(str(msg) + '\n') |
58 | 58 |
59 | 59 |
60 def GetWindowsEnvironment(): | 60 def GetWindowsEnvironment(): |
| 61 if oshelpers.FindExeInPath('cl.exe') is not None: |
| 62 # cl.exe is already in the path, let's just use that. |
| 63 return os.environ |
| 64 |
61 sys.path.append(os.path.join(NACL_DIR, 'buildbot')) | 65 sys.path.append(os.path.join(NACL_DIR, 'buildbot')) |
62 import buildbot_standard | 66 import buildbot_standard |
63 | 67 |
64 # buildbot_standard.SetupWindowsEnvironment expects a "context" object. We'll | 68 # buildbot_standard.SetupWindowsEnvironment expects a "context" object. We'll |
65 # fake enough of that here to work. | 69 # fake enough of that here to work. |
66 class FakeContext(object): | 70 class FakeContext(object): |
67 def __init__(self): | 71 def __init__(self): |
68 self.env = os.environ | 72 self.env = os.environ |
69 | 73 |
70 def GetEnv(self, key): | 74 def GetEnv(self, key): |
71 return self.env[key] | 75 return self.env[key] |
72 | 76 |
73 def __getitem__(self, key): | 77 def __getitem__(self, key): |
74 # The nacl side script now needs gyp_vars to return a list. | 78 # The nacl side script now needs gyp_vars to return a list. |
75 if key == 'gyp_vars': | 79 if key == 'gyp_vars': |
76 return [] | 80 return [] |
77 return self.env[key] | 81 return self.env[key] |
78 | 82 |
79 def SetEnv(self, key, value): | 83 def SetEnv(self, key, value): |
80 self.env[key] = value | 84 self.env[key] = value |
81 | 85 |
82 def __setitem__(self, key, value): | 86 def __setitem__(self, key, value): |
83 self.env[key] = value | 87 self.env[key] = value |
84 | 88 |
85 context = FakeContext() | 89 context = FakeContext() |
86 buildbot_standard.SetupWindowsEnvironment(context) | 90 buildbot_standard.SetupWindowsEnvironment(context) |
87 | 91 |
88 # buildbot_standard.SetupWindowsEnvironment adds the directory which contains | 92 env_script = 'vcvarsall.bat' |
89 # vcvarsall.bat to the path, but not the directory which contains cl.exe, | 93 |
90 # link.exe, etc. | 94 if not oshelpers.FindExeInPath(env_script): |
91 # Running vcvarsall.bat adds the correct directories to the path, which we | 95 # This might happen if Visual Studio is not installed. Check to see if |
92 # extract below. | 96 # vs2013 is in depot_tools. |
93 process = subprocess.Popen('vcvarsall.bat x86 > NUL && set', | 97 |
| 98 # Find depot_tools by looking for gclient.bat. |
| 99 gclient_bat = oshelpers.FindExeInPath('gclient.bat') |
| 100 if gclient_bat is None: |
| 101 ErrorExit('gclient.bat is not in the path. Where is depot_tools?') |
| 102 |
| 103 depot_tools_dir = os.path.dirname(gclient_bat) |
| 104 vs2013_dir = os.path.join(depot_tools_dir, 'win_toolchain', 'vs2013_files') |
| 105 if not os.path.exists(vs2013_dir): |
| 106 ErrorExit('Visual Studio not installed normally or in depot_tools.') |
| 107 |
| 108 # The depot_tools vs2013 toolchain has its own batch file (not |
| 109 # vcvarsall.bat) for setting the environment variables needed by vs2013. |
| 110 env_script = os.path.join(vs2013_dir, 'win8sdk', 'bin', 'SetEnv.cmd') |
| 111 |
| 112 # Running the env_script adds the correct directories to the path for |
| 113 # executables (e.g. cl.exe, link.exe), include paths, lib directories, etc, |
| 114 # which we extract below. |
| 115 process = subprocess.Popen(env_script + ' x86 > NUL && set', |
94 stdout=subprocess.PIPE, env=context.env, shell=True) | 116 stdout=subprocess.PIPE, env=context.env, shell=True) |
95 stdout, _ = process.communicate() | 117 stdout, _ = process.communicate() |
96 | 118 |
97 # Parse environment from "set" command above. | 119 # Parse environment from "set" command above. |
98 # It looks like this: | 120 # It looks like this: |
99 # KEY1=VALUE1\r\n | 121 # KEY1=VALUE1\r\n |
100 # KEY2=VALUE2\r\n | 122 # KEY2=VALUE2\r\n |
101 # ... | 123 # ... |
102 return dict(line.split('=', 1) for line in stdout.split('\r\n')[:-1]) | 124 return dict(line.split('=', 1) for line in stdout.split('\r\n')[:-1]) |
103 | 125 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 # Without shell=True the windows implementation of subprocess.call will not | 225 # Without shell=True the windows implementation of subprocess.call will not |
204 # search the PATH for the executable: http://bugs.python.org/issue8557 | 226 # search the PATH for the executable: http://bugs.python.org/issue8557 |
205 shell = getos.GetPlatform() == 'win' | 227 shell = getos.GetPlatform() == 'win' |
206 | 228 |
207 cmd = [GetGsutil(), 'cp', '-a', 'public-read', filename, full_dst] | 229 cmd = [GetGsutil(), 'cp', '-a', 'public-read', filename, full_dst] |
208 Run(cmd, shell=shell, cwd=cwd) | 230 Run(cmd, shell=shell, cwd=cwd) |
209 url = 'https://storage.googleapis.com/%s/%s' % (bucket_path, filename) | 231 url = 'https://storage.googleapis.com/%s/%s' % (bucket_path, filename) |
210 if step_link: | 232 if step_link: |
211 sys.stdout.flush() | 233 sys.stdout.flush() |
212 sys.stderr.write('@@@STEP_LINK@download@%s@@@\n' % url) | 234 sys.stderr.write('@@@STEP_LINK@download@%s@@@\n' % url) |
OLD | NEW |