OLD | NEW |
---|---|
(Empty) | |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
viettrungluu
2014/07/21 19:43:17
Please run pylint on this script.
brettw
2014/07/21 20:11:19
Done.
| |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
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). | |
11 # | |
12 # Usage: | |
13 # stamp_grit_sources.py <directory> <stamp-file> <.d-file> | |
viettrungluu
2014/07/21 19:43:17
It seems to me that this isn't very grit-specific
brettw
2014/07/21 20:11:19
Yes, I'm going to keep that in mind, but I don't w
| |
14 | |
15 import os | |
16 import sys | |
17 | |
18 def GritSourceFiles(grit_root_dir): | |
19 files = [] | |
20 for root, dirs, filenames in os.walk(grit_root_dir): | |
viettrungluu
2014/07/21 19:43:17
It's conventional to use _ for any variable you're
brettw
2014/07/21 20:11:19
Done.
| |
21 grit_src = [os.path.join(root, f) for f in filenames | |
22 if f.endswith('.py') and not f.endswith('_unittest.py')] | |
23 files.extend(grit_src) | |
24 files = [f.replace('\\', '/') for f in files] | |
25 return sorted(files) | |
26 | |
27 def WriteDepFile(dep_file, stamp_file, source_files): | |
28 with open(dep_file, "w") as f: | |
29 f.write(stamp_file) | |
30 f.write(": ") | |
31 f.write(' '.join(source_files)) | |
32 | |
33 def WriteStampFile(stamp_file): | |
34 with open(stamp_file, "w"): | |
35 pass | |
36 | |
37 if len(sys.argv) != 4: | |
viettrungluu
2014/07/21 19:43:17
Please put all of this in a main() function (or Ma
brettw
2014/07/21 20:11:19
Done.
| |
38 print "Error: expecting 3 args." | |
39 sys.exit(1) | |
40 | |
41 grit_root_dir = sys.argv[1] | |
42 stamp_file = sys.argv[2] | |
43 dep_file = sys.argv[3] | |
44 | |
45 WriteStampFile(stamp_file) | |
46 WriteDepFile(dep_file, stamp_file, GritSourceFiles(grit_root_dir)) | |
OLD | NEW |