这是indexloc提供的服务,不要输入任何密码
Skip to content

Adjust library paths when the extension is a dylib #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/thermite/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ def ruby_path(*path_components)
File.join(ruby_toplevel_dir, *path_components)
end

# :nocov:

#
# Absolute path to the shared libruby.
#
def libruby_path
@libruby_path ||= File.join(RbConfig::CONFIG['libdir'], RbConfig::CONFIG['LIBRUBY_SO'])
end

# :nocov:

#
# The top-level directory of the Cargo project. Defaults to the current working directory.
#
Expand Down
1 change: 1 addition & 0 deletions lib/thermite/custom_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def download_binary_from_custom_uri

debug "Unpacking binary from Cargo version: #{File.basename(uri)}"
unpack_tarball(tgz)
prepare_downloaded_library
true
end

Expand Down
2 changes: 2 additions & 0 deletions lib/thermite/github_release_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def download_cargo_version_from_github_release

debug "Unpacking GitHub release from Cargo version: #{File.basename(uri)}"
unpack_tarball(tgz)
prepare_downloaded_library
true
end

Expand All @@ -75,6 +76,7 @@ def download_latest_binary_from_github_release
next unless tgz
debug "Unpacking GitHub release: #{File.basename(download_uri)}"
unpack_tarball(tgz)
prepare_downloaded_library
installed_binary = true
break
end
Expand Down
24 changes: 24 additions & 0 deletions lib/thermite/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module Package
def build_package
filename = config.tarball_filename(config.toml[:package][:version])
relative_library_path = config.ruby_extension_path.sub("#{config.ruby_toplevel_dir}/", '')
prepare_built_library
Zlib::GzipWriter.open(filename) do |tgz|
Dir.chdir(config.ruby_toplevel_dir) do
Archive::Tar::Minitar.pack(relative_library_path, tgz)
Expand All @@ -55,6 +56,19 @@ def unpack_tarball(tgz)
end
end

# :nocov:

def prepare_downloaded_library
return unless config.target_os.start_with?('darwin')

libruby_path = Shellwords.escape(config.libruby_path)
library_path = Shellwords.escape(config.ruby_extension_path)
`install_name_tool -id #{library_path} #{library_path}`
`install_name_tool -change @libruby_path@ #{libruby_path} #{library_path}`
end

# :nocov:

private

def each_compressed_file(tgz)
Expand All @@ -68,5 +82,15 @@ def each_compressed_file(tgz)
end
end
end

# :nocov:

def prepare_built_library
return unless config.target_os.start_with?('darwin')

libruby_path = Shellwords.escape(config.libruby_path)
library_path = Shellwords.escape(config.ruby_extension_path)
`install_name_tool -change #{libruby_path} @libruby_path@ #{library_path}`
end
end
end
1 change: 1 addition & 0 deletions test/lib/thermite/custom_binary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def test_download_binary_from_custom_uri
Net::HTTP.stubs(:get_response).returns('location' => 'redirect')
mock_module.stubs(:http_get).returns('tarball')
mock_module.expects(:unpack_tarball).once
mock_module.expects(:prepare_downloaded_library).once

assert mock_module.download_binary_from_custom_uri
end
Expand Down
4 changes: 4 additions & 0 deletions test/lib/thermite/github_release_binary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def test_download_cargo_version_from_github_release
Net::HTTP.stubs(:get_response).returns('location' => 'redirect')
mock_module.stubs(:http_get).returns('tarball')
mock_module.expects(:unpack_tarball).once
mock_module.expects(:prepare_downloaded_library).once

assert mock_module.download_binary_from_github_release
end
Expand All @@ -67,6 +68,7 @@ def test_download_cargo_version_from_github_release_with_custom_git_tag_format
Net::HTTP.stubs(:get_response).returns('location' => 'redirect')
mock_module.stubs(:http_get).returns('tarball')
mock_module.expects(:unpack_tarball).once
mock_module.expects(:prepare_downloaded_library).once

assert mock_module.download_binary_from_github_release
end
Expand Down Expand Up @@ -114,6 +116,7 @@ def test_download_latest_binary_from_github_release
stub_releases_atom
mock_module.stubs(:download_versioned_github_release_binary).returns(StringIO.new('tarball'))
mock_module.expects(:unpack_tarball).once
mock_module.expects(:prepare_downloaded_library).once

assert mock_module.download_binary_from_github_release
end
Expand All @@ -131,6 +134,7 @@ def test_download_latest_binary_from_github_release_no_tarball_found
stub_releases_atom
mock_module.stubs(:download_versioned_github_release_binary).returns(nil)
mock_module.expects(:unpack_tarball).never
mock_module.expects(:prepare_downloaded_library).never

assert !mock_module.download_binary_from_github_release
end
Expand Down