Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gen_package.py
Go to the documentation of this file.
1#!/usr/bin/env python3
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
7""" Generate a Fuchsia FAR Archive from an asset manifest.
8"""
9
10import argparse
11import collections
12import json
13import os
14import subprocess
15import sys
16
17from gather_flutter_runner_artifacts import CreateMetaPackage
18
19
20# Generates the manifest and returns the file.
21def GenerateManifest(package_dir):
22 full_paths = []
23 for root, dirs, files in os.walk(package_dir):
24 for f in files:
25 common_prefix = os.path.commonprefix([root, package_dir])
26 rel_path = os.path.relpath(os.path.join(root, f), common_prefix)
27 from_package = os.path.abspath(os.path.join(package_dir, rel_path))
28 assert from_package, 'Failed to create from_package for %s' % os.path.join(root, f)
29 full_paths.append('%s=%s' % (rel_path, from_package))
30
31 parent_dir = os.path.abspath(os.path.join(package_dir, os.pardir))
32 manifest_file_name = os.path.basename(package_dir) + '.manifest'
33 manifest_path = os.path.join(parent_dir, manifest_file_name)
34 with open(manifest_path, 'w') as f:
35 for item in full_paths:
36 f.write("%s\n" % item)
37 return manifest_path
38
39
40def CreateFarPackage(pm_bin, package_dir, signing_key, dst_dir, api_level):
41 manifest_path = GenerateManifest(package_dir)
42
43 pm_command_base = [
44 pm_bin, '-m', manifest_path, '-k', signing_key, '-o', dst_dir, '--api-level', api_level
45 ]
46
47 # Build the package
48 subprocess.check_output(pm_command_base + ['build'])
49
50 # Archive the package
51 subprocess.check_output(pm_command_base + ['archive'])
52
53 return 0
54
55
56def main():
57 parser = argparse.ArgumentParser()
58
59 parser.add_argument('--pm-bin', dest='pm_bin', action='store', required=True)
60 parser.add_argument('--package-dir', dest='package_dir', action='store', required=True)
61 parser.add_argument('--manifest-file', dest='manifest_file', action='store', required=False)
62 parser.add_argument(
63 '--manifest-json-file', dest='manifest_json_file', action='store', required=True
64 )
65 parser.add_argument('--far-name', dest='far_name', action='store', required=False)
66 parser.add_argument('--api-level', dest='api_level', action='store', required=False)
67
68 args = parser.parse_args()
69
70 assert os.path.exists(args.pm_bin)
71 assert os.path.exists(args.package_dir)
72 pkg_dir = args.package_dir
73
74 if not os.path.exists(os.path.join(pkg_dir, 'meta', 'package')):
75 CreateMetaPackage(pkg_dir, args.far_name)
76
77 output_dir = os.path.abspath(pkg_dir + '_out')
78 if not os.path.exists(output_dir):
79 os.makedirs(output_dir)
80
81 manifest_file = None
82 if args.manifest_file is not None:
83 assert os.path.exists(args.manifest_file)
84 manifest_file = args.manifest_file
85 else:
86 manifest_file = GenerateManifest(args.package_dir)
87
88 pm_command_base = [
89 args.pm_bin,
90 '-o',
91 output_dir,
92 '-n',
93 args.far_name,
94 '-m',
95 manifest_file,
96 ]
97
98 # Build and then archive the package
99 # Use check_output so if anything goes wrong we get the output.
100 try:
101
102 build_command = ['build', '--output-package-manifest', args.manifest_json_file]
103
104 if args.api_level is not None:
105 build_command = ['--api-level', args.api_level] + build_command
106
107 archive_command = [
108 'archive', '--output=' + os.path.join(os.path.dirname(output_dir), args.far_name + "-0")
109 ]
110
111 pm_commands = [build_command, archive_command]
112
113 for pm_command in pm_commands:
114 subprocess.check_output(pm_command_base + pm_command)
115 except subprocess.CalledProcessError as e:
116 print('==================== Manifest contents =========================================')
117 with open(manifest_file, 'r') as manifest:
118 sys.stdout.write(manifest.read())
119 print('==================== End manifest contents =====================================')
120 meta_contents_path = os.path.join(output_dir, 'meta', 'contents')
121 if os.path.exists(meta_contents_path):
122 print('==================== meta/contents =============================================')
123 with open(meta_contents_path, 'r') as meta_contents:
124 sys.stdout.write(meta_contents.read())
125 print('==================== End meta/contents =========================================')
126 raise
127
128 return 0
129
130
131if __name__ == '__main__':
132 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
GenerateManifest(package_dir)
Definition main.py:1