Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit af4cd47

Browse files
committed
Copy lib_InternalSwiftSyntaxParser.dylib from Xcode toolchain
Resolves @SwiftDocOrg/swift-doc#197
1 parent 69123f2 commit af4cd47

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

Formula/swift-doc.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,39 @@ def install
1919
"--disable-sandbox",
2020
"--build-path", buildpath.to_s
2121

22+
copy_toolchain_libraries!
23+
2224
libexec.install buildpath/"release/swift-doc" => "swift-doc"
2325
libexec.install Dir[buildpath/"release/*.bundle"]
2426

27+
install_shim!
28+
end
29+
30+
test do
31+
system bin/"swift-doc"
32+
end
33+
34+
private
35+
36+
# rubocop:disable Metrics/AbcSize
37+
def copy_toolchain_libraries!
38+
return unless Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
39+
40+
macho = MachO.open(buildpath/"release/swift-doc")
41+
return unless (toolchain = macho.rpaths.find { |path| path.include?(".xctoolchain") })
42+
43+
cp "#{toolchain}/lib_InternalSwiftSyntaxParser.dylib", buildpath, verbose: true
44+
lib.install buildpath/"lib_InternalSwiftSyntaxParser.dylib"
45+
46+
macho.delete_rpath toolchain
47+
macho.change_install_name "@rpath/lib_InternalSwiftSyntaxParser.dylib",
48+
"#{lib}/lib_InternalSwiftSyntaxParser.dylib"
49+
50+
macho.write!
51+
end
52+
# rubocop:enable Metrics/AbcSize
53+
54+
def install_shim!
2555
(bin/"swift-doc").tap do |path|
2656
path.write <<~SHELL
2757
#!/bin/sh
@@ -30,8 +60,4 @@ def install
3060
chmod 0555, path
3161
end
3262
end
33-
34-
test do
35-
system "#{bin}/swift-doc"
36-
end
3763
end

0 commit comments

Comments
 (0)