Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: tools/utils.py

Issue 22393002: First CL for removing our dependency on the checked-in binary for building (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/print_version.py ('k') | utils/compiler/create_snapshot.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 # This file contains a set of utilities functions used by other Python-based 5 # This file contains a set of utilities functions used by other Python-based
6 # scripts. 6 # scripts.
7 7
8 import commands 8 import commands
9 import os 9 import os
10 import platform 10 import platform
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 'macos': os.path.join('xcodebuild'), 198 'macos': os.path.join('xcodebuild'),
199 } 199 }
200 200
201 def GetBuildbotGSUtilPath(): 201 def GetBuildbotGSUtilPath():
202 gsutil = '/b/build/scripts/slave/gsutil' 202 gsutil = '/b/build/scripts/slave/gsutil'
203 if platform.system() == 'Windows': 203 if platform.system() == 'Windows':
204 gsutil = 'e:\\\\b\\build\\scripts\\slave\\gsutil' 204 gsutil = 'e:\\\\b\\build\\scripts\\slave\\gsutil'
205 return gsutil 205 return gsutil
206 206
207 def GetBuildMode(mode): 207 def GetBuildMode(mode):
208 global BUILD_MODES
209 return BUILD_MODES[mode] 208 return BUILD_MODES[mode]
210 209
211 210
212 def GetBuildConf(mode, arch): 211 def GetBuildConf(mode, arch):
213 return '%s%s' % (GetBuildMode(mode), arch.upper()) 212 return '%s%s' % (GetBuildMode(mode), arch.upper())
214 213
215 ARCH_GUESS = GuessArchitecture() 214 ARCH_GUESS = GuessArchitecture()
216 BASE_DIR = os.path.abspath(os.path.join(os.curdir, '..')) 215 BASE_DIR = os.path.abspath(os.path.join(os.curdir, '..'))
216 DART_DIR = os.path.abspath(os.path.join(__file__, '..', '..'))
217 217
218 218
219 def GetBuildDir(host_os, target_os): 219 def GetBuildDir(host_os, target_os):
220 global BUILD_ROOT
221 build_dir = BUILD_ROOT[host_os] 220 build_dir = BUILD_ROOT[host_os]
222 if target_os and target_os != host_os: 221 if target_os and target_os != host_os:
223 build_dir = os.path.join(build_dir, target_os) 222 build_dir = os.path.join(build_dir, target_os)
224 return build_dir 223 return build_dir
225 224
226 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None): 225 def GetBuildRoot(host_os, mode=None, arch=None, target_os=None):
227 build_root = GetBuildDir(host_os, target_os) 226 build_root = GetBuildDir(host_os, target_os)
228 if mode: 227 if mode:
229 build_root = os.path.join(build_root, GetBuildConf(mode, arch)) 228 build_root = os.path.join(build_root, GetBuildConf(mode, arch))
230 return build_root 229 return build_root
231 230
232 def GetBaseDir(): 231 def GetBaseDir():
233 return BASE_DIR 232 return BASE_DIR
234 233
235 def GetVersion(): 234 def GetVersion():
236 dartbin = DartBinary() 235 version_tuple = ReadVersionFile()
237 version_script = VersionScript() 236 if not version_tuple:
238 p = subprocess.Popen([dartbin, version_script], stdout = subprocess.PIPE, 237 return None
239 stderr = subprocess.STDOUT, shell=IsWindows()) 238
240 output, not_used = p.communicate() 239 (major, minor, build, patch) = version_tuple
241 return output.strip() 240 revision = GetSVNRevision()
241 user = GetUserName()
242 # We don't add username to release builds (or any builds on the bots)
243 if user == 'chrome-bot':
244 user = ''
245
246 user_string = ''
247 revision_string = ''
248 if user:
249 user_string = '_%s' % user
250 if revision:
251 revision_string = '_r%s' % revision
252
253 return ("%s.%s.%s.%s%s%s" %
254 (major, minor, build, patch, revision_string, user_string))
255
256 def GetUserName():
257 key = 'USER'
258 if sys.platform == 'win32':
259 key = 'USERNAME'
260 return os.environ.get(key, '')
261
262 def ReadVersionFile():
263 version_file = os.path.join(DART_DIR, 'tools', 'VERSION')
264 try:
265 fd = open(version_file)
266 content = fd.read()
267 fd.close()
268 except:
269 print "Warning: Couldn't read VERSION file (%s)" % version_file
270 return None
271 major_match = re.search('MAJOR (\d+)', content)
272 minor_match = re.search('MINOR (\d+)', content)
273 build_match = re.search('BUILD (\d+)', content)
274 patch_match = re.search('PATCH (\d+)', content)
275 if major_match and minor_match and build_match and patch_match:
276 return (major_match.group(1), minor_match.group(1), build_match.group(1),
277 patch_match.group(1))
278 else:
279 print "Warning: VERSION file (%s) has wrong format" % version_file
280 return None
242 281
243 def GetSVNRevision(): 282 def GetSVNRevision():
283 # FIXME(kustermann): Make this work for newer SVN versions as well (where
284 # we've got only one '.svn' directory)
244 custom_env = dict(os.environ) 285 custom_env = dict(os.environ)
245 custom_env['LC_MESSAGES'] = 'en_GB' 286 custom_env['LC_MESSAGES'] = 'en_GB'
246 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE, 287 p = subprocess.Popen(['svn', 'info'], stdout = subprocess.PIPE,
247 stderr = subprocess.STDOUT, shell=IsWindows(), 288 stderr = subprocess.STDOUT, shell=IsWindows(),
248 env = custom_env) 289 env = custom_env,
249 output, not_used = p.communicate() 290 cwd = DART_DIR)
291 output, _ = p.communicate()
250 revision = ParseSvnInfoOutput(output) 292 revision = ParseSvnInfoOutput(output)
251 if revision: 293 if revision:
252 return revision 294 return revision
253 295
254 # maybe the builder is using git-svn, try that 296 # maybe the builder is using git-svn, try that
255 p = subprocess.Popen(['git', 'svn', 'info'], stdout = subprocess.PIPE, 297 p = subprocess.Popen(['git', 'svn', 'info'], stdout = subprocess.PIPE,
256 stderr = subprocess.STDOUT, shell=IsWindows()) 298 stderr = subprocess.STDOUT, shell=IsWindows(), cwd = DART_DIR)
257 output, not_used = p.communicate() 299 output, _ = p.communicate()
258 revision = ParseSvnInfoOutput(output) 300 revision = ParseSvnInfoOutput(output)
259 if revision: 301 if revision:
260 return revision 302 return revision
261 303
262 return None 304 return None
263 305
264 def ParseSvnInfoOutput(output): 306 def ParseSvnInfoOutput(output):
265 for line in output.split('\n'): 307 revision_match = re.search('Last Changed Rev: (\d+)', output)
266 if 'Revision' in line: 308 if revision_match:
267 return (line.strip().split())[1] 309 return revision_match.group(1)
268 return None 310 return None
269 311
270 def RewritePathSeparator(path, workspace): 312 def RewritePathSeparator(path, workspace):
271 # Paths in test files are always specified using '/' 313 # Paths in test files are always specified using '/'
272 # as the path separator. Replace with the actual 314 # as the path separator. Replace with the actual
273 # path separator before use. 315 # path separator before use.
274 if ('/' in path): 316 if ('/' in path):
275 split_path = path.split('/') 317 split_path = path.split('/')
276 path = os.sep.join(split_path) 318 path = os.sep.join(split_path)
277 path = os.path.join(workspace, path) 319 path = os.path.join(workspace, path)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if IsCrashExitCode(exit_code): 424 if IsCrashExitCode(exit_code):
383 sys.stderr.write('Command: %s\nCRASHED with exit code %d (0x%x)\n' % ( 425 sys.stderr.write('Command: %s\nCRASHED with exit code %d (0x%x)\n' % (
384 ' '.join(command), exit_code, exit_code & 0xffffffff)) 426 ' '.join(command), exit_code, exit_code & 0xffffffff))
385 427
386 428
387 def Touch(name): 429 def Touch(name):
388 with file(name, 'a'): 430 with file(name, 'a'):
389 os.utime(name, None) 431 os.utime(name, None)
390 432
391 433
392 def VersionScript():
393 tools_dir = os.path.dirname(os.path.realpath(__file__))
394 return os.path.join(tools_dir, 'version.dart')
395
396
397 def DartBinary(): 434 def DartBinary():
398 tools_dir = os.path.dirname(os.path.realpath(__file__)) 435 tools_dir = os.path.dirname(os.path.realpath(__file__))
399 dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin') 436 dart_binary_prefix = os.path.join(tools_dir, 'testing', 'bin')
400 if IsWindows(): 437 if IsWindows():
401 return os.path.join(dart_binary_prefix, 'windows', 'dart.exe') 438 return os.path.join(dart_binary_prefix, 'windows', 'dart.exe')
402 else: 439 else:
403 return os.path.join(dart_binary_prefix, GuessOS(), 'dart') 440 return os.path.join(dart_binary_prefix, GuessOS(), 'dart')
404 441
405 442
406 def DartSdkBinary(): 443 def DartSdkBinary():
(...skipping 10 matching lines...) Expand all
417 self._temp_dir = tempfile.mkdtemp(self._prefix) 454 self._temp_dir = tempfile.mkdtemp(self._prefix)
418 return self._temp_dir 455 return self._temp_dir
419 456
420 def __exit__(self, *_): 457 def __exit__(self, *_):
421 shutil.rmtree(self._temp_dir, ignore_errors=True) 458 shutil.rmtree(self._temp_dir, ignore_errors=True)
422 459
423 460
424 if __name__ == "__main__": 461 if __name__ == "__main__":
425 import sys 462 import sys
426 Main(sys.argv) 463 Main(sys.argv)
OLDNEW
« no previous file with comments | « tools/print_version.py ('k') | utils/compiler/create_snapshot.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698