11"""Implementation of the `custom_toolchain` rule."""
22
3+ load ("//xcodeproj/internal:providers.bzl" , "ToolchainInfo" )
4+
35def _get_xcode_product_version (* , xcode_config ):
46 raw_version = str (xcode_config .xcode_version ())
57 if not raw_version :
@@ -21,31 +23,39 @@ def _custom_toolchain_impl(ctx):
2123 )
2224
2325 toolchain_name_base = ctx .attr .toolchain_name
24- toolchain_dir = ctx . actions . declare_directory (
25- toolchain_name_base + "{}" .format (xcode_version ) + ".xctoolchain" ,
26- )
26+ toolchain_id = "com.rules_xcodeproj.{}.{}" . format ( toolchain_name_base , xcode_version )
27+ full_toolchain_name = "{}{} " .format (toolchain_name_base , xcode_version )
28+ toolchain_dir = ctx . actions . declare_directory ( full_toolchain_name + ".xctoolchain" )
2729
2830 resolved_overrides = {}
2931 override_files = []
3032
31- for tool_target , tool_name in ctx .attr .overrides .items ():
32- files = tool_target .files .to_list ()
33+ # Process tools from comma-separated list
34+ for stub_target , tools_str in ctx .attr .overrides .items ():
35+ files = stub_target .files .to_list ()
3336 if not files :
34- fail ("ERROR: Override for '{}' does not produce any files!" . format ( tool_name ) )
37+ fail ("ERROR: Override stub does not produce any files!" )
3538
3639 if len (files ) > 1 :
37- fail ("ERROR: Override for '{}' produces multiple files ({}). Each override must have exactly one file." .format (
38- tool_name ,
40+ fail ("ERROR: Override stub produces multiple files ({}). Each stub must have exactly one file." .format (
3941 len (files ),
4042 ))
4143
42- override_file = files [0 ]
43- override_files .append (override_file )
44- resolved_overrides [tool_name ] = override_file .path
44+ stub_file = files [0 ]
45+ if stub_file not in override_files :
46+ override_files .append (stub_file )
47+
48+ # Split comma-separated list of tool names
49+ tool_names = [name .strip () for name in tools_str .split ("," )]
50+
51+ # Add an entry for each tool name
52+ for tool_name in tool_names :
53+ if tool_name : # Skip empty names
54+ resolved_overrides [tool_name ] = stub_file .path
4555
4656 overrides_list = " " .join (["{}={}" .format (k , v ) for k , v in resolved_overrides .items ()])
4757
48- script_file = ctx .actions .declare_file (toolchain_name_base + "_setup.sh" )
58+ script_file = ctx .actions .declare_file (full_toolchain_name + "_setup.sh" )
4959
5060 ctx .actions .expand_template (
5161 template = ctx .file ._symlink_template ,
@@ -54,7 +64,8 @@ def _custom_toolchain_impl(ctx):
5464 substitutions = {
5565 "%overrides_list%" : overrides_list ,
5666 "%toolchain_dir%" : toolchain_dir .path ,
57- "%toolchain_name_base%" : toolchain_name_base ,
67+ "%toolchain_id%" : toolchain_id ,
68+ "%toolchain_name_base%" : full_toolchain_name ,
5869 "%xcode_version%" : xcode_version ,
5970 },
6071 )
@@ -74,21 +85,28 @@ def _custom_toolchain_impl(ctx):
7485 use_default_shell_env = True ,
7586 )
7687
77- # Create runfiles with the override files and script file
7888 runfiles = ctx .runfiles (files = override_files + [script_file ])
7989
80- return [DefaultInfo (
81- files = depset ([toolchain_dir ]),
82- runfiles = runfiles ,
83- )]
90+ toolchain_provider = ToolchainInfo (
91+ name = full_toolchain_name ,
92+ identifier = toolchain_id ,
93+ )
94+
95+ return [
96+ DefaultInfo (
97+ files = depset ([toolchain_dir ]),
98+ runfiles = runfiles ,
99+ ),
100+ toolchain_provider ,
101+ ]
84102
85103custom_toolchain = rule (
86104 implementation = _custom_toolchain_impl ,
87105 attrs = {
88106 "overrides" : attr .label_keyed_string_dict (
89107 allow_files = True ,
90- mandatory = False ,
91- default = {} ,
108+ mandatory = True ,
109+ doc = "Map from stub target to comma-separated list of tool names that should use that stub" ,
92110 ),
93111 "toolchain_name" : attr .string (mandatory = True ),
94112 "_symlink_template" : attr .label (
0 commit comments