| 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 Engine 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): | |
| 19 """Read the manifest and return the list of dependencies. | |
| 20 :raises IOError: if the manifest could not be read. | |
| 21 """ | |
| 22 deps = [] | |
| 23 with open(manifest) as f: | |
| 24 for line in f.readlines(): | |
| 25 # Strip comments. | |
| 26 dep = line.partition('#')[0].strip() | |
| 27 # Ignore empty strings. | |
| 28 if dep: | |
| 29 deps.append(dep) | |
| 30 return deps | |
| 31 | |
| 32 def main(): | |
| 33 parser = argparse.ArgumentParser(description=__doc__) | |
| 34 parser.add_argument('--build-dir', | |
| 35 help=('build output directory (e.g. out/Debug)'), | |
| 36 required=True, | |
| 37 metavar='DIR') | |
| 38 parser.add_argument('--dockerfile', | |
| 39 help=('Dockerfile to add to the bundle'), | |
| 40 required=True, | |
| 41 metavar='FILE') | |
| 42 parser.add_argument('--startup-script', | |
| 43 help=('Engine startup script to add to the bundle'), | |
| 44 required=True, | |
| 45 metavar='FILE') | |
| 46 parser.add_argument('--manifest', | |
| 47 help=('engine manifest'), | |
| 48 required=True) | |
| 49 parser.add_argument('--output', | |
| 50 help=('name and path of bundle to create'), | |
| 51 required=True, | |
| 52 metavar='FILE') | |
| 53 args = parser.parse_args() | |
| 54 | |
| 55 deps = ReadDependencies(args.manifest) | |
| 56 | |
| 57 dockerfile_dirname, dockerfile_basename = os.path.split(args.dockerfile) | |
| 58 startup_script_dirname, startup_script_basename = os.path.split( | |
| 59 args.startup_script) | |
| 60 | |
| 61 try: | |
| 62 env = os.environ.copy() | |
| 63 # Use fastest possible mode when gzipping. | |
| 64 env["GZIP"] = "-1" | |
| 65 subprocess.check_output( | |
| 66 ["tar", | |
| 67 "-zcf", args.output, | |
| 68 # Ensure tarball content group permissions are appropriately set for | |
| 69 # use as part of a "docker build". That is group readable with | |
| 70 # executable files also being group executable. | |
| 71 "--mode=g+rX", | |
| 72 "-C", dockerfile_dirname, dockerfile_basename, | |
| 73 "-C", startup_script_dirname, startup_script_basename, | |
| 74 "-C", args.build_dir] + deps, | |
| 75 # Redirect stderr to stdout, so that its output is captured. | |
| 76 stderr=subprocess.STDOUT, | |
| 77 env=env) | |
| 78 except subprocess.CalledProcessError as e: | |
| 79 print >> sys.stderr, "Failed to create tarball:" | |
| 80 print >> sys.stderr, e.output | |
| 81 sys.exit(1) | |
| 82 | |
| 83 if __name__ == "__main__": | |
| 84 main() | |
| OLD | NEW |