@@ -4,6 +4,7 @@ def _custom_toolchain_impl(ctx):
44
55 default_toolchain_path = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain"
66 user_toolchain_path = "$(eval echo ~)/Library/Developer/Toolchains/{}.xctoolchain" .format (ctx .attr .toolchain_name )
7+ built_toolchain_path = toolchain_dir .path
78
89 # Generate symlink creation commands dynamically, excluding plist files
910 symlink_script = """#!/bin/bash
@@ -12,26 +13,36 @@ set -e
1213mkdir -p "{toolchain_dir}"
1314
1415find "{default_toolchain}" -type f -o -type l | while read file; do
16+ base_name="$(basename "$file")"
1517 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+
1626 if [[ "$rel_path" != "ToolchainInfo.plist" ]]; then
1727 mkdir -p "{toolchain_dir}/$(dirname "$rel_path")"
1828 ln -s "$file" "{toolchain_dir}/$rel_path"
1929 fi
2030done
2131
22- mkdir -p "{toolchain_dir}"
2332mv "{toolchain_plist}" "{toolchain_dir}/ToolchainInfo.plist"
2433
2534# Remove existing symlink if present and create a new one in the user directory
2635if [ -e "{user_toolchain_path}" ]; then
2736 rm -f "{user_toolchain_path}"
2837fi
29- ln -s "{toolchain_dir }" "{user_toolchain_path}"
38+ ln -s "{built_toolchain_path }" "{user_toolchain_path}"
3039""" .format (
3140 toolchain_dir = toolchain_dir .path ,
3241 default_toolchain = default_toolchain_path ,
42+ overrides = ctx .attr .overrides ,
3343 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
3546 )
3647
3748 script_file = ctx .actions .declare_file (ctx .attr .toolchain_name + "_setup.sh" )
@@ -80,5 +91,7 @@ custom_toolchain = rule(
8091 implementation = _custom_toolchain_impl ,
8192 attrs = {
8293 "toolchain_name" : attr .string (mandatory = True ),
94+ "overrides" : attr .string_dict (default = {}),
8395 },
8496)
97+
0 commit comments