1#!/usr/bin/env python3 2# 3# Copyright 2019 The Hafnium Authors. 4# 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. 8 9"""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()) 43