blob: ba253c5c64c5993707ef0311191ed68457a6f3e3 [file] [log] [blame]
#!/usr/bin/env python3.8
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# list-input-file manifest-output-file
# Given a file containing a list of manifest files, each of which contain dest
# values (left side of =) that is a content-address, sort the content address
# and only emit a single line for a given content address. The paths on the
# right hand side will be rebased relative to the directory containing the
# manifest output file.
import os
import sys
def main():
infile = sys.argv[1]
outfile = sys.argv[2]
depfile = sys.argv[3]
outdir = os.path.dirname(outfile)
manifests = []
files = {}
with open(infile) as listfile:
for manifest in listfile:
with open(manifest.strip()) as f:
for line in f:
line = line.strip()
if line == "":
(id, src) = line.split("=", 2)
# There are often cases where one content address has more than one
# possible source, that's fine, it does not matter which we use.
files[id] = src
sys.stderr.write("Failed on line: " + line)
with open(depfile, "w") as df:
df.write("{}: {}\n".format(outfile, ' '.join(manifests)))
with open(outfile, "w") as f:
for id, src in list(files.items()):
f.write(id + "=")
f.write(os.path.relpath(src, outdir))
if __name__ == "__main__":