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

[8.0.0] Include apparent names of deps in bazel mod JSON output #24234

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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 @@ -106,7 +106,11 @@ public static ImmutableMap<ModuleKey, AugmentedModule> computeAugmentedGraph(
AugmentedModule.Builder parentBuilder =
depGraphAugmentBuilder
.computeIfAbsent(
parentKey, k -> AugmentedModule.builder(k).setName(parentModule.getName()))
parentKey,
k ->
AugmentedModule.builder(k)
.setName(parentModule.getName())
.setRepoName(parentModule.getRepoName()))
.setVersion(parentModule.getVersion())
.setLoaded(true);

Expand All @@ -122,6 +126,7 @@ public static ImmutableMap<ModuleKey, AugmentedModule> computeAugmentedGraph(
originalChildBuilder
.setName(originalModule.getName())
.setVersion(originalModule.getVersion())
.setRepoName(originalModule.getRepoName())
.setLoaded(true);
}

Expand All @@ -132,6 +137,7 @@ public static ImmutableMap<ModuleKey, AugmentedModule> computeAugmentedGraph(
AugmentedModule.builder(k)
.setName(module.getName())
.setVersion(module.getVersion())
.setRepoName(module.getRepoName())
.setLoaded(true));

// originalDependants and dependants can differ because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public abstract static class AugmentedModule {
/** {@link ModuleKey} of this module. Same as in {@link Module} */
public abstract ModuleKey getKey();

/** The apparent name used by the module to refer to its own repository. */
public abstract String getRepoName();

/**
* The set of modules in the resolved dep graph that depend on this module
* <strong>after</strong> the module resolution.
Expand Down Expand Up @@ -154,6 +157,7 @@ public static AugmentedModule.Builder builder(ModuleKey key) {
return new AutoValue_BazelModuleInspectorValue_AugmentedModule.Builder()
.setName(key.name())
.setVersion(key.version())
.setRepoName(key.name())
.setKey(key)
.setLoaded(false);
}
Expand All @@ -167,6 +171,8 @@ public abstract static class Builder {

public abstract AugmentedModule.Builder setKey(ModuleKey value);

public abstract AugmentedModule.Builder setRepoName(String value);

public abstract AugmentedModule.Builder setLoaded(boolean value);

abstract ImmutableSet.Builder<ModuleKey> originalDependantsBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nullable;

/** Outputs graph-based results of {@link ModExecutor} in JSON format. */
public class JsonOutputFormatter extends OutputFormatter {
Expand Down Expand Up @@ -89,17 +90,22 @@ private JsonObject printExtension(

// Depth-first traversal to display modules (while explicitly detecting cycles)
JsonObject printModule(
ModuleKey key, ModuleKey parent, IsExpanded expanded, IsIndirect indirect) {
ModuleKey key, @Nullable ModuleKey parent, IsExpanded expanded, IsIndirect indirect) {
ResultNode node = result.get(key);
AugmentedModule module = depGraph.get(key);
JsonObject json = new JsonObject();
json.addProperty("key", printKey(key));
if (!key.name().equals(module.getName())) {
json.addProperty("name", module.getName());
}
if (!key.version().equals(module.getVersion())) {
json.addProperty("version", module.getVersion().toString());
json.addProperty("name", module.getName());
json.addProperty("version", module.getVersion().toString());
String apparentName;
if (parent != null) {
// The apparent repository name under which parent refers to key.
apparentName = depGraph.get(parent).getDeps().inverse().get(key);
} else {
// The apparent repository name under which key refers to itself.
apparentName = module.getRepoName();
}
json.addProperty("apparentName", apparentName);

if (indirect == IsIndirect.FALSE && options.verbose && parent != null) {
Explanation explanation = getExtraResolutionExplanation(key, parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ public static AugmentedModuleBuilder buildAugmentedModule(
AugmentedModuleBuilder myBuilder = new AugmentedModuleBuilder();
myBuilder.key = key;
myBuilder.builder =
AugmentedModule.builder(key).setName(name).setVersion(version).setLoaded(loaded);
AugmentedModule.builder(key)
.setName(name)
.setVersion(version)
.setRepoName(name)
.setLoaded(loaded);
return myBuilder;
}

Expand Down
Loading