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 | |
627 | 628 |
628 Returns: | 629 Returns: |
629 A tuple consisting of (archive_dir, zip_file_path), where archive_dir | 630 A tuple consisting of (archive_dir, zip_file_path), where archive_dir |
630 is the full path to the newly created archive_name subdirectory. | 631 is the full path to the newly created archive_name subdirectory. |
631 | 632 |
632 Raises: | 633 Raises: |
633 PathNotFound if any of the files in the list is not found, unless | 634 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. | 635 raise_error is False, in which case the error will be ignored. |
635 """ | 636 """ |
636 | 637 |
(...skipping 27 matching lines...) Expand all Loading... | |
664 if os.path.isdir(src_path): | 665 if os.path.isdir(src_path): |
665 if WIN_LINK_FUNC: | 666 if WIN_LINK_FUNC: |
666 WIN_LINK_FUNC(src_path, os.path.join(archive_dir, needed_file)) | 667 WIN_LINK_FUNC(src_path, os.path.join(archive_dir, needed_file)) |
667 else: | 668 else: |
668 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), | 669 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), |
669 symlinks=True) | 670 symlinks=True) |
670 elif dirname != '' and basename != '': | 671 elif dirname != '' and basename != '': |
671 dest_dir = os.path.join(archive_dir, dirname) | 672 dest_dir = os.path.join(archive_dir, dirname) |
672 MaybeMakeDirectory(dest_dir) | 673 MaybeMakeDirectory(dest_dir) |
673 CopyFileToDir(src_path, dest_dir, basename, link_ok=True) | 674 CopyFileToDir(src_path, dest_dir, basename, link_ok=True) |
675 if strip_files and basename in strip_files: | |
676 cmd = ['strip', os.path.join(dest_dir, basename)] | |
stgao
2016/07/12 20:40:40
Will the strip also run on Mac and Windows? If so,
miimnk
2016/07/13 01:12:48
No. Strip will not run on Mac and Windows because
| |
677 RunCommand(cmd) | |
674 else: | 678 else: |
675 CopyFileToDir(src_path, archive_dir, basename, link_ok=True) | 679 CopyFileToDir(src_path, archive_dir, basename, link_ok=True) |
680 if strip_files and basename in strip_files: | |
681 cmd = ['strip', os.path.join(archive_dir, basename)] | |
682 RunCommand(cmd) | |
676 except PathNotFound: | 683 except PathNotFound: |
677 if raise_error: | 684 if raise_error: |
678 raise | 685 raise |
679 end_time = time.clock() | 686 end_time = time.clock() |
680 print 'Took %f seconds to create archive directory.' % (end_time - start_time) | 687 print 'Took %f seconds to create archive directory.' % (end_time - start_time) |
681 | 688 |
682 # Pack the zip file. | 689 # Pack the zip file. |
683 output_file = '%s.zip' % archive_dir | 690 output_file = '%s.zip' % archive_dir |
684 previous_file = '%s_old.zip' % archive_dir | 691 previous_file = '%s_old.zip' % archive_dir |
685 MoveFile(output_file, previous_file) | 692 MoveFile(output_file, previous_file) |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2088 seen = set() | 2095 seen = set() |
2089 for pathcomp in path: | 2096 for pathcomp in path: |
2090 pathcomp = os.path.normcase(pathcomp) | 2097 pathcomp = os.path.normcase(pathcomp) |
2091 if not pathcomp in seen: | 2098 if not pathcomp in seen: |
2092 seen.add(pathcomp) | 2099 seen.add(pathcomp) |
2093 for thefile in files: | 2100 for thefile in files: |
2094 name = os.path.join(pathcomp, thefile) | 2101 name = os.path.join(pathcomp, thefile) |
2095 if _access_check(name, mode): | 2102 if _access_check(name, mode): |
2096 return name | 2103 return name |
2097 return None | 2104 return None |
OLD | NEW |