tebako 0.12.9 → 0.12.11

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.
@@ -29,16 +29,17 @@ require_relative "patch_helpers"
29
29
  require_relative "patch_buildsystem"
30
30
 
31
31
  require_relative "patch"
32
+ require_relative "rubygems_patch"
32
33
  # Tebako - an executable packager
33
34
  module Tebako
34
35
  # Packager module
35
36
  module Packager
36
37
  class << self
37
- def crt_pass1_patch(os_type, mount_point, ruby_ver)
38
- case os_type
39
- when /darwin/
38
+ def crt_pass1_patch(ostype, mount_point, ruby_ver)
39
+ scmb = ScenarioManagerBase.new(ostype)
40
+ if scmb.macos?
40
41
  Pass1DarwinPatch.new(mount_point, ruby_ver)
41
- when /msys/
42
+ elsif scmb.msys?
42
43
  Pass1MSysPatch.new(mount_point, ruby_ver)
43
44
  else
44
45
  Pass1Patch.new(mount_point, ruby_ver)
@@ -46,24 +47,13 @@ module Tebako
46
47
  end
47
48
  end
48
49
  # Ruby patching definitions (pass1 - common)
49
- class Pass1Patch < Patch
50
+ class Pass1Patch < RubygemsPatch
50
51
  # [TODO] looks like it does not exist in 3.1.4
51
52
  # May be obsolete
52
53
  TOOL_RBINSTALL_RB_PATCH = {
53
54
  " next if files.empty?" => "# tebako patched next if files.empty?"
54
55
  }.freeze
55
56
 
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
57
  EXT_SETUP_PATCH = {
68
58
  "#option nodynamic" => "option nodynamic"
69
59
  }.freeze
@@ -131,9 +121,8 @@ module Tebako
131
121
  "Logging::message \"=== Checking done. ===\\n\"" => OPENSSL_EXTCONF_RB_SUBST
132
122
  }.freeze
133
123
 
134
- def initialize(mountpoint, ruby_ver)
135
- super()
136
- @mountpoint = mountpoint
124
+ def initialize(mount_point, ruby_ver)
125
+ super(mount_point)
137
126
  @ruby_ver = ruby_ver
138
127
  end
139
128
 
@@ -152,7 +141,7 @@ module Tebako
152
141
 
153
142
  # ....................................................
154
143
  # Allow only packaged gems (from within memfs)
155
- "lib/rubygems/path_support.rb" => rubygems_path_support_patch,
144
+ "lib/rubygems/path_support.rb" => rubygems_path_support_patch(@mount_point),
156
145
 
157
146
  # ....................................................
158
147
  # Disable dynamic extensions
@@ -170,46 +159,10 @@ module Tebako
170
159
  # ....................................................
171
160
  # autoload :OpenSSL, "openssl"
172
161
  # 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?
162
+ pm.store("lib/rubygems/openssl.rb", RUBYGEMS_OPENSSL_RB_PATCH) if @ruby_ver.ruby3x?
174
163
 
175
164
  pm.freeze
176
165
  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
166
  end
214
167
 
215
168
  # Ruby patching definitions (pass1 - darwin)
@@ -244,13 +197,10 @@ module Tebako
244
197
 
245
198
  private
246
199
 
247
- include Tebako::Packager::PatchBuildsystem
248
-
249
200
  def gnumakefile_in_patch_p1 # rubocop:disable Metrics/MethodLength
250
201
  objext = @ruby_ver.ruby32? ? "$(OBJEXT)" : "@OBJEXT@"
