1
+ """Implementation of the `custom_toolchain` rule."""
1
2
2
3
def _get_xcode_product_version (* , xcode_config ):
3
4
raw_version = str (xcode_config .xcode_version ())
@@ -14,15 +15,14 @@ def _get_xcode_product_version(*, xcode_config):
14
15
15
16
return version_components [3 ]
16
17
17
-
18
18
def _custom_toolchain_impl (ctx ):
19
19
xcode_version = _get_xcode_product_version (
20
20
xcode_config = ctx .attr ._xcode_config [apple_common .XcodeVersionConfig ],
21
21
)
22
22
23
23
toolchain_name_base = ctx .attr .toolchain_name
24
24
toolchain_dir = ctx .actions .declare_directory (
25
- toolchain_name_base + ".{}" .format (xcode_version ) + ".xctoolchain"
25
+ toolchain_name_base + ".{}" .format (xcode_version ) + ".xctoolchain" ,
26
26
)
27
27
28
28
resolved_overrides = {}
@@ -35,7 +35,9 @@ def _custom_toolchain_impl(ctx):
35
35
36
36
if len (files ) > 1 :
37
37
fail ("ERROR: Override for '{}' produces multiple files ({}). Each override must have exactly one file." .format (
38
- tool_name , len (files )))
38
+ tool_name ,
39
+ len (files ),
40
+ ))
39
41
40
42
override_file = files [0 ]
41
43
override_files .append (override_file )
@@ -50,9 +52,9 @@ def _custom_toolchain_impl(ctx):
50
52
output = script_file ,
51
53
is_executable = True ,
52
54
substitutions = {
53
- "%toolchain_name_base%" : toolchain_name_base ,
54
- "%toolchain_dir%" : toolchain_dir .path ,
55
55
"%overrides_list%" : overrides_list ,
56
+ "%toolchain_dir%" : toolchain_dir .path ,
57
+ "%toolchain_name_base%" : toolchain_name_base ,
56
58
"%xcode_version%" : xcode_version ,
57
59
},
58
60
)
@@ -64,9 +66,9 @@ def _custom_toolchain_impl(ctx):
64
66
mnemonic = "CreateCustomToolchain" ,
65
67
command = script_file .path ,
66
68
execution_requirements = {
67
- "no-sandbox" : "1" ,
68
- "no-cache" : "1" ,
69
69
"local" : "1" ,
70
+ "no-cache" : "1" ,
71
+ "no-sandbox" : "1" ,
70
72
"requires-darwin" : "1" ,
71
73
},
72
74
use_default_shell_env = True ,
@@ -83,10 +85,12 @@ def _custom_toolchain_impl(ctx):
83
85
custom_toolchain = rule (
84
86
implementation = _custom_toolchain_impl ,
85
87
attrs = {
86
- "toolchain_name" : attr .string (mandatory = True ),
87
88
"overrides" : attr .label_keyed_string_dict (
88
- allow_files = True , mandatory = False , default = {}
89
+ allow_files = True ,
90
+ mandatory = False ,
91
+ default = {},
89
92
),
93
+ "toolchain_name" : attr .string (mandatory = True ),
90
94
"_symlink_template" : attr .label (
91
95
allow_single_file = True ,
92
96
default = Label ("//xcodeproj/internal/templates:custom_toolchain_symlink.sh" ),
@@ -99,4 +103,3 @@ custom_toolchain = rule(
99
103
),
100
104
},
101
105
)
102
-
0 commit comments