1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Common utilities for all buildbot scripts that specifically don't rely
on having a full chromium checkout.
"""
import os
import subprocess
import sys
from build_paths import SDK_SRC_DIR, NACL_DIR, SRC_DIR
sys.path.append(os.path.join(SDK_SRC_DIR, 'tools'))
import oshelpers
import getos
verbose = True
def IsSDKBuilder():
"""Returns True if this script is running on an SDK builder.
False means it is either running on a trybot, or a user's machine.
Trybot names:
(win|mac|linux)_nacl_sdk
Build-only Trybot names:
(win|mac|linux)_nacl_sdk_build
Builder names:
(windows|mac|linux)-sdk-multi(bionic)(rel)?"""
bot = os.getenv('BUILDBOT_BUILDERNAME', '')
return '-sdk-multi' in bot or '-sdk-bionic-multi' in bot
def IsSDKTrybot():
"""Returns True if this script is running on an SDK trybot.
False means it is either running on an SDK builder, or a user's machine.
See IsSDKBuilder above for trybot/buildbot names."""
return '_nacl_sdk' in os.getenv('BUILDBOT_BUILDERNAME', '')
def ErrorExit(msg):
"""Write and error to stderr, then exit with 1 signaling failure."""
sys.stderr.write(str(msg) + '\n')
sys.exit(1)
def Trace(msg):
if verbose:
sys.stderr.write(str(msg) + '\n')
def GetWindowsEnvironment():
if oshelpers.FindExeInPath('cl.exe') is not None:
# cl.exe is already in the path, let's just use that.
return os.environ
sys.path.append(os.path.join(NACL_DIR, 'buildbot'))
import buildbot_standard
# buildbot_standard.SetupWindowsEnvironment expects a "context" object. We'll
# fake enough of that here to work.
class FakeContext(object):
def __init__(self):
self.env = os.environ
def GetEnv(self, key):
return self.env[key]
def __getitem__(self, key):
# The nacl side script now needs gyp_vars to return a list.
if key == 'gyp_vars':
return []
return self.env[key]
def SetEnv(self, key, value):
self.env[key] = value
def __setitem__(self, key, value):
self.env[key] = value
context = FakeContext()
buildbot_standard.SetupWindowsEnvironment(context)
env_script = 'vcvarsall.bat'
if not oshelpers.FindExeInPath(env_script):
# This might happen if Visual Studio is not installed. Check to see if
# vs2013 is in depot_tools.
# Find depot_tools by looking for gclient.bat.
gclient_bat = oshelpers.FindExeInPath('gclient.bat')
if gclient_bat is None:
ErrorExit('gclient.bat is not in the path. Where is depot_tools?')
depot_tools_dir = os.path.dirname(gclient_bat)
vs2013_dir = os.path.join(depot_tools_dir, 'win_toolchain', 'vs2013_files')
if not os.path.exists(vs2013_dir):
ErrorExit('Visual Studio not installed normally or in depot_tools.')
# The depot_tools vs2013 toolchain has its own batch file (not
# vcvarsall.bat) for setting the environment variables needed by vs2013.
env_script = os.path.join(vs2013_dir, 'win8sdk', 'bin', 'SetEnv.cmd')
# Running the env_script adds the correct directories to the path for
# executables (e.g. cl.exe, link.exe), include paths, lib directories, etc,
# which we extract below.
process = subprocess.Popen(env_script + ' x86 > NUL && set',
stdout=subprocess.PIPE, env=context.env, shell=True)
stdout, _ = process.communicate()
# Parse environment from "set" command above.
# It looks like this:
# KEY1=VALUE1\r\n
# KEY2=VALUE2\r\n
# ...
return dict(line.split('=', 1) for line in stdout.split('\r\n')[:-1])
def BuildStep(name):
"""Annotate a buildbot build step."""
sys.stdout.flush()
sys.stderr.write('\n@@@BUILD_STEP %s@@@\n' % name)
def Run(args, cwd=None, env=None, shell=False):
"""Start a process with the provided arguments.
Starts a process in the provided directory given the provided arguments. If
shell is not False, the process is launched via the shell to provide shell
interpretation of the arguments. Shell behavior can differ between platforms
so this should be avoided when not using platform dependent shell scripts."""
# We need to modify the environment to build host on Windows.
if not env and getos.GetPlatform() == 'win':
env = GetWindowsEnvironment()
Trace('Running: ' + ' '.join(args))
sys.stdout.flush()
sys.stderr.flush()
try:
subprocess.check_call(args, cwd=cwd, env=env, shell=shell)
except subprocess.CalledProcessError as e:
sys.stdout.flush()
sys.stderr.flush()
ErrorExit('buildbot_common: %s' % e)
sys.stdout.flush()
sys.stderr.flush()
def ShortFilename(filename):
drive = os.path.splitdrive(filename)[0]
if drive and drive != os.path.splitdrive(SRC_DIR)[0]:
return filename
return os.path.relpath(filename, SRC_DIR)
def CopyDir(src, dst, excludes=('.svn', '*/.svn')):
"""Recursively copy a directory using."""
args = ['-r', src, dst]
for exc in excludes:
args.append('--exclude=' + exc)
Trace('cp -r %s %s' % (ShortFilename(src), ShortFilename(dst)))
if os.path.abspath(src) == os.path.abspath(dst):
ErrorExit('ERROR: Copying directory onto itself: ' + src)
oshelpers.Copy(args)
def CopyFile(src, dst):
Trace('cp %s %s' % (ShortFilename(src), ShortFilename(dst)))
if os.path.abspath(src) == os.path.abspath(dst):
ErrorExit('ERROR: Copying file onto itself: ' + src)
args = [src, dst]
oshelpers.Copy(args)
def RemoveDir(dst):
"""Remove the provided path."""
Trace('rm -fr ' + ShortFilename(dst))
oshelpers.Remove(['-fr', dst])
def MakeDir(dst):
"""Create the path including all parent directories as needed."""
Trace('mkdir -p ' + ShortFilename(dst))
oshelpers.Mkdir(['-p', dst])
def Move(src, dst):
"""Move the path src to dst."""
Trace('mv -f %s %s' % (ShortFilename(src), ShortFilename(dst)))
oshelpers.Move(['-f', src, dst])
def RemoveFile(dst):
"""Remove the provided file."""
Trace('rm ' + ShortFilename(dst))
oshelpers.Remove(['-f', dst])
BOT_GSUTIL = '/b/build/scripts/slave/gsutil'
# On Windows, the current working directory may be on a different drive than
# gsutil.
WIN_BOT_GSUTIL = 'E:' + BOT_GSUTIL
LOCAL_GSUTIL = 'gsutil'
def GetGsutil():
if os.environ.get('BUILDBOT_BUILDERNAME') \
and not os.environ.get('BUILDBOT_FAKE'):
if getos.GetPlatform() == 'win':
return WIN_BOT_GSUTIL
return BOT_GSUTIL
else:
return LOCAL_GSUTIL
def Archive(filename, bucket_path, cwd=None, step_link=True):
"""Upload the given filename to Google Store."""
full_dst = 'gs://%s/%s' % (bucket_path, filename)
# Since GetGsutil() might just return 'gsutil' and expect it to be looked
# up in the PATH, we must pass shell=True on windows.
# Without shell=True the windows implementation of subprocess.call will not
# search the PATH for the executable: http://bugs.python.org/issue8557
shell = getos.GetPlatform() == 'win'
cmd = [GetGsutil(), 'cp', '-a', 'public-read', filename, full_dst]
Run(cmd, shell=shell, cwd=cwd)
url = 'https://storage.googleapis.com/%s/%s' % (bucket_path, filename)
if step_link:
sys.stdout.flush()
sys.stderr.write('@@@STEP_LINK@download@%s@@@\n' % url)
|