|
| 1 | +// Copyright 2024 The Bazel Authors. All rights reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +package com.google.devtools.build.lib.bazel.rules; |
| 15 | + |
| 16 | +import static com.google.common.truth.Truth.assertThat; |
| 17 | + |
| 18 | +import com.google.common.collect.ImmutableList; |
| 19 | +import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; |
| 20 | +import com.google.devtools.build.lib.packages.AutoloadSymbols; |
| 21 | +import com.google.devtools.build.lib.skyframe.PrecomputedValue; |
| 22 | +import com.google.devtools.build.skyframe.EvaluationContext; |
| 23 | +import com.google.devtools.build.skyframe.SkyKey; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.junit.runners.JUnit4; |
| 27 | + |
| 28 | +@RunWith(JUnit4.class) |
| 29 | +public class AutoloadSymbolsTest extends BuildViewTestCase { |
| 30 | + |
| 31 | + private static final SkyKey AUTOLOAD_SYMBOLS_KEY = AutoloadSymbols.AUTOLOAD_SYMBOLS.getKey(); |
| 32 | + private static final ImmutableList<SkyKey> KEYS_TO_EVALUATE = |
| 33 | + ImmutableList.of(AUTOLOAD_SYMBOLS_KEY); |
| 34 | + |
| 35 | + @Test |
| 36 | + public void bzlmodFlagUpdatesAutoloadConfig() throws Exception { |
| 37 | + EvaluationContext context = |
| 38 | + EvaluationContext.newBuilder().setParallelism(1).setEventHandler(reporter).build(); |
| 39 | + |
| 40 | + setBuildLanguageOptions("--enable_bzlmod"); |
| 41 | + AutoloadSymbols value1 = evaluateAutoloads(context); |
| 42 | + setBuildLanguageOptions("--noenable_bzlmod"); |
| 43 | + AutoloadSymbols value2 = evaluateAutoloads(context); |
| 44 | + |
| 45 | + assertThat(value1).isNotSameInstanceAs(value2); |
| 46 | + } |
| 47 | + |
| 48 | + private AutoloadSymbols evaluateAutoloads(EvaluationContext context) throws InterruptedException { |
| 49 | + return (AutoloadSymbols) |
| 50 | + ((PrecomputedValue) |
| 51 | + skyframeExecutor |
| 52 | + .getEvaluator() |
| 53 | + .evaluate(KEYS_TO_EVALUATE, context) |
| 54 | + .get(AUTOLOAD_SYMBOLS_KEY)) |
| 55 | + .get(); |
| 56 | + } |
| 57 | +} |
0 commit comments