| 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 """Returns a list of dependencies based on the specified manifest file. |
| 20 The returned dependencies will be made relative to |relative_path| and |
| 21 normalized. |
| 20 :raises IOError: if the manifest could not be read. | 22 :raises IOError: if the manifest could not be read. |
| 21 """ | 23 """ |
| 22 deps = [] | 24 dependency_list = [] |
| 23 with open(manifest) as f: | 25 with open(manifest) as f: |
| 24 for line in f.readlines(): | 26 for line in f.readlines(): |
| 25 # Strip comments. | 27 # Strip comments. |
| 26 dep = line.partition('#')[0].strip() | 28 dependency = line.partition('#')[0].strip() |
| 27 # Ignore empty strings. | 29 # Ignore empty strings. |
| 28 if dep: | 30 if dependency: |
| 29 deps.append(dep) | 31 dependency = os.path.normpath(os.path.join(relative_path, dependency)) |
| 30 return deps | 32 dependency_list.append(dependency) |
| 33 return dependency_list |
| 31 | 34 |
| 32 def main(): | 35 def main(): |
| 33 parser = argparse.ArgumentParser(description=__doc__) | 36 parser = argparse.ArgumentParser(description=__doc__) |
| 34 parser.add_argument('--build-dir', | 37 parser.add_argument('--build-dir', |
| 35 help=('build output directory (e.g. out/Debug)'), | 38 help=('build output directory (e.g. out/Debug)'), |
| 36 required=True, | 39 required=True, |
| 37 metavar='DIR') | 40 metavar='DIR') |
| 38 parser.add_argument('--filelist', | 41 parser.add_argument('--filelist', |
| 39 help=('optional space separated list of files (e.g. ' | 42 help=('optional space separated list of files (e.g. ' |
| 40 'Dockerfile and startup script) to add to the ' | 43 'Dockerfile and startup script) to add to the ' |
| 41 'bundle'), | 44 'bundle'), |
| 42 required=False, | 45 required=False, |
| 43 metavar='FILE', | 46 metavar='FILE', |
| 44 nargs='*') | 47 nargs='*') |
| 45 parser.add_argument('--manifest', | 48 parser.add_argument('--manifest', |
| 46 help=('file listing the set of files to include in ' | 49 help=('file listing the set of files to include in ' |
| 47 'the bundle'), | 50 'the bundle'), |
| 48 required=True) | 51 required=True) |
| 49 parser.add_argument('--output', | 52 parser.add_argument('--output', |
| 50 help=('name and path of bundle to create'), | 53 help=('name and path of bundle to create'), |
| 51 required=True, | 54 required=True, |
| 52 metavar='FILE') | 55 metavar='FILE') |
| 56 parser.add_argument('--tar-contents-rooted-in', |
| 57 help=('optional path prefix to use inside the resulting ' |
| 58 'tar file'), |
| 59 required=False, |
| 60 metavar='DIR') |
| 53 args = parser.parse_args() | 61 args = parser.parse_args() |
| 54 | 62 |
| 55 deps = ReadDependencies(args.manifest) | 63 dependencies_path = args.build_dir |
| 64 if args.tar_contents_rooted_in: |
| 65 dependencies_path = args.tar_contents_rooted_in |
| 66 relative_path = os.path.relpath(args.build_dir, dependencies_path) |
| 67 |
| 68 dependency_list = ReadDependencies(args.manifest, relative_path) |
| 56 | 69 |
| 57 try: | 70 try: |
| 58 env = os.environ.copy() | 71 env = os.environ.copy() |
| 59 # Use fastest possible mode when gzipping. | 72 # Use fastest possible mode when gzipping. |
| 60 env["GZIP"] = "-1" | 73 env["GZIP"] = "-1" |
| 61 subprocess_args = [ | 74 subprocess_args = [ |
| 62 "tar", | 75 "tar", |
| 63 "-zcf", args.output, | 76 "-zcf", args.output, |
| 64 # Ensure tarball content group permissions are appropriately set for | 77 # Ensure tarball content group permissions are appropriately set for |
| 65 # use as part of a "docker build". That is group readable with | 78 # use as part of a "docker build". That is group readable with |
| 66 # executable files also being group executable. | 79 # executable files also being group executable. |
| 67 "--mode=g+rX", | 80 "--mode=g+rX", |
| 68 "-C", args.build_dir] + deps | 81 "-C", dependencies_path] + dependency_list |
| 69 for f in args.filelist: | 82 for f in args.filelist: |
| 70 dirname, basename = os.path.split(f) | 83 dirname, basename = os.path.split(f) |
| 71 subprocess_args.extend(["-C", dirname, basename]) | 84 subprocess_args.extend(["-C", dirname, basename]) |
| 72 subprocess.check_output( | 85 subprocess.check_output( |
| 73 subprocess_args, | 86 subprocess_args, |
| 74 # Redirect stderr to stdout, so that its output is captured. | 87 # Redirect stderr to stdout, so that its output is captured. |
| 75 stderr=subprocess.STDOUT, | 88 stderr=subprocess.STDOUT, |
| 76 env=env) | 89 env=env) |
| 77 except subprocess.CalledProcessError as e: | 90 except subprocess.CalledProcessError as e: |
| 78 print >> sys.stderr, "Failed to create tarball:" | 91 print >> sys.stderr, "Failed to create tarball:" |
| 79 print >> sys.stderr, e.output | 92 print >> sys.stderr, e.output |
| 80 sys.exit(1) | 93 sys.exit(1) |
| 81 | 94 |
| 82 if __name__ == "__main__": | 95 if __name__ == "__main__": |
| 83 main() | 96 main() |
| OLD | NEW |