David Brazdil | 6c63a26 | 2019-12-23 13:23:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2019 The Hafnium Authors. |
| 4 | # |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 5 | # 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 Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 8 | |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 9 | """Generate a depfile for a folder.""" |
| 10 | |
| 11 | import argparse |
| 12 | import os |
| 13 | import sys |
| 14 | |
| 15 | def 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 | |
| 41 | if __name__ == "__main__": |
| 42 | sys.exit(main()) |