OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2015 Google Inc. | 3 # Copyright 2015 Google Inc. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
7 | 7 |
8 # This script does a very rough simulation of BUILD file expansion, | 8 # This script does a very rough simulation of BUILD file expansion, |
9 # mostly to see the effects of glob(). | 9 # mostly to see the effects of glob(). |
10 | 10 |
11 # We start by adding some symbols to our namespace that BUILD.public calls. | 11 # We start by adding some symbols to our namespace that BUILD.public calls. |
12 | 12 |
13 # We don't really care about this, so just no-op it. | 13 import glob |
14 def exports_files(files): | 14 import pprint |
| 15 |
| 16 def noop(*args, **kwargs): |
15 pass | 17 pass |
16 | 18 |
17 # Simulates BUILD file glob(). | 19 # Simulates BUILD file glob(). |
18 def glob(include, exclude=()): | 20 def BUILD_glob(include, exclude=()): |
19 from glob import glob as python_glob | |
20 | |
21 files = set() | 21 files = set() |
22 for pattern in include: | 22 for pattern in include: |
23 files.update(python_glob(pattern)) | 23 files.update(glob.glob(pattern)) |
24 for pattern in exclude: | 24 for pattern in exclude: |
25 files.difference_update(python_glob(pattern)) | 25 files.difference_update(glob.glob(pattern)) |
26 return list(sorted(files)) | 26 return list(sorted(files)) |
27 | 27 |
28 # We've put enough into our environment now to treat BUILD.public as if it were | 28 # With these namespaces, we can treat BUILD.public as if it were |
29 # Python code. This pulls its variable definitions (SRCS, HDRS, DEFINES, etc.) | 29 # Python code. This pulls its variable definitions (SRCS, HDRS, |
30 # into our local namespace. | 30 # DEFINES, etc.) into local_names. |
31 execfile('BUILD.public') | 31 global_names = { |
| 32 'exports_files': noop, |
| 33 'glob': BUILD_glob, |
| 34 } |
| 35 local_names = {} |
| 36 execfile('BUILD.public', global_names, local_names) |
32 | 37 |
33 # Pretty-print every variable whose name is COMPLETELY_UPPERCASE, | |
34 # i.e. every variable from BUILD.public. This is obviously quite heuristic. | |
35 from pprint import pprint | |
36 with open('tools/BUILD.public.expected', 'w') as out: | 38 with open('tools/BUILD.public.expected', 'w') as out: |
37 print >>out, "This file is auto-generated by tools/BUILD_simulator.py." | 39 print >>out, "This file is auto-generated by tools/BUILD_simulator.py." |
38 print >>out, "It expands BUILD.public to make it easy to see changes." | 40 print >>out, "It expands BUILD.public to make it easy to see changes." |
39 for name, value in sorted(locals().items()): | 41 for name, value in sorted(local_names.items()): |
40 if name.isupper(): | 42 print >>out, name, '= ', |
41 print >>out, name, '= ', | 43 pprint.pprint(value, out) |
42 pprint(value, out) | |
OLD | NEW |