blob: 72908403e22e64190ffe408d750e75f6df540499 [file] [log] [blame]
David Brazdilb4802bc2019-07-30 12:39:41 +01001#!/usr/bin/env python
2#
3# Copyright 2019 The Hafnium Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17#!/usr/bin/env python
18"""Generate a depfile for a folder."""
19
20import argparse
21import os
22import sys
23
24def main():
25 parser = argparse.ArgumentParser()
26 parser.add_argument("root_dir", help="input directory")
27 parser.add_argument("stamp_file", help="stamp file to be touched")
28 parser.add_argument("dep_file", help="depfile to be written")
29 args = parser.parse_args()
30
31 # Compile list of all files in the folder, relative to `root_dir`.
32 sources = []
33 for root, _, files in os.walk(args.root_dir):
34 sources.extend([ os.path.join(root, f) for f in files ])
35 sources = sorted(sources)
36
37 # Write `dep_file` as a Makefile rule for `stamp_file`.
38 with open(args.dep_file, "w") as f:
39 f.write(args.stamp_file)
40 f.write(":")
41 for source in sources:
42 f.write(' ');
43 f.write(source)
44 f.write(os.linesep)
45
46 # Touch `stamp_file`.
47 with open(args.stamp_file, "w"):
48 pass
49
50if __name__ == "__main__":
51 sys.exit(main())