Skip to content

Commit

Permalink
[7.0.0] Expose repo mapping manifest to Starlark (bazelbuild#20022)
Browse files Browse the repository at this point in the history
The new `repo_mapping_manifest` field on `FilesToRunProvider` allows
Starlark rule implementations to access the `File` containing the repo
mapping manifest for an executable target, e.g. to include the manifest
into a synthetic runfiles structure for packaging purposes.

Fixes bazelbuild#19937

Closes bazelbuild#19944.

Commit
bazelbuild@3575211

PiperOrigin-RevId: 578735848
Change-Id: Ida78778af5aef4ba0c216815563aef4b54c9d1db

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
  • Loading branch information
bazel-io and fmeum authored Nov 2, 2023
1 parent 8f44ab7 commit f71be9c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
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

0 comments on commit f71be9c

Please sign in to comment.