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 """ 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 from contextlib import contextmanager | 7 from contextlib import contextmanager |
8 import ast | 8 import ast |
9 import base64 | 9 import base64 |
10 import cStringIO | 10 import cStringIO |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 # try to make the copy faster on Windows. http://crbug.com/418702. | 593 # try to make the copy faster on Windows. http://crbug.com/418702. |
594 if link_ok and WIN_LINK_FUNC: | 594 if link_ok and WIN_LINK_FUNC: |
595 WIN_LINK_FUNC(src_path, os.path.join(dest_dir, dest_fn)) | 595 WIN_LINK_FUNC(src_path, os.path.join(dest_dir, dest_fn)) |
596 else: | 596 else: |
597 shutil.copy2(src_path, os.path.join(dest_dir, dest_fn)) | 597 shutil.copy2(src_path, os.path.join(dest_dir, dest_fn)) |
598 else: | 598 else: |
599 shutil.copy2(src_path, os.path.join(dest_dir, src_file)) | 599 shutil.copy2(src_path, os.path.join(dest_dir, src_file)) |
600 | 600 |
601 | 601 |
602 def MakeZip(output_dir, archive_name, file_list, file_relative_dir, | 602 def MakeZip(output_dir, archive_name, file_list, file_relative_dir, |
603 raise_error=True, remove_archive_directory=True): | 603 raise_error=True, remove_archive_directory=True, strip_files=None): |
604 """Packs files into a new zip archive. | 604 """Packs files into a new zip archive. |
605 | 605 |
606 Files are first copied into a directory within the output_dir named for | 606 Files are first copied into a directory within the output_dir named for |
607 the archive_name, which will be created if necessary and emptied if it | 607 the archive_name, which will be created if necessary and emptied if it |
608 already exists. The files are then then packed using archive names | 608 already exists. The files are then then packed using archive names |
609 relative to the output_dir. That is, if the zipfile is unpacked in place, | 609 relative to the output_dir. That is, if the zipfile is unpacked in place, |
610 it will create a directory identical to the new archive_name directory, in | 610 it will create a directory identical to the new archive_name directory, in |
611 the output_dir. The zip file will be named as the archive_name, plus | 611 the output_dir. The zip file will be named as the archive_name, plus |
612 '.zip'. | 612 '.zip'. |
613 | 613 |
614 Args: | 614 Args: |
615 output_dir: Absolute path to the directory in which the archive is to | 615 output_dir: Absolute path to the directory in which the archive is to |
616 be created. | 616 be created. |
617 archive_dir: Subdirectory of output_dir holding files to be added to | 617 archive_dir: Subdirectory of output_dir holding files to be added to |
618 the new zipfile. | 618 the new zipfile. |
619 file_list: List of paths to files or subdirectories, relative to the | 619 file_list: List of paths to files or subdirectories, relative to the |
620 file_relative_dir. | 620 file_relative_dir. |
621 file_relative_dir: Absolute path to the directory containing the files | 621 file_relative_dir: Absolute path to the directory containing the files |
622 and subdirectories in the file_list. | 622 and subdirectories in the file_list. |
623 raise_error: Whether to raise a PathNotFound error if one of the files in | 623 raise_error: Whether to raise a PathNotFound error if one of the files in |
624 the list is not found. | 624 the list is not found. |
625 remove_archive_directory: Whether to remove the archive staging directory | 625 remove_archive_directory: Whether to remove the archive staging directory |
626 before copying files over to it. | 626 before copying files over to it. |
| 627 strip_files: List of executable files to strip symbols when zipping. The |
| 628 option currently does not work in Windows. |
627 | 629 |
628 Returns: | 630 Returns: |
629 A tuple consisting of (archive_dir, zip_file_path), where archive_dir | 631 A tuple consisting of (archive_dir, zip_file_path), where archive_dir |
630 is the full path to the newly created archive_name subdirectory. | 632 is the full path to the newly created archive_name subdirectory. |
631 | 633 |
632 Raises: | 634 Raises: |
633 PathNotFound if any of the files in the list is not found, unless | 635 PathNotFound if any of the files in the list is not found, unless |
634 raise_error is False, in which case the error will be ignored. | 636 raise_error is False, in which case the error will be ignored. |
635 """ | 637 """ |
636 | 638 if not strip_files: |
| 639 strip_files = [] |
637 start_time = time.clock() | 640 start_time = time.clock() |
638 # Collect files into the archive directory. | 641 # Collect files into the archive directory. |
639 archive_dir = os.path.join(output_dir, archive_name) | 642 archive_dir = os.path.join(output_dir, archive_name) |
640 print 'output_dir: %s, archive_name: %s' % (output_dir, archive_name) | 643 print 'output_dir: %s, archive_name: %s' % (output_dir, archive_name) |
641 print 'archive_dir: %s, remove_archive_directory: %s, exists: %s' % ( | 644 print 'archive_dir: %s, remove_archive_directory: %s, exists: %s' % ( |
642 archive_dir, remove_archive_directory, os.path.exists(archive_dir)) | 645 archive_dir, remove_archive_directory, os.path.exists(archive_dir)) |
643 if remove_archive_directory and os.path.exists(archive_dir): | 646 if remove_archive_directory and os.path.exists(archive_dir): |
644 # Move it even if it's not a directory as expected. This can happen with | 647 # Move it even if it's not a directory as expected. This can happen with |
645 # FILES.cfg archive creation where we create an archive staging directory | 648 # FILES.cfg archive creation where we create an archive staging directory |
646 # that is the same name as the ultimate archive name. | 649 # that is the same name as the ultimate archive name. |
(...skipping 17 matching lines...) Expand all Loading... |
664 if os.path.isdir(src_path): | 667 if os.path.isdir(src_path): |
665 if WIN_LINK_FUNC: | 668 if WIN_LINK_FUNC: |
666 WIN_LINK_FUNC(src_path, os.path.join(archive_dir, needed_file)) | 669 WIN_LINK_FUNC(src_path, os.path.join(archive_dir, needed_file)) |
667 else: | 670 else: |
668 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), | 671 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), |
669 symlinks=True) | 672 symlinks=True) |
670 elif dirname != '' and basename != '': | 673 elif dirname != '' and basename != '': |
671 dest_dir = os.path.join(archive_dir, dirname) | 674 dest_dir = os.path.join(archive_dir, dirname) |
672 MaybeMakeDirectory(dest_dir) | 675 MaybeMakeDirectory(dest_dir) |
673 CopyFileToDir(src_path, dest_dir, basename, link_ok=True) | 676 CopyFileToDir(src_path, dest_dir, basename, link_ok=True) |
| 677 if not IsWindows() and basename in strip_files: |
| 678 cmd = ['strip', os.path.join(dest_dir, basename)] |
| 679 RunCommand(cmd) |
674 else: | 680 else: |
675 CopyFileToDir(src_path, archive_dir, basename, link_ok=True) | 681 CopyFileToDir(src_path, archive_dir, basename, link_ok=True) |
| 682 if not IsWindows() and basename in strip_files: |
| 683 cmd = ['strip', os.path.join(archive_dir, basename)] |
| 684 RunCommand(cmd) |
676 except PathNotFound: | 685 except PathNotFound: |
677 if raise_error: | 686 if raise_error: |
678 raise | 687 raise |
679 end_time = time.clock() | 688 end_time = time.clock() |
680 print 'Took %f seconds to create archive directory.' % (end_time - start_time) | 689 print 'Took %f seconds to create archive directory.' % (end_time - start_time) |
681 | 690 |
682 # Pack the zip file. | 691 # Pack the zip file. |
683 output_file = '%s.zip' % archive_dir | 692 output_file = '%s.zip' % archive_dir |
684 previous_file = '%s_old.zip' % archive_dir | 693 previous_file = '%s_old.zip' % archive_dir |
685 MoveFile(output_file, previous_file) | 694 MoveFile(output_file, previous_file) |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 seen = set() | 2102 seen = set() |
2094 for pathcomp in path: | 2103 for pathcomp in path: |
2095 pathcomp = os.path.normcase(pathcomp) | 2104 pathcomp = os.path.normcase(pathcomp) |
2096 if not pathcomp in seen: | 2105 if not pathcomp in seen: |
2097 seen.add(pathcomp) | 2106 seen.add(pathcomp) |
2098 for thefile in files: | 2107 for thefile in files: |
2099 name = os.path.join(pathcomp, thefile) | 2108 name = os.path.join(pathcomp, thefile) |
2100 if _access_check(name, mode): | 2109 if _access_check(name, mode): |
2101 return name | 2110 return name |
2102 return None | 2111 return None |
OLD | NEW |