251
202
  {
252
- " DLLWRAP += -mno-cygwin" =>
253
- "# tebako patched DLLWRAP += -mno-cygwin",
203
+ "$(Q) $(DLLWRAP) \\" => GNUMAKEFILE_IN_DLLTOOL_SUBST,
254
204
 
255
205
  "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext}" =>
256
206
  "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext} $(WINMAINOBJ) # tebako patched",
@@ -258,14 +208,12 @@ module Tebako
258
208
  "$(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@" =>
259
209
  "$(WINMAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ # tebako patched",
260
210
 
261
- "--output-exp=$(RUBY_EXP) \\" =>
262
- "--output-exp=$(RUBY_EXP) --output-lib=$(LIBRUBY) --output-def=tebako.def \\",
211
+ "--output-exp=$(RUBY_EXP) \\" => "# tebako patched --output-exp=$(RUBY_EXP) \\",
263
212
 
264
213
  "--export-all $(LIBRUBY_A) $(LIBS) -o $(PROGRAM)" =>
265
- "--export-all $(LIBRUBY_A) $(LIBS) -o program-stub.exe # tebako patched",
214
+ "# tebako patched --export-all $(LIBRUBY_A) $(LIBS) -o $(PROGRAM)",
266
215
 
267
- "@rm -f $(PROGRAM)" =>
268
- "@rm -f program-stub.exe # tebako patched",
216
+ "@rm -f $(PROGRAM)" => "# tebako patched @rm -f $(PROGRAM)",
269
217
 
270
218
  " $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)" =>
271
219
  "# tebako patched $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)",
@@ -0,0 +1,219 @@
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_literals"
29
+ require_relative "patch_main"
30
+ require_relative "patch_libraries"
31
+ require_relative "patch_helpers"
32
+ require_relative "patch_buildsystem"
33
+
34
+ # Tebako - an executable packager
35
+ module Tebako
36
+ # Packager module
37
+ module Packager
38
+ class << self
39
+ def crt_pass2_patch(ostype, deps_lib_dir, ruby_ver)
40
+ scmb = ScenarioManagerBase.new(ostype)
41
+ if scmb.msys?
42
+ Pass2MSysPatch.new(ostype, deps_lib_dir, ruby_ver)
43
+ else
44
+ Pass2NonMSysPatch.new(ostype, deps_lib_dir, ruby_ver)
45
+ end
46
+ end
47
+ end
48
+ # Ruby patching definitions (pass2)
49
+ class Pass2Patch < Patch
50
+ def initialize(ostype, deps_lib_dir, ruby_ver)
51
+ super()
52
+ @ostype = ostype
53
+ @scmb = ScenarioManagerBase.new(@ostype)
54
+ @deps_lib_dir = deps_lib_dir
55
+ @ruby_ver = ruby_ver
56
+ end
57
+
58
+ def patch_map
59
+ pm = patch_map_base
60
+ pm.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if @scmb.musl?
61
+ pm.store("prism_compile.c", PRISM_PATCHES) if @ruby_ver.ruby34?
62
+ pm
63
+ end
64
+
65
+ private
66
+
67
+ include Tebako::Packager::PatchBuildsystem
68
+ include Tebako::Packager::PatchLiterals
69
+
70
+ def dir_c_patch
71
+ pattern = @scmb.msys? ? "/* define system APIs */" : "#ifdef HAVE_GETATTRLIST"
72
+ patch = PatchHelpers.patch_c_file_pre(pattern)
73
+ patch.merge!(DIR_C_BASE_PATCH)
74
+ patch
75
+ end
76
+
77
+ def dln_c_patch
78
+ pattern = "#ifndef dln_loaderror"
79
+ # Not using substitutions of dlxxx functions on Windows
80
+ patch = {
81
+ pattern => "#{@scmb.msys? ? C_FILE_SUBST_LESS : C_FILE_SUBST}\n#{pattern}\n"
82
+ }
83
+
84
+ if @scmb.msys?
85
+ patch.merge!(@ruby_ver.ruby32? ? DLN_C_MSYS_PATCH : DLN_C_MSYS_PATCH_PRE32)
86
+ end
87
+
88
+ patch
89
+ end
90
+
91
+ def io_c_msys_patch
92
+ patch = @ruby_ver.ruby32? ? IO_C_MSYS_PATCH : IO_C_MSYS_PATCH_PRE_32
93
+ patch.merge(IO_C_MSYS_BASE_PATCH)
94
+ end
95
+
96
+ def io_c_patch
97
+ patch = PatchHelpers.patch_c_file_pre("/* define system APIs */")
98
+ patch.merge!(io_c_msys_patch) if @scmb.msys?
99
+ patch
100
+ end
101
+
102
+ def util_c_patch
103
+ if @ruby_ver.ruby31?
104
+ PatchHelpers.patch_c_file_post("#endif /* !HAVE_GNU_QSORT_R */")
105
+ else
106
+ PatchHelpers.patch_c_file_pre("#ifndef S_ISDIR")
107
+ end
108
+ end
109
+
110
+ def tool_mkconfig_rb_patch
111
+ subst = @scmb.msys? ? TOOL_MKCONFIG_RB_SUBST_MSYS : TOOL_MKCONFIG_RB_SUBST
112
+ {
113
+ " if fast[name]" => subst
114
+ }
115
+ end
116
+
117
+ def patch_map_base
118
+ {
119
+ "template/Makefile.in" => template_makefile_in_patch,
120
+ "tool/mkconfig.rb" => tool_mkconfig_rb_patch,
121
+ "dir.c" => dir_c_patch, "dln.c" => dln_c_patch,
122
+ "io.c" => io_c_patch, "main.c" => PatchMain.get_main_c_patch(@ruby_ver),
123
+ "file.c" => PatchHelpers.patch_c_file_pre("/* define system APIs */"),
124
+ "util.c" => util_c_patch
125
+ }
126
+ end
127
+
128
+ def mlibs_subst
129
+ yjit_libs = @ruby_ver.ruby32only? ? "$(YJIT_LIBS) " : ""
130
+ {
131
+ "MAINLIBS = #{yjit_libs}@MAINLIBS@" =>
132
+ "# -- Start of tebako patch -- \n" \
133
+ "MAINLIBS = #{yjit_libs}#{PatchLibraries.mlibs(@ostype, @deps_lib_dir, @ruby_ver, true)}\n" \
134
+ "# -- End of tebako patch -- \n"
135
+ }
136
+ end
137
+
138
+ def template_makefile_in_patch
139
+ template_makefile_in_patch_two(@ruby_ver).merge(mlibs_subst)
140
+ end
141
+ end
142
+
143
+ # Msys Pass2 patches
144
+ class Pass2MSysPatch < Pass2Patch
145
+ def patch_map
146
+ pm = super
147
+ pm.merge!(msys_patches)
148
+ pm.store("config.status", get_config_status_patch(@ostype, @deps_lib_dir, @ruby_ver))
149
+ pm
150
+ end
151
+
152
+ private
153
+
154
+ include Tebako::Packager::PatchBuildsystem
155
+ include Tebako::Packager::PatchLiterals
156
+
157
+ # Other MSYS (GNUMakefile) specific patches
158
+ # - The same issue with libraries as for Makefile above
159
+ # - 'Kill' ruby.exp regeneration on pass2
160
+ # since we want to use output from pass1 for implib generation
161
+ # [VERY UGLY HACK]
162
+ # - Introduce LIBRUBY dependency on static extensions
163
+ # This is an addition to COMMON_MK_PATCH specified above
164
+ def gnumakefile_in_patch_p2 # rubocop:disable Metrics/MethodLength
165
+ objext = @ruby_ver.ruby32? ? "$(OBJEXT)" : "@OBJEXT@"
166
+
167
+ {
168
+ "$(Q) $(DLLWRAP) \\" => GNUMAKEFILE_IN_DLLTOOL_SUBST,
169
+
170
+ "--output-exp=$(RUBY_EXP) \\" => "# tebako patched --output-exp=$(RUBY_EXP) \\",
171
+
172
+ "--export-all $(LIBRUBY_A) $(LIBS) -o $(PROGRAM)" =>
173
+ "# tebako patched --export-all $(LIBRUBY_A) $(LIBS) -o $(PROGRAM)",
174
+
175
+ "@rm -f $(PROGRAM)" => "# tebako patched @rm -f $(PROGRAM)",
176
+
177
+ " $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)" =>
178
+ "# tebako patched $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)",
179
+
180
+ "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext}" =>
181
+ "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext} $(WINMAINOBJ) # tebako patched",
182
+
183
+ "RUBYDEF = $(DLL_BASE_NAME).def" => GNUMAKEFILE_IN_WINMAIN_SUBST,
184
+
185
+ "$(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@" =>
186
+ "$(WINMAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) -o $@ # tebako patched",
187
+
188
+ "$(RUBY_EXP): $(LIBRUBY_A)" => "dummy.exp: $(LIBRUBY_A) # tebako patched",
189
+
190
+ "$(PROGRAM): $(RUBY_INSTALL_NAME).res.#{objext}" =>
191
+ "$(PROGRAM): $(RUBY_INSTALL_NAME).res.#{objext} $(LIBRUBY_A) # tebako patched\n" \
192
+ "$(LIBRUBY_A): $(LIBRUBY_A_OBJS) $(INITOBJS) # tebako patched\n"
193
+ }
194
+ end
195
+
196
+ def msys_patches
197
+ {
198
+ "cygwin/GNUmakefile.in" => gnumakefile_in_patch_p2,
199
+ "ruby.c" => RUBY_C_MSYS_PATCHES,
200
+ "win32/file.c" => WIN32_FILE_C_MSYS_PATCHES,
201
+ "win32/win32.c" => WIN32_WIN32_C_MSYS_PATCHES
202
+ }
203
+ end
204
+ end
205
+
206
+ # Non-msys Pass2 patches
207
+ class Pass2NonMSysPatch < Pass2Patch
208
+ def patch_map
209
+ pm = super
210
+ pm.store("common.mk", COMMON_MK_PATCH) if @ruby_ver.ruby3x?
211
+ pm.store("config.status", get_config_status_patch(@ostype, @deps_lib_dir, @ruby_ver)) if @ruby_ver.ruby33?
212
+ pm
213
+ end
214
+
215
+ include Tebako::Packager::PatchBuildsystem
216
+ include Tebako::Packager::PatchLiterals
217
+ end
218
+ end
219
+ end
@@ -28,6 +28,22 @@
28
28
  # Tebako - an executable packager
29
29
  module Tebako
30
30
  module Packager
31
+ # Substitutions for cygwin/Gnumakefile.in shared across Pass1 and Pass2
32
+ GNUMAKEFILE_IN_DLLTOOL_SUBST = <<~SUBST
33
+ $(Q) dlltool --output-lib=$(LIBRUBY) --output-def=tebako.def --export-all $(LIBRUBY_A) --output-exp=$(RUBY_EXP) # tebako patched
34
+ SUBST
35
+
36
+ # This MSYS specific thing ensure compilation of winmain.c
37
+ # Did try to understand why it did not work out of the box
38
+ GNUMAKEFILE_IN_WINMAIN_SUBST = <<~SUBST
39
+ RUBYDEF = $(DLL_BASE_NAME).def
40
+
41
+ # Start of tebako patch
42
+ WINMAINOBJ = win32/winmain.$(OBJEXT)
43
+ $(WINMAINOBJ): win32/winmain.c
44
+ # End of tebako patch
45
+ SUBST
46
+
31
47
  # Ruby patching definitions (common base)
32
48
  class Patch
33
49
  def patch_map
@@ -77,8 +77,8 @@ module Tebako
77
77
  "$(EXTOBJS) $(LIBRUBYARG_STATIC) $(OUTFLAG)$@\n" \
78
78
  "# -- End of tebako patch --"
79
79
 
80
- def template_makefile_in_subst(ostype, ruby_ver)
81
- if PatchHelpers.msys?(ostype)
80
+ def template_makefile_in_subst(ruby_ver)
81
+ if ScenarioManagerBase.new.msys?
82
82
  TEMPLATE_MAKEFILE_IN_BASE_PATCH_MSYS
83
83
  elsif !ruby_ver.ruby31?
84
84
  TEMPLATE_MAKEFILE_IN_BASE_PATCH_PRE_3_1
@@ -87,37 +87,24 @@ module Tebako
87
87
  end
88
88
  end
89
89
 
90
- def template_makefile_in_patch_two(ostype, ruby_ver)
90
+ def template_makefile_in_patch_two(ruby_ver)
91
91
  if !ruby_ver.ruby31?
92
- { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_1 => template_makefile_in_subst(ostype, ruby_ver) }
92
+ { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_1 => template_makefile_in_subst(ruby_ver) }
93
93
  elsif !ruby_ver.ruby33?
94
- { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_3 => template_makefile_in_subst(ostype, ruby_ver) }
94
+ { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_3 => template_makefile_in_subst(ruby_ver) }
95
95
  else
96
- { TEMPLATE_MAKEFILE_IN_BASE_PATTERN => template_makefile_in_subst(ostype, ruby_ver) }
96
+ { TEMPLATE_MAKEFILE_IN_BASE_PATTERN => template_makefile_in_subst(ruby_ver) }
97
97
  end
98
98
  end
99
99
 
100
- # This MSYS specific thing ensure compilation of winmain.c
101
- # Did try to understand why it did not work out of the box
102
- GNUMAKEFILE_IN_WINMAIN_SUBST = <<~SUBST
103
- RUBYDEF = $(DLL_BASE_NAME).def
104
-
105
- # Start of tebako patch
106
- WINMAINOBJ = win32/winmain.$(OBJEXT)
107
- $(WINMAINOBJ): win32/winmain.c
108
- # End of tebako patch
109
- SUBST
110
-
111
100
  def get_config_status_pattern(ostype)
112
- case ostype
113
- when /linux-/
114
- "S[\"MAINLIBS\"]=\"-lz -lrt -lrt -ldl -lcrypt -lm -lpthread \""
115
- when /darwin/
101
+ scmb = ScenarioManagerBase.new(ostype)
102
+ if scmb.macos?
116
103
  "S[\"MAINLIBS\"]=\"-ldl -lobjc -lpthread \""
117
- when /msys/
104
+ elsif scmb.msys?
118
105
  "S[\"MAINLIBS\"]=\"-lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt \""
119
106
  else
120
- raise Tebako::Error, "Unknown ostype #{ostype}"
107
+ "S[\"MAINLIBS\"]=\"-lz -lrt -lrt -ldl -lcrypt -lm -lpthread \""
121
108
  end
122
109
  end
123
110
 
@@ -127,33 +114,6 @@ module Tebako
127
114
  "S[\"MAINLIBS\"]=\"#{PatchLibraries.mlibs(ostype, deps_lib_dir, ruby_ver, false)}\""
128
115
  }
