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,38 @@ 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 ,
39
- len (files ),
40
- ))
40
+ fail ("ERROR: Override stub produces multiple files ({}). Each stub must have exactly one file." .format (
41
+ len (files )))
42
+
43
+ stub_file = files [0 ]
44
+ if stub_file not in override_files :
45
+ override_files .append (stub_file )
41
46
42
- override_file = files [0 ]
43
- override_files .append (override_file )
44
- resolved_overrides [tool_name ] = override_file .path
47
+ # Split comma-separated list of tool names
48
+ tool_names = [name .strip () for name in tools_str .split ("," )]
49
+
50
+ # Add an entry for each tool name
51
+ for tool_name in tool_names :
52
+ if tool_name : # Skip empty names
53
+ resolved_overrides [tool_name ] = stub_file .path
45
54
46
55
overrides_list = " " .join (["{}={}" .format (k , v ) for k , v in resolved_overrides .items ()])
47
56
48
- script_file = ctx .actions .declare_file (toolchain_name_base + "_setup.sh" )
57
+ script_file = ctx .actions .declare_file (full_toolchain_name + "_setup.sh" )
49
58
50
59
ctx .actions .expand_template (
51
60
template = ctx .file ._symlink_template ,
@@ -54,8 +63,9 @@ def _custom_toolchain_impl(ctx):
54
63
substitutions = {
55
64
"%overrides_list%" : overrides_list ,
56
65
"%toolchain_dir%" : toolchain_dir .path ,
57
- "%toolchain_name_base%" : toolchain_name_base ,
66
+ "%toolchain_name_base%" : full_toolchain_name ,
58
67
"%xcode_version%" : xcode_version ,
68
+ "%toolchain_id%" : toolchain_id ,
59
69
},
60
70
)
61
71
@@ -74,23 +84,30 @@ def _custom_toolchain_impl(ctx):
74
84
use_default_shell_env = True ,
75
85
)
76
86
77
- # Create runfiles with the override files and script file
78
87
runfiles = ctx .runfiles (files = override_files + [script_file ])
79
88
80
- return [DefaultInfo (
81
- files = depset ([toolchain_dir ]),
82
- runfiles = runfiles ,
83
- )]
89
+ toolchain_provider = ToolchainInfo (
90
+ name = full_toolchain_name ,
91
+ identifier = toolchain_id ,
92
+ )
93
+
94
+ return [
95
+ DefaultInfo (
96
+ files = depset ([toolchain_dir ]),
97
+ runfiles = runfiles ,
98
+ ),
99
+ toolchain_provider ,
100
+ ]
84
101
85
102
custom_toolchain = rule (
86
103
implementation = _custom_toolchain_impl ,
87
104
attrs = {
105
+ "toolchain_name" : attr .string (mandatory = True ),
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
- "toolchain_name" : attr .string (mandatory = True ),
94
111
"_symlink_template" : attr .label (
95
112
allow_single_file = True ,
96
113
default = Label ("//xcodeproj/internal/templates:custom_toolchain_symlink.sh" ),
@@ -102,4 +119,4 @@ custom_toolchain = rule(
102
119
),
103
120
),
104
121
},
105
- )
122
+ )
0 commit comments