@@ -32,7 +32,7 @@ def _cc_tool_map_impl(ctx):
32
32
action_to_as = {}
33
33
for i in range (len (action_sets )):
34
34
action_set = action_sets [i ]
35
- tool = tools [i ]
35
+ tool = tools [ctx . attr . tool_index_for_action [ i ] ]
36
36
37
37
for action in action_set .actions .to_list ():
38
38
if action in action_to_as :
@@ -63,6 +63,10 @@ See //cc/toolchains/actions:BUILD for valid options.
63
63
The tool may be a `cc_tool` or other executable rule.
64
64
""" ,
65
65
),
66
+ "tool_index_for_action" : attr .int_list (
67
+ mandatory = True ,
68
+ doc = """The index of the tool in `tools` for the action in `actions`.""" ,
69
+ )
66
70
},
67
71
provides = [ToolConfigInfo ],
68
72
)
@@ -100,21 +104,27 @@ def cc_tool_map(name, tools, **kwargs):
100
104
)
101
105
```
102
106
103
- Note:
104
- Due to an implementation limitation, if you need to map the same tool to multiple actions,
105
- you will need to create an intermediate alias for the tool for each set of actions. See
106
- https://github.com/bazelbuild/rules_cc/issues/235 for more details.
107
-
108
107
Args:
109
108
name: (str) The name of the target.
110
109
tools: (Dict[Label, Label]) A mapping between
111
110
`cc_action_type`/`cc_action_type_set` targets
112
111
and the `cc_tool` or executable target that implements that action.
113
112
**kwargs: [common attributes](https://bazel.build/reference/be/common-definitions#common-attributes) that should be applied to this rule.
114
113
"""
114
+ actions = []
115
+ tool_index_for_action = []
116
+ deduplicated_tools = {}
117
+ for action , tool in tools .items ():
118
+ actions .append (action )
119
+ label = native .package_relative_label (tool )
120
+ if label not in deduplicated_tools :
121
+ deduplicated_tools [label ] = len (deduplicated_tools )
122
+ tool_index_for_action .append (deduplicated_tools [label ])
123
+
115
124
_cc_tool_map (
116
125
name = name ,
117
- actions = tools .keys (),
118
- tools = tools .values (),
126
+ actions = actions ,
127
+ tools = deduplicated_tools .keys (),
128
+ tool_index_for_action = tool_index_for_action ,
119
129
** kwargs
120
130
)
0 commit comments