blob: d0b4b38ec00a4f75df10c0a0c8dc23a5552c75e9 [file] [log] [blame] [edit]
#!/usr/bin/env fuchsia-vendored-python
# 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.
import argparse
import os
import sys
import tarfile
def main():
parser = argparse.ArgumentParser("Archives a directory")
parser.add_argument(
"--src", help="Path to the directory to archive", required=True
)
parser.add_argument("--dst", help="Path to the archive", required=True)
parser.add_argument(
"--depfile", help="Path to dependency file", required=True
)
args = parser.parse_args()
deps = []
with tarfile.open(args.dst, "w:gz") as tar:
for dirpath, dirnames, filenames in os.walk(args.src):
for filename in filenames:
path = os.path.join(dirpath, filename)
deps.append(os.path.relpath(path))
tar.add(path, arcname=os.path.relpath(path, args.src))
with open(args.depfile, "w") as depfile:
depfile.write("%s: %s\n" % (args.dst, " ".join(sorted(deps))))
return 0
if __name__ == "__main__":
sys.exit(main())