Add a test case for ctx.build_file_path.
@@ -2421,6 +2421,7 @@ public final class StarlarkRuleContextTest extends BuildViewTestCase {
"actions.run_shell(command = 'foo', outputs = [file])",
"actions.write(file, 'foo')",
"check_placeholders('foo', [])",
+ "build_file_path",
"runfiles()",
"resolve_command(command = 'foo')",
"resolve_tools()");
@@ -2995,4 +2996,23 @@ public final class StarlarkRuleContextTest extends BuildViewTestCase {
assertThrows(AssertionError.class, () -> getConfiguredTarget("//something:nectarine"));
assertContainsEvent("Exec group name '" + badName + "' is not a valid name.");
}
+
+ @Test
+ public void testBuildFilePath() throws Exception {
+ scratch.file("/foo/WORKSPACE");
+ scratch.file("/foo/bar/BUILD", "genrule(name = 'baz', cmd = 'dummy_cmd', outs = ['a.txt'])");
+
+ scratch.overwriteFile(
+ "WORKSPACE",
+ new ImmutableList.Builder<String>()
+ .addAll(analysisMock.getWorkspaceContents(mockToolsConfig))
+ .add("local_repository(name='foo', path='/foo')")
+ .build());
+
+ invalidatePackages(false);
+
+ setRuleContext(createRuleContext("@foo//bar:baz"));
+ Object result = ev.eval("ruleContext.build_file_path");
+ assertThat(result).isEqualTo("foo/bar/BUILD");
+ }
}
