File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
main/java/com/google/devtools/build/lib/rules/config
test/java/com/google/devtools/build/lib/rules/config Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 6767import java .util .LinkedHashMap ;
6868import java .util .List ;
6969import java .util .Map ;
70+ import java .util .Optional ;
7071import javax .annotation .Nullable ;
7172
7273/**
@@ -83,6 +84,20 @@ public ConfiguredTarget create(RuleContext ruleContext)
8384 throws InterruptedException , ActionConflictException {
8485 AttributeMap attributes = NonconfigurableAttributeMapper .of (ruleContext .getRule ());
8586
87+ Optional <String > likelyLabelInvalidSetting =
88+ attributes .get (ConfigSettingRule .SETTINGS_ATTRIBUTE , Type .STRING_DICT ).keySet ().stream ()
89+ .filter (s -> s .startsWith ("@" ) || s .startsWith ("//" ) || s .startsWith (":" ))
90+ .findFirst ();
91+ if (likelyLabelInvalidSetting .isPresent ()) {
92+ ruleContext .attributeError (
93+ ConfigSettingRule .SETTINGS_ATTRIBUTE ,
94+ String .format (
95+ "'%s' is not a valid setting name, but appears to be a label. Did you mean to place"
96+ + " it in %s instead?" ,
97+ likelyLabelInvalidSetting .get (), ConfigSettingRule .FLAG_SETTINGS_ATTRIBUTE ));
98+ return null ;
99+ }
100+
86101 // Get the built-in Blaze flag settings that match this rule.
87102 ImmutableMultimap <String , String > nativeFlagSettings =
88103 ImmutableMultimap .<String , String >builder ()
Original file line number Diff line number Diff line change @@ -2317,4 +2317,20 @@ public void singleValueThatLooksLikeMultiValueIsOkay() throws Exception {
23172317 assertThat (getConfiguredTarget ("//test:fg" )).isNotNull ();
23182318 assertNoEvents ();
23192319 }
2320+
2321+ @ Test
2322+ public void labelInValuesError () throws Exception {
2323+ scratch .file (
2324+ "test/BUILD" ,
2325+ "config_setting(" ,
2326+ " name = 'match'," ,
2327+ " values = {'//foo:bar': 'value'}," ,
2328+ ")" );
2329+ reporter .removeHandler (failFastHandler ); // expect errors
2330+ assertThat (getConfiguredTarget ("//test:match" )).isNull ();
2331+ assertContainsEvent (
2332+ "in values attribute of config_setting rule //test:match: '//foo:bar' is"
2333+ + " not a valid setting name, but appears to be a label. Did you mean to place it in"
2334+ + " flag_values instead?" );
2335+ }
23202336}
You can’t perform that action at this time.
0 commit comments