Merge mozilla-central to autoland. a=merge CLOSED TREE
[gecko.git] / third_party / libwebrtc / tools / grit / stamp_grit_sources.py
blobbc7265c6cb7730ff1cb8209cb3f7dcf3e9963ad6
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 # This script enumerates the files in the given directory, writing an empty
6 # stamp file and a .d file listing the inputs required to make the stamp. This
7 # allows us to dynamically depend on the grit sources without enumerating the
8 # grit directory for every invocation of grit (which is what adding the source
9 # files to every .grd file's .d file would entail) or shelling out to grit
10 # synchronously during GN execution to get the list (which would be slow).
12 # Usage:
13 # stamp_grit_sources.py <directory> <stamp-file> <.d-file>
15 from __future__ import print_function
17 import os
18 import sys
20 def GritSourceFiles(grit_root_dir):
21 files = []
22 for root, _, filenames in os.walk(grit_root_dir):
23 grit_src = [os.path.join(root, f) for f in filenames
24 if f.endswith('.py') and not f.endswith('_unittest.py')]
25 files.extend(grit_src)
26 files = [f.replace('\\', '/') for f in files]
27 return sorted(files)
30 def WriteDepFile(dep_file, stamp_file, source_files):
31 with open(dep_file, "w") as f:
32 f.write(stamp_file)
33 f.write(": ")
34 f.write(' '.join(source_files))
37 def WriteStampFile(stamp_file):
38 with open(stamp_file, "w"):
39 pass
42 def main(argv):
43 if len(argv) != 4:
44 print("Error: expecting 3 args.")
45 return 1
47 grit_root_dir = sys.argv[1]
48 stamp_file = sys.argv[2]
49 dep_file = sys.argv[3]
51 WriteStampFile(stamp_file)
52 WriteDepFile(dep_file, stamp_file, GritSourceFiles(grit_root_dir))
53 return 0
56 if __name__ == '__main__':
57 sys.exit(main(sys.argv))