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 = []): |
dtu
2016/08/05 21:06:18
There's a tricky Python caveat with lists (or any
miimnk
2016/08/08 22:41:23
Done.
| |
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 |
(...skipping 27 matching lines...) Expand all Loading... | |
664 if os.path.isdir(src_path): | 666 if os.path.isdir(src_path): |
665 if WIN_LINK_FUNC: | 667 if WIN_LINK_FUNC: |
666 WIN_LINK_FUNC(src_path, os.path.join(archive_dir, needed_file)) | 668 WIN_LINK_FUNC(src_path, os.path.join(archive_dir, needed_file)) |
667 else: | 669 else: |
668 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), | 670 shutil.copytree(src_path, os.path.join(archive_dir, needed_file), |
669 symlinks=True) | 671 symlinks=True) |
670 elif dirname != '' and basename != '': | 672 elif dirname != '' and basename != '': |
671 dest_dir = os.path.join(archive_dir, dirname) | 673 dest_dir = os.path.join(archive_dir, dirname) |
672 MaybeMakeDirectory(dest_dir) | 674 MaybeMakeDirectory(dest_dir) |
673 CopyFileToDir(src_path, dest_dir, basename, link_ok=True) | 675 CopyFileToDir(src_path, dest_dir, basename, link_ok=True) |
676 if not IsWindows() and basename in strip_files: | |
677 cmd = ['strip', os.path.join(dest_dir, basename)] | |
678 RunCommand(cmd) | |
674 else: | 679 else: |
675 CopyFileToDir(src_path, archive_dir, basename, link_ok=True) | 680 CopyFileToDir(src_path, archive_dir, basename, link_ok=True) |
681 if not IsWindows() and basename in strip_files: | |
682 cmd = ['strip', os.path.join(archive_dir, basename)] | |
683 RunCommand(cmd) | |
676 except PathNotFound: | 684 except PathNotFound: |
677 if raise_error: | 685 if raise_error: |
678 raise | 686 raise |
679 end_time = time.clock() | 687 end_time = time.clock() |
680 print 'Took %f seconds to create archive directory.' % (end_time - start_time) | 688 print 'Took %f seconds to create archive directory.' % (end_time - start_time) |
681 | 689 |
682 # Pack the zip file. | 690 # Pack the zip file. |
683 output_file = '%s.zip' % archive_dir | 691 output_file = '%s.zip' % archive_dir |
684 previous_file = '%s_old.zip' % archive_dir | 692 previous_file = '%s_old.zip' % archive_dir |
685 MoveFile(output_file, previous_file) | 693 MoveFile(output_file, previous_file) |
(...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2032 return False | 2040 return False |
2033 # Matches e.g. "cl_x86 = path/to/clang-cl.exe" | 2041 # Matches e.g. "cl_x86 = path/to/clang-cl.exe" |
2034 clang_cl_re = re.compile( | 2042 clang_cl_re = re.compile( |
2035 r'^cl_x\d\d\s+\=\s+(?P<compiler_path>[^ ]+)\s.*$', | 2043 r'^cl_x\d\d\s+\=\s+(?P<compiler_path>[^ ]+)\s.*$', |
2036 re.VERBOSE) | 2044 re.VERBOSE) |
2037 for line in open(build_file): | 2045 for line in open(build_file): |
2038 m = clang_cl_re.match(line) | 2046 m = clang_cl_re.match(line) |
2039 if m: | 2047 if m: |
2040 return 'clang' in m.group('compiler_path') | 2048 return 'clang' in m.group('compiler_path') |
2041 return False | 2049 return False |
OLD | NEW |