2019-09-25 21:14:35 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Copyright 2019 Google LLC. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Opens |base_manifest| and copies the contents to |manifest| then traverses
|
|
|
|
|root_dir| and appends every file as a Fuchsia package manifest entry to
|
|
|
|
|manifest|.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--root_dir', dest='root_dir', action='store', required=True)
|
|
|
|
parser.add_argument('--base_manifest', dest='base_manifest', action='store', required=True)
|
|
|
|
parser.add_argument('--manifest', dest='manifest', action='store', required=True)
|
2019-11-26 23:11:41 +00:00
|
|
|
parser.add_argument('--deps', dest='deps', action='store', required=True)
|
|
|
|
parser.add_argument('--root_build_dir', dest='root_build_dir', action='store', required=True)
|
2019-09-25 21:14:35 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
root_dir = args.root_dir
|
|
|
|
if not os.path.exists(root_dir):
|
2019-11-26 23:11:41 +00:00
|
|
|
print "--root_dir path specified: " + root_dir + " doesn't exist.\n"
|
2019-09-25 21:14:35 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
base_manifest = args.base_manifest
|
|
|
|
if not os.path.exists(base_manifest):
|
2019-11-26 23:11:41 +00:00
|
|
|
print "--base_manifest specified: " + base_manifest + " doesn't exist.\n"
|
2019-09-25 21:14:35 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
manifest = args.manifest
|
2019-11-26 23:11:41 +00:00
|
|
|
root_build_dir = args.root_build_dir
|
2019-09-25 21:14:35 +00:00
|
|
|
|
|
|
|
# Prepend |base_manifest| contents to |manifest|.
|
2019-11-26 23:11:41 +00:00
|
|
|
deps_file = open(args.deps, 'w')
|
|
|
|
relative_path = os.path.relpath(args.manifest, root_build_dir)
|
|
|
|
deps_file.write('%s: ' % relative_path)
|
|
|
|
|
2019-09-25 21:14:35 +00:00
|
|
|
out_file = open(manifest, 'w')
|
|
|
|
with open(base_manifest, 'r') as in_file:
|
2019-11-26 23:11:41 +00:00
|
|
|
base_content = in_file.readlines()
|
|
|
|
|
|
|
|
for base_line in base_content:
|
|
|
|
out_file.write(base_line)
|
|
|
|
base_line_list = base_line.split("=")
|
|
|
|
if len(base_line_list) != 2:
|
|
|
|
print "Error: Base manifest line format error. Expected \"lhs=rhs\" but got: " + base_line
|
|
|
|
exit(1)
|
|
|
|
base_line_rhs = base_line_list[1].strip()
|
|
|
|
relative_path = os.path.relpath(base_line_rhs, root_build_dir)
|
|
|
|
deps_file.write(relative_path + " ")
|
2019-09-25 21:14:35 +00:00
|
|
|
|
|
|
|
# Append all files discovered under |root_dir| to |manifest|.
|
|
|
|
files = subprocess.check_output(["find", root_dir, "-type", "f"])
|
|
|
|
file_lines = files.splitlines()
|
|
|
|
|
|
|
|
for file in file_lines:
|
|
|
|
source = file
|
|
|
|
if not source.startswith(root_dir):
|
|
|
|
print "Error: source path " + source + " is not under |root_dir|\n"
|
|
|
|
exit(1)
|
|
|
|
dest = source[len(root_dir):]
|
|
|
|
out_file.write('data%s=' % dest)
|
|
|
|
out_file.write('%s\n' % source)
|
2019-11-26 23:11:41 +00:00
|
|
|
relative_path = os.path.relpath(source, root_build_dir)
|
|
|
|
deps_file.write(relative_path + " ")
|
2019-09-25 21:14:35 +00:00
|
|
|
|
|
|
|
out_file.close()
|
2019-11-26 23:11:41 +00:00
|
|
|
deps_file.close()
|