Skip to content

Commit

Permalink
Fix dicts with same key
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroPatti committed Mar 30, 2022
1 parent fc898ff commit 7ff757c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,11 @@ public Map<KeyT, ValueT> convert(Object x, Object what, Object context)

@Override
public Map<KeyT, ValueT> concat(Iterable<Map<KeyT, ValueT>> iterable) {
ImmutableMap.Builder<KeyT, ValueT> output = ImmutableMap.builder();
LinkedHashMap<KeyT, ValueT> output = new LinkedHashMap<>();
for (Map<KeyT, ValueT> map: iterable){
output.putAll(map);
}
return output.build();
return ImmutableMap.copyOf(output);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,50 @@ public void selectConcatenatedWithSelect() throws Exception {
/*not expected:*/ ImmutableList.of("bin java/foo/liba.jar", "bin java/foo/liba2.jar"));
}

@Test
public void dictsWithSameKey() throws Exception {
writeConfigRules();
scratch.file("java/foo/rule.bzl",
"def _rule_impl(ctx):",
" outputs = []",
" for target, value in ctx.attr.deps.items():",
" output = ctx.actions.declare_file(target.label.name + value)",
" ctx.actions.write(content = value, output = output)",
" outputs.append(output)",
" return [DefaultInfo(files=depset(outputs))]",
"myrule = rule(",
" implementation = _rule_impl,",
" attrs = {",
" 'deps': attr.label_keyed_string_dict()",
" },",
")");
scratch.file("java/foo/BUILD",
"load(':rule.bzl', 'myrule')",
"myrule(",
" name = 'mytarget',",
" deps = select({",
" '//conditions:a': {':a': 'a'},",
" }) | select({",
" '//conditions:a': {':a': 'a2'},",
" })",
")",
"java_library(",
" name = 'a',",
" srcs = ['a.java']",
")",
"filegroup(",
" name = 'group',",
" srcs = [':mytarget'],",
")");

checkRule(
"//java/foo:group",
"srcs",
ImmutableList.of("--foo=a"),
/*expected:*/ ImmutableList.of("bin java/foo/aa2"),
/*not expected:*/ ImmutableList.of("bin java/foo/aa"));
}

@Test
public void selectConcatenatedWithNonSupportingType() throws Exception {
writeConfigRules();
Expand Down

0 comments on commit 7ff757c

Please sign in to comment.