John Rosasco | 24cbdab | 2019-09-25 14:14:35 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2019 Google LLC. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | """ |
| 8 | Builds a Fuchsia FAR archive. |
| 9 | """ |
| 10 | |
| 11 | import argparse |
| 12 | import os |
| 13 | import subprocess |
| 14 | import sys |
| 15 | |
| 16 | def main(): |
| 17 | parser = argparse.ArgumentParser() |
| 18 | |
| 19 | parser.add_argument('--pm-bin', dest='pm_bin', action='store', required=True) |
| 20 | parser.add_argument( |
| 21 | '--pkg-dir', dest='pkg_dir', action='store', required=True) |
| 22 | parser.add_argument( |
| 23 | '--pkg-name', dest='pkg_name', action='store', required=True) |
| 24 | parser.add_argument( |
| 25 | '--pkg-version', dest='pkg_version', action='store', required=True) |
| 26 | parser.add_argument( |
| 27 | '--pkg-manifest', dest='pkg_manifest', action='store', required=True) |
| 28 | |
| 29 | args = parser.parse_args() |
| 30 | |
| 31 | assert os.path.exists(args.pm_bin) |
| 32 | assert os.path.exists(args.pkg_dir) |
| 33 | |
| 34 | pkg_dir = args.pkg_dir |
| 35 | pkg_name = args.pkg_name |
| 36 | pkg_manifest = args.pkg_manifest |
| 37 | pkg_version = args.pkg_version |
| 38 | |
| 39 | pm_command_base = [ |
| 40 | args.pm_bin, |
| 41 | '-o', |
| 42 | pkg_dir, |
| 43 | ] |
| 44 | |
| 45 | # Create the package ID file. |
| 46 | subprocess.check_call(pm_command_base + ['-n'] + [pkg_name] + ['init']) |
| 47 | |
| 48 | # Build the package. |
| 49 | subprocess.check_call(pm_command_base + ['-m'] + [pkg_manifest] + ['build']) |
| 50 | |
| 51 | # Archive the package. |
| 52 | subprocess.check_call(pm_command_base + ['-m'] + [pkg_manifest] + ['-version'] + [pkg_version] + ['archive']) |
| 53 | |
| 54 | return 0 |
| 55 | |
| 56 | |
| 57 | if __name__ == '__main__': |
| 58 | sys.exit(main()) |