Skip to content

Commit

Permalink
bzlmod: "fork" case for multiple_version_override
Browse files Browse the repository at this point in the history
    (bazelbuild/bazel#13316)

    It's okay for a module depends on foo@1.2 and foo@1.3 with different repo names as long as there's a multiple_version_override for foo that allows both 1.2 and 1.3. If only 1.3 is allowed or if there's no multiple_version_override at all, then selection will succeed right now, and the module will depend on foo@1.3 twice. This CL adds a check that this doesn't happen.

    PiperOrigin-RevId: 384906574
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent e05ead7 commit 86de4b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package com.google.devtools.build.lib.bazel.bzlmod;

import static com.google.common.collect.ImmutableMap.toImmutableMap;

import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
Expand All @@ -25,7 +23,6 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Maps;
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 Down Expand Up @@ -172,8 +169,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
return null;
}
ImmutableMap<ModuleKey, Module> depGraph = discovery.getDepGraph();
RootModuleFileValue rootModule =
(RootModuleFileValue) env.getValue(ModuleFileValue.keyForRootModule());
ModuleFileValue rootModule = (ModuleFileValue) env.getValue(ModuleFileValue.keyForRootModule());
if (rootModule == null) {
return null;
}
Expand Down Expand Up @@ -239,22 +235,7 @@ public SkyValue compute(SkyKey skyKey, Environment env)
throw new SelectionFunctionException(e);
}

newDepGraph = walker.getNewDepGraph();
ImmutableMap<String, ModuleKey> canonicalRepoNameLookup =
depGraph.keySet().stream()
.collect(toImmutableMap(ModuleKey::getCanonicalRepoName, key -> key));
ImmutableMap<String, ModuleKey> moduleNameLookup =
Maps.filterKeys(
newDepGraph,
key -> !(overrides.get(key.getName()) instanceof MultipleVersionOverride))
.keySet()
.stream()
.collect(toImmutableMap(ModuleKey::getName, key -> key));
return SelectionValue.create(
discovery.getRootModuleName(),
walker.getNewDepGraph(),
canonicalRepoNameLookup,
moduleNameLookup);
return SelectionValue.create(discovery.getRootModuleName(), walker.getNewDepGraph());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileValue.RootModuleFileValue;
import com.google.devtools.build.lib.skyframe.SkyFunctions;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
import com.google.devtools.build.skyframe.EvaluationContext;
Expand Down Expand Up @@ -71,14 +70,12 @@ private void setUpSkyFunctions(
public SkyValue compute(SkyKey skyKey, Environment env) {
Preconditions.checkArgument(
skyKey.equals(ModuleFileValue.keyForRootModule()));
return RootModuleFileValue.create(
return ModuleFileValue.create(
Module.builder()
.setName(rootModuleName)
.setVersion(Version.EMPTY)
.build(),
overrides,
// This lookup is not used in this test
ImmutableMap.of());
overrides);
}

@Override
Expand Down

0 comments on commit 86de4b9

Please sign in to comment.