mini_portile2 2.8.3 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/mini_portile2/mini_portile.rb +31 -3
- data/lib/mini_portile2/mini_portile_cmake.rb +83 -7
- data/lib/mini_portile2/version.rb +1 -1
- data/test/test_cmake.rb +136 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 999335cad76fefd8e0ec313bb0bd7260a0259ef37760a01ee34153754ea2661f
|
4
|
+
data.tar.gz: 472586aad90ab8c61df7fffd60f6507206d3900fb71d505edef100ceef6e7e2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c978de2664efdee0bd9b89a842d33844c7ab6ee5d9dce45baaa53e061ab04777fcfb0ecc4900b772e4a2cf64c80c615b727d1227f9d09e223e30834f1dbf5ddc
|
7
|
+
data.tar.gz: 58a18c5ee2c34ab370dd0d30449aa2bf06e40d7e070ab1bd5e8fcf4226e8e390516718b2b6aed0e17ee3736aa04eea45917cee53a5a1b117b78ffcb12dc4bfd3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## mini_portile changelog
|
2
2
|
|
3
|
+
### 2.8.4 / 2023-07-18
|
4
|
+
|
5
|
+
- cmake: set CMAKE compile flags to configure cross-compilation similarly to `autotools` `--host` flag: `SYSTEM_NAME`, `SYSTEM_PROCESSOR`, `C_COMPILER`, and `CXX_COMPILER`. [#130] (Thanks, @stanhu!)
|
6
|
+
|
7
|
+
|
3
8
|
### 2.8.3 / 2023-07-18
|
4
9
|
|
5
10
|
#### Fixed
|
@@ -35,17 +35,45 @@ class MiniPortile
|
|
35
35
|
attr_accessor :host, :files, :patch_files, :target, :logger, :source_directory
|
36
36
|
|
37
37
|
def self.windows?
|
38
|
-
|
38
|
+
target_os =~ /mswin|mingw/
|
39
39
|
end
|
40
40
|
|
41
41
|
# GNU MinGW compiled Ruby?
|
42
42
|
def self.mingw?
|
43
|
-
|
43
|
+
target_os =~ /mingw/
|
44
44
|
end
|
45
45
|
|
46
46
|
# MS Visual-C compiled Ruby?
|
47
47
|
def self.mswin?
|
48
|
-
|
48
|
+
target_os =~ /mswin/
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.darwin?
|
52
|
+
target_os =~ /darwin/
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.freebsd?
|
56
|
+
target_os =~ /freebsd/
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.openbsd?
|
60
|
+
target_os =~ /openbsd/
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.linux?
|
64
|
+
target_os =~ /linux/
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.solaris?
|
68
|
+
target_os =~ /solaris/
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.target_os
|
72
|
+
RbConfig::CONFIG['target_os']
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.target_cpu
|
76
|
+
RbConfig::CONFIG['target_cpu']
|
49
77
|
end
|
50
78
|
|
51
79
|
def initialize(name, version, **kwargs)
|
@@ -2,6 +2,8 @@ require 'mini_portile2/mini_portile'
|
|
2
2
|
require 'open3'
|
3
3
|
|
4
4
|
class MiniPortileCMake < MiniPortile
|
5
|
+
attr_accessor :system_name
|
6
|
+
|
5
7
|
def configure_prefix
|
6
8
|
"-DCMAKE_INSTALL_PREFIX=#{File.expand_path(port_path)}"
|
7
9
|
end
|
@@ -12,13 +14,10 @@ class MiniPortileCMake < MiniPortile
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def configure_defaults
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
[]
|
21
|
-
end
|
17
|
+
[
|
18
|
+
generator_defaults,
|
19
|
+
cmake_compile_flags,
|
20
|
+
].flatten
|
22
21
|
end
|
23
22
|
|
24
23
|
def configure
|
@@ -52,6 +51,77 @@ class MiniPortileCMake < MiniPortile
|
|
52
51
|
|
53
52
|
private
|
54
53
|
|
54
|
+
def generator_defaults
|
55
|
+
if MiniPortile.mswin? && generator_available?('NMake')
|
56
|
+
['-G', 'NMake Makefiles']
|
57
|
+
elsif MiniPortile.mingw? && generator_available?('MSYS')
|
58
|
+
['-G', 'MSYS Makefiles']
|
59
|
+
else
|
60
|
+
[]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def cmake_compile_flags
|
65
|
+
c_compiler, cxx_compiler = find_c_and_cxx_compilers(host)
|
66
|
+
|
67
|
+
# needed to ensure cross-compilation with CMake targets the right CPU and compilers
|
68
|
+
[
|
69
|
+
"-DCMAKE_SYSTEM_NAME=#{cmake_system_name}",
|
70
|
+
"-DCMAKE_SYSTEM_PROCESSOR=#{cpu_type}",
|
71
|
+
"-DCMAKE_C_COMPILER=#{c_compiler}",
|
72
|
+
"-DCMAKE_CXX_COMPILER=#{cxx_compiler}"
|
73
|
+
]
|
74
|
+
end
|
75
|
+
|
76
|
+
def find_compiler(compilers)
|
77
|
+
compilers.find { |binary| which(binary) }
|
78
|
+
end
|
79
|
+
|
80
|
+
# configure automatically searches for the right compiler based on the
|
81
|
+
# `--host` parameter. However, CMake doesn't have an equivalent feature.
|
82
|
+
# Search for the right compiler for the target architecture using
|
83
|
+
# some basic heruistics.
|
84
|
+
def find_c_and_cxx_compilers(host)
|
85
|
+
c_compiler = ENV["CC"]
|
86
|
+
cxx_compiler = ENV["CXX"]
|
87
|
+
|
88
|
+
if MiniPortile.darwin?
|
89
|
+
c_compiler ||= 'clang'
|
90
|
+
cxx_compiler ||='clang++'
|
91
|
+
else
|
92
|
+
c_compiler ||= 'gcc'
|
93
|
+
cxx_compiler ||= 'g++'
|
94
|
+
end
|
95
|
+
|
96
|
+
c_platform_compiler = "#{host}-#{c_compiler}"
|
97
|
+
cxx_platform_compiler = "#{host}-#{cxx_compiler}"
|
98
|
+
c_compiler = find_compiler([c_platform_compiler, c_compiler])
|
99
|
+
cxx_compiler = find_compiler([cxx_platform_compiler, cxx_compiler])
|
100
|
+
|
101
|
+
[c_compiler, cxx_compiler]
|
102
|
+
end
|
103
|
+
|
104
|
+
# Full list: https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.4/Modules/CMakeDetermineSystem.cmake?ref_type=tags#L12-31
|
105
|
+
def cmake_system_name
|
106
|
+
return system_name if system_name
|
107
|
+
|
108
|
+
if MiniPortile.linux?
|
109
|
+
'Linux'
|
110
|
+
elsif MiniPortile.darwin?
|
111
|
+
'Darwin'
|
112
|
+
elsif MiniPortile.windows?
|
113
|
+
'Windows'
|
114
|
+
elsif MiniPortile.freebsd?
|
115
|
+
'FreeBSD'
|
116
|
+
elsif MiniPortile.openbsd?
|
117
|
+
'OpenBSD'
|
118
|
+
elsif MiniPortile.solaris?
|
119
|
+
'SunOS'
|
120
|
+
else
|
121
|
+
raise "Unable to set CMAKE_SYSTEM_NAME for #{MiniPortile.target_os}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
55
125
|
def generator_available?(generator_type)
|
56
126
|
stdout_str, status = Open3.capture2("#{cmake_cmd} --help")
|
57
127
|
|
@@ -59,4 +129,10 @@ class MiniPortileCMake < MiniPortile
|
|
59
129
|
|
60
130
|
stdout_str.include?("#{generator_type} Makefiles")
|
61
131
|
end
|
132
|
+
|
133
|
+
def cpu_type
|
134
|
+
return 'x86_64' if MiniPortile.target_cpu == 'x64'
|
135
|
+
|
136
|
+
MiniPortile.target_cpu
|
137
|
+
end
|
62
138
|
end
|
data/test/test_cmake.rb
CHANGED
@@ -14,13 +14,11 @@ class TestCMake < TestCase
|
|
14
14
|
create_tar(@tar_path, @assets_path, "test-cmake-1.0")
|
15
15
|
start_webrick(File.dirname(@tar_path))
|
16
16
|
|
17
|
-
@recipe =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
recipe.cook
|
23
|
-
end
|
17
|
+
@recipe = init_recipe
|
18
|
+
|
19
|
+
git_dir = File.join(@assets_path, "git")
|
20
|
+
with_custom_git_dir(git_dir) do
|
21
|
+
recipe.cook
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
@@ -57,6 +55,13 @@ class TestCMake < TestCase
|
|
57
55
|
binary = File.join(recipe.path, "bin", exe_name)
|
58
56
|
assert File.exist?(binary), binary
|
59
57
|
end
|
58
|
+
|
59
|
+
def init_recipe
|
60
|
+
MiniPortileCMake.new("test-cmake", "1.0").tap do |recipe|
|
61
|
+
recipe.files << "http://localhost:#{HTTP_PORT}/#{ERB::Util.url_encode(File.basename(@tar_path))}"
|
62
|
+
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
|
63
|
+
end
|
64
|
+
end
|
60
65
|
end
|
61
66
|
|
62
67
|
class TestCMakeConfig < TestCMake
|
@@ -77,26 +82,103 @@ class TestCMakeConfig < TestCMake
|
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
85
|
+
def test_configure_defaults_with_macos
|
86
|
+
recipe = init_recipe
|
87
|
+
recipe.host = 'some-host'
|
88
|
+
|
89
|
+
with_env({ "CC" => nil, "CXX" => nil }) do
|
90
|
+
MiniPortile.stub(:darwin?, true) do
|
91
|
+
with_stubbed_target(os: 'darwin22', cpu: 'arm64') do
|
92
|
+
with_compilers(recipe, host_prefix: true, c_compiler: 'clang', cxx_compiler: 'clang++') do
|
93
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
94
|
+
assert_equal(
|
95
|
+
[
|
96
|
+
"-DCMAKE_SYSTEM_NAME=Darwin",
|
97
|
+
"-DCMAKE_SYSTEM_PROCESSOR=arm64",
|
98
|
+
"-DCMAKE_C_COMPILER=some-host-clang",
|
99
|
+
"-DCMAKE_CXX_COMPILER=some-host-clang++"
|
100
|
+
],
|
101
|
+
recipe.configure_defaults)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_configure_defaults_with_manual_system_name
|
110
|
+
recipe = init_recipe
|
111
|
+
recipe.system_name = 'Custom'
|
112
|
+
|
113
|
+
MiniPortile.stub(:darwin?, false) do
|
114
|
+
with_stubbed_target do
|
115
|
+
with_compilers(recipe) do
|
116
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
117
|
+
assert_equal(
|
118
|
+
[
|
119
|
+
"-DCMAKE_SYSTEM_NAME=Custom",
|
120
|
+
"-DCMAKE_SYSTEM_PROCESSOR=x86_64",
|
121
|
+
"-DCMAKE_C_COMPILER=gcc",
|
122
|
+
"-DCMAKE_CXX_COMPILER=g++"
|
123
|
+
],
|
124
|
+
recipe.configure_defaults)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
80
131
|
def test_configure_defaults_with_unix_makefiles
|
81
|
-
|
82
|
-
|
83
|
-
|
132
|
+
recipe = init_recipe
|
133
|
+
|
134
|
+
MiniPortile.stub(:linux?, true) do
|
135
|
+
MiniPortile.stub(:darwin?, false) do
|
136
|
+
with_stubbed_target do
|
137
|
+
with_compilers(recipe) do
|
138
|
+
Open3.stub(:capture2, cmake_help_mock('Unix')) do
|
139
|
+
MiniPortile.stub(:mingw?, true) do
|
140
|
+
assert_equal(default_x86_compile_flags,
|
141
|
+
recipe.configure_defaults)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
84
146
|
end
|
85
147
|
end
|
86
148
|
end
|
87
149
|
|
88
150
|
def test_configure_defaults_with_msys_makefiles
|
89
|
-
|
90
|
-
|
91
|
-
|
151
|
+
recipe = init_recipe
|
152
|
+
|
153
|
+
MiniPortile.stub(:linux?, true) do
|
154
|
+
MiniPortile.stub(:darwin?, false) do
|
155
|
+
with_stubbed_target do
|
156
|
+
with_compilers(recipe) do
|
157
|
+
Open3.stub(:capture2, cmake_help_mock('MSYS')) do
|
158
|
+
MiniPortile.stub(:mingw?, true) do
|
159
|
+
assert_equal(['-G', 'MSYS Makefiles'] + default_x86_compile_flags, recipe.configure_defaults)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
92
164
|
end
|
93
165
|
end
|
94
166
|
end
|
95
167
|
|
96
168
|
def test_configure_defaults_with_nmake_makefiles
|
97
|
-
|
98
|
-
|
99
|
-
|
169
|
+
recipe = init_recipe
|
170
|
+
|
171
|
+
MiniPortile.stub(:linux?, true) do
|
172
|
+
MiniPortile.stub(:darwin?, false) do
|
173
|
+
with_stubbed_target do
|
174
|
+
with_compilers(recipe) do
|
175
|
+
Open3.stub(:capture2, cmake_help_mock('NMake')) do
|
176
|
+
MiniPortile.stub(:mswin?, true) do
|
177
|
+
assert_equal(['-G', 'NMake Makefiles'] + default_x86_compile_flags, recipe.configure_defaults)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
100
182
|
end
|
101
183
|
end
|
102
184
|
end
|
@@ -114,12 +196,47 @@ class TestCMakeConfig < TestCMake
|
|
114
196
|
|
115
197
|
private
|
116
198
|
|
199
|
+
def with_stubbed_target(os: 'linux', cpu: 'x86_64')
|
200
|
+
MiniPortile.stub(:target_os, os) do
|
201
|
+
MiniPortile.stub(:target_cpu, cpu) do
|
202
|
+
yield
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def with_compilers(recipe, host_prefix: false, c_compiler: 'gcc', cxx_compiler: 'g++')
|
208
|
+
mock = MiniTest::Mock.new
|
209
|
+
|
210
|
+
if host_prefix
|
211
|
+
mock.expect(:call, true, ["#{recipe.host}-#{c_compiler}"])
|
212
|
+
mock.expect(:call, true, ["#{recipe.host}-#{cxx_compiler}"])
|
213
|
+
else
|
214
|
+
mock.expect(:call, false, ["#{recipe.host}-#{c_compiler}"])
|
215
|
+
mock.expect(:call, true, [c_compiler])
|
216
|
+
mock.expect(:call, false, ["#{recipe.host}-#{cxx_compiler}"])
|
217
|
+
mock.expect(:call, true, [cxx_compiler])
|
218
|
+
end
|
219
|
+
|
220
|
+
recipe.stub(:which, mock) do
|
221
|
+
yield
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def default_x86_compile_flags
|
226
|
+
[
|
227
|
+
"-DCMAKE_SYSTEM_NAME=Linux",
|
228
|
+
"-DCMAKE_SYSTEM_PROCESSOR=x86_64",
|
229
|
+
"-DCMAKE_C_COMPILER=gcc",
|
230
|
+
"-DCMAKE_CXX_COMPILER=g++"
|
231
|
+
]
|
232
|
+
end
|
233
|
+
|
117
234
|
def cmake_help_mock(generator_type)
|
118
235
|
open3_mock = MiniTest::Mock.new
|
119
236
|
cmake_script = <<~SCRIPT
|
120
|
-
|
121
|
-
|
122
|
-
|
237
|
+
echo "The following generators are available on this platform (* marks default):"
|
238
|
+
echo "* #{generator_type} Makefiles = Generates standard #{generator_type.upcase} makefiles."
|
239
|
+
SCRIPT
|
123
240
|
|
124
241
|
exit_status = MiniTest::Mock.new
|
125
242
|
exit_status.expect(:success?, true)
|