Skip to content

Commit

Permalink
Fix Autoloads skyframe injection
Browse files Browse the repository at this point in the history
Before this, changing the value of `--enable_bzlmod` did not invalidate the existing skyframe precomputed value as the instances were considered the same/equal (see `src/main/java/com/google/devtools/build/skyframe/AbstractInMemoryMemoizingEvaluator.java#pruneInjectedValues`)

Fixes bazelbuild/rules_python#2387

PiperOrigin-RevId: 695696010
Change-Id: I136f2bec4e2c668d020f6cb1a7d3200f7523e5a0
  • Loading branch information
hvadehra authored and copybara-github committed Nov 12, 2024
1 parent 5b25f8c commit a5b6c30
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,11 @@ public final int hashCode() {
// These fields are used to generate all other private fields.
// Thus, other fields don't need to be included in hash code.
return Objects.hash(
autoloadedSymbols, removedSymbols, partiallyRemovedSymbols, reposDisallowingAutoloads);
bzlmodEnabled,
autoloadedSymbols,
removedSymbols,
partiallyRemovedSymbols,
reposDisallowingAutoloads);
}

@Override
Expand All @@ -553,7 +557,8 @@ public final boolean equals(Object that) {
AutoloadSymbols other = (AutoloadSymbols) that;
// These fields are used to generate all other private fields.
// Thus, other fields don't need to be included in comparison.
return this.autoloadedSymbols.equals(other.autoloadedSymbols)
return this.bzlmodEnabled == other.bzlmodEnabled
&& this.autoloadedSymbols.equals(other.autoloadedSymbols)
&& this.removedSymbols.equals(other.removedSymbols)
&& this.partiallyRemovedSymbols.equals(other.partiallyRemovedSymbols)
&& this.reposDisallowingAutoloads.equals(other.reposDisallowingAutoloads);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.devtools.build.lib.bazel.rules;

import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.packages.AutoloadSymbols;
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.skyframe.EvaluationContext;
import com.google.devtools.build.skyframe.SkyKey;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class AutoloadSymbolsTest extends BuildViewTestCase {

private static final SkyKey AUTOLOAD_SYMBOLS_KEY = AutoloadSymbols.AUTOLOAD_SYMBOLS.getKey();
private static final ImmutableList<SkyKey> KEYS_TO_EVALUATE =
ImmutableList.of(AUTOLOAD_SYMBOLS_KEY);

@Test
public void bzlmodFlagUpdatesAutoloadConfig() throws Exception {
EvaluationContext context =
EvaluationContext.newBuilder().setParallelism(1).setEventHandler(reporter).build();

setBuildLanguageOptions("--enable_bzlmod");
AutoloadSymbols value1 = evaluateAutoloads(context);
setBuildLanguageOptions("--noenable_bzlmod");
AutoloadSymbols value2 = evaluateAutoloads(context);

assertThat(value1).isNotSameInstanceAs(value2);
}

private AutoloadSymbols evaluateAutoloads(EvaluationContext context) throws InterruptedException {
return (AutoloadSymbols)
((PrecomputedValue)
skyframeExecutor
.getEvaluator()
.evaluate(KEYS_TO_EVALUATE, context)
.get(AUTOLOAD_SYMBOLS_KEY))
.get();
}
}
4 changes: 4 additions & 0 deletions src/test/java/com/google/devtools/build/lib/bazel/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/bazel/rules",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages:autoload_symbols",
"//src/main/java/com/google/devtools/build/lib/rules:core_workspace_rules",
"//src/main/java/com/google/devtools/build/lib/rules/config",
"//src/main/java/com/google/devtools/build/lib/rules/core",
"//src/main/java/com/google/devtools/build/lib/skyframe:precomputed_value",
"//src/main/java/com/google/devtools/build/lib/util:os",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/com/google/devtools/common/options",
"//src/test/java/com/google/devtools/build/lib/analysis/util",
"//third_party:guava",
Expand Down

0 comments on commit a5b6c30

Please sign in to comment.