Skip to content

Commit

Permalink
bzlmod: Remove overrides from DiscoveryValue and SelectionValue
Browse files Browse the repository at this point in the history
    (bazelbuild/bazel#13316)

    The overrides cannot be nicely encapsulated in SelectionValue because we need the overrides when fetching modules with non-registry overrides, which happens during discovery. Any consumers of overrides should get them from the ModuleFileValue of the root module directly instead.

    PiperOrigin-RevId: 384236547
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent acb8ab3 commit 4db3bab
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 1,377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.google.devtools.build.lib.bazel.bzlmod;

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileValue.RootModuleFileValue;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyKey;
Expand All @@ -40,12 +39,11 @@ public class DiscoveryFunction implements SkyFunction {
@Override
public SkyValue compute(SkyKey skyKey, Environment env)
throws SkyFunctionException, InterruptedException {
RootModuleFileValue root =
(RootModuleFileValue) env.getValue(ModuleFileValue.keyForRootModule());
ModuleFileValue root = (ModuleFileValue) env.getValue(ModuleFileValue.keyForRootModule());
if (root == null) {
return null;
}
ModuleKey rootModuleKey = ModuleKey.create(root.getModule().getName(), Version.EMPTY);
ModuleKey rootModuleKey = ModuleKey.create(root.getModule().getName(), "");
ImmutableMap<String, ModuleOverride> overrides = root.getOverrides();
Map<ModuleKey, Module> depGraph = new HashMap<>();
depGraph.put(
Expand Down Expand Up @@ -88,13 +86,13 @@ private static Module rewriteDepKeys(
Module module, ImmutableMap<String, ModuleOverride> overrides, String rootModuleName) {
return module.withDepKeysTransformed(
depKey -> {
Version newVersion = depKey.getVersion();
String newVersion = depKey.getVersion();

@Nullable ModuleOverride override = overrides.get(depKey.getName());
if (override instanceof NonRegistryOverride || rootModuleName.equals(depKey.getName())) {
newVersion = Version.EMPTY;
newVersion = "";
} else if (override instanceof SingleVersionOverride) {
Version overrideVersion = ((SingleVersionOverride) override).getVersion();
String overrideVersion = ((SingleVersionOverride) override).getVersion();
if (!overrideVersion.isEmpty()) {
newVersion = overrideVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ public abstract class DiscoveryValue implements SkyValue {
@AutoCodec public static final SkyKey KEY = () -> SkyFunctions.DISCOVERY;

public static DiscoveryValue create(
String rootModuleName,
ImmutableMap<ModuleKey, Module> depGraph,
ImmutableMap<String, ModuleOverride> overrides) {
return new AutoValue_DiscoveryValue(rootModuleName, depGraph, overrides);
String rootModuleName, ImmutableMap<ModuleKey, Module> depGraph) {
return new AutoValue_DiscoveryValue(rootModuleName, depGraph);
}

public abstract String getRootModuleName();

public abstract ImmutableMap<ModuleKey, Module> getDepGraph();

public abstract ImmutableMap<String, ModuleOverride> getOverrides();
}

0 comments on commit 4db3bab

Please sign in to comment.