Merge pull request #811 from acozzette:staleness-test

PiperOrigin-RevId: 477840652
diff --git a/cmake/BUILD.bazel b/cmake/BUILD.bazel
index 2be41e5..a4d4ff8 100644
--- a/cmake/BUILD.bazel
+++ b/cmake/BUILD.bazel
@@ -40,6 +40,9 @@
     name = "staleness_test_lib",
     testonly = 1,
     srcs = ["staleness_test_lib.py"],
+    # This is public only for use by the staleness_test() macro. Please do not
+    # depend on this target directly.
+    visibility = ["//visibility:public"],
 )
 
 py_binary(
diff --git a/cmake/build_defs.bzl b/cmake/build_defs.bzl
index 82c37b7..eddeaf0 100644
--- a/cmake/build_defs.bzl
+++ b/cmake/build_defs.bzl
@@ -42,7 +42,7 @@
     """
 
     script_name = name + ".py"
-    script_src = ":staleness_test.py"
+    script_src = Label("//cmake:staleness_test.py")
 
     # Filter out non-existing rules so Blaze doesn't error out before we even
     # run the test.
@@ -57,7 +57,7 @@
         outs = [script_name],
         srcs = [script_src],
         testonly = 1,
-        cmd = "cat $(location " + script_src + ") > $@; " +
+        cmd = "cp $< $@; " +
               "sed -i.bak -e 's|INSERT_FILE_LIST_HERE|" + "\\\n  ".join(file_list) + "|' $@",
     )
 
@@ -67,7 +67,7 @@
         data = existing_outs + [generated_pattern % file for file in outs],
         python_version = "PY3",
         deps = [
-            ":staleness_test_lib",
+            Label("//cmake:staleness_test_lib"),
         ],
         **kwargs
     )