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