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

Side by Side Diff: editor/build/build.py

Issue 19523003: Use a utils.TempDir() decorator for temporary files, to make sure we clean up even in case of excep… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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 | « no previous file | tools/bots/editor.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 import glob 7 import glob
8 import optparse 8 import optparse
9 import os 9 import os
10 import re 10 import re
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 os.chdir(buildpath) 238 os.chdir(buildpath)
239 ant_property_file = None 239 ant_property_file = None
240 sdk_zip = None 240 sdk_zip = None
241 241
242 try: 242 try:
243 ant_property_file = tempfile.NamedTemporaryFile(suffix='.property', 243 ant_property_file = tempfile.NamedTemporaryFile(suffix='.property',
244 prefix='AntProperties', 244 prefix='AntProperties',
245 delete=False) 245 delete=False)
246 ant_property_file.close() 246 ant_property_file.close()
247 extra_artifacts = tempfile.mkdtemp(prefix='ExtraArtifacts')
248 ant = AntWrapper(ant_property_file.name, os.path.join(antpath, 'bin'), 247 ant = AntWrapper(ant_property_file.name, os.path.join(antpath, 'bin'),
249 bzip2libpath) 248 bzip2libpath)
250 249
251 ant.RunAnt(os.getcwd(), '', '', '', '', 250 ant.RunAnt(os.getcwd(), '', '', '', '',
252 '', '', buildos, ['-diagnostics']) 251 '', '', buildos, ['-diagnostics'])
253 252
254 parser = BuildOptions() 253 parser = BuildOptions()
255 (options, args) = parser.parse_args() 254 (options, args) = parser.parse_args()
256 # Determine which targets to build. By default we build the "all" target. 255 # Determine which targets to build. By default we build the "all" target.
257 if args: 256 if args:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 except: 368 except:
370 BuildStepFailure() 369 BuildStepFailure()
371 370
372 StartBuildStep(builder_name) 371 StartBuildStep(builder_name)
373 372
374 if PLUGINS_BUILD: 373 if PLUGINS_BUILD:
375 status = BuildUpdateSite(ant, revision, builder_name, buildroot, buildout, 374 status = BuildUpdateSite(ant, revision, builder_name, buildroot, buildout,
376 editorpath, buildos) 375 editorpath, buildos)
377 return status 376 return status
378 377
379 #tell the ant script where to write the sdk zip file so it can 378 with utils.TempDir('ExtraArtifacts') as extra_artifacts:
380 #be expanded later 379 #tell the ant script where to write the sdk zip file so it can
381 status = ant.RunAnt('.', 'build_rcp.xml', revision, builder_name, 380 #be expanded later
382 buildroot, buildout, editorpath, buildos, 381 status = ant.RunAnt('.', 'build_rcp.xml', revision, builder_name,
383 sdk_zip=sdk_zip, 382 buildroot, buildout, editorpath, buildos,
384 running_on_bot=running_on_buildbot, 383 sdk_zip=sdk_zip,
385 extra_artifacts=extra_artifacts) 384 running_on_bot=running_on_buildbot,
386 #the ant script writes a property file in a known location so 385 extra_artifacts=extra_artifacts)
387 #we can read it. 386 #the ant script writes a property file in a known location so
388 properties = ReadPropertyFile(buildos, ant_property_file.name) 387 #we can read it.
388 properties = ReadPropertyFile(buildos, ant_property_file.name)
389 389
390 if not properties: 390 if not properties:
391 raise Exception('no data was found in file {%s}' % ant_property_file.name) 391 raise Exception('no data was found in file {%s}'
392 if status: 392 % ant_property_file.name)
393 if properties['build.runtime']: 393 if status:
394 PrintErrorLog(properties['build.runtime']) 394 if properties['build.runtime']:
395 return status 395 PrintErrorLog(properties['build.runtime'])
396 return status
396 397
397 #For the dart-editor build, return at this point. 398 #For the dart-editor build, return at this point.
398 #We don't need to install the sdk+dartium, run tests, or copy to google 399 #We don't need to install the sdk+dartium, run tests, or copy to google
399 #storage. 400 #storage.
400 if not buildos: 401 if not buildos:
401 print 'skipping sdk and dartium steps for dart-editor build' 402 print 'skipping sdk and dartium steps for dart-editor build'
403 return 0
404
405 #This is an override for local testing
406 force_run_install = os.environ.get('FORCE_RUN_INSTALL')
407
408 if force_run_install or (not PLUGINS_BUILD):
409 InstallSdk(buildroot, buildout, buildos, buildout)
410 InstallDartium(buildroot, buildout, buildos, gsu)
411
412 if status:
413 return status
414
415 if not build_skip_tests:
416 RunEditorTests(buildout, buildos)
417
418 if buildos:
419 StartBuildStep('upload_artifacts')
420
421 _InstallArtifacts(buildout, buildos, extra_artifacts)
422
423 # dart-editor-linux.gtk.x86.zip --> darteditor-linux-32.zip
424 RenameRcpZipFiles(buildout)
425
426 PostProcessEditorBuilds(buildout)
427
428 if running_on_buildbot:
429 version_file = _FindVersionFile(buildout)
430 if version_file:
431 UploadFile(version_file, False)
432
433 found_zips = _FindRcpZipFiles(buildout)
434 for zipfile in found_zips:
435 UploadFile(zipfile)
436
402 return 0 437 return 0
403
404 #This is an override for local testing
405 force_run_install = os.environ.get('FORCE_RUN_INSTALL')
406
407 if force_run_install or (not PLUGINS_BUILD):
408 InstallSdk(buildroot, buildout, buildos, buildout)
409 InstallDartium(buildroot, buildout, buildos, gsu)
410
411 if status:
412 return status
413
414 if not build_skip_tests:
415 RunEditorTests(buildout, buildos)
416
417 if buildos:
418 StartBuildStep('upload_artifacts')
419
420 _InstallArtifacts(buildout, buildos, extra_artifacts)
421
422 # dart-editor-linux.gtk.x86.zip --> darteditor-linux-32.zip
423 RenameRcpZipFiles(buildout)
424
425 PostProcessEditorBuilds(buildout)
426
427 if running_on_buildbot:
428 version_file = _FindVersionFile(buildout)
429 if version_file:
430 UploadFile(version_file, False)
431
432 found_zips = _FindRcpZipFiles(buildout)
433 for zipfile in found_zips:
434 UploadFile(zipfile)
435
436 return 0
437 finally: 438 finally:
438 if ant_property_file is not None: 439 if ant_property_file is not None:
439 print 'cleaning up temp file {0}'.format(ant_property_file.name) 440 print 'cleaning up temp file {0}'.format(ant_property_file.name)
440 os.remove(ant_property_file.name) 441 os.remove(ant_property_file.name)
441 if extra_artifacts:
442 print 'cleaning up temp dir {0}'.format(extra_artifacts)
443 shutil.rmtree(extra_artifacts)
444 print 'cleaning up {0}'.format(buildroot) 442 print 'cleaning up {0}'.format(buildroot)
445 shutil.rmtree(buildroot, True) 443 shutil.rmtree(buildroot, True)
446 print 'Build Done' 444 print 'Build Done'
447 445
448 446
449 def ReadPropertyFile(buildos, property_file): 447 def ReadPropertyFile(buildos, property_file):
450 """Read a property file and return a dictionary of key/value pairs. 448 """Read a property file and return a dictionary of key/value pairs.
451 449
452 Args: 450 Args:
453 buildos: the os the build is running under 451 buildos: the os the build is running under
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 f.write('%s *%s' % (checksum, os.path.basename(filename))) 761 f.write('%s *%s' % (checksum, os.path.basename(filename)))
764 762
765 return checksum_filename 763 return checksum_filename
766 764
767 765
768 def RunEditorTests(buildout, buildos): 766 def RunEditorTests(buildout, buildos):
769 StartBuildStep('run_tests') 767 StartBuildStep('run_tests')
770 768
771 for editorArchive in _FindRcpZipFiles(buildout): 769 for editorArchive in _FindRcpZipFiles(buildout):
772 if (editorArchive.endswith('_64.zip')): 770 if (editorArchive.endswith('_64.zip')):
773 print 'Running tests for %s...' % editorArchive 771 with utils.TempDir('editor_') as tempDir:
774 tempDir = tempfile.mkdtemp(prefix='editor_') 772 print 'Running tests for %s...' % editorArchive
775
776 zipper = ziputils.ZipUtil(join(buildout, editorArchive), buildos)
777 zipper.UnZip(tempDir)
778 773
779 editorExecutable = GetEditorExecutable(join(tempDir, 'dart')) 774 zipper = ziputils.ZipUtil(join(buildout, editorArchive), buildos)
780 args = [editorExecutable, '-consoleLog', '--test', '--auto-exit', 775 zipper.UnZip(tempDir)
781 '-data', join(tempDir, 'workspace')]
782 if sys.platform == 'linux':
783 args = ['xvfb-run', '-a'] + args
784 if (subprocess.call(args, shell=IsWindows())):
785 BuildStepFailure()
786 776
787 shutil.rmtree(tempDir, True) 777 editorExecutable = GetEditorExecutable(join(tempDir, 'dart'))
778 args = [editorExecutable, '-consoleLog', '--test', '--auto-exit',
779 '-data', join(tempDir, 'workspace')]
780 if sys.platform == 'linux':
781 args = ['xvfb-run', '-a'] + args
782 if (subprocess.call(args, shell=IsWindows())):
783 BuildStepFailure()
788 784
789 785
790 def GetEditorExecutable(editorDir): 786 def GetEditorExecutable(editorDir):
791 if sys.platform == 'darwin': 787 if sys.platform == 'darwin':
792 executable = join('DartEditor.app', 'Contents', 'MacOS', 'DartEditor') 788 executable = join('DartEditor.app', 'Contents', 'MacOS', 'DartEditor')
793 elif sys.platform == 'win32': 789 elif sys.platform == 'win32':
794 executable = 'DartEditor.exe' 790 executable = 'DartEditor.exe'
795 else: 791 else:
796 executable = 'DartEditor' 792 executable = 'DartEditor'
797 return join(editorDir, executable) 793 return join(editorDir, executable)
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 """delete the given file - do not re-throw any exceptions that occur""" 1074 """delete the given file - do not re-throw any exceptions that occur"""
1079 if os.path.exists(f): 1075 if os.path.exists(f):
1080 try: 1076 try:
1081 os.remove(f) 1077 os.remove(f)
1082 except OSError: 1078 except OSError:
1083 print 'error deleting %s' % f 1079 print 'error deleting %s' % f
1084 1080
1085 1081
1086 if __name__ == '__main__': 1082 if __name__ == '__main__':
1087 sys.exit(main()) 1083 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools/bots/editor.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698