mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Fix caching and correctness of --update_goldens (#709)
- `PATH` is a caching issue, as commented. - `exec.map` is a correctness issue, the reference to `test` was incorrect on threading so it wasn't updating all tests. Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
committed by
GitHub
co-authored by
Geoff Romer
parent
2e9e4f4cb3
commit
642addfe48
@@ -132,6 +132,20 @@ def _update_golden(test):
|
||||
|
||||
def _update_goldens():
|
||||
"""Runs bazel to update golden files."""
|
||||
# This should typically be called through pyenv due to the shebang. However,
|
||||
# pyenv then modifies the PATH, which affects build caching. In order to
|
||||
# mimic the calling environment for bazel, this strips out PATH entries
|
||||
# which pyenv likely added.
|
||||
# TODO: remove this when/if we're able to add
|
||||
# `--incompatible_strict_action_env=true` to the project .bazelrc, because
|
||||
# that will cause Bazel to ignore PATH.
|
||||
env = os.environ.copy()
|
||||
stripped_path = []
|
||||
for x in env["PATH"].split(":"):
|
||||
if not ("/Cellar/pyenv/" in x or "/.pyenv/versions/" in x):
|
||||
stripped_path.append(x)
|
||||
env["PATH"] = ":".join(stripped_path)
|
||||
|
||||
# Load tests from the bzl file. This isn't done through os.listdir because
|
||||
# building new tests requires --update_list.
|
||||
bzl_content = open(_TEST_LIST_BZL).read()
|
||||
@@ -140,15 +154,18 @@ def _update_goldens():
|
||||
# Build all tests at once in order to allow parallel updates.
|
||||
print("Building tests...")
|
||||
subprocess.check_call(
|
||||
["bazel", "build", "//executable_semantics:golden_tests"]
|
||||
[
|
||||
"bazel",
|
||||
"build",
|
||||
"//executable_semantics:golden_tests",
|
||||
],
|
||||
env=env,
|
||||
)
|
||||
|
||||
print("Updating %d goldens..." % len(tests))
|
||||
with futures.ThreadPoolExecutor() as exec:
|
||||
results = [exec.submit(lambda: _update_golden(test)) for test in tests]
|
||||
# Propagate exceptions.
|
||||
for result in results:
|
||||
result.result()
|
||||
# list() iterates to propagate exceptions.
|
||||
list([exec.map(_update_golden, tests)])
|
||||
# Each golden indicates progress with a dot without a newline, so put a
|
||||
# newline to wrap.
|
||||
print("\nUpdated goldens.")
|
||||
|
||||
Reference in New Issue
Block a user