|
14 | 14 | package com.google.devtools.build.lib.analysis;
|
15 | 15 |
|
16 | 16 | import static com.google.common.truth.Truth.assertThat;
|
| 17 | +import static com.google.devtools.build.lib.bazel.bzlmod.BzlmodTestUtil.createModuleKey; |
17 | 18 |
|
| 19 | +import com.google.common.collect.ImmutableList; |
18 | 20 | import com.google.common.collect.ImmutableMap;
|
19 | 21 | import com.google.common.collect.ImmutableSet;
|
20 | 22 | import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
|
|
23 | 25 | import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
|
24 | 26 | import com.google.devtools.build.lib.analysis.util.DummyTestFragment;
|
25 | 27 | import com.google.devtools.build.lib.analysis.util.DummyTestFragment.DummyTestOptions;
|
| 28 | +import com.google.devtools.build.lib.bazel.bzlmod.BazelModuleResolutionFunction; |
| 29 | +import com.google.devtools.build.lib.bazel.bzlmod.FakeRegistry; |
| 30 | +import com.google.devtools.build.lib.bazel.bzlmod.ModuleFileFunction; |
| 31 | +import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.CheckDirectDepsMode; |
26 | 32 | import com.google.devtools.build.lib.cmdline.Label;
|
27 | 33 | import com.google.devtools.build.lib.packages.Rule;
|
28 | 34 | import com.google.devtools.build.lib.packages.RuleTransitionData;
|
29 | 35 | import com.google.devtools.build.lib.rules.cpp.CppOptions;
|
30 | 36 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
|
| 37 | +import com.google.devtools.build.lib.skyframe.PrecomputedValue; |
| 38 | +import com.google.devtools.build.lib.skyframe.PrecomputedValue.Injected; |
31 | 39 | import com.google.devtools.build.lib.testutil.TestConstants;
|
32 | 40 | import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
|
33 | 41 | import com.google.devtools.build.lib.vfs.ModifiedFileSet;
|
34 | 42 | import com.google.devtools.build.lib.vfs.PathFragment;
|
35 | 43 | import com.google.devtools.build.lib.vfs.Root;
|
36 | 44 | import com.google.testing.junit.testparameterinjector.TestParameterInjector;
|
37 | 45 | import com.google.testing.junit.testparameterinjector.TestParameters;
|
| 46 | +import java.io.IOException; |
38 | 47 | import java.util.List;
|
39 | 48 | import java.util.Map;
|
40 | 49 | import java.util.regex.Pattern;
|
|
44 | 53 | /** Tests for StarlarkRuleTransitionProvider. */
|
45 | 54 | @RunWith(TestParameterInjector.class)
|
46 | 55 | public final class StarlarkRuleTransitionProviderTest extends BuildViewTestCase {
|
| 56 | + private FakeRegistry registry; |
| 57 | + |
| 58 | + @Override |
| 59 | + protected ImmutableList<Injected> extraPrecomputedValues() { |
| 60 | + try { |
| 61 | + registry = |
| 62 | + FakeRegistry.DEFAULT_FACTORY.newFakeRegistry(scratch.dir("modules").getPathString()); |
| 63 | + } catch (IOException e) { |
| 64 | + throw new IllegalStateException(e); |
| 65 | + } |
| 66 | + return ImmutableList.of( |
| 67 | + PrecomputedValue.injected( |
| 68 | + ModuleFileFunction.REGISTRIES, ImmutableList.of(registry.getUrl())), |
| 69 | + PrecomputedValue.injected(ModuleFileFunction.IGNORE_DEV_DEPS, false), |
| 70 | + PrecomputedValue.injected( |
| 71 | + BazelModuleResolutionFunction.CHECK_DIRECT_DEPENDENCIES, CheckDirectDepsMode.WARNING)); |
| 72 | + } |
47 | 73 |
|
48 | 74 | @Override
|
49 | 75 | protected ConfiguredRuleClassProvider createRuleClassProvider() {
|
@@ -1272,6 +1298,50 @@ public void successfulTypeConversionOfNativeListOption() throws Exception {
|
1272 | 1298 | assertNoEvents();
|
1273 | 1299 | }
|
1274 | 1300 |
|
| 1301 | + @Test |
| 1302 | + public void successfulTypeConversionOfNativeListOption_unambiguousLabels() throws Exception { |
| 1303 | + setBuildLanguageOptions("--enable_bzlmod", "--incompatible_unambiguous_label_stringification"); |
| 1304 | + |
| 1305 | + scratch.overwriteFile("MODULE.bazel", "bazel_dep(name='rules_x',version='1.0')"); |
| 1306 | + registry.addModule(createModuleKey("rules_x", "1.0"), "module(name='rules_x', version='1.0')"); |
| 1307 | + scratch.file("modules/rules_x~1.0/WORKSPACE"); |
| 1308 | + scratch.file("modules/rules_x~1.0/BUILD"); |
| 1309 | + scratch.file( |
| 1310 | + "modules/rules_x~1.0/defs.bzl", |
| 1311 | + "def _tr_impl(settings, attr):", |
| 1312 | + " return {'//command_line_option:platforms': [Label('@@//test:my_platform')]}", |
| 1313 | + "my_transition = transition(implementation = _tr_impl, inputs = [],", |
| 1314 | + " outputs = ['//command_line_option:platforms'])", |
| 1315 | + "def _impl(ctx):", |
| 1316 | + " pass", |
| 1317 | + "my_rule = rule(", |
| 1318 | + " implementation = _impl,", |
| 1319 | + " cfg = my_transition,", |
| 1320 | + " attrs = {", |
| 1321 | + " '_allowlist_function_transition': attr.label(", |
| 1322 | + " default = '@@//tools/allowlists/function_transition_allowlist',", |
| 1323 | + " ),", |
| 1324 | + " })"); |
| 1325 | + |
| 1326 | + scratch.overwriteFile( |
| 1327 | + "tools/allowlists/function_transition_allowlist/BUILD", |
| 1328 | + "package_group(", |
| 1329 | + " name = 'function_transition_allowlist',", |
| 1330 | + " packages = [", |
| 1331 | + " '//...',", |
| 1332 | + " ],", |
| 1333 | + ")"); |
| 1334 | + |
| 1335 | + scratch.file( |
| 1336 | + "test/BUILD", |
| 1337 | + "load('@rules_x//:defs.bzl', 'my_rule')", |
| 1338 | + "platform(name = 'my_platform')", |
| 1339 | + "my_rule(name = 'test')"); |
| 1340 | + |
| 1341 | + getConfiguredTarget("//test"); |
| 1342 | + assertNoEvents(); |
| 1343 | + } |
| 1344 | + |
1275 | 1345 | // Regression test for b/170729565
|
1276 | 1346 | @Test
|
1277 | 1347 | public void testSetBooleanNativeOptionWithStarlarkBoolean() throws Exception {
|
|
0 commit comments