129
116
  end
130
-
131
- # Other MSYS (GNUMakefile) specific patches
132
- # - The same issue with libraries as for Makefile above
133
- # - 'Kill' ruby.exp regeneration on pass2
134
- # since we want to use output from pass1 for implib generation
135
- # [VERY UGLY HACK]
136
- # - Introduce LIBRUBY dependency on static extensions
137
- # This is an addition to COMMON_MK_PATCH specified above
138
- def get_gnumakefile_in_patch_p2(ruby_ver) # rubocop:disable Metrics/MethodLength
139
- objext = ruby_ver.ruby32? ? "$(OBJEXT)" : "@OBJEXT@"
140
-
141
- {
142
- "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext}" =>
143
- "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext} $(WINMAINOBJ) # tebako patched",
144
-
145
- "RUBYDEF = $(DLL_BASE_NAME).def" => GNUMAKEFILE_IN_WINMAIN_SUBST,
146
-
147
- "$(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@" =>
148
- "$(WINMAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) -o $@ # tebako patched",
149
-
150
- "$(RUBY_EXP): $(LIBRUBY_A)" => "dummy.exp: $(LIBRUBY_A) # tebako patched",
151
-
152
- "$(PROGRAM): $(RUBY_INSTALL_NAME).res.#{objext}" =>
153
- "$(PROGRAM): $(RUBY_INSTALL_NAME).res.#{objext} $(LIBRUBY_A) # tebako patched\n" \
154
- "$(LIBRUBY_A): $(LIBRUBY_A_OBJS) $(INITOBJS) # tebako patched\n"
155
- }
156
- end
157
117
  end
