tebako 0.10.0 → 0.12.0
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/CMakeLists.txt +5 -15
- data/README.adoc +241 -78
- data/common.env +2 -2
- data/include/tebako/tebako-prism.h +51 -0
- data/lib/tebako/cli.rb +34 -11
- data/lib/tebako/cli_helpers.rb +25 -9
- data/lib/tebako/codegen.rb +95 -10
- data/lib/tebako/deploy_helper.rb +1 -1
- data/lib/tebako/options_manager.rb +89 -12
- data/lib/tebako/package_descriptor.rb +143 -0
- data/lib/tebako/packager/pass1_patch.rb +301 -0
- data/lib/tebako/packager/pass1a_patch.rb +55 -0
- data/lib/tebako/packager/pass2.rb +4 -3
- data/lib/tebako/packager/{pass1a.rb → patch.rb} +5 -13
- data/lib/tebako/packager/patch_literals.rb +39 -15
- data/lib/tebako/packager.rb +18 -23
- data/lib/tebako/packager_lite.rb +78 -0
- data/lib/tebako/ruby_version.rb +9 -3
- data/lib/tebako/scenario_manager.rb +1 -1
- data/lib/tebako/version.rb +1 -1
- data/src/tebako-main.cpp +46 -30
- metadata +8 -4
- data/lib/tebako/packager/pass1.rb +0 -242
@@ -0,0 +1,301 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2021-2025 [Ribose Inc](https://www.ribose.com).
|
4
|
+
# All rights reserved.
|
5
|
+
# This file is a part of tebako
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions
|
9
|
+
# are met:
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
|
20
|
+
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
require_relative "patch_helpers"
|
29
|
+
require_relative "patch_buildsystem"
|
30
|
+
|
31
|
+
require_relative "patch"
|
32
|
+
# Tebako - an executable packager
|
33
|
+
module Tebako
|
34
|
+
# Packager module
|
35
|
+
module Packager
|
36
|
+
class << self
|
37
|
+
def crt_pass1_patch(os_type, mount_point, ruby_ver)
|
38
|
+
case os_type
|
39
|
+
when /darwin/
|
40
|
+
Pass1DarwinPatch.new(mount_point, ruby_ver)
|
41
|
+
when /msys/
|
42
|
+
Pass1MSysPatch.new(mount_point, ruby_ver)
|
43
|
+
else
|
44
|
+
Pass1Patch.new(mount_point, ruby_ver)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
# Ruby patching definitions (pass1 - common)
|
49
|
+
class Pass1Patch < Patch
|
50
|
+
# [TODO] looks like it does not exist in 3.1.4
|
51
|
+
# May be obsolete
|
52
|
+
TOOL_RBINSTALL_RB_PATCH = {
|
53
|
+
" next if files.empty?" => "# tebako patched next if files.empty?"
|
54
|
+
}.freeze
|
55
|
+
|
56
|
+
RUBYGEM_OPENSSL_RB_SUBST = <<~SUBST
|
57
|
+
# Start of tebako patch
|
58
|
+
require "openssl"
|
59
|
+
# End of tebako patch
|
60
|
+
autoload :OpenSSL, "openssl"
|
61
|
+
SUBST
|
62
|
+
|
63
|
+
RUBYGEM_OPENSSL_RB_PATCH = {
|
64
|
+
'autoload :OpenSSL, "openssl"' => RUBYGEM_OPENSSL_RB_SUBST
|
65
|
+
}.freeze
|
66
|
+
|
67
|
+
EXT_SETUP_PATCH = {
|
68
|
+
"#option nodynamic" => "option nodynamic"
|
69
|
+
}.freeze
|
70
|
+
|
71
|
+
# ....................................................
|
72
|
+
# This is something that I cannnot explain
|
73
|
+
# (this patch does not seem related to static compilation)
|
74
|
+
|
75
|
+
EXT_BIGDECIMAL_BIGDECIMAL_H_PATCH = {
|
76
|
+
"#include \"ruby/ruby.h\"" => <<~SUBST
|
77
|
+
#include "ruby/ruby.h"
|
78
|
+
|
79
|
+
/* -- Start of tebako patch -- */
|
80
|
+
#ifndef HAVE_RB_SYM2STR
|
81
|
+
#define HAVE_RB_SYM2STR 1
|
82
|
+
#endif
|
83
|
+
|
84
|
+
#ifndef HAVE_RB_ARRAY_CONST_PTR
|
85
|
+
#define HAVE_RB_ARRAY_CONST_PTR 1
|
86
|
+
#endif
|
87
|
+
|
88
|
+
#ifndef HAVE_RB_RATIONAL_NUM
|
89
|
+
#define HAVE_RB_RATIONAL_NUM 1
|
90
|
+
#endif
|
91
|
+
|
92
|
+
#ifndef HAVE_RB_RATIONAL_DEN
|
93
|
+
#define HAVE_RB_RATIONAL_DEN 1
|
94
|
+
#endif
|
95
|
+
|
96
|
+
#ifndef HAVE_RB_COMPLEX_REAL
|
97
|
+
#define HAVE_RB_COMPLEX_REAL
|
98
|
+
#endif
|
99
|
+
|
100
|
+
#ifndef HAVE_RB_COMPLEX_IMAG
|
101
|
+
#define HAVE_RB_COMPLEX_IMAG
|
102
|
+
#endif
|
103
|
+
/* -- End of tebako patch -- */
|
104
|
+
|
105
|
+
SUBST
|
106
|
+
}.freeze
|
107
|
+
|
108
|
+
# The logic for statically linked extensions is broken entirely in the latest Ruby versions.
|
109
|
+
# The code below looks reasonble - we do not set -bundle_loader when building with -with-static-ext option
|
110
|
+
# However Gems bundled with Ruby just ignore with-static-ext option and build extensions as shared libraries
|
111
|
+
# So the -bundler_loader option is required for them to link.
|
112
|
+
# It is strange that it is disabled in any case because this option does not create any issues for static
|
113
|
+
# libraries.
|
114
|
+
# ---------------------------------------------------
|
115
|
+
# elif test "x$EXTSTATIC" = x
|
116
|
+
# then :
|
117
|
+
#
|
118
|
+
# # When building exts as bundles, a mach-o bundle needs to know its loader
|
119
|
+
# # program to bind symbols from the ruby executable
|
120
|
+
# EXTDLDFLAGS="-bundle_loader '\$(BUILTRUBY)'"
|
121
|
+
|
122
|
+
OPENSSL_EXTCONF_RB_SUBST = <<~SUBST
|
123
|
+
# Start of tebako patch
|
124
|
+
$defs.push("-DRUBY_EXPORT=1")
|
125
|
+
# End of tebako patch
|
126
|
+
|
127
|
+
Logging::message "=== Checking done. ===\\n"
|
128
|
+
SUBST
|
129
|
+
|
130
|
+
OPENSSL_EXTCONF_RB_PATCH = {
|
131
|
+
"Logging::message \"=== Checking done. ===\\n\"" => OPENSSL_EXTCONF_RB_SUBST
|
132
|
+
}.freeze
|
133
|
+
|
134
|
+
def initialize(mountpoint, ruby_ver)
|
135
|
+
super()
|
136
|
+
@mountpoint = mountpoint
|
137
|
+
@ruby_ver = ruby_ver
|
138
|
+
end
|
139
|
+
|
140
|
+
def base_patch_map
|
141
|
+
{
|
142
|
+
# ....................................................
|
143
|
+
# It won't install gems with no files defined in spec
|
144
|
+
# However if
|
145
|
+
# -- we are installing a default gem from extension
|
146
|
+
# -- extension is build statically
|
147
|
+
# there may be no files install in addition to spec
|
148
|
+
# Example: io/wait extension (and others)
|
149
|
+
# [TODO] Check if it is still required
|
150
|
+
# No match and patching on Ruby 3.1.4 but works wo issues
|
151
|
+
"tool/rbinstall.rb" => TOOL_RBINSTALL_RB_PATCH,
|
152
|
+
|
153
|
+
# ....................................................
|
154
|
+
# Allow only packaged gems (from within memfs)
|
155
|
+
"lib/rubygems/path_support.rb" => rubygems_path_support_patch,
|
156
|
+
|
157
|
+
# ....................................................
|
158
|
+
# Disable dynamic extensions
|
159
|
+
"ext/Setup" => EXT_SETUP_PATCH
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
def patch_map
|
164
|
+
pm = base_patch_map
|
165
|
+
pm.merge!(super)
|
166
|
+
|
167
|
+
# ....................................................
|
168
|
+
pm.store("ext/bigdecimal/bigdecimal.h", EXT_BIGDECIMAL_BIGDECIMAL_H_PATCH) unless @ruby_ver.ruby34?
|
169
|
+
|
170
|
+
# ....................................................
|
171
|
+
# autoload :OpenSSL, "openssl"
|
172
|
+
# fails to deal with a default gem from statically linked extension
|
173
|
+
pm.store("lib/rubygems/openssl.rb", RUBYGEM_OPENSSL_RB_PATCH) if @ruby_ver.ruby3x?
|
174
|
+
|
175
|
+
pm.freeze
|
176
|
+
end
|
177
|
+
|
178
|
+
private
|
179
|
+
|
180
|
+
def rubygems_path_support_patch_one
|
181
|
+
<<~SUBST
|
182
|
+
@home = env["GEM_HOME"] || Gem.default_dir
|
183
|
+
# -- Start of tebako patch --
|
184
|
+
unless env["TEBAKO_PASS_THROUGH"]
|
185
|
+
@home = Gem.default_dir unless @home.index("#{@mount_point}") == 0
|
186
|
+
end
|
187
|
+
# -- End of tebako patch --
|
188
|
+
|
189
|
+
SUBST
|
190
|
+
end
|
191
|
+
|
192
|
+
def rubygems_path_support_patch_two
|
193
|
+
<<~SUBST
|
194
|
+
|
195
|
+
@path = split_gem_path env["GEM_PATH"], @home
|
196
|
+
# -- Start of tebako patch --
|
197
|
+
unless env["TEBAKO_PASS_THROUGH"]
|
198
|
+
@path.keep_if do |xpath|
|
199
|
+
xpath.index("#{@mount_point}") == 0
|
200
|
+
end
|
201
|
+
end
|
202
|
+
# -- End of tebako patch --
|
203
|
+
|
204
|
+
SUBST
|
205
|
+
end
|
206
|
+
|
207
|
+
def rubygems_path_support_patch
|
208
|
+
{
|
209
|
+
' @home = env["GEM_HOME"] || Gem.default_dir' => rubygems_path_support_patch_one,
|
210
|
+
' @path = split_gem_path env["GEM_PATH"], @home' => rubygems_path_support_patch_two
|
211
|
+
}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
# Ruby patching definitions (pass1 - darwin)
|
216
|
+
class Pass1DarwinPatch < Pass1Patch
|
217
|
+
DARWIN_CONFIGURE_PATCH = {
|
218
|
+
"elif test \"x$EXTSTATIC\" = x" => "elif true"
|
219
|
+
}.freeze
|
220
|
+
|
221
|
+
def patch_map
|
222
|
+
pm = { "configure" => DARWIN_CONFIGURE_PATCH }
|
223
|
+
pm.merge!(super)
|
224
|
+
pm.freeze
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# Ruby patching definitions (pass1 - Windows)
|
229
|
+
class Pass1MSysPatch < Pass1Patch
|
230
|
+
INCLUDE_RUBY_ONIGMO_H_PATCH = {
|
231
|
+
"# define ONIG_EXTERN RUBY_EXTERN" => "# define ONIG_EXTERN extern"
|
232
|
+
}.freeze
|
233
|
+
|
234
|
+
WIN32_WINMAIN_C_PATCH = {
|
235
|
+
"WinMain(HINSTANCE current, HINSTANCE prev, LPSTR cmdline, int showcmd)" =>
|
236
|
+
"wWinMain(HINSTANCE current, HINSTANCE prev, LPWSTR cmdline, int showcmd)"
|
237
|
+
}.freeze
|
238
|
+
|
239
|
+
def patch_map
|
240
|
+
pm = msys_patches
|
241
|
+
pm.merge!(super)
|
242
|
+
pm.freeze
|
243
|
+
end
|
244
|
+
|
245
|
+
private
|
246
|
+
|
247
|
+
include Tebako::Packager::PatchBuildsystem
|
248
|
+
|
249
|
+
def gnumakefile_in_patch_p1 # rubocop:disable Metrics/MethodLength
|
250
|
+
objext = @ruby_ver.ruby32? ? "$(OBJEXT)" : "@OBJEXT@"
|
251
|
+
{
|
252
|
+
" DLLWRAP += -mno-cygwin" =>
|
253
|
+
"# tebako patched DLLWRAP += -mno-cygwin",
|
254
|
+
|
255
|
+
"$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext}" =>
|
256
|
+
"$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext} $(WINMAINOBJ) # tebako patched",
|
257
|
+
|
258
|
+
"$(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@" =>
|
259
|
+
"$(WINMAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ # tebako patched",
|
260
|
+
|
261
|
+
"--output-exp=$(RUBY_EXP) \\" =>
|
262
|
+
"--output-exp=$(RUBY_EXP) --output-lib=$(LIBRUBY) --output-def=tebako.def \\",
|
263
|
+
|
264
|
+
"--export-all $(LIBRUBY_A) $(LIBS) -o $(PROGRAM)" =>
|
265
|
+
"--export-all $(LIBRUBY_A) $(LIBS) -o program-stub.exe # tebako patched",
|
266
|
+
|
267
|
+
"@rm -f $(PROGRAM)" =>
|
268
|
+
"@rm -f program-stub.exe # tebako patched",
|
269
|
+
|
270
|
+
" $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)" =>
|
271
|
+
"# tebako patched $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)",
|
272
|
+
|
273
|
+
"RUBYDEF = $(DLL_BASE_NAME).def" => GNUMAKEFILE_IN_WINMAIN_SUBST
|
274
|
+
}
|
275
|
+
end
|
276
|
+
|
277
|
+
def msys_base_patches
|
278
|
+
{
|
279
|
+
# ....................................................
|
280
|
+
# Generate export definitions; use WinMain to build rubyw.exe
|
281
|
+
"cygwin/GNUmakefile.in" => gnumakefile_in_patch_p1,
|
282
|
+
# ....................................................
|
283
|
+
# RUBY_EXPORT=1 (shall be set for static builds but is missing in openssl extension)
|
284
|
+
"ext/openssl/extconf.rb" => OPENSSL_EXTCONF_RB_PATCH
|
285
|
+
}
|
286
|
+
end
|
287
|
+
|
288
|
+
def msys_patches
|
289
|
+
pm = msys_base_patches
|
290
|
+
|
291
|
+
if @ruby_ver.ruby34?
|
292
|
+
# ....................................................
|
293
|
+
# RUBY_EXTERN shall be extern for static build but is set to __declspec(dllimport) for encodin libarary
|
294
|
+
pm.store("include/ruby/onigmo.h", INCLUDE_RUBY_ONIGMO_H_PATCH)
|
295
|
+
pm.store("win32/winmain.c", WIN32_WINMAIN_C_PATCH)
|
296
|
+
end
|
297
|
+
pm
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2024-2025 [Ribose Inc](https://www.ribose.com).
|
4
|
+
# All rights reserved.
|
5
|
+
# This file is a part of tebako
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions
|
9
|
+
# are met:
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
|
20
|
+
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
require_relative "patch"
|
29
|
+
# Tebako - an executable packager
|
30
|
+
module Tebako
|
31
|
+
module Packager
|
32
|
+
# Ruby patching definitions (pass1a)
|
33
|
+
class Pass1APatch < Patch
|
34
|
+
GEM_PRELUDE_RB_PATCH = {
|
35
|
+
"if defined?(DidYouMean)" => <<~SUBST
|
36
|
+
if defined?(DidYouMean)
|
37
|
+
|
38
|
+
# -- Start of tebako patch --
|
39
|
+
begin
|
40
|
+
require 'tebako-runtime'
|
41
|
+
rescue LoadError
|
42
|
+
warn "'tebako-runtime' was not loaded."
|
43
|
+
end
|
44
|
+
# -- End of tebako patch --
|
45
|
+
SUBST
|
46
|
+
}.freeze
|
47
|
+
|
48
|
+
def patch_map
|
49
|
+
{
|
50
|
+
"gem_prelude.rb" => GEM_PRELUDE_RB_PATCH
|
51
|
+
}.freeze
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -46,6 +46,8 @@ module Tebako
|
|
46
46
|
patch_map.store("common.mk", COMMON_MK_PATCH)
|
47
47
|
end
|
48
48
|
extend_patch_map_r33(patch_map, ostype, deps_lib_dir, ruby_ver)
|
49
|
+
patch_map.store("prism_compile.c", PRISM_PATCHES) if ruby_ver.ruby34?
|
50
|
+
patch_map
|
49
51
|
end
|
50
52
|
|
51
53
|
private
|
@@ -68,11 +70,10 @@ module Tebako
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def get_dln_c_patch(ostype, ruby_ver)
|
73
|
+
pattern = "#ifndef dln_loaderror"
|
71
74
|
# Not using substitutions of dlxxx functions on Windows
|
72
75
|
dln_c_patch = {
|
73
|
-
|
74
|
-
"#{PatchHelpers.msys?(ostype) ? C_FILE_SUBST_LESS : C_FILE_SUBST}\n" \
|
75
|
-
"static const char funcname_prefix[sizeof(FUNCNAME_PREFIX) - 1] = FUNCNAME_PREFIX;\n"
|
76
|
+
pattern => "#{PatchHelpers.msys?(ostype) ? C_FILE_SUBST_LESS : C_FILE_SUBST}\n#{pattern}\n"
|
76
77
|
}
|
77
78
|
|
78
79
|
if PatchHelpers.msys?(ostype)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c)
|
3
|
+
# Copyright (c) 2025 [Ribose Inc](https://www.ribose.com).
|
4
4
|
# All rights reserved.
|
5
5
|
# This file is a part of tebako
|
6
6
|
#
|
@@ -25,21 +25,13 @@
|
|
25
25
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
26
|
# POSSIBILITY OF SUCH DAMAGE.
|
27
27
|
|
28
|
-
require_relative "patch_literals"
|
29
|
-
|
30
28
|
# Tebako - an executable packager
|
31
29
|
module Tebako
|
32
30
|
module Packager
|
33
|
-
# Ruby patching definitions (
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
{
|
38
|
-
"gem_prelude.rb" => GEM_PRELUDE_RB_PATCH
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
include Tebako::Packager::PatchLiterals
|
31
|
+
# Ruby patching definitions (common base)
|
32
|
+
class Patch
|
33
|
+
def patch_map
|
34
|
+
{}.freeze
|
43
35
|
end
|
44
36
|
end
|
45
37
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2023-
|
3
|
+
# Copyright (c) 2023-2025 [Ribose Inc](https://www.ribose.com).
|
4
4
|
# All rights reserved.
|
5
5
|
# This file is a part of tebako
|
6
6
|
#
|
@@ -150,6 +150,10 @@ module Tebako
|
|
150
150
|
"else if (e == EIO /* tebako patch */ && !within_tebako_memfs(path)) {"
|
151
151
|
}.freeze
|
152
152
|
|
153
|
+
DLN_C_PRE34_PATCH_PATTERN = "static const char funcname_prefix[sizeof(FUNCNAME_PREFIX) - 1] = FUNCNAME_PREFIX;"
|
154
|
+
|
155
|
+
DLN_C_PATCH_PATTERN = "#define init_funcname(buf, file) build_funcname(FUNCNAME_PREFIX, buf, file)"
|
156
|
+
|
153
157
|
DLN_C_MSYS_PATCH_PRE32 = {
|
154
158
|
" winfile = rb_w32_mbstr_to_wstr(CP_UTF8, file, -1, NULL);" => <<~SUBST
|
155
159
|
/* -- Start of tebako patch -- */
|
@@ -209,20 +213,6 @@ module Tebako
|
|
209
213
|
/* -- End of tebako patch -- */
|
210
214
|
SUBST
|
211
215
|
|
212
|
-
GEM_PRELUDE_RB_PATCH = {
|
213
|
-
"if defined?(DidYouMean)" => <<~SUBST
|
214
|
-
if defined?(DidYouMean)
|
215
|
-
|
216
|
-
# -- Start of tebako patch --
|
217
|
-
begin
|
218
|
-
require 'tebako-runtime'
|
219
|
-
rescue LoadError
|
220
|
-
warn "'tebako-runtime' was not loaded."
|
221
|
-
end
|
222
|
-
# -- End of tebako patch --
|
223
|
-
SUBST
|
224
|
-
}.freeze
|
225
|
-
|
226
216
|
IO_C_SUBST = <<~SUBST
|
227
217
|
/* -- Start of tebako patch -- */
|
228
218
|
if (is_tebako_file_descriptor(fd)) return;
|
@@ -328,6 +318,40 @@ module Tebako
|
|
328
318
|
"mf.macro \"EXTLIBS\", $extlibs" => "# mf.macro \"EXTLIBS\", $extlibs tebako patched"
|
329
319
|
}
|
330
320
|
}.freeze
|
321
|
+
|
322
|
+
PRISM_PATTERN_1 = "pm_string_init_result_t init_result = pm_read_file(&result->input, RSTRING_PTR(filepath));"
|
323
|
+
|
324
|
+
PRISM_SUBST_1 = <<~SUBST
|
325
|
+
/* -- Start of tebako patch -- */
|
326
|
+
pm_string_init_result_t init_result;
|
327
|
+
if (within_tebako_memfs(RSTRING_PTR(filepath)))
|
328
|
+
{
|
329
|
+
init_result = tebako_string_file_init(&result->input, RSTRING_PTR(filepath));
|
330
|
+
}
|
331
|
+
else
|
332
|
+
{
|
333
|
+
init_result = pm_read_file(&result->input, RSTRING_PTR(filepath));
|
334
|
+
}
|
335
|
+
/* -- End of tebako patch -- */
|
336
|
+
SUBST
|
337
|
+
|
338
|
+
PRISM_PATTERN_2 = "#include \"prism.h\""
|
339
|
+
PRISM_SUBST_2 = <<~SUBST
|
340
|
+
#{PRISM_PATTERN_2}
|
341
|
+
|
342
|
+
/* -- Start of tebako patch -- */
|
343
|
+
#include <tebako/tebako-config.h>
|
344
|
+
#include <tebako/tebako-defines.h>
|
345
|
+
#include <tebako/tebako-io.h>
|
346
|
+
#include <tebako/tebako-prism.h>
|
347
|
+
/* -- End of tebako patch -- */
|
348
|
+
|
349
|
+
SUBST
|
350
|
+
|
351
|
+
PRISM_PATCHES = {
|
352
|
+
PRISM_PATTERN_1 => PRISM_SUBST_1,
|
353
|
+
PRISM_PATTERN_2 => PRISM_SUBST_2
|
354
|
+
}.freeze
|
331
355
|
end
|
332
356
|
end
|
333
357
|
end
|
data/lib/tebako/packager.rb
CHANGED
@@ -33,8 +33,8 @@ require_relative "error"
|
|
33
33
|
require_relative "deploy_helper"
|
34
34
|
require_relative "ruby_builder"
|
35
35
|
require_relative "stripper"
|
36
|
-
require_relative "packager/
|
37
|
-
require_relative "packager/
|
36
|
+
require_relative "packager/pass1_patch"
|
37
|
+
require_relative "packager/pass1a_patch"
|
38
38
|
require_relative "packager/pass2"
|
39
39
|
require_relative "packager/patch_helpers"
|
40
40
|
|
@@ -67,9 +67,10 @@ module Tebako
|
|
67
67
|
class << self
|
68
68
|
# Create implib
|
69
69
|
def create_implib(src_dir, package_src_dir, app_name, ruby_ver)
|
70
|
-
|
70
|
+
a_name = File.basename(app_name, ".*")
|
71
|
+
create_def(src_dir, a_name)
|
71
72
|
puts " ... creating Windows import library"
|
72
|
-
params = ["dlltool", "-d", def_fname(src_dir,
|
73
|
+
params = ["dlltool", "-d", def_fname(src_dir, a_name), "-D", out_fname(a_name), "--output-lib",
|
73
74
|
lib_fname(package_src_dir, ruby_ver)]
|
74
75
|
BuildHelpers.run_with_capture(params)
|
75
76
|
end
|
@@ -85,13 +86,12 @@ module Tebako
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def finalize(os_type, src_dir, app_name, ruby_ver, patchelf)
|
89
|
+
puts "-- Running finalize script"
|
90
|
+
|
88
91
|
RubyBuilder.new(ruby_ver, src_dir).final_build
|
89
92
|
exe_suffix = Packager::PatchHelpers.exe_suffix(os_type)
|
90
93
|
src_name = File.join(src_dir, "ruby#{exe_suffix}")
|
91
|
-
|
92
|
-
params = [patchelf, "--remove-needed-version", "libpthread.so.0", "GLIBC_PRIVATE", src_name]
|
93
|
-
BuildHelpers.run_with_capture(params)
|
94
|
-
end
|
94
|
+
patchelf(src_name, patchelf)
|
95
95
|
package_name = "#{app_name}#{exe_suffix}"
|
96
96
|
strip_or_copy(os_type, src_name, package_name)
|
97
97
|
puts "Created tebako package at \"#{package_name}\""
|
@@ -106,9 +106,10 @@ module Tebako
|
|
106
106
|
FileUtils.cp_r "#{stash_dir}/.", src_dir
|
107
107
|
end
|
108
108
|
|
109
|
-
def mkdwarfs(deps_bin_dir, data_bin_file, data_src_dir)
|
109
|
+
def mkdwarfs(deps_bin_dir, data_bin_file, data_src_dir, descriptor = nil)
|
110
110
|
puts "-- Running mkdwarfs script"
|
111
111
|
params = [File.join(deps_bin_dir, "mkdwarfs"), "-o", data_bin_file, "-i", data_src_dir, "--no-progress"]
|
112
|
+
params << "--header" << descriptor if descriptor
|
112
113
|
BuildHelpers.run_with_capture_v(params)
|
113
114
|
end
|
114
115
|
|
@@ -118,7 +119,8 @@ module Tebako
|
|
118
119
|
puts "-- Running pass1 script"
|
119
120
|
|
120
121
|
PatchHelpers.recreate(src_dir)
|
121
|
-
|
122
|
+
patch = crt_pass1_patch(ostype, mount_point, ruby_ver)
|
123
|
+
do_patch(patch.patch_map, ruby_source_dir)
|
122
124
|
|
123
125
|
# Roll back pass1a, pass2 patches
|
124
126
|
# Just in case we are recovering after some error
|
@@ -131,8 +133,8 @@ module Tebako
|
|
131
133
|
# Patch gem_prelude.rb
|
132
134
|
def pass1a(ruby_source_dir)
|
133
135
|
puts "-- Running pass1a script"
|
134
|
-
|
135
|
-
do_patch(
|
136
|
+
patch = Pass1APatch.new.patch_map
|
137
|
+
do_patch(patch, ruby_source_dir)
|
136
138
|
end
|
137
139
|
|
138
140
|
# Pass2
|
@@ -189,18 +191,11 @@ module Tebako
|
|
189
191
|
patch_map.each { |fname, mapping| PatchHelpers.patch_file("#{root}/#{fname}", mapping) }
|
190
192
|
end
|
191
193
|
|
192
|
-
def
|
193
|
-
|
194
|
-
PatchHelpers.with_env(DEPLOY_ENV) do
|
195
|
-
out, st = Open3.capture2e("#{tbd}/ruby", "--version")
|
196
|
-
raise Tebako::Error, "Failed to run ruby --version" unless st.exitstatus.zero?
|
194
|
+
def patchelf(src_name, patchelf)
|
195
|
+
return if patchelf.nil?
|
197
196
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
ruby_version = match[1]
|
202
|
-
end
|
203
|
-
ruby_version
|
197
|
+
params = [patchelf, "--remove-needed-version", "libpthread.so.0", "GLIBC_PRIVATE", src_name]
|
198
|
+
BuildHelpers.run_with_capture(params)
|
204
199
|
end
|
205
200
|
|
206
201
|
def strip_or_copy(os_type, src_name, package_name)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
|
4
|
+
# All rights reserved.
|
5
|
+
# This file is a part of tebako
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions
|
9
|
+
# are met:
|
10
|
+
# 1. Redistributions of source code must retain the above copyright
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
12
|
+
# 2. Redistributions in binary form must reproduce the above copyright
|
13
|
+
# notice, this list of conditions and the following disclaimer in the
|
14
|
+
# documentation and/or other materials provided with the distribution.
|
15
|
+
#
|
16
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
18
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
|
20
|
+
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
27
|
+
|
28
|
+
require "pathname"
|
29
|
+
require "fileutils"
|
30
|
+
|
31
|
+
require_relative "options_manager"
|
32
|
+
require_relative "scenario_manager"
|
33
|
+
require_relative "package_descriptor"
|
34
|
+
require_relative "packager"
|
35
|
+
|
36
|
+
module Tebako
|
37
|
+
# Tebako application package descriptor
|
38
|
+
class PackagerLite
|
39
|
+
def initialize(options_manager, scenario_manager)
|
40
|
+
@opts = options_manager
|
41
|
+
@scm = scenario_manager
|
42
|
+
@scm.configure_scenario
|
43
|
+
end
|
44
|
+
|
45
|
+
def codegen
|
46
|
+
puts "-- Generating files"
|
47
|
+
Tebako::Codegen.generate_package_descriptor(@opts, @scm)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_implib
|
51
|
+
rv = Tebako::RubyVersion.new(@opts.ruby_ver)
|
52
|
+
bname = if @opts.mode == "application"
|
53
|
+
@opts.ref
|
54
|
+
else # @opts.mode == "both"
|
55
|
+
@opts.package
|
56
|
+
end
|
57
|
+
Tebako::Packager.create_implib(@opts.ruby_src_dir, @opts.data_src_dir, bname, rv)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_package
|
61
|
+
deploy
|
62
|
+
FileUtils.rm_f(name)
|
63
|
+
Tebako::Packager.mkdwarfs(@opts.deps_bin_dir, name, @opts.data_src_dir, codegen)
|
64
|
+
puts "Created tebako package at \"#{name}\""
|
65
|
+
end
|
66
|
+
|
67
|
+
def deploy
|
68
|
+
Tebako::Packager.init(@opts.stash_dir, @opts.data_src_dir, @opts.data_pre_dir, @opts.data_bin_dir)
|
69
|
+
create_implib if @scm.msys?
|
70
|
+
Tebako::Packager.deploy(@opts.data_src_dir, @opts.data_pre_dir, @opts.rv, @opts.root, @scm.fs_entrance, @opts.cwd)
|
71
|
+
end
|
72
|
+
|
73
|
+
def name
|
74
|
+
bname = Pathname.new(@opts.package).cleanpath.to_s
|
75
|
+
@name ||= "#{bname}.tebako"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|