blob: 3e94e8dff8c8591b7f4f94a6cccd41e20f4896c4 [file] [log] [blame]
David Brazdil6c63a262019-12-23 13:23:46 +00001#!/usr/bin/env python3
David Brazdilb4802bc2019-07-30 12:39:41 +01002#
3# Copyright 2019 The Hafnium Authors.
4#
Andrew Walbrane959ec12020-06-17 15:01:09 +01005# Use of this source code is governed by a BSD-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/BSD-3-Clause.
David Brazdilb4802bc2019-07-30 12:39:41 +01008
David Brazdilb4802bc2019-07-30 12:39:41 +01009"""Generate a depfile for a folder."""
10
11import argparse
12import os
13import sys
14
15def main():
16 parser = argparse.ArgumentParser()
17 parser.add_argument("root_dir", help="input directory")
18 parser.add_argument("stamp_file", help="stamp file to be touched")
19 parser.add_argument("dep_file", help="depfile to be written")
20 args = parser.parse_args()
21
22 # Compile list of all files in the folder, relative to `root_dir`.
23 sources = []
24 for root, _, files in os.walk(args.root_dir):
25 sources.extend([ os.path.join(root, f) for f in files ])
26 sources = sorted(sources)
27
28 # Write `dep_file` as a Makefile rule for `stamp_file`.
29 with open(args.dep_file, "w") as f:
30 f.write(args.stamp_file)
31 f.write(":")
32 for source in sources:
33 f.write(' ');
34 f.write(source)
35 f.write(os.linesep)
36
37 # Touch `stamp_file`.
38 with open(args.stamp_file, "w"):
39 pass
40
41if __name__ == "__main__":
42 sys.exit(main())