2015-08-17 22:02:57 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright 2015 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
# This script does a very rough simulation of BUILD file expansion,
|
|
|
|
# mostly to see the effects of glob().
|
|
|
|
|
|
|
|
# We start by adding some symbols to our namespace that BUILD.public calls.
|
|
|
|
|
2015-08-18 15:35:45 +00:00
|
|
|
import glob
|
|
|
|
import pprint
|
|
|
|
|
|
|
|
def noop(*args, **kwargs):
|
2015-08-17 22:02:57 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
# Simulates BUILD file glob().
|
2015-08-18 15:35:45 +00:00
|
|
|
def BUILD_glob(include, exclude=()):
|
2015-08-17 22:02:57 +00:00
|
|
|
files = set()
|
|
|
|
for pattern in include:
|
2015-08-18 15:35:45 +00:00
|
|
|
files.update(glob.glob(pattern))
|
2015-08-17 22:02:57 +00:00
|
|
|
for pattern in exclude:
|
2015-08-18 15:35:45 +00:00
|
|
|
files.difference_update(glob.glob(pattern))
|
2015-08-17 22:02:57 +00:00
|
|
|
return list(sorted(files))
|
|
|
|
|
2015-08-18 15:35:45 +00:00
|
|
|
# With these namespaces, we can treat BUILD.public as if it were
|
|
|
|
# Python code. This pulls its variable definitions (SRCS, HDRS,
|
|
|
|
# DEFINES, etc.) into local_names.
|
|
|
|
global_names = {
|
|
|
|
'exports_files': noop,
|
|
|
|
'glob': BUILD_glob,
|
|
|
|
}
|
|
|
|
local_names = {}
|
|
|
|
execfile('BUILD.public', global_names, local_names)
|
2015-08-17 22:02:57 +00:00
|
|
|
|
|
|
|
with open('tools/BUILD.public.expected', 'w') as out:
|
|
|
|
print >>out, "This file is auto-generated by tools/BUILD_simulator.py."
|
|
|
|
print >>out, "It expands BUILD.public to make it easy to see changes."
|
2015-08-18 15:35:45 +00:00
|
|
|
for name, value in sorted(local_names.items()):
|
|
|
|
print >>out, name, '= ',
|
|
|
|
pprint.pprint(value, out)
|