Skip to content

Commit f71be9c

Browse files
bazel-iofmeum
andauthored
[7.0.0] Expose repo mapping manifest to Starlark (#20022)
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 #19937 Closes #19944. Commit 3575211 PiperOrigin-RevId: 578735848 Change-Id: Ida78778af5aef4ba0c216815563aef4b54c9d1db Co-authored-by: Fabian Meumertzheim <[email protected]>
1 parent 8f44ab7 commit f71be9c

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ public final Artifact getRunfilesManifest() {
9595
return runfilesSupport != null ? runfilesSupport.getRunfilesManifest() : null;
9696
}
9797

98+
@Nullable
99+
@Override
100+
public Artifact getRepoMappingManifest() {
101+
var runfilesSupport = getRunfilesSupport();
102+
return runfilesSupport != null ? runfilesSupport.getRepoMappingManifest() : null;
103+
}
104+
98105
/** Returns a {@link RunfilesSupplier} encapsulating runfiles for this tool. */
99106
public final RunfilesSupplier getRunfilesSupplier() {
100107
return firstNonNull(getRunfilesSupport(), EmptyRunfilesSupplier.INSTANCE);

src/main/java/com/google/devtools/build/lib/starlarkbuildapi/FilesToRunProviderApi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ public interface FilesToRunProviderApi<FileT extends FileApi> extends StarlarkVa
3939
allowReturnNones = true)
4040
@Nullable
4141
FileT getRunfilesManifest();
42+
43+
@StarlarkMethod(
44+
name = "repo_mapping_manifest",
45+
doc = "The repo mapping manifest or None if it does not exist.",
46+
structField = true,
47+
allowReturnNones = true)
48+
@Nullable
49+
FileT getRepoMappingManifest();
4250
}

src/test/java/com/google/devtools/build/lib/analysis/RunfilesRepoMappingManifestTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,32 @@ public void hasMappingForSymlinks() throws Exception {
391391
.inOrder();
392392
}
393393

394+
@Test
395+
public void repoMappingOnFilesToRunProvider() throws Exception {
396+
scratch.overwriteFile("MODULE.bazel", "bazel_dep(name='bare_rule',version='1.0')");
397+
scratch.overwriteFile(
398+
"defs.bzl",
399+
"def _get_repo_mapping_impl(ctx):",
400+
" files_to_run = ctx.attr.bin[DefaultInfo].files_to_run",
401+
" return [",
402+
" DefaultInfo(files = depset([files_to_run.repo_mapping_manifest])),",
403+
" ]",
404+
"get_repo_mapping = rule(",
405+
" implementation = _get_repo_mapping_impl,",
406+
" attrs = {'bin':attr.label(cfg='target',executable=True)}",
407+
")");
408+
scratch.overwriteFile(
409+
"BUILD",
410+
"load('@bare_rule//:defs.bzl', 'bare_binary')",
411+
"load('//:defs.bzl', 'get_repo_mapping')",
412+
"bare_binary(name='aaa')",
413+
"get_repo_mapping(name='get_repo_mapping', bin=':aaa')");
414+
invalidatePackages();
415+
416+
assertThat(getFilesToBuild(getConfiguredTarget("//:get_repo_mapping")).toList())
417+
.containsExactly(getRunfilesSupport("//:aaa").getRepoMappingManifest());
418+
}
419+
394420
/**
395421
* Similar to {@link BuildViewTestCase#rewriteWorkspace(String...)}, but does not call {@link
396422
* BuildViewTestCase#invalidatePackages()}.

0 commit comments

Comments
 (0)