aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/BUILD_simulator.py
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-08-17 15:02:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-17 15:02:57 -0700
commitdf5b7603d2d2bb3ec75cfbf235a672ee80cf8d3a (patch)
treefcc31bdf2b27b8eb45e7456847a0a5552a3cf526 /tools/BUILD_simulator.py
parente349d6b92574c1b0acdb4ba1ed8ff905ea830131 (diff)
Add a simple script to simulate BUILD file glob() expansion.
This lets us test changes to BUILD.public. This is not yet automated in any way. My hope is to trigger it quietly via the presubmit for any CL that adds or removes a file, or changes BUILD.public. BUG=skia: Review URL: https://codereview.chromium.org/1290833003
Diffstat (limited to 'tools/BUILD_simulator.py')
-rw-r--r--tools/BUILD_simulator.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/BUILD_simulator.py b/tools/BUILD_simulator.py
new file mode 100644
index 0000000000..65e6b7d11e
--- /dev/null
+++ b/tools/BUILD_simulator.py
@@ -0,0 +1,42 @@
+#!/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.
+
+# We don't really care about this, so just no-op it.
+def exports_files(files):
+ pass
+
+# Simulates BUILD file glob().
+def glob(include, exclude=()):
+ from glob import glob as python_glob
+
+ files = set()
+ for pattern in include:
+ files.update(python_glob(pattern))
+ for pattern in exclude:
+ files.difference_update(python_glob(pattern))
+ return list(sorted(files))
+
+# We've put enough into our environment now to treat BUILD.public as if it were
+# Python code. This pulls its variable definitions (SRCS, HDRS, DEFINES, etc.)
+# into our local namespace.
+execfile('BUILD.public')
+
+# Pretty-print every variable whose name is COMPLETELY_UPPERCASE,
+# i.e. every variable from BUILD.public. This is obviously quite heuristic.
+from pprint import pprint
+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."
+ for name, value in sorted(locals().items()):
+ if name.isupper():
+ print >>out, name, '= ',
+ pprint(value, out)