OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # TODO(brettw) bug 582594: merge this with build/android/gn/zip.py and update | 7 # TODO(brettw) bug 582594: merge this with build/android/gn/zip.py and update |
8 # callers to use the existing template rather than invoking this directly. | 8 # callers to use the existing template rather than invoking this directly. |
9 | 9 |
10 """Archives a set of files. | 10 """Archives a set of files. |
11 """ | 11 """ |
12 | 12 |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import sys | 15 import sys |
16 import zipfile | 16 import zipfile |
17 | 17 |
18 sys.path.append(os.path.join(os.path.dirname(__file__), | 18 sys.path.append(os.path.join(os.path.dirname(__file__), |
19 os.pardir, os.pardir, os.pardir, os.pardir, | 19 os.pardir, os.pardir, os.pardir, os.pardir, |
20 "build")) | 20 "build")) |
21 import gn_helpers | 21 import gn_helpers |
22 | 22 |
| 23 sys.path.append(os.path.join(os.path.dirname(__file__), |
| 24 os.pardir, os.pardir, os.pardir, os.pardir, |
| 25 'build', 'android', 'gyp')) |
| 26 from util import build_utils |
| 27 |
| 28 |
23 def DoZip(inputs, link_inputs, zip_inputs, output, base_dir): | 29 def DoZip(inputs, link_inputs, zip_inputs, output, base_dir): |
24 files = [] | 30 files = [] |
25 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as outfile: | 31 with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as outfile: |
26 for f in inputs: | 32 for f in inputs: |
27 file_name = os.path.relpath(f, base_dir) | 33 file_name = os.path.relpath(f, base_dir) |
28 files.append(file_name) | 34 files.append(file_name) |
29 outfile.write(f, file_name) | 35 build_utils.AddToZipHermetic(outfile, file_name, f) |
30 for f in link_inputs: | 36 for f in link_inputs: |
31 realf = os.path.realpath(f) # Resolve symlinks. | 37 realf = os.path.realpath(f) # Resolve symlinks. |
32 file_name = os.path.relpath(realf, base_dir) | 38 file_name = os.path.relpath(realf, base_dir) |
33 files.append(file_name) | 39 files.append(file_name) |
34 outfile.write(realf, file_name) | 40 build_utils.AddToZipHermetic(outfile, file_name, realf) |
35 for zf_name in zip_inputs: | 41 for zf_name in zip_inputs: |
36 with zipfile.ZipFile(zf_name, 'r') as zf: | 42 with zipfile.ZipFile(zf_name, 'r') as zf: |
37 for f in zf.namelist(): | 43 for f in zf.namelist(): |
38 if f not in files: | 44 if f not in files: |
39 files.append(f) | 45 files.append(f) |
40 with zf.open(f) as zff: | 46 build_utils.AddToZipHermetic(outfile, f, data=zf.read(f)) |
41 outfile.writestr(f, zff.read()) | |
42 | 47 |
43 | 48 |
44 def main(): | 49 def main(): |
45 parser = optparse.OptionParser() | 50 parser = optparse.OptionParser() |
46 | 51 |
47 parser.add_option('--inputs', | 52 parser.add_option('--inputs', |
48 help='GN format list of files to archive.') | 53 help='GN format list of files to archive.') |
49 parser.add_option('--link-inputs', | 54 parser.add_option('--link-inputs', |
50 help='GN-format list of files to archive. Symbolic links are resolved.') | 55 help='GN-format list of files to archive. Symbolic links are resolved.') |
51 parser.add_option('--zip-inputs', | 56 parser.add_option('--zip-inputs', |
(...skipping 20 matching lines...) Expand all Loading... |
72 parser = gn_helpers.GNValueParser(options.zip_inputs) | 77 parser = gn_helpers.GNValueParser(options.zip_inputs) |
73 zip_inputs = parser.ParseList() | 78 zip_inputs = parser.ParseList() |
74 | 79 |
75 output = options.output | 80 output = options.output |
76 base_dir = options.base_dir | 81 base_dir = options.base_dir |
77 | 82 |
78 DoZip(inputs, link_inputs, zip_inputs, output, base_dir) | 83 DoZip(inputs, link_inputs, zip_inputs, output, base_dir) |
79 | 84 |
80 if __name__ == '__main__': | 85 if __name__ == '__main__': |
81 sys.exit(main()) | 86 sys.exit(main()) |
OLD | NEW |