@@ -4935,4 +4935,68 @@ def _impl(ctx):
49354935 assertThat (buildSettingProvider .getDefaultValue ()).isEqualTo (ImmutableSet .copyOf (defaultValue ));
49364936 assertThat (buildSettingProvider .getType ()).isEqualTo (Types .STRING_SET );
49374937 }
4938+
4939+ @ Test
4940+ public void testLabelKeyedStringDictAttrTransitioned () throws Exception {
4941+ scratch .file (
4942+ "test/rules.bzl" ,
4943+ """
4944+ MyProvider = provider()
4945+
4946+ def _my_transition_impl(settings, attr):
4947+ return {"//command_line_option:compilation_mode": "opt"}
4948+
4949+ my_transition = transition(
4950+ implementation = _my_transition_impl,
4951+ inputs = [],
4952+ outputs = ["//command_line_option:compilation_mode"],
4953+ )
4954+
4955+ def _impl(ctx):
4956+ result = []
4957+ for k, v in ctx.attr.dict_attr.items():
4958+ result.append(k[DefaultInfo].files.to_list()[0].path)
4959+ return MyProvider(result = result)
4960+
4961+ my_rule = rule(
4962+ implementation = _impl,
4963+ attrs = {
4964+ 'dict_attr': attr.label_keyed_string_dict(
4965+ cfg = my_transition,
4966+ ),
4967+ },
4968+ )
4969+
4970+ def _dep_impl(ctx):
4971+ f = ctx.actions.declare_file(ctx.label.name + ".txt")
4972+ ctx.actions.write(f, "hello")
4973+ return DefaultInfo(files = depset([f]))
4974+
4975+ my_dep = rule(
4976+ implementation = _dep_impl,
4977+ )
4978+ """ );
4979+
4980+ scratch .file (
4981+ "test/BUILD" ,
4982+ """
4983+ load("//test:rules.bzl", "my_rule", "my_dep")
4984+
4985+ my_rule(
4986+ name = "my_target",
4987+ dict_attr = {":d1": "s1", ":d2": "s2"},
4988+ )
4989+ my_dep(name = "d1")
4990+ my_dep(name = "d2")
4991+ """ );
4992+
4993+ ConfiguredTarget myTarget = getConfiguredTarget ("//test:my_target" );
4994+ Provider .Key myProviderKey =
4995+ new StarlarkProvider .Key (
4996+ keyForBuild (Label .create (myTarget .getLabel ().getPackageIdentifier (), "rules.bzl" )),
4997+ "MyProvider" );
4998+ var result = ((StarlarkInfo ) myTarget .get (myProviderKey )).getValue ("result" );
4999+ // Dependencies output path should have `-opt` after the transition.
5000+ ((Iterable <?>) result ).forEach (s -> assertThat (s .toString ()).contains ("-opt/" ));
5001+ }
49385002}
0 commit comments