• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright 2013 The Flutter Authors. 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""" Genrate a Fuchsia FAR Archive from an asset manifest and a signing key.
7"""
8
9import argparse
10import collections
11import json
12import os
13import subprocess
14import sys
15
16
17# Generates the manifest and returns the file.
18def GenerateManifest(package_dir):
19  full_paths = []
20  for root, dirs, files in os.walk(package_dir):
21    for f in files:
22      common_prefix = os.path.commonprefix([root, package_dir])
23      rel_path = os.path.relpath(os.path.join(root, f), common_prefix)
24      from_package = os.path.abspath(os.path.join(package_dir, rel_path))
25      full_paths.append('%s=%s' % (rel_path, from_package))
26  parent_dir = os.path.abspath(os.path.join(package_dir, os.pardir))
27  manifest_file_name = os.path.basename(package_dir) + '.manifest'
28  manifest_path = os.path.join(parent_dir, manifest_file_name)
29  with open(manifest_path, 'w') as f:
30    for item in full_paths:
31      f.write("%s\n" % item)
32  return manifest_path
33
34
35def CreateFarPackage(pm_bin, package_dir, signing_key, dst_dir):
36  manifest_path = GenerateManifest(package_dir)
37
38  pm_command_base = [
39      pm_bin, '-m', manifest_path, '-k', signing_key, '-o', dst_dir
40  ]
41
42  # Build the package
43  subprocess.check_call(pm_command_base + ['build'])
44
45  # Archive the package
46  subprocess.check_call(pm_command_base + ['archive'])
47
48  return 0
49
50
51def main():
52  parser = argparse.ArgumentParser()
53
54  parser.add_argument('--pm-bin', dest='pm_bin', action='store', required=True)
55  parser.add_argument(
56      '--package-dir', dest='package_dir', action='store', required=True)
57  parser.add_argument(
58      '--signing-key', dest='signing_key', action='store', required=True)
59  parser.add_argument(
60      '--manifest-file', dest='manifest_file', action='store', required=True)
61
62  args = parser.parse_args()
63
64  assert os.path.exists(args.pm_bin)
65  assert os.path.exists(args.package_dir)
66  assert os.path.exists(args.signing_key)
67  assert os.path.exists(args.manifest_file)
68
69  pm_command_base = [
70      args.pm_bin,
71      '-o',
72      args.package_dir,
73      '-k',
74      args.signing_key,
75      '-m',
76      args.manifest_file,
77  ]
78
79  # Build the package
80  subprocess.check_call(pm_command_base + ['build'])
81
82  # Archive the package
83  subprocess.check_call(pm_command_base + ['archive'])
84
85  return 0
86
87
88if __name__ == '__main__':
89  sys.exit(main())
90