Skip to content

Commit a49a5dd

Browse files
committed
Add CLI for dumping Swift toolchain bundle ids
1 parent 2cb54e1 commit a49a5dd

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ following flag to Bazel:
100100
where `toolchain.id` is the value of the `CFBundleIdentifier` key in the
101101
toolchain's Info.plist file.
102102

103+
To list the available toolchains and their bundle identifiers, you can run:
104+
105+
```
106+
bazel run @build_bazel_rules_swift//tools/dump_toolchains
107+
```
108+
103109
**Linux hosts:** At this time, Bazel uses whichever `swift` executable is
104110
encountered first on your `PATH`.
105111

tools/dump_toolchains/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
licenses(["notice"])
2+
3+
sh_binary(
4+
name = "dump_toolchains",
5+
srcs = ["dump_toolchains.sh"],
6+
visibility = ["//visibility:public"],
7+
)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2019 The Bazel Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
if [[ "$(uname)" != Darwin ]]; then
20+
echo "error: dumping toolchains is only supported on macOS"
21+
exit 1
22+
fi
23+
24+
toolchain_directory=/Library/Developer/Toolchains
25+
if [[ ! -d "$toolchain_directory" ]]; then
26+
echo "error: '$toolchain_directory' doesn't exist"
27+
exit 1
28+
fi
29+
30+
for toolchain in "$toolchain_directory"/*.xctoolchain
31+
do
32+
plist_path="$toolchain/Info.plist"
33+
34+
if [[ ! -f "$plist_path" ]]; then
35+
echo "error: '$toolchain' is missing Info.plist"
36+
exit 1
37+
fi
38+
39+
bundle_id=$(/usr/libexec/PlistBuddy -c "print :CFBundleIdentifier" "$plist_path")
40+
toolchain_name=$(basename "$toolchain")
41+
echo "$toolchain_name -> $bundle_id"
42+
done

0 commit comments

Comments
 (0)