OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Bundles the Blimp target and its runtime dependencies into a tarball. | 6 '''Bundles the Blimp target and its runtime dependencies into a tarball. |
7 | 7 |
8 The created bundle can be passed as input to docker build. E.g. | 8 The created bundle can be passed as input to docker build. E.g. |
9 docker build - < ../../out-linux/Debug/blimp_engine_deps.tar.gz | 9 docker build - < ../../out-linux/Debug/blimp_engine_deps.tar.gz |
10 ''' | 10 ''' |
11 | 11 |
12 | 12 |
13 import argparse | 13 import argparse |
14 import os | 14 import os |
15 import subprocess | 15 import subprocess |
16 import sys | 16 import sys |
17 | 17 |
18 def ReadDependencies(manifest): | 18 def ReadDependencies(manifest, relative_path): |
19 """Read the manifest and return the list of dependencies. | 19 """Read the manifest and return the list of dependencies. |
maniscalco
2016/07/18 16:01:05
Docs of this function need to be updated now that
Jess
2016/07/19 21:36:08
Done.
| |
20 :raises IOError: if the manifest could not be read. | 20 :raises IOError: if the manifest could not be read. |
21 """ | 21 """ |
22 deps = [] | 22 dependency_list = [] |
23 with open(manifest) as f: | 23 with open(manifest) as f: |
24 for line in f.readlines(): | 24 for line in f.readlines(): |
25 # Strip comments. | 25 # Strip comments. |
26 dep = line.partition('#')[0].strip() | 26 dependency = line.partition('#')[0].strip() |
27 # Ignore empty strings. | 27 # Ignore empty strings. |
28 if dep: | 28 if dependency: |
29 deps.append(dep) | 29 if relative_path != '': |
30 return deps | 30 dependency = os.path.normpath(os.path.join(relative_path, dependency)) |
31 dependency_list.append(dependency) | |
32 return dependency_list | |
31 | 33 |
32 def main(): | 34 def main(): |
33 parser = argparse.ArgumentParser(description=__doc__) | 35 parser = argparse.ArgumentParser(description=__doc__) |
34 parser.add_argument('--build-dir', | 36 parser.add_argument('--build-dir', |
35 help=('build output directory (e.g. out/Debug)'), | 37 help=('build output directory (e.g. out/Debug)'), |
36 required=True, | 38 required=True, |
37 metavar='DIR') | 39 metavar='DIR') |
38 parser.add_argument('--filelist', | 40 parser.add_argument('--filelist', |
39 help=('optional space separated list of files (e.g. ' | 41 help=('optional space separated list of files (e.g. ' |
40 'Dockerfile and startup script) to add to the ' | 42 'Dockerfile and startup script) to add to the ' |
41 'bundle'), | 43 'bundle'), |
42 required=False, | 44 required=False, |
43 metavar='FILE', | 45 metavar='FILE', |
44 nargs='*') | 46 nargs='*') |
45 parser.add_argument('--manifest', | 47 parser.add_argument('--manifest', |
46 help=('file listing the set of files to include in ' | 48 help=('file listing the set of files to include in ' |
47 'the bundle'), | 49 'the bundle'), |
48 required=True) | 50 required=True) |
49 parser.add_argument('--output', | 51 parser.add_argument('--output', |
50 help=('name and path of bundle to create'), | 52 help=('name and path of bundle to create'), |
51 required=True, | 53 required=True, |
52 metavar='FILE') | 54 metavar='FILE') |
55 parser.add_argument('--root-dir', | |
maniscalco
2016/07/18 16:01:05
Let's say the manifest (really the runtime deps fi
Jess
2016/07/19 21:36:08
Updated. PTAL. Agree this value's meaning is not t
| |
56 help=('optional docker rootdir to use to reference ' | |
57 'dependencies; defaults to build-dir'), | |
58 required=False, | |
59 metavar='DIR') | |
53 args = parser.parse_args() | 60 args = parser.parse_args() |
54 | 61 |
55 deps = ReadDependencies(args.manifest) | 62 dependencies_path = args.build_dir |
63 if args.root_dir: | |
64 dependencies_path = args.root_dir | |
65 relative_path = os.path.relpath(args.build_dir, dependencies_path) | |
66 | |
67 dependency_list = ReadDependencies(args.manifest, relative_path) | |
56 | 68 |
57 try: | 69 try: |
58 env = os.environ.copy() | 70 env = os.environ.copy() |
59 # Use fastest possible mode when gzipping. | 71 # Use fastest possible mode when gzipping. |
60 env["GZIP"] = "-1" | 72 env["GZIP"] = "-1" |
61 subprocess_args = [ | 73 subprocess_args = [ |
62 "tar", | 74 "tar", |
63 "-zcf", args.output, | 75 "-zcf", args.output, |
64 # Ensure tarball content group permissions are appropriately set for | 76 # Ensure tarball content group permissions are appropriately set for |
65 # use as part of a "docker build". That is group readable with | 77 # use as part of a "docker build". That is group readable with |
66 # executable files also being group executable. | 78 # executable files also being group executable. |
67 "--mode=g+rX", | 79 "--mode=g+rX", |
68 "-C", args.build_dir] + deps | 80 "-C", dependencies_path] + dependency_list |
69 for f in args.filelist: | 81 for f in args.filelist: |
70 dirname, basename = os.path.split(f) | 82 dirname, basename = os.path.split(f) |
71 subprocess_args.extend(["-C", dirname, basename]) | 83 subprocess_args.extend(["-C", dirname, basename]) |
72 subprocess.check_output( | 84 subprocess.check_output( |
73 subprocess_args, | 85 subprocess_args, |
74 # Redirect stderr to stdout, so that its output is captured. | 86 # Redirect stderr to stdout, so that its output is captured. |
75 stderr=subprocess.STDOUT, | 87 stderr=subprocess.STDOUT, |
76 env=env) | 88 env=env) |
77 except subprocess.CalledProcessError as e: | 89 except subprocess.CalledProcessError as e: |
78 print >> sys.stderr, "Failed to create tarball:" | 90 print >> sys.stderr, "Failed to create tarball:" |
79 print >> sys.stderr, e.output | 91 print >> sys.stderr, e.output |
80 sys.exit(1) | 92 sys.exit(1) |
81 | 93 |
82 if __name__ == "__main__": | 94 if __name__ == "__main__": |
83 main() | 95 main() |
OLD | NEW |