7""" Generate a Fuchsia FAR Archive from an asset manifest.
17from gather_flutter_runner_artifacts
import CreateMetaPackage
23 for root, dirs, files
in os.walk(package_dir):
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))
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)
44 pm_bin,
'-m', manifest_path,
'-k', signing_key,
'-o', dst_dir,
'--api-level', api_level
48 subprocess.check_output(pm_command_base + [
'build'])
51 subprocess.check_output(pm_command_base + [
'archive'])
57 parser = argparse.ArgumentParser()
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)
63 '--manifest-json-file', dest=
'manifest_json_file', action=
'store', required=
True
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)
68 args = parser.parse_args()
70 assert os.path.exists(args.pm_bin)
71 assert os.path.exists(args.package_dir)
72 pkg_dir = args.package_dir
74 if not os.path.exists(os.path.join(pkg_dir,
'meta',
'package')):
77 output_dir = os.path.abspath(pkg_dir +
'_out')
78 if not os.path.exists(output_dir):
79 os.makedirs(output_dir)
82 if args.manifest_file
is not None:
83 assert os.path.exists(args.manifest_file)
84 manifest_file = args.manifest_file
102 build_command = [
'build',
'--output-package-manifest', args.manifest_json_file]
104 if args.api_level
is not None:
105 build_command = [
'--api-level', args.api_level] + build_command
108 'archive',
'--output=' + os.path.join(os.path.dirname(output_dir), args.far_name +
"-0")
111 pm_commands = [build_command, archive_command]
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 =========================================')
131if __name__ ==
'__main__':
def CreateMetaPackage(dst_root, far_name)
def GenerateManifest(package_dir)
def CreateFarPackage(pm_bin, package_dir, signing_key, dst_dir, api_level)
def print(*args, **kwargs)