• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Opens |base_manifest| and copies the contents to |manifest| then traverses
9 |root_dir| and appends every file as a Fuchsia package manifest entry to
10 |manifest|.
11"""
12
13import argparse
14import os
15import subprocess
16
17parser = argparse.ArgumentParser()
18parser.add_argument('--root_dir', dest='root_dir', action='store', required=True)
19parser.add_argument('--base_manifest', dest='base_manifest', action='store', required=True)
20parser.add_argument('--manifest', dest='manifest', action='store', required=True)
21parser.add_argument('--deps', dest='deps', action='store', required=True)
22parser.add_argument('--root_build_dir', dest='root_build_dir', action='store', required=True)
23args = parser.parse_args()
24
25root_dir = args.root_dir
26if not os.path.exists(root_dir):
27    print "--root_dir path specified: " + root_dir + " doesn't exist.\n"
28    exit(1)
29
30base_manifest = args.base_manifest
31if not os.path.exists(base_manifest):
32    print "--base_manifest specified: " + base_manifest + " doesn't exist.\n"
33    exit(1)
34
35manifest = args.manifest
36root_build_dir = args.root_build_dir
37
38# Prepend |base_manifest| contents to |manifest|.
39deps_file = open(args.deps, 'w')
40relative_path = os.path.relpath(args.manifest, root_build_dir)
41deps_file.write('%s: ' % relative_path)
42
43out_file = open(manifest, 'w')
44with open(base_manifest, 'r') as in_file:
45    base_content = in_file.readlines()
46
47for base_line in base_content:
48    out_file.write(base_line)
49    base_line_list = base_line.split("=")
50    if len(base_line_list) != 2:
51        print "Error: Base manifest line format error. Expected \"lhs=rhs\" but got: " + base_line
52        exit(1)
53    base_line_rhs = base_line_list[1].strip()
54    relative_path = os.path.relpath(base_line_rhs, root_build_dir)
55    deps_file.write(relative_path + " ")
56
57# Append all files discovered under |root_dir| to |manifest|.
58files = subprocess.check_output(["find", root_dir, "-type", "f"])
59file_lines = files.splitlines()
60
61for file in file_lines:
62        source = file
63        if not source.startswith(root_dir):
64            print "Error: source path " + source + " is not under |root_dir|\n"
65            exit(1)
66        dest = source[len(root_dir):]
67        out_file.write('data%s=' % dest)
68        out_file.write('%s\n' % source)
69        relative_path = os.path.relpath(source, root_build_dir)
70        deps_file.write(relative_path + " ")
71
72out_file.close()
73deps_file.close()
74