|
18 | 18 | import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; |
19 | 19 |
|
20 | 20 | import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; |
| 21 | +import com.google.devtools.build.lib.analysis.config.CoreOptions.IncludeConfigFragmentsEnum; |
21 | 22 | import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; |
22 | 23 | import com.google.devtools.build.lib.packages.AspectDefinition; |
23 | 24 | import com.google.devtools.build.lib.packages.AspectParameters; |
|
31 | 32 | import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; |
32 | 33 | import com.google.devtools.build.lib.testutil.TestRuleClassProvider; |
33 | 34 | import com.google.devtools.build.lib.util.FileTypeSet; |
| 35 | +import com.google.testing.junit.testparameterinjector.TestParameter; |
| 36 | +import com.google.testing.junit.testparameterinjector.TestParameterInjector; |
34 | 37 | import org.junit.Test; |
35 | 38 | import org.junit.runner.RunWith; |
36 | | -import org.junit.runners.JUnit4; |
37 | 39 |
|
38 | 40 | /** Tests for {@link RequiredConfigFragmentsProvider}. */ |
39 | | -@RunWith(JUnit4.class) |
| 41 | +@RunWith(TestParameterInjector.class) |
40 | 42 | public final class RequiredConfigFragmentsTest extends BuildViewTestCase { |
41 | 43 |
|
42 | 44 | @Test |
@@ -350,4 +352,93 @@ public void starlarkAttrTransition() throws Exception { |
350 | 352 | // But not the child's rule transition. |
351 | 353 | assertThat(requiredFragments.getOptionsClasses()).doesNotContain(CppOptions.class); |
352 | 354 | } |
| 355 | + |
| 356 | + @Test |
| 357 | + public void aspectInheritsTransitiveFragmentsFromBaseCT( |
| 358 | + @TestParameter({"DIRECT", "TRANSITIVE"}) IncludeConfigFragmentsEnum setting) |
| 359 | + throws Exception { |
| 360 | + writeStarlarkTransitionsAndAllowList(); |
| 361 | + scratch.file( |
| 362 | + "a/defs.bzl", |
| 363 | + "", |
| 364 | + "A1Info = provider()", |
| 365 | + "def _a1_impl(target, ctx):", |
| 366 | + " return []", |
| 367 | + "a1 = aspect(implementation = _a1_impl)", |
| 368 | + "", |
| 369 | + "def _java_depender_impl(ctx):", |
| 370 | + " return []", |
| 371 | + "java_depender = rule(", |
| 372 | + " implementation = _java_depender_impl,", |
| 373 | + " fragments = ['java'],", |
| 374 | + " attrs = {})", |
| 375 | + "", |
| 376 | + "def _r_impl(ctx):", |
| 377 | + " return []", |
| 378 | + "r = rule(", |
| 379 | + " implementation = _r_impl,", |
| 380 | + " attrs = {'dep': attr.label(aspects = [a1])})"); |
| 381 | + scratch.file( |
| 382 | + "a/BUILD", |
| 383 | + "load(':defs.bzl', 'java_depender', 'r')", |
| 384 | + "java_depender(name = 'lib')", |
| 385 | + "r(name = 'r', dep = ':lib')"); |
| 386 | + |
| 387 | + useConfiguration("--include_config_fragments_provider=" + setting); |
| 388 | + getConfiguredTarget("//a:r"); |
| 389 | + RequiredConfigFragmentsProvider requiredFragments = |
| 390 | + getAspect("//a:defs.bzl%a1").getProvider(RequiredConfigFragmentsProvider.class); |
| 391 | + |
| 392 | + if (setting == IncludeConfigFragmentsEnum.TRANSITIVE) { |
| 393 | + assertThat(requiredFragments.getFragmentClasses()).contains(JavaConfiguration.class); |
| 394 | + } else { |
| 395 | + assertThat(requiredFragments.getFragmentClasses()).doesNotContain(JavaConfiguration.class); |
| 396 | + } |
| 397 | + } |
| 398 | + |
| 399 | + @Test |
| 400 | + public void aspectInheritsTransitiveFragmentsFromRequiredAspect( |
| 401 | + @TestParameter({"DIRECT", "TRANSITIVE"}) IncludeConfigFragmentsEnum setting) |
| 402 | + throws Exception { |
| 403 | + scratch.file( |
| 404 | + "a/defs.bzl", |
| 405 | + "", |
| 406 | + "A1Info = provider()", |
| 407 | + "def _a1_impl(target, ctx):", |
| 408 | + " return A1Info(var = ctx.var.get('my_var', '0'))", |
| 409 | + "a1 = aspect(implementation = _a1_impl, provides = [A1Info])", |
| 410 | + "", |
| 411 | + "A2Info = provider()", |
| 412 | + "def _a2_impl(target, ctx):", |
| 413 | + " return A2Info()", |
| 414 | + "a2 = aspect(implementation = _a2_impl, required_aspect_providers = [A1Info])", |
| 415 | + "", |
| 416 | + "def _simple_rule_impl(ctx):", |
| 417 | + " return []", |
| 418 | + "simple_rule = rule(", |
| 419 | + " implementation = _simple_rule_impl,", |
| 420 | + " attrs = {})", |
| 421 | + "", |
| 422 | + "def _r_impl(ctx):", |
| 423 | + " return []", |
| 424 | + "r = rule(", |
| 425 | + " implementation = _r_impl,", |
| 426 | + " attrs = {'dep': attr.label(aspects = [a1, a2])})"); |
| 427 | + scratch.file( |
| 428 | + "a/BUILD", |
| 429 | + "load(':defs.bzl', 'r', 'simple_rule')", |
| 430 | + "simple_rule(name = 'lib')", |
| 431 | + "r(name = 'r', dep = ':lib')"); |
| 432 | + |
| 433 | + useConfiguration("--include_config_fragments_provider=" + setting, "--define", "my_var=1"); |
| 434 | + getConfiguredTarget("//a:r"); |
| 435 | + RequiredConfigFragmentsProvider requiredFragments = |
| 436 | + getAspect("//a:defs.bzl%a2").getProvider(RequiredConfigFragmentsProvider.class); |
| 437 | + |
| 438 | + if (setting == IncludeConfigFragmentsEnum.TRANSITIVE) { |
| 439 | + assertThat(requiredFragments.getDefines()).contains("my_var"); |
| 440 | + } else { |
| 441 | + assertThat(requiredFragments.getDefines()).doesNotContain("my_var"); |
| 442 | + } |
| 443 | + } |
353 | 444 | } |
0 commit comments