| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 '''Bundles the Blimp target and its runtime dependencies into a tarball. | |
| 7 | |
| 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 | |
| 10 ''' | |
| 11 | |
| 12 | |
| 13 import argparse | |
| 14 import os | |
| 15 import subprocess | |
| 16 import sys | |
| 17 | |
| 18 def ReadDependencies(manifest, relative_path): | |
| 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. | |
| 22 :raises IOError: if the manifest could not be read. | |
| 23 """ | |
| 24 dependency_list = [] | |
| 25 with open(manifest) as f: | |
| 26 for line in f.readlines(): | |
| 27 # Strip comments. | |
| 28 dependency = line.partition('#')[0].strip() | |
| 29 # Ignore empty strings. | |
| 30 if dependency: | |
| 31 dependency = os.path.normpath(os.path.join(relative_path, dependency)) | |
| 32 dependency_list.append(dependency) | |
| 33 return dependency_list | |
| 34 | |
| 35 def main(): | |
| 36 parser = argparse.ArgumentParser(description=__doc__) | |
| 37 parser.add_argument('--build-dir', | |
| 38 help=('build output directory (e.g. out/Debug)'), | |
| 39 required=True, | |
| 40 metavar='DIR') | |
| 41 parser.add_argument('--filelist', | |
| 42 help=('optional space separated list of files (e.g. ' | |
| 43 'Dockerfile and startup script) to add to the ' | |
| 44 'bundle'), | |
| 45 required=False, | |
| 46 metavar='FILE', | |
| 47 nargs='*') | |
| 48 parser.add_argument('--manifest', | |
| 49 help=('file listing the set of files to include in ' | |
| 50 'the bundle'), | |
| 51 required=True) | |
| 52 parser.add_argument('--output', | |
| 53 help=('name and path of bundle to create'), | |
| 54 required=True, | |
| 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') | |
| 61 args = parser.parse_args() | |
| 62 | |
| 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) | |
| 69 | |
| 70 try: | |
| 71 env = os.environ.copy() | |
| 72 # Use fastest possible mode when gzipping. | |
| 73 env["GZIP"] = "-1" | |
| 74 subprocess_args = [ | |
| 75 "tar", | |
| 76 "-zcf", args.output, | |
| 77 # Ensure tarball content group permissions are appropriately set for | |
| 78 # use as part of a "docker build". That is group readable with | |
| 79 # executable files also being group executable. | |
| 80 "--mode=g+rX", | |
| 81 "-C", dependencies_path] + dependency_list | |
| 82 for f in args.filelist: | |
| 83 dirname, basename = os.path.split(f) | |
| 84 subprocess_args.extend(["-C", dirname, basename]) | |
| 85 subprocess.check_output( | |
| 86 subprocess_args, | |
| 87 # Redirect stderr to stdout, so that its output is captured. | |
| 88 stderr=subprocess.STDOUT, | |
| 89 env=env) | |
| 90 except subprocess.CalledProcessError as e: | |
| 91 print >> sys.stderr, "Failed to create tarball:" | |
| 92 print >> sys.stderr, e.output | |
| 93 sys.exit(1) | |
| 94 | |
| 95 if __name__ == "__main__": | |
| 96 main() | |
| OLD | NEW |