@@ -1137,10 +1137,59 @@ public void testTransitionOnBuildSetting_fromCommandLine() throws Exception {
1137
1137
.isEqualTo (StarlarkInt .of (42 ));
1138
1138
}
1139
1139
1140
+ @ Test
1141
+ public void testTransitionOnBuildSetting_onlyTransitionsAffectsDirectory () throws Exception {
1142
+ writeAllowlistFile ();
1143
+ writeBuildSettingsBzl ();
1144
+ writeRulesWithAttrTransitionBzl ();
1145
+ scratch .file (
1146
+ "test/starlark/BUILD" ,
1147
+ "load('//test/starlark:rules.bzl', 'my_rule')" ,
1148
+ "load('//test/starlark:build_settings.bzl', 'int_flag')" ,
1149
+ "my_rule(name = 'test', dep = ':dep')" ,
1150
+ "my_rule(name = 'dep')" ,
1151
+ "int_flag(name = 'the-answer', build_setting_default = 0)" ,
1152
+ "int_flag(name = 'cmd-line-option', build_setting_default = 0)" );
1153
+
1154
+ useConfiguration (ImmutableMap .of ("//test/starlark:cmd-line-option" , 100 ), "--cpu=FOO" );
1155
+
1156
+ ConfiguredTarget test = getConfiguredTarget ("//test/starlark:test" );
1157
+
1158
+ @ SuppressWarnings ("unchecked" )
1159
+ ConfiguredTarget dep =
1160
+ Iterables .getOnlyElement (
1161
+ (List <ConfiguredTarget >) getMyInfoFromTarget (test ).getValue ("dep" ));
1162
+
1163
+ // Assert starlark option set via transition.
1164
+ assertThat (getStarlarkOption (dep , "//test/starlark:the-answer" )).isEqualTo (StarlarkInt .of (42 ));
1165
+
1166
+ // Assert starlark option set via command line.
1167
+ assertThat (getStarlarkOption (dep , "//test/starlark:cmd-line-option" )).isEqualTo (100 );
1168
+
1169
+ // Assert native option set via command line.
1170
+ assertThat (getCoreOptions (dep ).cpu ).isEqualTo ("FOO" );
1171
+
1172
+ // Assert that transitionDirectoryNameFragment is only affected by options
1173
+ // set via transitions. Not by native or starlark options set via command line,
1174
+ // never touched by any transition.
1175
+ assertThat (getCoreOptions (dep ).transitionDirectoryNameFragment )
1176
+ .isEqualTo (
1177
+ FunctionTransitionUtil .transitionDirectoryNameFragment (
1178
+ ImmutableList .of ("//test/starlark:the-answer=42" )));
1179
+ }
1180
+
1140
1181
private CoreOptions getCoreOptions (ConfiguredTarget target ) {
1141
1182
return getConfiguration (target ).getOptions ().get (CoreOptions .class );
1142
1183
}
1143
1184
1185
+ private ImmutableMap <Label , Object > getStarlarkOptions (ConfiguredTarget target ) {
1186
+ return getConfiguration (target ).getOptions ().getStarlarkOptions ();
1187
+ }
1188
+
1189
+ private Object getStarlarkOption (ConfiguredTarget target , String absName ) {
1190
+ return getStarlarkOptions (target ).get (Label .parseAbsoluteUnchecked (absName ));
1191
+ }
1192
+
1144
1193
@ Test
1145
1194
public void testOutputDirHash_multipleNativeOptionTransitions () throws Exception {
1146
1195
writeAllowlistFile ();
@@ -1182,7 +1231,7 @@ public void testOutputDirHash_multipleNativeOptionTransitions() throws Exception
1182
1231
1183
1232
List <String > affectedOptions = getCoreOptions (test ).affectedByStarlarkTransition ;
1184
1233
1185
- assertThat (affectedOptions ).containsExactly ("foo" );
1234
+ assertThat (affectedOptions ).containsExactly ("//command_line_option: foo" );
1186
1235
1187
1236
@ SuppressWarnings ("unchecked" )
1188
1237
ConfiguredTarget dep =
@@ -1191,17 +1240,19 @@ public void testOutputDirHash_multipleNativeOptionTransitions() throws Exception
1191
1240
1192
1241
affectedOptions = getCoreOptions (dep ).affectedByStarlarkTransition ;
1193
1242
1194
- assertThat (affectedOptions ).containsExactly ("foo" , "bar" );
1243
+ assertThat (affectedOptions )
1244
+ .containsExactly ("//command_line_option:foo" , "//command_line_option:bar" );
1195
1245
1196
1246
assertThat (getCoreOptions (test ).transitionDirectoryNameFragment )
1197
1247
.isEqualTo (
1198
1248
FunctionTransitionUtil .transitionDirectoryNameFragment (
1199
- ImmutableList .of ("foo=foosball" )));
1249
+ ImmutableList .of ("//command_line_option: foo=foosball" )));
1200
1250
1201
1251
assertThat (getCoreOptions (dep ).transitionDirectoryNameFragment )
1202
1252
.isEqualTo (
1203
1253
FunctionTransitionUtil .transitionDirectoryNameFragment (
1204
- ImmutableList .of ("bar=barsball" , "foo=foosball" )));
1254
+ ImmutableList .of (
1255
+ "//command_line_option:bar=barsball" , "//command_line_option:foo=foosball" )));
1205
1256
}
1206
1257
1207
1258
// Test that a no-op starlark transition to an already starlark transitioned configuration
@@ -1523,8 +1574,7 @@ public void testOutputDirHash_multipleStarlarkTransitions() throws Exception {
1523
1574
List <String > affectedOptions =
1524
1575
getConfiguration (dep ).getOptions ().get (CoreOptions .class ).affectedByStarlarkTransition ;
1525
1576
1526
- // Assert that affectedOptions is empty but final fragment is still different.
1527
- assertThat (affectedOptions ).isEmpty ();
1577
+ assertThat (affectedOptions ).containsExactly ("//test:bar" , "//test:foo" );
1528
1578
assertThat (getCoreOptions (test ).transitionDirectoryNameFragment )
1529
1579
.isEqualTo (
1530
1580
FunctionTransitionUtil .transitionDirectoryNameFragment (
@@ -1611,12 +1661,12 @@ public void testOutputDirHash_multipleMixedTransitions() throws Exception {
1611
1661
List <String > affectedOptionsTop =
1612
1662
getConfiguration (top ).getOptions ().get (CoreOptions .class ).affectedByStarlarkTransition ;
1613
1663
1614
- assertThat (affectedOptionsTop ).containsExactly ("foo" );
1664
+ assertThat (affectedOptionsTop ).containsExactly ("//command_line_option: foo" );
1615
1665
assertThat (getConfiguration (top ).getOptions ().getStarlarkOptions ()).isEmpty ();
1616
1666
assertThat (getCoreOptions (top ).transitionDirectoryNameFragment )
1617
1667
.isEqualTo (
1618
1668
FunctionTransitionUtil .transitionDirectoryNameFragment (
1619
- ImmutableList .of ("foo=foosball" )));
1669
+ ImmutableList .of ("//command_line_option: foo=foosball" )));
1620
1670
1621
1671
// test:middle (foo_transition, zee_transition, bar_transition)
1622
1672
@ SuppressWarnings ("unchecked" )
@@ -1626,14 +1676,20 @@ public void testOutputDirHash_multipleMixedTransitions() throws Exception {
1626
1676
List <String > affectedOptionsMiddle =
1627
1677
getConfiguration (middle ).getOptions ().get (CoreOptions .class ).affectedByStarlarkTransition ;
1628
1678
1629
- assertThat (affectedOptionsMiddle ).containsExactly ("foo" , "bar" );
1679
+ assertThat (affectedOptionsMiddle )
1680
+ .containsExactly ("//command_line_option:foo" , "//command_line_option:bar" , "//test:zee" );
1681
+
1630
1682
assertThat (getConfiguration (middle ).getOptions ().getStarlarkOptions ().entrySet ())
1631
1683
.containsExactly (
1632
1684
Maps .immutableEntry (Label .parseAbsoluteUnchecked ("//test:zee" ), "zeesball" ));
1685
+
1633
1686
assertThat (getCoreOptions (middle ).transitionDirectoryNameFragment )
1634
1687
.isEqualTo (
1635
1688
FunctionTransitionUtil .transitionDirectoryNameFragment (
1636
- ImmutableList .of ("//test:zee=zeesball" , "bar=barsball" , "foo=foosball" )));
1689
+ ImmutableList .of (
1690
+ "//command_line_option:bar=barsball" ,
1691
+ "//command_line_option:foo=foosball" ,
1692
+ "//test:zee=zeesball" )));
1637
1693
1638
1694
// test:bottom (foo_transition, zee_transition, bar_transition, xan_transition)
1639
1695
@ SuppressWarnings ("unchecked" )
@@ -1644,7 +1700,10 @@ public void testOutputDirHash_multipleMixedTransitions() throws Exception {
1644
1700
List <String > affectedOptionsBottom =
1645
1701
getConfiguration (bottom ).getOptions ().get (CoreOptions .class ).affectedByStarlarkTransition ;
1646
1702
1647
- assertThat (affectedOptionsBottom ).containsExactly ("foo" , "bar" );
1703
+ assertThat (affectedOptionsBottom )
1704
+ .containsExactly (
1705
+ "//command_line_option:foo" , "//command_line_option:bar" , "//test:xan" , "//test:zee" );
1706
+
1648
1707
assertThat (getConfiguration (bottom ).getOptions ().getStarlarkOptions ().entrySet ())
1649
1708
.containsExactly (
1650
1709
Maps .immutableEntry (Label .parseAbsoluteUnchecked ("//test:zee" ), "zeesball" ),
@@ -1653,7 +1712,8 @@ public void testOutputDirHash_multipleMixedTransitions() throws Exception {
1653
1712
.isEqualTo (
1654
1713
FunctionTransitionUtil .transitionDirectoryNameFragment (
1655
1714
ImmutableList .of (
1656
- "//test:xan=xansball" , "//test:zee=zeesball" , "bar=barsball" , "foo=foosball" )));
1715
+ "//command_line_option:bar=barsball" , "//command_line_option:foo=foosball" ,
1716
+ "//test:xan=xansball" , "//test:zee=zeesball" )));
1657
1717
}
1658
1718
1659
1719
@ Test
0 commit comments