|
1 | 1 | def _custom_toolchain_impl(ctx):
|
2 | 2 | toolchain_dir = ctx.actions.declare_directory(ctx.attr.toolchain_name + ".xctoolchain")
|
3 |
| - toolchain_info_plist_file = ctx.actions.declare_file(ctx.attr.toolchain_name + "_ToolchainInfo.plist") |
4 |
| - info_plist_file = ctx.actions.declare_file(ctx.attr.toolchain_name + "_Info.plist") |
| 3 | + toolchain_plist_file = ctx.actions.declare_file(ctx.attr.toolchain_name + "_ToolchainInfo.plist") |
5 | 4 |
|
6 | 5 | default_toolchain_path = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain"
|
| 6 | + user_toolchain_path = "$(eval echo ~)/Library/Developer/Toolchains/{}.xctoolchain".format(ctx.attr.toolchain_name) |
7 | 7 |
|
8 |
| - # Generate symlink creation commands dynamically, excluding ToolchainInfo.plist |
| 8 | + # Generate symlink creation commands dynamically, excluding plist files |
9 | 9 | symlink_script = """#!/bin/bash
|
10 | 10 | set -e
|
11 | 11 |
|
12 | 12 | mkdir -p "{toolchain_dir}"
|
13 | 13 |
|
14 | 14 | find "{default_toolchain}" -type f -o -type l | while read file; do
|
15 | 15 | rel_path="${{file#"{default_toolchain}/"}}"
|
16 |
| - if [[ "$rel_path" != "ToolchainInfo.plist" && "$rel_path" != "Info.plist" ]]; then |
| 16 | + if [[ "$rel_path" != "ToolchainInfo.plist" ]]; then |
17 | 17 | mkdir -p "{toolchain_dir}/$(dirname "$rel_path")"
|
18 | 18 | ln -s "$file" "{toolchain_dir}/$rel_path"
|
19 | 19 | fi
|
20 | 20 | done
|
21 | 21 |
|
22 | 22 | mkdir -p "{toolchain_dir}"
|
23 |
| -mv "{toolchain_info_plist}" "{toolchain_dir}/ToolchainInfo.plist" |
24 |
| -mv "{info_plist}" "{toolchain_dir}/Info.plist" |
| 23 | +mv "{toolchain_plist}" "{toolchain_dir}/ToolchainInfo.plist" |
| 24 | +
|
| 25 | +# Remove existing symlink if present and create a new one in the user directory |
| 26 | +if [ -e "{user_toolchain_path}" ]; then |
| 27 | + rm -f "{user_toolchain_path}" |
| 28 | +fi |
| 29 | +ln -s "{toolchain_dir}" "{user_toolchain_path}" |
25 | 30 | """.format(
|
26 | 31 | toolchain_dir=toolchain_dir.path,
|
27 | 32 | default_toolchain=default_toolchain_path,
|
28 |
| - toolchain_info_plist=toolchain_info_plist_file.path, |
29 |
| - info_plist=info_plist_file.path |
| 33 | + toolchain_plist=toolchain_plist_file.path, |
| 34 | + user_toolchain_path=user_toolchain_path |
30 | 35 | )
|
31 | 36 |
|
32 | 37 | script_file = ctx.actions.declare_file(ctx.attr.toolchain_name + "_setup.sh")
|
33 | 38 | ctx.actions.write(output=script_file, content=symlink_script, is_executable=True)
|
34 | 39 |
|
35 |
| - # Generate ToolchainInfo.plist separately |
36 |
| - toolchain_info_plist_content = """<?xml version="1.0" encoding="UTF-8"?> |
| 40 | + # Generate ToolchainInfo.plist |
| 41 | + toolchain_plist_content = """<?xml version="1.0" encoding="UTF-8"?> |
37 | 42 | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
38 | 43 | <plist version="1.0">
|
39 |
| -<dict> |
40 |
| - <key>Identifier</key> |
| 44 | + <dict> |
| 45 | + <key>Aliases</key> |
| 46 | + <array> |
| 47 | + <string>{name}</string> |
| 48 | + </array> |
| 49 | + <key>CFBundleIdentifier</key> |
41 | 50 | <string>com.example.{name}</string>
|
| 51 | + <key>CompatibilityVersion</key> |
| 52 | + <integer>2</integer> |
| 53 | + <key>CompatibilityVersionDisplayString</key> |
| 54 | + <string>Xcode 13.0</string> |
42 | 55 | <key>DisplayName</key>
|
43 | 56 | <string>{name}</string>
|
44 |
| - <key>CompatibilityVersion</key> |
45 |
| - <string>9999</string> |
46 |
| -</dict> |
47 |
| -</plist> |
48 |
| -""".format(name=ctx.attr.toolchain_name) |
49 |
| - |
50 |
| - ctx.actions.write(output=toolchain_info_plist_file, content=toolchain_info_plist_content) |
51 |
| - |
52 |
| - # Generate Info.plist |
53 |
| - info_plist_content = """<?xml version="1.0" encoding="UTF-8"?> |
54 |
| -<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
55 |
| -<plist version="1.0"> |
56 |
| -<dict> |
57 |
| - <key>CFBundleIdentifier</key> |
58 |
| - <string>com.example.{name}</string> |
59 |
| - <key>CFBundleName</key> |
| 57 | + <key>ReportProblemURL</key> |
| 58 | + <string>https://github.com/MobileNativeFoundation/rules_xcodeproj</string> |
| 59 | + <key>ShortDisplayName</key> |
60 | 60 | <string>{name}</string>
|
61 |
| - <key>CFBundleVersion</key> |
62 |
| - <string>1.0</string> |
63 |
| - <key>DTSDKName</key> |
64 |
| - <string>macosx</string> |
65 |
| - <key>DTSDKBuild</key> |
66 |
| - <string>9999</string> |
67 |
| - <key>DTCompiler</key> |
68 |
| - <string>com.apple.compilers.llvm.clang.1_0</string> |
69 |
| -</dict> |
| 61 | + <key>Version</key> |
| 62 | + <string>0.0.1</string> |
| 63 | + </dict> |
70 | 64 | </plist>
|
71 | 65 | """.format(name=ctx.attr.toolchain_name)
|
72 | 66 |
|
73 |
| - ctx.actions.write(output=info_plist_file, content=info_plist_content) |
| 67 | + ctx.actions.write(output=toolchain_plist_file, content=toolchain_plist_content) |
74 | 68 |
|
75 | 69 | # Run the generated shell script
|
76 | 70 | ctx.actions.run_shell(
|
77 | 71 | outputs=[toolchain_dir],
|
78 |
| - inputs=[toolchain_info_plist_file, info_plist_file], |
| 72 | + inputs=[toolchain_plist_file], |
79 | 73 | tools=[script_file],
|
80 | 74 | command=script_file.path
|
81 | 75 | )
|
|
0 commit comments