Pārlūkot izejas kodu

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>
Jon Meow 4 gadi atpakaļ
vecāks
revīzija
642addfe48
1 mainītis faili ar 22 papildinājumiem un 5 dzēšanām
  1. 22 5
      executable_semantics/tests.py

+ 22 - 5
executable_semantics/tests.py

@@ -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.")