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

Side by Side Diff: scripts/common/chromium_utils.py

Issue 11379003: Add Windows ASAN bots. (Closed) Base URL: http://git.chromium.org/chromium/tools/build.git@neuter
Patch Set: Rebase, tweaks, lint Created 8 years, 1 month 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
OLDNEW
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 """ Set of basic operations/utilities that are used by the build. """ 5 """ Set of basic operations/utilities that are used by the build. """
6 6
7 import copy 7 import copy
8 import errno 8 import errno
9 import fnmatch 9 import fnmatch
10 import glob 10 import glob
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 if not os.path.isdir(dest_dir): 468 if not os.path.isdir(dest_dir):
469 raise PathNotFound('Unable to find dir %s' % dest_dir) 469 raise PathNotFound('Unable to find dir %s' % dest_dir)
470 src_file = os.path.basename(src_path) 470 src_file = os.path.basename(src_path)
471 if dest_fn: 471 if dest_fn:
472 shutil.copy(src_path, os.path.join(dest_dir, dest_fn)) 472 shutil.copy(src_path, os.path.join(dest_dir, dest_fn))
473 else: 473 else:
474 shutil.copy(src_path, os.path.join(dest_dir, src_file)) 474 shutil.copy(src_path, os.path.join(dest_dir, src_file))
475 475
476 476
477 def MakeZip(output_dir, archive_name, file_list, file_relative_dir, 477 def MakeZip(output_dir, archive_name, file_list, file_relative_dir,
478 raise_error=True, remove_archive_directory=True): 478 raise_error=True, remove_archive_directory=True, replacements=None):
479 """Packs files into a new zip archive. 479 """Packs files into a new zip archive.
480 480
481 Files are first copied into a directory within the output_dir named for 481 Files are first copied into a directory within the output_dir named for
482 the archive_name, which will be created if necessary and emptied if it 482 the archive_name, which will be created if necessary and emptied if it
483 already exists. The files are then then packed using archive names 483 already exists. The files are then then packed using archive names
484 relative to the output_dir. That is, if the zipfile is unpacked in place, 484 relative to the output_dir. That is, if the zipfile is unpacked in place,
485 it will create a directory identical to the new archiev_name directory, in 485 it will create a directory identical to the new archiev_name directory, in
486 the output_dir. The zip file will be named as the archive_name, plus 486 the output_dir. The zip file will be named as the archive_name, plus
487 '.zip'. 487 '.zip'.
488 488
489 Args: 489 Args:
490 output_dir: Absolute path to the directory in which the archive is to 490 output_dir: Absolute path to the directory in which the archive is to
491 be created. 491 be created.
492 archive_dir: Subdirectory of output_dir holding files to be added to 492 archive_dir: Subdirectory of output_dir holding files to be added to
493 the new zipfile. 493 the new zipfile.
494 file_list: List of paths to files or subdirectories, relative to the 494 file_list: List of paths to files or subdirectories, relative to the
495 file_relative_dir. 495 file_relative_dir.
496 file_relative_dir: Absolute path to the directory containing the files 496 file_relative_dir: Absolute path to the directory containing the files
497 and subdirectories in the file_list. 497 and subdirectories in the file_list.
498 raise_error: Whether to raise a PathNotFound error if one of the files in 498 raise_error: Whether to raise a PathNotFound error if one of the files in
499 the list is not found. 499 the list is not found.
500 remove_archive_directory: Whether to remove the archive staging directory 500 remove_archive_directory: Whether to remove the archive staging directory
501 before copying files over to it. 501 before copying files over to it.
502 replacements: A list of fun(path) -> path functions. For each file
503 to add, transform the path with each function in replacements in order,
504 and read data from the resulting file instead. i.e. foo.exe could actually
505 contain data from foo.asan.exe.
502 506
503 Returns: 507 Returns:
504 A tuple consisting of (archive_dir, zip_file_path), where archive_dir 508 A tuple consisting of (archive_dir, zip_file_path), where archive_dir
505 is the full path to the newly created archive_name subdirectory. 509 is the full path to the newly created archive_name subdirectory.
506 510
507 Raises: 511 Raises:
508 PathNotFound if any of the files in the list is not found, unless 512 PathNotFound if any of the files in the list is not found, unless
509 raise_error is False, in which case the error will be ignored. 513 raise_error is False, in which case the error will be ignored.
510 """ 514 """
511 515
512 # Collect files into the archive directory. 516 # Collect files into the archive directory.
513 archive_dir = os.path.join(output_dir, archive_name) 517 archive_dir = os.path.join(output_dir, archive_name)
514 if remove_archive_directory and os.path.exists(archive_dir): 518 if remove_archive_directory and os.path.exists(archive_dir):
515 # Move it even if it's not a directory as expected. This can happen with 519 # Move it even if it's not a directory as expected. This can happen with
516 # FILES.cfg archive creation where we create an archive staging directory 520 # FILES.cfg archive creation where we create an archive staging directory
517 # that is the same name as the ultimate archive name. 521 # that is the same name as the ultimate archive name.
518 if not os.path.isdir(archive_dir): 522 if not os.path.isdir(archive_dir):
519 print 'Moving old "%s" file to create same name directory.' % archive_dir 523 print 'Moving old "%s" file to create same name directory.' % archive_dir
520 previous_archive_file = '%s.old' % archive_dir 524 previous_archive_file = '%s.old' % archive_dir
521 MoveFile(archive_dir, previous_archive_file) 525 MoveFile(archive_dir, previous_archive_file)
522 else: 526 else:
523 RemoveDirectory(archive_dir) 527 RemoveDirectory(archive_dir)
524 MaybeMakeDirectory(archive_dir) 528 MaybeMakeDirectory(archive_dir)
525 for needed_file in file_list: 529 for needed_file in file_list:
526 needed_file = needed_file.rstrip() 530 needed_file = needed_file.rstrip()
527 # These paths are relative to the file_relative_dir. We need to copy 531 # These paths are relative to the file_relative_dir. We need to copy
528 # them over maintaining the relative directories, where applicable. 532 # them over maintaining the relative directories, where applicable.
529 src_path = os.path.join(file_relative_dir, needed_file) 533 src_path = os.path.join(file_relative_dir, needed_file)
534 new_src_path = src_path
535 for func in (replacements or []):
536 new_src_path = func(src_path)
537 if new_src_path is None:
538 print 'Skipping %s' % src_path
539 continue
540 if new_src_path != src_path:
541 print 'Replacing contents of %s with %s' % (src_path, new_src_path)
542 src_path = new_src_path
530 dirname, basename = os.path.split(needed_file) 543 dirname, basename = os.path.split(needed_file)
531 try: 544 try:
532 if os.path.isdir(src_path): 545 if os.path.isdir(src_path):
533 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), 546 shutil.copytree(src_path, os.path.join(archive_dir, needed_file),
534 symlinks=True) 547 symlinks=True)
535 elif dirname != '' and basename != '': 548 elif dirname != '' and basename != '':
536 dest_dir = os.path.join(archive_dir, dirname) 549 dest_dir = os.path.join(archive_dir, dirname)
537 MaybeMakeDirectory(dest_dir) 550 MaybeMakeDirectory(dest_dir)
538 CopyFileToDir(src_path, dest_dir) 551 CopyFileToDir(src_path, dest_dir, basename)
539 else: 552 else:
540 CopyFileToDir(src_path, archive_dir) 553 CopyFileToDir(src_path, archive_dir, basename)
541 except PathNotFound: 554 except PathNotFound:
542 if raise_error: 555 if raise_error:
543 raise 556 raise
544 557
545 # Pack the zip file. 558 # Pack the zip file.
546 output_file = '%s.zip' % archive_dir 559 output_file = '%s.zip' % archive_dir
547 previous_file = '%s_old.zip' % archive_dir 560 previous_file = '%s_old.zip' % archive_dir
548 MoveFile(output_file, previous_file) 561 MoveFile(output_file, previous_file)
549 # On Windows we use the python zip module; on Linux and Mac, we use the zip 562 # On Windows we use the python zip module; on Linux and Mac, we use the zip
550 # command as it will handle links and file bits (executable). Which is much 563 # command as it will handle links and file bits (executable). Which is much
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 conn.close() 1130 conn.close()
1118 1131
1119 return rev, 'ok' 1132 return rev, 'ok'
1120 1133
1121 1134
1122 def AbsoluteCanonicalPath(*path): 1135 def AbsoluteCanonicalPath(*path):
1123 """Return the most canonical path Python can provide.""" 1136 """Return the most canonical path Python can provide."""
1124 1137
1125 file_path = os.path.join(*path) 1138 file_path = os.path.join(*path)
1126 return os.path.realpath(os.path.abspath(os.path.expanduser(file_path))) 1139 return os.path.realpath(os.path.abspath(os.path.expanduser(file_path)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698