From fe83597b2cdd91031e9926f324e29463c9149958 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Fri, 31 Jan 2025 11:51:46 -0800 Subject: [PATCH] Implement `debugPrint` for built-in file providers Simplifies `print` style debugging. Closes #24156. PiperOrigin-RevId: 721850583 Change-Id: I8b3c3a1063f1dbfa3c0c1556e1112c1885a5c6a9 --- .../com/google/devtools/build/lib/analysis/BUILD | 1 + .../devtools/build/lib/analysis/FileProvider.java | 9 +++++++++ .../build/lib/analysis/FilesToRunProvider.java | 13 +++++++++++++ .../devtools/build/lib/analysis/Runfiles.java | 14 ++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD index df0afa3ed268a0..be1c22b7226dec 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD @@ -795,6 +795,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/collect/nestedset", "//src/main/java/com/google/devtools/build/lib/concurrent", "//src/main/java/com/google/devtools/build/lib/starlarkbuildapi", + "//src/main/java/net/starlark/java/eval", ], ) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/FileProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/FileProvider.java index 2a18929d24279d..a706f45ee99696 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/FileProvider.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/FileProvider.java @@ -21,6 +21,8 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.starlarkbuildapi.FileProviderApi; +import net.starlark.java.eval.Printer; +import net.starlark.java.eval.StarlarkThread; /** * A representation of the concept "this transitive info provider builds these files". @@ -53,6 +55,13 @@ public boolean isImmutable() { return Depset.of(Artifact.class, filesToBuild); } + @Override + public void debugPrint(Printer printer, StarlarkThread thread) { + printer.append("FileProvider(files_to_build = "); + printer.debugPrint(getFilesToBuildForStarlark(), thread); + printer.append(")"); + } + public NestedSet getFilesToBuild() { return filesToBuild; } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java index fb26c9018f3502..804e0f99a0529e 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/FilesToRunProvider.java @@ -23,6 +23,8 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.starlarkbuildapi.FilesToRunProviderApi; import javax.annotation.Nullable; +import net.starlark.java.eval.Printer; +import net.starlark.java.eval.StarlarkThread; /** Returns information about executables produced by a target and the files needed to run it. */ @Immutable @@ -106,6 +108,17 @@ public Artifact getRepoMappingManifest() { return runfilesSupport != null ? runfilesSupport.getRepoMappingManifest() : null; } + @Override + public void debugPrint(Printer printer, StarlarkThread thread) { + printer.append("FilesToRunProvider(executable = "); + printer.debugPrint(getExecutable(), thread); + printer.append(", repo_mapping_manifest = "); + printer.debugPrint(getRepoMappingManifest(), thread); + printer.append(", runfiles_manifest = "); + printer.debugPrint(getRunfilesManifest(), thread); + printer.append(")"); + } + /** A single executable. */ private static final class SingleExecutableFilesToRunProvider extends FilesToRunProvider { diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java index 007467064e45c8..46a720890f043f 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java @@ -55,6 +55,7 @@ import java.util.UUID; import javax.annotation.Nullable; import net.starlark.java.eval.EvalException; +import net.starlark.java.eval.Printer; import net.starlark.java.eval.Sequence; import net.starlark.java.eval.Starlark; import net.starlark.java.eval.StarlarkSemantics; @@ -1104,4 +1105,17 @@ String describeFingerprint(boolean digestAbsolutePaths) { artifacts)) + String.format("emptyFilesSupplier: %s\n", emptyFilesSupplier.getClass().getName()); } + + @Override + public void debugPrint(Printer printer, StarlarkThread thread) { + printer.append("Runfiles(empty_files = "); + printer.debugPrint(getEmptyFilenamesForStarlark(), thread); + printer.append(", files = "); + printer.debugPrint(getArtifactsForStarlark(), thread); + printer.append(", root_symlinks = "); + printer.debugPrint(getRootSymlinksForStarlark(), thread); + printer.append(", symlinks = "); + printer.debugPrint(getSymlinksForStarlark(), thread); + printer.append(")"); + } }