blob: 46d3cd79e7008511d4b322b4153ef488565c5da4 [file] [log] [blame]
mtkleindf5b7602015-08-17 15:02:57 -07001#!/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
halcanarybf3dde22015-08-18 08:35:45 -070013import glob
14import pprint
15
16def noop(*args, **kwargs):
mtkleindf5b7602015-08-17 15:02:57 -070017 pass
18
19# Simulates BUILD file glob().
halcanarybf3dde22015-08-18 08:35:45 -070020def BUILD_glob(include, exclude=()):
mtkleindf5b7602015-08-17 15:02:57 -070021 files = set()
22 for pattern in include:
halcanarybf3dde22015-08-18 08:35:45 -070023 files.update(glob.glob(pattern))
mtkleindf5b7602015-08-17 15:02:57 -070024 for pattern in exclude:
halcanarybf3dde22015-08-18 08:35:45 -070025 files.difference_update(glob.glob(pattern))
mtkleindf5b7602015-08-17 15:02:57 -070026 return list(sorted(files))
27
halcanarybf3dde22015-08-18 08:35:45 -070028# 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.
31global_names = {
32 'exports_files': noop,
33 'glob': BUILD_glob,
34}
35local_names = {}
36execfile('BUILD.public', global_names, local_names)
mtkleindf5b7602015-08-17 15:02:57 -070037
mtkleindf5b7602015-08-17 15:02:57 -070038with 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."
halcanarybf3dde22015-08-18 08:35:45 -070041 for name, value in sorted(local_names.items()):
42 print >>out, name, '= ',
43 pprint.pprint(value, out)