thermite-ruby3-fork-dont-use 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +29 -0
- data/.ruby-version +1 -0
- data/.yardopts +2 -0
- data/CONTRIBUTING.md +67 -0
- data/Gemfile +9 -0
- data/LICENSE +9 -0
- data/NEWS.md +180 -0
- data/README.md +144 -0
- data/Rakefile +32 -0
- data/lib/thermite/cargo.rb +125 -0
- data/lib/thermite/config.rb +293 -0
- data/lib/thermite/custom_binary.rb +66 -0
- data/lib/thermite/fiddle.rb +45 -0
- data/lib/thermite/github_release_binary.rb +125 -0
- data/lib/thermite/package.rb +96 -0
- data/lib/thermite/semver.rb +50 -0
- data/lib/thermite/tasks.rb +160 -0
- data/lib/thermite/util.rb +59 -0
- data/test/fixtures/config/Cargo.toml +5 -0
- data/test/fixtures/github/releases.atom +30 -0
- data/test/lib/thermite/cargo_test.rb +95 -0
- data/test/lib/thermite/config_test.rb +239 -0
- data/test/lib/thermite/custom_binary_test.rb +59 -0
- data/test/lib/thermite/github_release_binary_test.rb +160 -0
- data/test/lib/thermite/package_test.rb +119 -0
- data/test/lib/thermite/semver_test.rb +58 -0
- data/test/lib/thermite/util_test.rb +55 -0
- data/test/test_helper.rb +57 -0
- data/thermite.gemspec +27 -0
- metadata +184 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'fileutils'
|
21
|
+
require 'rake/tasklib'
|
22
|
+
require 'thermite/cargo'
|
23
|
+
require 'thermite/config'
|
24
|
+
require 'thermite/custom_binary'
|
25
|
+
require 'thermite/github_release_binary'
|
26
|
+
require 'thermite/package'
|
27
|
+
require 'thermite/util'
|
28
|
+
|
29
|
+
#
|
30
|
+
# Helpers for Rust-based Ruby extensions.
|
31
|
+
#
|
32
|
+
module Thermite
|
33
|
+
#
|
34
|
+
# Create the following rake tasks:
|
35
|
+
#
|
36
|
+
# * `thermite:build`
|
37
|
+
# * `thermite:clean`
|
38
|
+
# * `thermite:test`
|
39
|
+
# * `thermite:tarball`
|
40
|
+
#
|
41
|
+
class Tasks < Rake::TaskLib
|
42
|
+
include Thermite::Cargo
|
43
|
+
include Thermite::CustomBinary
|
44
|
+
include Thermite::GithubReleaseBinary
|
45
|
+
include Thermite::Package
|
46
|
+
include Thermite::Util
|
47
|
+
|
48
|
+
#
|
49
|
+
# The configuration used for the Rake tasks. See: {Thermite::Config}
|
50
|
+
#
|
51
|
+
attr_reader :config
|
52
|
+
|
53
|
+
#
|
54
|
+
# Possible configuration options for Thermite tasks:
|
55
|
+
#
|
56
|
+
# * `binary_uri_format` - if set, the interpolation-formatted string used to construct the
|
57
|
+
# download URI for the pre-built native extension. If the environment variable
|
58
|
+
# `THERMITE_BINARY_URI_FORMAT` is set, it takes precedence over this option. Either method of
|
59
|
+
# setting this option overrides the `github_releases` option.
|
60
|
+
# Example: `https://example.com/download/%{version}/%{filename}`. Replacement variables:
|
61
|
+
# - `filename` - The value of {Config#tarball_filename}
|
62
|
+
# - `version` - the crate version from the `Cargo.toml` file
|
63
|
+
# * `cargo_project_path` - the path to the Cargo project. Defaults to the current
|
64
|
+
# working directory.
|
65
|
+
# * `cargo_workspace_member` - if set, the relative path to the Cargo workspace member. Usually
|
66
|
+
# used when it is part of a repository containing multiple crates.
|
67
|
+
# * `github_releases` - whether to look for rust binaries via GitHub releases when installing
|
68
|
+
# the gem, and `cargo` is not found. Defaults to `false`.
|
69
|
+
# * `github_release_type` - when `github_releases` is `true`, the mode to use to download the
|
70
|
+
# Rust binary from GitHub releases. `'cargo'` (the default) uses the version in `Cargo.toml`,
|
71
|
+
# along with the `git_tag_format` option (described below) to determine the download URI.
|
72
|
+
# `'latest'` takes the latest release matching the `git_tag_regex` option (described below) to
|
73
|
+
# determine the download URI.
|
74
|
+
# * `git_tag_format` - when `github_release_type` is `'cargo'` (the default), the
|
75
|
+
# [format string](http://ruby-doc.org/core/String.html#method-i-25) used to determine the
|
76
|
+
# tag used in the GitHub download URI. Defaults to `v%s`, where `%s` is the version in
|
77
|
+
# `Cargo.toml`.
|
78
|
+
# * `git_tag_regex` - when `github_releases` is enabled and `github_release_type` is
|
79
|
+
# `'latest'`, a regular expression (expressed as a `String`) that determines which tagged
|
80
|
+
# releases to look for precompiled Rust tarballs. One group must be specified that indicates
|
81
|
+
# the version number to be used in the tarball filename. Defaults to the [semantic versioning
|
82
|
+
# 2.0.0 format](https://semver.org/spec/v2.0.0.html). In this case, the group is around the
|
83
|
+
# entire expression.
|
84
|
+
# * `optional_rust_extension` - prints a warning to STDERR instead of raising an exception, if
|
85
|
+
# Cargo is unavailable and `github_releases` is either disabled or unavailable. Useful for
|
86
|
+
# projects where either fallback code exists, or a native extension is desirable but not
|
87
|
+
# required. Defaults to `false`.
|
88
|
+
# * `ruby_project_path` - the toplevel directory of the Ruby gem's project. Defaults to the
|
89
|
+
# current working directory.
|
90
|
+
# * `ruby_extension_dir` - the directory relative to `ruby_project_path` where the extension is
|
91
|
+
# located. Defaults to `lib`.
|
92
|
+
#
|
93
|
+
# These values can be overridden by values with the same key name in the
|
94
|
+
# `package.metadata.thermite` section of `Cargo.toml`, if that section exists. The exceptions
|
95
|
+
# to this are `cargo_project_path` and `cargo_workspace_member`, since they are both used to
|
96
|
+
# find the `Cargo.toml` file.
|
97
|
+
#
|
98
|
+
attr_reader :options
|
99
|
+
|
100
|
+
#
|
101
|
+
# Define the Thermite tasks with the given configuration parameters (see {#options}).
|
102
|
+
#
|
103
|
+
# Example:
|
104
|
+
#
|
105
|
+
# ```ruby
|
106
|
+
# Thermite::Tasks.new(cargo_project_path: 'rust')
|
107
|
+
# ```
|
108
|
+
#
|
109
|
+
def initialize(options = {})
|
110
|
+
@options = options
|
111
|
+
@config = Config.new(options)
|
112
|
+
@options.merge!(@config.toml_config)
|
113
|
+
define_build_task
|
114
|
+
define_clean_task
|
115
|
+
define_test_task
|
116
|
+
define_package_task
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
def define_build_task
|
122
|
+
desc 'Build or download the Rust shared library: CARGO_PROFILE controls Cargo profile'
|
123
|
+
task 'thermite:build' do
|
124
|
+
# if cargo found, build. Otherwise, grab binary (when github_releases is enabled).
|
125
|
+
if cargo
|
126
|
+
profile = ENV.fetch('CARGO_PROFILE', 'release')
|
127
|
+
run_cargo_rustc(profile)
|
128
|
+
FileUtils.cp(config.cargo_target_path(profile, config.cargo_shared_library),
|
129
|
+
config.ruby_extension_path)
|
130
|
+
elsif !download_binary_from_custom_uri && !download_binary_from_github_release
|
131
|
+
inform_user_about_cargo
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def define_clean_task
|
137
|
+
desc 'Clean up after thermite:build task'
|
138
|
+
task 'thermite:clean' do
|
139
|
+
FileUtils.rm(config.ruby_extension_path, force: true)
|
140
|
+
run_cargo_if_exists 'clean', *cargo_manifest_path_args
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def define_test_task
|
145
|
+
desc 'Run Rust testsuite'
|
146
|
+
task 'thermite:test' do
|
147
|
+
run_cargo_if_exists 'test', *cargo_manifest_path_args
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def define_package_task
|
152
|
+
namespace :thermite do
|
153
|
+
desc 'Package rust library in a tarball'
|
154
|
+
task tarball: %w[thermite:build] do
|
155
|
+
build_package
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'net/http'
|
21
|
+
|
22
|
+
module Thermite
|
23
|
+
#
|
24
|
+
# Utility methods
|
25
|
+
#
|
26
|
+
module Util
|
27
|
+
#
|
28
|
+
# Logs a debug message to the specified `config.debug_filename`, if set.
|
29
|
+
#
|
30
|
+
def debug(msg)
|
31
|
+
# Should probably replace with a Logger
|
32
|
+
return unless config.debug_filename
|
33
|
+
|
34
|
+
@debug ||= File.open(config.debug_filename, 'w')
|
35
|
+
@debug.write("#{msg}\n")
|
36
|
+
@debug.flush
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Wrapper for a Net::HTTP GET request that handles redirects.
|
41
|
+
#
|
42
|
+
# :nocov:
|
43
|
+
def http_get(uri, retries_left = 10)
|
44
|
+
raise RedirectError, 'Too many redirects' if retries_left.zero?
|
45
|
+
|
46
|
+
case (response = Net::HTTP.get_response(URI(uri)))
|
47
|
+
when Net::HTTPClientError
|
48
|
+
nil
|
49
|
+
when Net::HTTPServerError
|
50
|
+
raise Net::HTTPServerException.new(response.message, response)
|
51
|
+
when Net::HTTPFound, Net::HTTPPermanentRedirect
|
52
|
+
http_get(response['location'], retries_left - 1)
|
53
|
+
else
|
54
|
+
StringIO.new(response.body)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
# :nocov:
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xml:lang="en-US">
|
3
|
+
<id>tag:github.com,2008:https://github.com/ghost/project/releases</id>
|
4
|
+
<link type="text/html" rel="alternate" href="https://github.com/ghost/project/releases"/>
|
5
|
+
<link type="application/atom+xml" rel="self" href="https://github.com/ghost/project/releases.atom"/>
|
6
|
+
<title>Release notes from project</title>
|
7
|
+
<updated>2016-07-10T01:57:28Z</updated>
|
8
|
+
<entry>
|
9
|
+
<id>tag:github.com,2008:Repository/12345678/v0.1.12_rust</id>
|
10
|
+
<updated>2016-07-10T01:59:24Z</updated>
|
11
|
+
<link rel="alternate" type="text/html" href="/ghost/project/releases/tag/v0.1.12_rust"/>
|
12
|
+
<title>v0.1.12_rust</title>
|
13
|
+
<content>No content.</content>
|
14
|
+
<author>
|
15
|
+
<name>ghost</name>
|
16
|
+
</author>
|
17
|
+
<media:thumbnail height="30" width="30" url="about:blank"/>
|
18
|
+
</entry>
|
19
|
+
<entry>
|
20
|
+
<id>tag:github.com,2008:Repository/12345678/v0.1.11_rust</id>
|
21
|
+
<updated>2016-07-09T22:47:09Z</updated>
|
22
|
+
<link rel="alternate" type="text/html" href="/ghost/project/releases/tag/v0.1.11_rust"/>
|
23
|
+
<title>v0.1.11_rust</title>
|
24
|
+
<content>No content.</content>
|
25
|
+
<author>
|
26
|
+
<name>ghost</name>
|
27
|
+
</author>
|
28
|
+
<media:thumbnail height="30" width="30" url="about:blank"/>
|
29
|
+
</entry>
|
30
|
+
</feed>
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016, 2017 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'test_helper'
|
21
|
+
require 'thermite/cargo'
|
22
|
+
|
23
|
+
module Thermite
|
24
|
+
class CargoTest < Minitest::Test
|
25
|
+
include Thermite::ModuleTester
|
26
|
+
|
27
|
+
class Tester
|
28
|
+
include Thermite::Cargo
|
29
|
+
include Thermite::TestHelper
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_run_cargo_if_exists
|
33
|
+
mock_module.stubs(:find_executable).returns('/opt/cargo-test/bin/cargo')
|
34
|
+
mock_module.expects(:sh).with('/opt/cargo-test/bin/cargo', 'foo', 'bar').once
|
35
|
+
mock_module.run_cargo_if_exists('foo', 'bar')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_run_cargo_if_exists_sans_cargo
|
39
|
+
mock_module.stubs(:find_executable).returns(nil)
|
40
|
+
mock_module.expects(:sh).never
|
41
|
+
mock_module.run_cargo_if_exists('foo', 'bar')
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_run_cargo_debug_rustc
|
45
|
+
mock_module.config.stubs(:dynamic_linker_flags).returns('')
|
46
|
+
mock_module.expects(:run_cargo).with('rustc').once
|
47
|
+
mock_module.run_cargo_rustc('debug')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_run_cargo_release_rustc
|
51
|
+
mock_module.config.stubs(:dynamic_linker_flags).returns('')
|
52
|
+
mock_module.expects(:run_cargo).with('rustc', '--release').once
|
53
|
+
mock_module.run_cargo_rustc('release')
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_run_cargo_rustc_with_workspace_member
|
57
|
+
mock_module.config.stubs(:dynamic_linker_flags).returns('')
|
58
|
+
mock_module.config.stubs(:cargo_workspace_member).returns('foo/bar')
|
59
|
+
mock_module.expects(:run_cargo).with('rustc', '--manifest-path', 'foo/bar/Cargo.toml').once
|
60
|
+
mock_module.run_cargo_rustc('debug')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_run_cargo_rustc_with_dynamic_linker_flags
|
64
|
+
mock_module.config.stubs(:dynamic_linker_flags).returns('foo bar')
|
65
|
+
if RbConfig::CONFIG['target_os'] == 'mingw32'
|
66
|
+
mock_module.expects(:run_cargo).with('rustc').once
|
67
|
+
else
|
68
|
+
mock_module.expects(:run_cargo).with('rustc', '--lib', '--', '-C', 'link-args=foo bar').once
|
69
|
+
end
|
70
|
+
mock_module.run_cargo_rustc('debug')
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_inform_user_about_cargo_exception
|
74
|
+
_, err = capture_io do
|
75
|
+
assert_raises RuntimeError do
|
76
|
+
mock_module(optional_rust_extension: false).inform_user_about_cargo
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_equal '', err
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_inform_user_about_cargo_warning
|
84
|
+
_, err = capture_io do
|
85
|
+
mock_module(optional_rust_extension: true).inform_user_about_cargo
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_equal mock_module.cargo_recommended_msg, err
|
89
|
+
end
|
90
|
+
|
91
|
+
def described_class
|
92
|
+
Tester
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,239 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016, 2017 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'test_helper'
|
21
|
+
|
22
|
+
module Thermite
|
23
|
+
class ConfigTest < Minitest::Test
|
24
|
+
def test_debug_filename
|
25
|
+
assert_nil described_class.new.debug_filename
|
26
|
+
ENV['THERMITE_DEBUG_FILENAME'] = 'foo'
|
27
|
+
assert_equal 'foo', described_class.new.debug_filename
|
28
|
+
ENV['THERMITE_DEBUG_FILENAME'] = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_shared_ext_osx
|
32
|
+
config.stubs(:dlext).returns('bundle')
|
33
|
+
assert_equal 'dylib', config.shared_ext
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_shared_ext_windows
|
37
|
+
config.stubs(:dlext).returns('so')
|
38
|
+
Gem.stubs(:win_platform?).returns(true)
|
39
|
+
assert_equal 'dll', config.shared_ext
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_shared_ext_unix
|
43
|
+
config.stubs(:dlext).returns('foobar')
|
44
|
+
Gem.stubs(:win_platform?).returns(false)
|
45
|
+
assert_equal 'foobar', config.shared_ext
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_ruby_version
|
49
|
+
config.stubs(:rbconfig_ruby_version).returns('3.2.0')
|
50
|
+
assert_equal 'ruby32', config.ruby_version
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_library_name_from_cargo_lib
|
54
|
+
config.stubs(:toml).returns(lib: { name: 'foobar' }, package: { name: 'barbaz' })
|
55
|
+
assert_equal 'foobar', config.library_name
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_library_name_from_cargo_package
|
59
|
+
config.stubs(:toml).returns(lib: {}, package: { name: 'barbaz' })
|
60
|
+
assert_equal 'barbaz', config.library_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_library_name_from_cargo_lib_has_no_hyphens
|
64
|
+
config.stubs(:toml).returns(lib: { name: 'foo-bar' }, package: { name: 'bar-baz' })
|
65
|
+
assert_equal 'foo_bar', config.library_name
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_library_name_from_cargo_package_has_no_hyphens
|
69
|
+
config.stubs(:toml).returns(lib: {}, package: { name: 'bar-baz' })
|
70
|
+
assert_equal 'bar_baz', config.library_name
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_shared_library
|
74
|
+
config.stubs(:library_name).returns('foobar')
|
75
|
+
config.stubs(:shared_ext).returns('ext')
|
76
|
+
Gem.stubs(:win_platform?).returns(false)
|
77
|
+
assert_equal 'foobar.so', config.shared_library
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_shared_library_windows
|
81
|
+
config.stubs(:library_name).returns('foobar')
|
82
|
+
config.stubs(:shared_ext).returns('ext')
|
83
|
+
Gem.stubs(:win_platform?).returns(true)
|
84
|
+
assert_equal 'foobar.so', config.shared_library
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_cargo_shared_library
|
88
|
+
config.stubs(:library_name).returns('foobar')
|
89
|
+
config.stubs(:shared_ext).returns('ext')
|
90
|
+
Gem.stubs(:win_platform?).returns(false)
|
91
|
+
assert_equal 'libfoobar.ext', config.cargo_shared_library
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_cargo_shared_library_windows
|
95
|
+
config.stubs(:library_name).returns('foobar')
|
96
|
+
config.stubs(:shared_ext).returns('ext')
|
97
|
+
Gem.stubs(:win_platform?).returns(true)
|
98
|
+
assert_equal 'foobar.ext', config.cargo_shared_library
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_tarball_filename
|
102
|
+
stub_tarball_filename_params(false)
|
103
|
+
assert_equal 'foobar-0.1.2-ruby12-c64-z80.tar.gz', config.tarball_filename('0.1.2')
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_tarball_filename_with_static_extension
|
107
|
+
stub_tarball_filename_params(true)
|
108
|
+
assert_equal 'foobar-0.1.2-ruby12-c64-z80-static.tar.gz', config.tarball_filename('0.1.2')
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_default_ruby_toplevel_dir
|
112
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
113
|
+
assert_equal '/tmp/foobar', config.ruby_toplevel_dir
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_ruby_toplevel_dir
|
117
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
118
|
+
assert_equal '/tmp/barbaz', config(ruby_project_path: '/tmp/barbaz').ruby_toplevel_dir
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_ruby_path
|
122
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
123
|
+
assert_equal '/tmp/foobar/baz/quux', config.ruby_path('baz', 'quux')
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_ruby_extension_path
|
127
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
128
|
+
config.stubs(:shared_library).returns('libfoo.ext')
|
129
|
+
assert_equal '/tmp/foobar/lib/libfoo.ext', config.ruby_extension_path
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_ruby_extension_path_with_custom_extension_dir
|
133
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
134
|
+
config.stubs(:ruby_extension_dir).returns('lib/ext')
|
135
|
+
config.stubs(:shared_library).returns('libfoo.ext')
|
136
|
+
assert_equal '/tmp/foobar/lib/ext/libfoo.ext', config.ruby_extension_path
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_default_rust_toplevel_dir
|
140
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
141
|
+
assert_equal '/tmp/foobar', config.rust_toplevel_dir
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_rust_toplevel_dir
|
145
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
146
|
+
assert_equal '/tmp/barbaz', config(cargo_project_path: '/tmp/barbaz').rust_toplevel_dir
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_rust_path
|
150
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
151
|
+
assert_equal '/tmp/foobar/baz/quux', config.rust_path('baz', 'quux')
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_cargo_target_path_with_env_var
|
155
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
156
|
+
ENV['CARGO_TARGET_DIR'] = 'foo'
|
157
|
+
assert_equal File.join('foo', 'debug', 'bar'), config.cargo_target_path('debug', 'bar')
|
158
|
+
ENV['CARGO_TARGET_DIR'] = nil
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_cargo_target_path_without_env_var
|
162
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
163
|
+
ENV['CARGO_TARGET_DIR'] = nil
|
164
|
+
assert_equal File.join('/tmp/foobar', 'target', 'debug', 'bar'),
|
165
|
+
config.cargo_target_path('debug', 'bar')
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_cargo_toml_path_with_workspace_member
|
169
|
+
FileUtils.stubs(:pwd).returns('/tmp/foobar')
|
170
|
+
config(cargo_workspace_member: 'baz')
|
171
|
+
assert_equal '/tmp/foobar/baz/Cargo.toml', config.cargo_toml_path
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_default_git_tag_regex
|
175
|
+
assert_equal described_class::DEFAULT_TAG_REGEX, config.git_tag_regex
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_git_tag_regex
|
179
|
+
assert_equal(/abc(\d)/, config(git_tag_regex: 'abc(\d)').git_tag_regex)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_toml
|
183
|
+
expected = {
|
184
|
+
package: {
|
185
|
+
name: 'fixture',
|
186
|
+
metadata: {
|
187
|
+
thermite: {
|
188
|
+
github_releases: true
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
assert_equal expected, config(cargo_project_path: fixtures_path('config')).toml
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_default_toml_config
|
197
|
+
config.stubs(:toml).returns({})
|
198
|
+
assert_equal({}, config.toml_config)
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_toml_config
|
202
|
+
expected = { github_releases: true }
|
203
|
+
assert_equal expected, config(cargo_project_path: fixtures_path('config')).toml_config
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_static_extension_sans_env_var
|
207
|
+
ENV.stubs(:key?).with('RUBY_STATIC').returns(false)
|
208
|
+
RbConfig::CONFIG.stubs(:[]).with('ENABLE_SHARED').returns('yes')
|
209
|
+
refute config.static_extension?
|
210
|
+
|
211
|
+
RbConfig::CONFIG.stubs(:[]).with('ENABLE_SHARED').returns('no')
|
212
|
+
assert config.static_extension?
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_static_extension_with_env_var
|
216
|
+
ENV.stubs(:key?).with('RUBY_STATIC').returns(true)
|
217
|
+
RbConfig::CONFIG.stubs(:[]).with('ENABLE_SHARED').returns('yes')
|
218
|
+
assert config.static_extension?
|
219
|
+
end
|
220
|
+
|
221
|
+
private
|
222
|
+
|
223
|
+
def config(options = {})
|
224
|
+
@config ||= described_class.new(options)
|
225
|
+
end
|
226
|
+
|
227
|
+
def described_class
|
228
|
+
Thermite::Config
|
229
|
+
end
|
230
|
+
|
231
|
+
def stub_tarball_filename_params(static_extension)
|
232
|
+
config.stubs(:library_name).returns('foobar')
|
233
|
+
config.stubs(:ruby_version).returns('ruby12')
|
234
|
+
config.stubs(:target_os).returns('c64')
|
235
|
+
config.stubs(:target_arch).returns('z80')
|
236
|
+
config.stubs(:static_extension?).returns(static_extension)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright (c) 2016, 2017 Mark Lee and contributors
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
6
|
+
# associated documentation files (the "Software"), to deal in the Software without restriction,
|
7
|
+
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
8
|
+
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all copies or
|
12
|
+
# substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
15
|
+
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
17
|
+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
18
|
+
# OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'tmpdir'
|
21
|
+
require 'test_helper'
|
22
|
+
require 'thermite/custom_binary'
|
23
|
+
require 'thermite/util'
|
24
|
+
|
25
|
+
module Thermite
|
26
|
+
class CustomBinaryTest < Minitest::Test
|
27
|
+
include Thermite::ModuleTester
|
28
|
+
|
29
|
+
class Tester
|
30
|
+
include Thermite::CustomBinary
|
31
|
+
include Thermite::TestHelper
|
32
|
+
include Thermite::Util
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_no_downloading_when_binary_uri_is_falsey
|
36
|
+
mock_module(binary_uri_format: false)
|
37
|
+
mock_module.expects(:http_get).never
|
38
|
+
|
39
|
+
assert !mock_module.download_binary_from_custom_uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_download_binary_from_custom_uri
|
43
|
+
mock_module(binary_uri_format: 'http://example.com/download/%<version>s/%<filename>s')
|
44
|
+
mock_module.config.stubs(:toml).returns(package: { version: '4.5.6' })
|
45
|
+
Net::HTTP.stubs(:get_response).returns('location' => 'redirect')
|
46
|
+
mock_module.stubs(:http_get).returns('tarball')
|
47
|
+
mock_module.expects(:unpack_tarball).once
|
48
|
+
mock_module.expects(:prepare_downloaded_library).once
|
49
|
+
|
50
|
+
assert mock_module.download_binary_from_custom_uri
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def described_class
|
56
|
+
Tester
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|