@@ -4,6 +4,7 @@ def _custom_toolchain_impl(ctx):
4
4
5
5
default_toolchain_path = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain"
6
6
user_toolchain_path = "$(eval echo ~)/Library/Developer/Toolchains/{}.xctoolchain" .format (ctx .attr .toolchain_name )
7
+ built_toolchain_path = toolchain_dir .path
7
8
8
9
# Generate symlink creation commands dynamically, excluding plist files
9
10
symlink_script = """#!/bin/bash
@@ -12,26 +13,36 @@ set -e
12
13
mkdir -p "{toolchain_dir}"
13
14
14
15
find "{default_toolchain}" -type f -o -type l | while read file; do
16
+ base_name="$(basename "$file")"
15
17
rel_path="${{file#"{default_toolchain}/"}}"
18
+
19
+ override_path="$(echo {overrides} | jq -r --arg key "$base_name" '.[$key] // empty')"
20
+ if [[ -f "$override_path" ]]; then
21
+ mkdir -p "{toolchain_dir}/$(dirname "$rel_path")"
22
+ cp "$override_path" "{toolchain_dir}/$rel_path"
23
+ continue
24
+ fi
25
+
16
26
if [[ "$rel_path" != "ToolchainInfo.plist" ]]; then
17
27
mkdir -p "{toolchain_dir}/$(dirname "$rel_path")"
18
28
ln -s "$file" "{toolchain_dir}/$rel_path"
19
29
fi
20
30
done
21
31
22
- mkdir -p "{toolchain_dir}"
23
32
mv "{toolchain_plist}" "{toolchain_dir}/ToolchainInfo.plist"
24
33
25
34
# Remove existing symlink if present and create a new one in the user directory
26
35
if [ -e "{user_toolchain_path}" ]; then
27
36
rm -f "{user_toolchain_path}"
28
37
fi
29
- ln -s "{toolchain_dir }" "{user_toolchain_path}"
38
+ ln -s "{built_toolchain_path }" "{user_toolchain_path}"
30
39
""" .format (
31
40
toolchain_dir = toolchain_dir .path ,
32
41
default_toolchain = default_toolchain_path ,
42
+ overrides = ctx .attr .overrides ,
33
43
toolchain_plist = toolchain_plist_file .path ,
34
- user_toolchain_path = user_toolchain_path
44
+ user_toolchain_path = user_toolchain_path ,
45
+ built_toolchain_path = built_toolchain_path
35
46
)
36
47
37
48
script_file = ctx .actions .declare_file (ctx .attr .toolchain_name + "_setup.sh" )
@@ -80,5 +91,7 @@ custom_toolchain = rule(
80
91
implementation = _custom_toolchain_impl ,
81
92
attrs = {
82
93
"toolchain_name" : attr .string (mandatory = True ),
94
+ "overrides" : attr .string_dict (default = {}),
83
95
},
84
96
)
97
+
0 commit comments