158
118
  end
159
119
  end
@@ -62,18 +62,6 @@ module Tebako
62
62
  out
63
63
  end
64
64
 
65
- def exe_suffix(ostype)
66
- msys?(ostype) ? ".exe" : ""
67
- end
68
-
69
- def msys?(ostype)
70
- ostype =~ /msys|cygwin|mingw/
71
- end
72
-
73
- def macos?(ostype)
74
- ostype =~ /darwin/
75
- end
76
-
77
65
  def patch_c_file_pre(pattern)
78
66
  {
79
67
  pattern => "#{PatchLiterals::C_FILE_SUBST}\n#{pattern}"
@@ -148,18 +148,16 @@ module Tebako
148
148
  # This is fixed by ext/extmk.rb patch [TODO ?]
149
149
  # .....................................................
150
150
 
151
- def mlibs(ostype, deps_lib_dir, ruby_ver, with_compression) # rubocop:disable Metrics/MethodLength
152
- case ostype
153
- when /linux-gnu/
154
- linux_gnu_libraries(ruby_ver, with_compression)
155
- when /linux-musl/
156
- linux_musl_libraries(ruby_ver, with_compression)
157
- when /darwin/
158
- darwin_libraries(deps_lib_dir, ruby_ver, with_compression)
159
- when /msys/
151
+ def mlibs(ostype, deps_lib_dir, ruby_ver, with_compression)
152
+ scmb = ScenarioManagerBase.new(ostype)
153
+ if scmb.msys?
160
154
  msys_libraries(ruby_ver, with_compression)
155
+ elsif scmb.macos?
156
+ darwin_libraries(deps_lib_dir, ruby_ver, with_compression)
157
+ elsif scmb.musl?
158
+ linux_musl_libraries(ruby_ver, with_compression)
161
159
  else
162
- raise Tebako::Error, "Unknown ostype #{ostype}"
160
+ linux_gnu_libraries(ruby_ver, with_compression)
163
161
  end
164
162
  end
165
163
  end
@@ -0,0 +1,83 @@
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
+ # Shared accross Pass1Patch and RybugemsUpdatePatch
33
+ class RubygemsPatch < Patch
34
+ RUBYGEMS_OPENSSL_RB_SUBST = <<~SUBST
35
+ # Start of tebako patch
36
+ require "openssl"
37
+ # End of tebako patch
38
+ autoload :OpenSSL, "openssl"
39
+ SUBST
40
+
41
+ RUBYGEMS_OPENSSL_RB_PATCH = {
42
+ 'autoload :OpenSSL, "openssl"' => RUBYGEMS_OPENSSL_RB_SUBST
43
+ }.freeze
44
+
45
+ def initialize(mount_point)
46
+ super()
47
+ @mount_point = mount_point
48
+ end
49
+
50
+ protected
51
+
52
+ def rubygems_path_support_patch(mount_point)
53
+ patch = <<~SUBST
54
+ # -- Start of tebako patch --
55
+ @home = Gem.default_dir unless @home.index("#{mount_point}") == 0 unless env["TEBAKO_PASS_THROUGH"]
56
+ # -- End of tebako patch --
57
+ @path = split_gem_path env["GEM_PATH"], @home
58
+ # -- Start of tebako patch --
59
+ @path.keep_if do |xpath|
60
+ xpath.index("#{mount_point}") == 0
61
+ end unless env["TEBAKO_PASS_THROUGH"]
62
+ # -- End of tebako patch --
63
+ SUBST
64
+
65
+ {
66
+ ' @path = split_gem_path env["GEM_PATH"], @home' => patch
67
+ }
68
+ end
69
+ end
70
+
71
+ # Rubygems patch after update
72
+ class RubygemsUpdatePatch < RubygemsPatch
73
+ def patch_map
74
+ pm = {
75
+ "rubygems/openssl.rb" => RUBYGEMS_OPENSSL_RB_PATCH,
76
+ "rubygems/path_support.rb" => rubygems_path_support_patch(@mount_point)
77
+ }
78
+ pm.merge!(super)
79
+ pm.freeze
80
+ end
81
+ end
82
+ end
83
+ end