1
1
"""Implementation of the `custom_toolchain` rule."""
2
2
3
+ load ("//xcodeproj/internal:providers.bzl" , "ToolchainInfo" )
4
+
3
5
def _get_xcode_product_version (* , xcode_config ):
4
6
raw_version = str (xcode_config .xcode_version ())
5
7
if not raw_version :
@@ -21,31 +23,39 @@ def _custom_toolchain_impl(ctx):
21
23
)
22
24
23
25
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" )
27
29
28
30
resolved_overrides = {}
29
31
override_files = []
30
32
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 ()
33
36
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!" )
35
38
36
39
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 (
39
41
len (files ),
40
42
))
41
43
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
45
55
46
56
overrides_list = " " .join (["{}={}" .format (k , v ) for k , v in resolved_overrides .items ()])
47
57
48
- script_file = ctx .actions .declare_file (toolchain_name_base + "_setup.sh" )
58
+ script_file = ctx .actions .declare_file (full_toolchain_name + "_setup.sh" )
49
59
50
60
ctx .actions .expand_template (
51
61
template = ctx .file ._symlink_template ,
@@ -54,7 +64,8 @@ def _custom_toolchain_impl(ctx):
54
64
substitutions = {
55
65
"%overrides_list%" : overrides_list ,
56
66
"%toolchain_dir%" : toolchain_dir .path ,
57
- "%toolchain_name_base%" : toolchain_name_base ,
67
+ "%toolchain_id%" : toolchain_id ,
68
+ "%toolchain_name_base%" : full_toolchain_name ,
58
69
"%xcode_version%" : xcode_version ,
59
70
},
60
71
)
@@ -74,21 +85,28 @@ def _custom_toolchain_impl(ctx):
74
85
use_default_shell_env = True ,
75
86
)
76
87
77
- # Create runfiles with the override files and script file
78
88
runfiles = ctx .runfiles (files = override_files + [script_file ])
79
89
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
+ ]
84
102
85
103
custom_toolchain = rule (
86
104
implementation = _custom_toolchain_impl ,
87
105
attrs = {
88
106
"overrides" : attr .label_keyed_string_dict (
89
107
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" ,
92
110
),
93
111
"toolchain_name" : attr .string (mandatory = True ),
94
112
"_symlink_template" : attr .label (
0 commit comments