Chromium Code Reviews| 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) : |
|
RobertoCN
2016/08/03 20:49:49
nit: Doesn't it make more sense to default to an e
miimnk
2016/08/03 21:37:11
Changed
| |
| 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)] | |
|
RobertoCN
2016/08/03 20:49:49
'strip' is a gnu command, right? what happens if t
miimnk
2016/08/03 21:37:11
Yes. It seems that it would give error for windows
| |
| 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 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2032 return False | 2039 return False |
| 2033 # Matches e.g. "cl_x86 = path/to/clang-cl.exe" | 2040 # Matches e.g. "cl_x86 = path/to/clang-cl.exe" |
| 2034 clang_cl_re = re.compile( | 2041 clang_cl_re = re.compile( |
| 2035 r'^cl_x\d\d\s+\=\s+(?P<compiler_path>[^ ]+)\s.*$', | 2042 r'^cl_x\d\d\s+\=\s+(?P<compiler_path>[^ ]+)\s.*$', |
| 2036 re.VERBOSE) | 2043 re.VERBOSE) |
| 2037 for line in open(build_file): | 2044 for line in open(build_file): |
| 2038 m = clang_cl_re.match(line) | 2045 m = clang_cl_re.match(line) |
| 2039 if m: | 2046 if m: |
| 2040 return 'clang' in m.group('compiler_path') | 2047 return 'clang' in m.group('compiler_path') |
| 2041 return False | 2048 return False |
| OLD | NEW |