Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose repo mapping manifest to Starlark #19944

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public final Artifact getRunfilesManifest() {
return runfilesSupport != null ? runfilesSupport.getRunfilesManifest() : null;
}

@Nullable
@Override
public Artifact getRepoMappingManifest() {
var runfilesSupport = getRunfilesSupport();
return runfilesSupport != null ? runfilesSupport.getRepoMappingManifest() : null;
}

/** Returns a {@link RunfilesSupplier} encapsulating runfiles for this tool. */
public final RunfilesSupplier getRunfilesSupplier() {
return firstNonNull(getRunfilesSupport(), EmptyRunfilesSupplier.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ public interface FilesToRunProviderApi<FileT extends FileApi> extends StarlarkVa
allowReturnNones = true)
@Nullable
FileT getRunfilesManifest();

@StarlarkMethod(
name = "repo_mapping_manifest",
doc = "The repo mapping manifest or None if it does not exist.",
structField = true,
allowReturnNones = true)
@Nullable
FileT getRepoMappingManifest();
}
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,32 @@ public void hasMappingForSymlinks() throws Exception {
.inOrder();
}

@Test
public void repoMappingOnFilesToRunProvider() throws Exception {
scratch.overwriteFile("MODULE.bazel", "bazel_dep(name='bare_rule',version='1.0')");
scratch.overwriteFile(
"defs.bzl",
"def _get_repo_mapping_impl(ctx):",
" files_to_run = ctx.attr.bin[DefaultInfo].files_to_run",
" return [",
" DefaultInfo(files = depset([files_to_run.repo_mapping_manifest])),",
" ]",
"get_repo_mapping = rule(",
" implementation = _get_repo_mapping_impl,",
" attrs = {'bin':attr.label(cfg='target',executable=True)}",
")");
scratch.overwriteFile(
"BUILD",
"load('@bare_rule//:defs.bzl', 'bare_binary')",
"load('//:defs.bzl', 'get_repo_mapping')",
"bare_binary(name='aaa')",
"get_repo_mapping(name='get_repo_mapping', bin=':aaa')");
invalidatePackages();

assertThat(getFilesToBuild(getConfiguredTarget("//:get_repo_mapping")).toList())
.containsExactly(getRunfilesSupport("//:aaa").getRepoMappingManifest());
}

/**
* Similar to {@link BuildViewTestCase#rewriteWorkspace(String...)}, but does not call {@link
* BuildViewTestCase#invalidatePackages()}.
Expand Down
Loading