blob: 12fbd51b1889cfd3595c9f087618fbcc914bd0d9 [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#
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
David Brazdilb4802bc2019-07-30 12:39:41 +010017"""Generate a depfile for a folder."""
18
19import argparse
20import os
21import sys
22
23def main():
24 parser = argparse.ArgumentParser()
25 parser.add_argument("root_dir", help="input directory")
26 parser.add_argument("stamp_file", help="stamp file to be touched")
27 parser.add_argument("dep_file", help="depfile to be written")
28 args = parser.parse_args()
29
30 # Compile list of all files in the folder, relative to `root_dir`.
31 sources = []
32 for root, _, files in os.walk(args.root_dir):
33 sources.extend([ os.path.join(root, f) for f in files ])
34 sources = sorted(sources)
35
36 # Write `dep_file` as a Makefile rule for `stamp_file`.
37 with open(args.dep_file, "w") as f:
38 f.write(args.stamp_file)
39 f.write(":")
40 for source in sources:
41 f.write(' ');
42 f.write(source)
43 f.write(os.linesep)
44
45 # Touch `stamp_file`.
46 with open(args.stamp_file, "w"):
47 pass
48
49if __name__ == "__main__":
50 sys.exit(main())