@@ -181,11 +181,15 @@ MAKE_VARIABLES = "@rules_sh//sh/posix:make_variables"
181181
182182def _sh_posix_toolchain_impl (ctx ):
183183 commands = {}
184+ cmds = ctx .attr .cmds
184185 for cmd in _commands :
185- cmd_path = getattr ( ctx . attr , cmd , None )
186+ cmd_path = cmds . get ( cmd , None )
186187 if not cmd_path :
187188 cmd_path = None
188189 commands [cmd ] = cmd_path
190+ unrecognizeds = [cmd for cmd in cmds .keys () if cmd not in _commands ]
191+ if unrecognizeds :
192+ fail ("Unrecognized commands in keys of sh_posix_toolchain's \" cmds\" attributes: {}. See posix.commands in @rules_sh//sh:posix.bzl for the list of recognized commands." .format (", " .join (unrecognizeds )))
189193 cmd_paths = {
190194 paths .dirname (cmd_path ): None
191195 for cmd_path in commands .values ()
@@ -198,11 +202,10 @@ def _sh_posix_toolchain_impl(ctx):
198202
199203sh_posix_toolchain = rule (
200204 attrs = {
201- cmd : attr .string (
202- doc = "Absolute path to the {} command." . format ( cmd ) ,
203- mandatory = False ,
205+ "cmds" : attr .string_dict (
206+ doc = "dict where keys are command names and values are paths" ,
207+ mandatory = True ,
204208 )
205- for cmd in _commands
206209 },
207210 doc = """
208211A toolchain capturing standard Unix shell commands.
@@ -300,7 +303,9 @@ load("@rules_sh//sh:posix.bzl", "sh_posix_toolchain")
300303sh_posix_toolchain(
301304 name = "local_posix",
302305 visibility = ["//visibility:public"],
303- {commands}
306+ cmds = {{
307+ {commands}
308+ }}
304309)
305310toolchain(
306311 name = "local_posix_toolchain",
@@ -316,8 +321,8 @@ toolchain(
316321 ],
317322)
318323""" .format (
319- commands = ",\n " .join ([
320- '{cmd} = "{path}"' .format (cmd = cmd , path = cmd_path )
324+ commands = ",\n " .join ([
325+ '" {cmd}": "{path}"' .format (cmd = cmd , path = cmd_path )
321326 for (cmd , cmd_path ) in commands .items ()
322327 if cmd_path
323328 ]),
0 commit comments