Skip to content

Commit

Permalink
[8.1.0] Implement debugPrint for built-in file providers (#25161)
Browse files Browse the repository at this point in the history
Simplifies `print` style debugging.

Closes #24156.

PiperOrigin-RevId: 721850583
Change-Id: I8b3c3a1063f1dbfa3c0c1556e1112c1885a5c6a9

Commit
fe7b4ab

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
  • Loading branch information
bazel-io and fmeum authored Feb 3, 2025
1 parent 549e13e commit 09cebfc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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<Artifact> getFilesToBuild() {
return filesToBuild;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(")");
}
}

0 comments on commit 09cebfc

Please sign in to comment.