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 30 matching lines...) Expand all Loading... | |
41 See IsSDKBuilder above for trybot/buildbot names.""" | 41 See IsSDKBuilder above for trybot/buildbot names.""" |
42 return '_nacl_sdk' in os.getenv('BUILDBOT_BUILDERNAME', '') | 42 return '_nacl_sdk' in os.getenv('BUILDBOT_BUILDERNAME', '') |
43 | 43 |
44 | 44 |
45 def ErrorExit(msg): | 45 def ErrorExit(msg): |
46 """Write and error to stderr, then exit with 1 signaling failure.""" | 46 """Write and error to stderr, then exit with 1 signaling failure.""" |
47 sys.stderr.write(str(msg) + '\n') | 47 sys.stderr.write(str(msg) + '\n') |
48 sys.exit(1) | 48 sys.exit(1) |
49 | 49 |
50 | 50 |
51 def Trace(verbose, msg): | |
52 if verbose: | |
53 sys.stderr.write(str(msg) + '\n') | |
54 | |
55 | |
51 def GetWindowsEnvironment(): | 56 def GetWindowsEnvironment(): |
52 sys.path.append(os.path.join(NACL_DIR, 'buildbot')) | 57 sys.path.append(os.path.join(NACL_DIR, 'buildbot')) |
53 import buildbot_standard | 58 import buildbot_standard |
54 | 59 |
55 # buildbot_standard.SetupWindowsEnvironment expects a "context" object. We'll | 60 # buildbot_standard.SetupWindowsEnvironment expects a "context" object. We'll |
56 # fake enough of that here to work. | 61 # fake enough of that here to work. |
57 class FakeContext(object): | 62 class FakeContext(object): |
58 def __init__(self): | 63 def __init__(self): |
59 self.env = os.environ | 64 self.env = os.environ |
60 | 65 |
(...skipping 25 matching lines...) Expand all Loading... | |
86 # It looks like this: | 91 # It looks like this: |
87 # KEY1=VALUE1\r\n | 92 # KEY1=VALUE1\r\n |
88 # KEY2=VALUE2\r\n | 93 # KEY2=VALUE2\r\n |
89 # ... | 94 # ... |
90 return dict(line.split('=') for line in stdout.split('\r\n')[:-1]) | 95 return dict(line.split('=') for line in stdout.split('\r\n')[:-1]) |
91 | 96 |
92 | 97 |
93 def BuildStep(name): | 98 def BuildStep(name): |
94 """Annotate a buildbot build step.""" | 99 """Annotate a buildbot build step.""" |
95 sys.stdout.flush() | 100 sys.stdout.flush() |
96 print '\n@@@BUILD_STEP %s@@@' % name | 101 print >> sys.stderr, '\n@@@BUILD_STEP %s@@@' % name |
97 sys.stdout.flush() | 102 sys.stdout.flush() |
98 | 103 |
99 | 104 |
100 def Run(args, cwd=None, env=None, shell=False): | 105 def Run(args, cwd=None, env=None, shell=False, verbose=True): |
Sam Clegg
2014/05/07 23:25:23
What about having a buildbot_common.verbose variab
binji
2014/05/07 23:51:16
Done.
| |
101 """Start a process with the provided arguments. | 106 """Start a process with the provided arguments. |
102 | 107 |
103 Starts a process in the provided directory given the provided arguments. If | 108 Starts a process in the provided directory given the provided arguments. If |
104 shell is not False, the process is launched via the shell to provide shell | 109 shell is not False, the process is launched via the shell to provide shell |
105 interpretation of the arguments. Shell behavior can differ between platforms | 110 interpretation of the arguments. Shell behavior can differ between platforms |
106 so this should be avoided when not using platform dependent shell scripts.""" | 111 so this should be avoided when not using platform dependent shell scripts.""" |
107 | 112 |
108 # We need to modify the environment to build host on Windows. | 113 # We need to modify the environment to build host on Windows. |
109 if not env and getos.GetPlatform() == 'win': | 114 if not env and getos.GetPlatform() == 'win': |
110 env = GetWindowsEnvironment() | 115 env = GetWindowsEnvironment() |
111 | 116 |
112 print 'Running: ' + ' '.join(args) | 117 Trace(verbose, 'Running: ' + ' '.join(args)) |
113 sys.stdout.flush() | 118 sys.stdout.flush() |
114 sys.stderr.flush() | 119 sys.stderr.flush() |
115 try: | 120 try: |
116 subprocess.check_call(args, cwd=cwd, env=env, shell=shell) | 121 subprocess.check_call(args, cwd=cwd, env=env, shell=shell) |
117 except subprocess.CalledProcessError as e: | 122 except subprocess.CalledProcessError as e: |
118 sys.stdout.flush() | 123 sys.stdout.flush() |
119 sys.stderr.flush() | 124 sys.stderr.flush() |
120 ErrorExit('buildbot_common: %s' % e) | 125 ErrorExit('buildbot_common: %s' % e) |
121 | 126 |
122 sys.stdout.flush() | 127 sys.stdout.flush() |
123 sys.stderr.flush() | 128 sys.stderr.flush() |
124 | 129 |
125 | 130 |
126 def CopyDir(src, dst, excludes=('.svn', '*/.svn')): | 131 def CopyDir(src, dst, excludes=('.svn', '*/.svn'), verbose=True): |
127 """Recursively copy a directory using.""" | 132 """Recursively copy a directory using.""" |
128 args = ['-r', src, dst] | 133 args = ['-r', src, dst] |
129 for exc in excludes: | 134 for exc in excludes: |
130 args.append('--exclude=' + exc) | 135 args.append('--exclude=' + exc) |
131 print 'cp -r %s %s' % (src, dst) | 136 Trace(verbose, 'cp -r %s %s' % (src, dst)) |
132 if os.path.abspath(src) == os.path.abspath(dst): | 137 if os.path.abspath(src) == os.path.abspath(dst): |
133 ErrorExit('ERROR: Copying directory onto itself: ' + src) | 138 ErrorExit('ERROR: Copying directory onto itself: ' + src) |
134 oshelpers.Copy(args) | 139 oshelpers.Copy(args) |
135 | 140 |
136 | 141 |
137 def CopyFile(src, dst): | 142 def CopyFile(src, dst, verbose=True): |
138 print 'cp %s %s' % (src, dst) | 143 Trace(verbose, 'cp %s %s' % (src, dst)) |
139 if os.path.abspath(src) == os.path.abspath(dst): | 144 if os.path.abspath(src) == os.path.abspath(dst): |
140 ErrorExit('ERROR: Copying file onto itself: ' + src) | 145 ErrorExit('ERROR: Copying file onto itself: ' + src) |
141 args = [src, dst] | 146 args = [src, dst] |
142 oshelpers.Copy(args) | 147 oshelpers.Copy(args) |
143 | 148 |
144 | 149 |
145 def RemoveDir(dst): | 150 def RemoveDir(dst, verbose=True): |
146 """Remove the provided path.""" | 151 """Remove the provided path.""" |
147 print 'rm -fr ' + dst | 152 Trace(verbose, 'rm -fr ' + dst) |
148 oshelpers.Remove(['-fr', dst]) | 153 oshelpers.Remove(['-fr', dst]) |
149 | 154 |
150 | 155 |
151 def MakeDir(dst): | 156 def MakeDir(dst, verbose=True): |
152 """Create the path including all parent directories as needed.""" | 157 """Create the path including all parent directories as needed.""" |
153 print 'mkdir -p ' + dst | 158 Trace(verbose, 'mkdir -p ' + dst) |
154 oshelpers.Mkdir(['-p', dst]) | 159 oshelpers.Mkdir(['-p', dst]) |
155 | 160 |
156 | 161 |
157 def Move(src, dst): | 162 def Move(src, dst, verbose=True): |
158 """Move the path src to dst.""" | 163 """Move the path src to dst.""" |
159 print 'mv -f %s %s' % (src, dst) | 164 Trace(verbose, 'mv -f %s %s' % (src, dst)) |
160 oshelpers.Move(['-f', src, dst]) | 165 oshelpers.Move(['-f', src, dst]) |
161 | 166 |
162 | 167 |
163 def RemoveFile(dst): | 168 def RemoveFile(dst, verbose=True): |
164 """Remove the provided file.""" | 169 """Remove the provided file.""" |
165 print 'rm ' + dst | 170 Trace(verbose, 'rm ' + dst) |
166 oshelpers.Remove(['-f', dst]) | 171 oshelpers.Remove(['-f', dst]) |
167 | 172 |
168 | 173 |
169 BOT_GSUTIL = '/b/build/scripts/slave/gsutil' | 174 BOT_GSUTIL = '/b/build/scripts/slave/gsutil' |
170 # On Windows, the current working directory may be on a different drive than | 175 # On Windows, the current working directory may be on a different drive than |
171 # gsutil. | 176 # gsutil. |
172 WIN_BOT_GSUTIL = 'E:' + BOT_GSUTIL | 177 WIN_BOT_GSUTIL = 'E:' + BOT_GSUTIL |
173 LOCAL_GSUTIL = 'gsutil' | 178 LOCAL_GSUTIL = 'gsutil' |
174 | 179 |
175 | 180 |
(...skipping 14 matching lines...) Expand all Loading... | |
190 # Since GetGsutil() might just return 'gsutil' and expect it to be looked | 195 # Since GetGsutil() might just return 'gsutil' and expect it to be looked |
191 # up in the PATH, we must pass shell=True on windows. | 196 # up in the PATH, we must pass shell=True on windows. |
192 # Without shell=True the windows implementation of subprocess.call will not | 197 # Without shell=True the windows implementation of subprocess.call will not |
193 # search the PATH for the executable: http://bugs.python.org/issue8557 | 198 # search the PATH for the executable: http://bugs.python.org/issue8557 |
194 shell = getos.GetPlatform() == 'win' | 199 shell = getos.GetPlatform() == 'win' |
195 | 200 |
196 cmd = [GetGsutil(), 'cp', '-a', 'public-read', filename, full_dst] | 201 cmd = [GetGsutil(), 'cp', '-a', 'public-read', filename, full_dst] |
197 Run(cmd, shell=shell, cwd=cwd) | 202 Run(cmd, shell=shell, cwd=cwd) |
198 url = 'https://storage.googleapis.com/%s/%s' % (bucket_path, filename) | 203 url = 'https://storage.googleapis.com/%s/%s' % (bucket_path, filename) |
199 if step_link: | 204 if step_link: |
200 print '@@@STEP_LINK@download@%s@@@' % url | 205 print >> sys.stderr, '@@@STEP_LINK@download@%s@@@' % url |
Sam Clegg
2014/05/07 23:25:23
I don't like the >> syntax.
How about sys.stderr.
binji
2014/05/07 23:51:16
Done.
| |
201 sys.stdout.flush() | 206 sys.stdout.flush() |
OLD | NEW |