tebako 0.5.2 → 0.5.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.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CMakeLists.txt +24 -34
  3. data/README.adoc +53 -28
  4. data/Rakefile +1 -1
  5. data/common.env +2 -2
  6. data/exe/tebako-packager +5 -3
  7. data/lib/tebako/cli.rb +23 -0
  8. data/lib/tebako/cli_helpers.rb +3 -3
  9. data/lib/tebako/packager/pass1.rb +3 -1
  10. data/lib/tebako/packager/pass2.rb +68 -284
  11. data/{tests-2/fixtures/gems-expressir/gems-expressir.rb → lib/tebako/packager/patch_helpers.rb} +34 -5
  12. data/lib/tebako/packager/patch_literals.rb +277 -0
  13. data/lib/tebako/packager.rb +47 -16
  14. data/lib/tebako/version.rb +1 -1
  15. data/tebako.gemspec +1 -1
  16. data/version.txt +1 -1
  17. metadata +4 -63
  18. data/cmake/def_tty_colours.cmake +0 -19
  19. data/tests/scripts/cross-tests.sh +0 -34
  20. data/tests/scripts/functional-tests.sh +0 -335
  21. data/tests/test-00/test.rb +0 -4
  22. data/tests/test-01/tebako-test-run.rb +0 -5
  23. data/tests/test-09/tebako-test-0.0.1.gem +0 -0
  24. data/tests/test-11/bin/tebako-test-run.rb +0 -10
  25. data/tests/test-11/lib/tebako-test.rb +0 -20
  26. data/tests/test-11/tebako-test.gemspec +0 -15
  27. data/tests/test-12/tebako-test-a.gemspec +0 -15
  28. data/tests/test-12/tebako-test-b.gemspec +0 -15
  29. data/tests/test-13/bin/tebako-test-run.rb +0 -10
  30. data/tests/test-13/lib/tebako-test.rb +0 -20
  31. data/tests/test-13/tebako-test.gemspec +0 -15
  32. data/tests/test-15/Gemfile +0 -8
  33. data/tests/test-15/Rakefile +0 -4
  34. data/tests/test-15/bin/tebako-test-run.rb +0 -10
  35. data/tests/test-15/lib/tebako/bundle/test/version.rb +0 -9
  36. data/tests/test-15/lib/tebako/bundle/test.rb +0 -29
  37. data/tests/test-15/tebako-bundle-test.gemspec +0 -30
  38. data/tests/test-16/Gemfile +0 -8
  39. data/tests/test-16/Rakefile +0 -4
  40. data/tests/test-16/bin/tebako-test-run.rb +0 -10
  41. data/tests/test-16/lib/tebako/bundle/test/version.rb +0 -9
  42. data/tests/test-16/lib/tebako/bundle/test.rb +0 -29
  43. data/tests/test-16/tebako-bundle-test.gemspec +0 -24
  44. data/tests/test-18/Gemfile +0 -5
  45. data/tests/test-18/tebako-test-run.rb +0 -12
  46. data/tests/test-19/Gemfile +0 -6
  47. data/tests/test-19/tebako-test-run.rb +0 -11
  48. data/tests-2/fixtures/gems-bundler/Gemfile +0 -4
  49. data/tests-2/fixtures/gems-bundler/gems-bundler.rb +0 -34
  50. data/tests-2/fixtures/gems-byebug/Gemfile +0 -5
  51. data/tests-2/fixtures/gems-byebug/gems-byebug.rb +0 -31
  52. data/tests-2/fixtures/gems-expressir/Gemfile +0 -7
  53. data/tests-2/fixtures/gems-libmspack/Gemfile +0 -5
  54. data/tests-2/fixtures/gems-libmspack/gems-libmspack.rb +0 -91
  55. data/tests-2/fixtures/gems-sassc/Gemfile +0 -6
  56. data/tests-2/fixtures/gems-sassc/base_style/all.scss +0 -1
  57. data/tests-2/fixtures/gems-sassc/base_style/reset.scss +0 -100
  58. data/tests-2/fixtures/gems-sassc/gems-sassc.rb +0 -129
  59. data/tests-2/fixtures/gems-seven-zip/Gemfile +0 -7
  60. data/tests-2/fixtures/gems-seven-zip/gems-seven-zip.rb +0 -53
  61. data/tests-2/fixtures/launcher-coreincl/launcher-coreincl.rb +0 -29
  62. data/tests-2/fixtures/launcher-package/launcher-package.rb +0 -29
  63. data/tests-2/fixtures/launcher-pwd/launcher-pwd.rb +0 -28
  64. data/tests-2/fixtures/launcher-stdinredir/input.txt +0 -1
  65. data/tests-2/fixtures/launcher-stdinredir/launcher-stdinredir.rb +0 -31
  66. data/tests-2/fixtures/launcher-stdoutredir/launcher-stdoutredir.rb +0 -28
  67. data/tests-2/fixtures/patches-dir/level-1/level-2/file-1.txt +0 -1
  68. data/tests-2/fixtures/patches-dir/level-1/level-2/file-2.txt +0 -1
  69. data/tests-2/fixtures/patches-dir/level-1/level-2/file-3.txt +0 -1
  70. data/tests-2/fixtures/patches-dir/patches-dir.rb +0 -154
  71. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-1.txt +0 -1
  72. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-2.txt +0 -2
  73. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-3.txt +0 -1
  74. data/tests-2/fixtures/patches-io-and-file/level-1/link-3 +0 -1
  75. data/tests-2/fixtures/patches-io-and-file/patches-io-and-file.rb +0 -87
  76. data/tests-2/fixtures/patches-main/patches-main.rb +0 -6
  77. data/tests-2/tebako-test.rb +0 -313
@@ -25,321 +25,113 @@
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 "open3"
28
+ require_relative "patch_literals"
29
+ require_relative "patch_helpers"
29
30
 
30
31
  # Tebako - an executable packager
31
32
  module Tebako
32
33
  module Packager
33
34
  # Ruby patching definitions (pass2)
34
- # rubocop:disable Metrics/ModuleLength
35
35
  module Pass2
36
- LINUX_GNU_LIBS = <<~SUBST
37
- # -- Start of tebako patch --
38
- MAINLIBS = -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libfolly.a -l:libfsst.a -l:libmetadata_thrift.a -l:libthrift_light.a -l:libxxhash.a \
39
- -l:libfmt.a -l:libdouble-conversion.a -l:libglog.a -l:libgflags.a -l:libevent.a -l:libiberty.a -l:libacl.a -l:libssl.a -l:libcrypto.a -l:liblz4.a -l:libz.a \
40
- -l:libzstd.a -l:libgdbm.a -l:libreadline.a -l:libtinfo.a -l:libffi.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:libcrypt.a -l:libanl.a -l:liblzma.a \
41
- -l:libboost_system.a -l:libstdc++.a -l:librt.a -ldl -lpthread
42
- # -- End of tebako patch --
43
- SUBST
44
-
45
- LINUX_MUSL_LIBS = <<~SUBST
46
- # -- Start of tebako patch --
47
- MAINLIBS = -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libfolly.a -l:libfsst.a -l:libmetadata_thrift.a -l:libthrift_light.a -l:libxxhash.a \
48
- -l:libfmt.a -l:libdouble-conversion.a -l:libglog.a -l:libgflags.a -l:libevent.a -l:libiberty.a -l:libacl.a -l:libssl.a -l:libcrypto.a -l:liblz4.a -l:libz.a \
49
- -l:libzstd.a -l:libgdbm.a -l:libreadline.a -l:libffi.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:libcrypt.a -l:liblzma.a \
50
- -l:libboost_system.a -l:libstdc++.a -l:librt.a -ldl -lpthread
51
- # -- End of tebako patch --
52
- SUBST
53
-
54
- MSYS_LIBS = <<~SUBST
55
- # -- Start of tebako patch --
56
- MAINLIBS = -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libfolly.a -l:libfsst.a -l:libmetadata_thrift.a -l:libthrift_light.a -l:libxxhash.a \
57
- -l:libfmt.a -l:libdouble-conversion.a -l:libglog.a -l:libgflags.a -l:libevent.a -l:libssl.a -l:libcrypto.a -l:liblz4.a -l:libz.a \
58
- -l:libzstd.a -l:libffi.a -l:libgdbm.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:liblzma.a -l:libiberty.a \
59
- -l:libstdc++.a -l:libdl.a -lole32 -loleaut32 -luuid
60
- # -- End of tebako patch --
61
- SUBST
62
-
63
- TOOL_MKCONFIG_RB_PATCH = {
64
- " if fast[name]" => <<~SUBST
65
- # -- Start of tebako patch --
66
- v_head_comp = " CONFIG[\\"prefix\\"] \#{eq} "
67
- if v_head_comp == v[0...(v_head_comp.length)]
68
- if win32
69
- v = "\#{v[0...(v_head_comp.length)]}CONFIG[\\"RUBY_EXEC_PREFIX\\"] = '/__tebako_memfs__'
70
- "
71
- else
72
- v = "\#{v[0...(v_head_comp.length)]}'/__tebako_memfs__'
73
- "
74
- end
75
- end
76
- v_head_comp = " CONFIG[\\"RUBY_EXEC_PREFIX\\"] \#{eq} "
77
- if v_head_comp == v[0...(v_head_comp.length)]
78
- v = "\#{v[0...(v_head_comp.length)]}'/__tebako_memfs__'
79
- "
80
- end
81
- # -- End of tebako patch --
82
- if fast[name]
83
- SUBST
84
- }.freeze
85
-
86
- # Alpine-specific patches https://github.com/docker-library/ruby/blob/master/3.1/alpine3.15/Dockerfile
87
- # -- Patch no. 1 --
88
- # https://github.com/docker-library/ruby/issues/196
89
- # https://bugs.ruby-lang.org/issues/14387#note-13 (patch source)
90
- # https://bugs.ruby-lang.org/issues/14387#note-16
91
- # ("Therefore ncopa's patch looks good for me in general." -- only breaks glibc which doesn't matter here)
92
-
93
- # -- Patch no. 2 -- not needed: isnan, isinf are detected correctly by configure script
94
- # the configure script does not detect isnan/isinf as macros
95
- # export ac_cv_func_isnan=yes ac_cv_func_isinf=yes;
96
-
97
- # -- Patch no. 3 --
98
- # hack in "ENABLE_PATH_CHECK" disabling to suppress: "warning: Insecure world writable dir"
99
- # Applied in CMakeLists.txt
100
-
101
- LINUX_MUSL_THREAD_PTHREAD_PATCH = {
102
- "#if MAINSTACKADDR_AVAILABLE && !defined(get_main_stack)" => <<~SUBST
103
- /* -- Start of tebako patch -- */
104
- #if defined(__linux__) && !defined(__GLIBC__) && defined(HAVE_GETRLIMIT)
105
- #ifndef PAGE_SIZE
106
- #include <unistd.h>
107
- #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
108
- #endif
109
- static int
110
- get_main_stack(void **addr, size_t *size)
111
- {
112
- size_t start, end, limit, prevend = 0;
113
- struct rlimit r;
114
- FILE *f;
115
- char buf[PATH_MAX+80], s[8];
116
- int n;
117
- STACK_GROW_DIR_DETECTION;
118
- f = fopen("/proc/self/maps", "re");
119
- if (!f)
120
- return -1;
121
- n = 0;
122
- while (fgets(buf, sizeof buf, f)) {
123
- n = sscanf(buf, "%zx-%zx %*s %*s %*s %*s %7s", &start, &end, s);
124
- if (n >= 2) {
125
- if (n == 3 && strcmp(s, "[stack]") == 0)
126
- break;
127
- prevend = end;
128
- }
129
- n = 0;
130
- }
131
- fclose(f);
132
- if (n == 0)
133
- return -1;
134
- limit = 100 << 20; /* 100MB stack limit */
135
- if (getrlimit(RLIMIT_STACK, &r)==0 && r.rlim_cur < limit)
136
- limit = r.rlim_cur & -PAGE_SIZE;
137
- if (limit > end) limit = end;
138
- if (prevend < end - limit) prevend = end - limit;
139
- if (start > prevend) start = prevend;
140
- *addr = IS_STACK_DIR_UPPER() ? (void *)start : (void *)end;
141
- *size = end - start;
142
- return 0;
143
- }
144
- #else
145
- /* -- End of tebako patch -- */
146
- SUBST
147
- }.freeze
148
-
149
- MAIN_C_PATCH = {
150
- "int\nmain(int argc, char **argv)" =>
151
- "#include <tebako/tebako-main.h>\n\nint\nmain(int argc, char **argv)",
152
-
153
- " ruby_sysinit(&argc, &argv);" => <<~SUBST
154
- ruby_sysinit(&argc, &argv);
155
- /* -- Start of tebako patch -- */
156
- if (tebako_main(&argc, &argv) != 0) {
157
- return -1;
158
- }
159
- /* -- End of tebako patch -- */
160
- SUBST
161
- }.freeze
162
-
163
- # Compensate ruby incorrect processing of (f)getattrlist returning ENOTSUP
164
- # Note. We are not patching need_normalization function
165
- # In this function (f)getattrlist failure with ENOTSUP is processed correctly
166
-
167
- DIR_C_BASE_PATCH_ONE = <<~SUBST
168
- #if defined HAVE_GETATTRLIST && defined ATTR_DIR_ENTRYCOUNT
169
- /* tebako patch */ if (!within_tebako_memfs(path))
170
- SUBST
171
-
172
- DIR_C_BASE_PATCH_TWO = <<~SUBST
173
- #if USE_NAME_ON_FS == USE_NAME_ON_FS_REAL_BASENAME
174
- /* tebako patch */ if (!within_tebako_memfs(path)) plain = 1; else magical = 1;
175
- SUBST
176
-
177
- DIR_C_BASE_PATCH = {
178
- "#if defined HAVE_GETATTRLIST && defined ATTR_DIR_ENTRYCOUNT" => DIR_C_BASE_PATCH_ONE,
179
- "#if USE_NAME_ON_FS == USE_NAME_ON_FS_REAL_BASENAME\n plain = 1;" => DIR_C_BASE_PATCH_TWO,
180
- "if (is_case_sensitive(dirp, path) == 0)" =>
181
- "if (is_case_sensitive(dirp, path) == 0 /* tebako patch */ && !within_tebako_memfs(path))",
182
- "if ((*cur)->type == ALPHA) {" =>
183
- "if ((*cur)->type == ALPHA /* tebako patch */ && !within_tebako_memfs(buf)) {",
184
- "else if (e == EIO) {" =>
185
- "else if (e == EIO /* tebako patch */ && !within_tebako_memfs(path)) {"
186
- }.freeze
187
-
188
- COMMON_MK_PATCH = {
189
- "ext/extinit.c: $(srcdir)/template/extinit.c.tmpl $(PREP)" =>
190
- "ext/extinit.c: $(srcdir)/template/extinit.c.tmpl $(PREP) $(EXTS_MK)"
191
- }.freeze
192
-
193
- C_FILES_TO_PATCH = [
194
- ["file.c", "/* define system APIs */"],
195
- ["io.c", "/* define system APIs */"],
196
- ["util.c", "#ifndef S_ISDIR"],
197
- ["dln.c", "static const char funcname_prefix[sizeof(FUNCNAME_PREFIX) - 1] = FUNCNAME_PREFIX;"]
198
- ].freeze
199
-
200
- TEMPLATE_MAKEFILE_IN_BASE_PATTERN_TWO_PRE_3_1 =
201
- "\t\t$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINOBJ) " \
202
- "$(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@"
203
-
204
- TEMPLATE_MAKEFILE_IN_BASE_PATCH_TWO_PRE_3_1 =
205
- "# -- Start of tebako patch --\n" \
206
- "\t\t$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINOBJ) " \
207
- "$(EXTOBJS) $(LIBRUBYARG_STATIC) $(LIBS) $(OUTFLAG)$@\n" \
208
- "# -- End of tebako patch --"
209
-
210
- TEMPLATE_MAKEFILE_IN_BASE_PATTERN_TWO =
211
- "\t\t$(Q) $(PURIFY) $(CC) $(EXE_LDFLAGS) $(XLDFLAGS) $(MAINOBJ) " \
212
- "$(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@"
213
-
214
- TEMPLATE_MAKEFILE_IN_BASE_PATCH_TWO =
215
- "# -- Start of tebako patch --\n" \
216
- "\t\t$(Q) $(PURIFY) $(CC) $(EXE_LDFLAGS) $(XLDFLAGS) $(MAINOBJ) " \
217
- "$(EXTOBJS) $(LIBRUBYARG_STATIC) $(LIBS) $(OUTFLAG)$@\n" \
218
- "# -- End of tebako patch --"
219
-
220
- C_FILE_SUBST = <<~SUBST
221
- /* -- Start of tebako patch -- */
222
- #ifndef NO_TEBAKO_INCLUDES
223
- #include <tebako/tebako-config.h>
224
- #include <tebako/tebako-defines.h>
225
- #include <tebako/tebako-io-rb-w32.h>
226
- #include <tebako/tebako-io.h>
227
- #endif
228
- /* -- End of tebako patch -- */
229
- SUBST
36
+ class << self
37
+ def get_patch_map(ostype, deps_lib_dir, ruby_ver)
38
+ patch_map = get_patch_map_base(ostype, deps_lib_dir, ruby_ver)
230
39
 
231
- MSYS_PATCHES = {
232
- "ruby.c" => {
233
- "#define RUBY_RELATIVE(path, len) rb_str_buf_cat(BASEPATH(), (path), (len))" =>
234
- "#define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len)) /* tebako patched */",
235
- "#define PREFIX_PATH() sopath" =>
236
- "#define PREFIX_PATH() rubylib_path_new(tebako_mount_point(), " \
237
- "strlen(tebako_mount_point())) /* tebako patched */",
238
- '#include "mjit.h"' =>
239
- "#include \"mjit.h\"\n" \
240
- "/* -- Start of tebako patch -- */\n" \
241
- "#include <tebako/tebako-main.h>\n" \
242
- "/* -- End of tebako patch -- */"
243
- },
244
- "/win32/win32.c" => {
245
- "#undef __STRICT_ANSI__" =>
246
- "#undef __STRICT_ANSI__\n" \
247
- "/* -- Start of tebako patch -- */\n" \
248
- "#define NO_TEBAKO_INCLUDES\n" \
249
- "/* -- End of tebako patch -- */"
250
- },
251
- "win32/dir.h" => {
252
- "#define opendir(s) rb_w32_opendir((s))" => "#{C_FILE_SUBST}\n#define opendir(s) rb_w32_opendir((s))"
253
- },
254
- "file.c" => {
255
- " wpath = mbstr_to_wstr(CP_UTF8, path, -1, &len);" =>
256
- "/* -- Start of tebako patch -- */\n" \
257
- "if (tebako_file_load_ok(path)) return 1;\n" \
258
- "/* -- End of tebako patch -- */\n" \
259
- "wpath = mbstr_to_wstr(CP_UTF8, path, -1, &len);",
260
- '#include "win32/file.h' =>
261
- "#include \"win32/file.h\"\n" \
262
- "/* -- Start of tebako patch -- */\n" \
263
- "#include <tebako/tebako-main.h>\n" \
264
- "/* -- End of tebako patch -- */"
265
- }
40
+ C_FILES_TO_PATCH.each { |patch| patch_map.store(patch[0], patch_c_file(patch[1])) }
41
+ patch_map.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if ostype =~ /linux-musl/
42
+ patch_map.store("common.mk", COMMON_MK_PATCH) if PatchHelpers.ruby3x?(ruby_ver)
266
43
 
267
- }.freeze
44
+ ostype =~ /msys/ ? patch_map.merge!(MSYS_PATCHES) : patch_map
45
+ end
268
46
 
269
- # rubocop:disable Style/WordArray
270
- DARWIN_BREW_LIBS = [
271
- ["openssl@1.1", "ssl"], ["openssl@1.1", "crypto"],
272
- ["zlib", "z"], ["gdbm", "gdbm"],
273
- ["readline", "readline"], ["libffi", "ffi"],
274
- ["ncurses", "ncurses"], ["fmt", "fmt"],
275
- ["lz4", "lz4"], ["xz", "lzma"],
276
- ["double-conversion", "double-conversion"]
277
- ].freeze
47
+ private
278
48
 
279
- DARWIN_DEP_LIBS = ["glog", "gflags"].freeze
280
- # rubocop:enable Style/WordArray
49
+ include Tebako::Packager::PatchLiterals
281
50
 
282
- class << self
283
- # rubocop:disable Metrics/MethodLength
284
- def get_patch_map(ostype, deps_lib_dir, ruby_ver)
51
+ def get_dir_c_patch(ostype)
285
52
  dir_c_patch = patch_c_file(ostype =~ /msys/ ? "/* define system APIs */" : "#ifdef HAVE_GETATTRLIST")
286
53
  dir_c_patch.merge!(DIR_C_BASE_PATCH)
54
+ end
287
55
 
288
- patch_map = {
56
+ def get_patch_map_base(ostype, deps_lib_dir, ruby_ver)
57
+ {
289
58
  "template/Makefile.in" => template_makefile_in_patch(ostype, deps_lib_dir, ruby_ver),
290
59
  "main.c" => MAIN_C_PATCH,
291
60
  "tool/mkconfig.rb" => TOOL_MKCONFIG_RB_PATCH,
292
- "dir.c" => dir_c_patch
61
+ "gem_prelude.rb" => GEM_PRELUDE_RB_PATCH,
62
+ "dir.c" => get_dir_c_patch(ostype)
293
63
  }
64
+ end
294
65
 
295
- C_FILES_TO_PATCH.each { |patch| patch_map.store(patch[0], patch_c_file(patch[1])) }
296
- patch_map.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if ostype =~ /linux-musl/
297
- patch_map.merge!(MSYS_PATCHES) if ostype =~ /msys/
298
-
299
- patch_map.store("common.mk", COMMON_MK_PATCH) if ruby_ver[0] == "3"
300
-
301
- patch_map
66
+ def process_brew_libs!(libs, brew_libs)
67
+ brew_libs.each { |lib| libs << "#{PatchHelpers.get_prefix(lib[0]).chop}/lib/lib#{lib[1]}.a " }
302
68
  end
303
- # rubocop:enable Metrics/MethodLength
304
69
 
305
- private
70
+ def darwin_libs(deps_lib_dir, ruby_ver)
71
+ libs = String.new
72
+ process_brew_libs!(libs, DARWIN_BREW_LIBS)
73
+ process_brew_libs!(libs, DARWIN_BREW_LIBS_32) if PatchHelpers.ruby32?(ruby_ver)
74
+ DARWIN_DEP_LIBS.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
75
+ <<~SUBST
76
+ -ltebako-fs -ldwarfs-wr -ldwarfs -lfolly -lfsst -lmetadata_thrift -lthrift_light -lxxhash \
77
+ -lzstd #{libs} -ljemalloc -lc++
78
+ SUBST
79
+ end
306
80
 
307
- def get_prefix(package)
308
- out, st = Open3.capture2("brew --prefix #{package}")
309
- raise Tebako::Error, "brew --prefix #{package} failed with code #{st.exitstatus}" unless st.exitstatus.zero?
81
+ def linux_gnu_libs(ruby_ver)
82
+ <<~SUBST
83
+ -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libfolly.a -l:libfsst.a -l:libmetadata_thrift.a -l:libthrift_light.a -l:libxxhash.a \
84
+ -l:libfmt.a -l:libdouble-conversion.a -l:libglog.a -l:libgflags.a -l:libevent.a -l:libiberty.a -l:libacl.a -l:libssl.a -l:libcrypto.a -l:liblz4.a -l:libz.a \
85
+ -l:libzstd.a -l:libgdbm.a -l:libreadline.a -l:libtinfo.a -l:libffi.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:libcrypt.a -l:libanl.a -l:liblzma.a \
86
+ #{PatchHelpers.yaml_reference(ruby_ver)} -l:libboost_system.a -l:libstdc++.a -l:librt.a -ldl -lpthread
87
+ SUBST
88
+ end
310
89
 
311
- out
90
+ def linux_musl_libs(ruby_ver)
91
+ <<~SUBST
92
+ -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libfolly.a -l:libfsst.a -l:libmetadata_thrift.a -l:libthrift_light.a -l:libxxhash.a \
93
+ -l:libfmt.a -l:libdouble-conversion.a -l:libglog.a -l:libgflags.a -l:libevent.a -l:libiberty.a -l:libacl.a -l:libssl.a -l:libcrypto.a -l:liblz4.a -l:libz.a \
94
+ -l:libzstd.a -l:libgdbm.a -l:libreadline.a -l:libffi.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:libcrypt.a -l:liblzma.a \
95
+ #{PatchHelpers.yaml_reference(ruby_ver)} -l:libboost_system.a -l:libstdc++.a -l:librt.a -ldl -lpthread
96
+ SUBST
312
97
  end
313
98
 
314
- def darwin_libs(deps_lib_dir)
315
- libs = String.new
316
- DARWIN_BREW_LIBS.each { |lib| libs << get_prefix(lib[0]).chop << "/lib/lib#{lib[1]}.a " }
317
- DARWIN_DEP_LIBS.each { |lib| libs << deps_lib_dir << "/lib#{lib}.a " }
99
+ def msys_libs(ruby_ver)
318
100
  <<~SUBST
319
- # -- Start of tebako patch --
320
- MAINLIBS = -ltebako-fs -ldwarfs-wr -ldwarfs -lfolly -lfsst -lmetadata_thrift -lthrift_light -lxxhash \
321
- -lzstd #{libs} -ljemalloc -lc++
322
- # -- End of tebako patch --
101
+ -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libfolly.a -l:libfsst.a -l:libmetadata_thrift.a -l:libthrift_light.a -l:libxxhash.a \
102
+ -l:libfmt.a -l:libdouble-conversion.a -l:libglog.a -l:libgflags.a -l:libevent.a -l:libssl.a -l:libcrypto.a -l:liblz4.a -l:libz.a \
103
+ -l:libzstd.a -l:libffi.a -l:libgdbm.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:liblzma.a -l:libiberty.a \
104
+ #{PatchHelpers.yaml_reference(ruby_ver)} -l:libstdc++.a -l:libdl.a -lole32 -loleaut32 -luuid
323
105
  SUBST
324
106
  end
325
107
 
326
108
  # rubocop:disable Metrics/MethodLength
327
- def mlibs(ostype, deps_lib_dir)
109
+ def mlibs(ostype, deps_lib_dir, ruby_ver)
328
110
  case ostype
329
111
  when /linux-gnu/
330
- LINUX_GNU_LIBS
112
+ linux_gnu_libs(ruby_ver)
331
113
  when /linux-musl/
332
- LINUX_MUSL_LIBS
114
+ linux_musl_libs(ruby_ver)
333
115
  when /darwin/
334
- darwin_libs(deps_lib_dir)
116
+ darwin_libs(deps_lib_dir, ruby_ver)
335
117
  when /msys/
336
- MSYS_LIBS
118
+ msys_libs(ruby_ver)
337
119
  else
338
120
  raise Tebako::Error, "Unknown ostype #{ostype}"
339
121
  end
340
122
  end
341
123
  # rubocop:enable Metrics/MethodLength
342
124
 
125
+ def mlibs_subst(ostype, deps_lib_dir, ruby_ver)
126
+ yjit_libs = PatchHelpers.ruby32?(ruby_ver) ? "$(YJIT_LIBS) " : ""
127
+ {
128
+ "MAINLIBS = #{yjit_libs}@MAINLIBS@" =>
129
+ "# -- Start of tebako patch -- \n" \
130
+ "MAINLIBS = #{yjit_libs}#{mlibs(ostype, deps_lib_dir, ruby_ver)}" \
131
+ "# -- End of tebako patch -- \n"
132
+ }
133
+ end
134
+
343
135
  def patch_c_file(pattern)
344
136
  {
345
137
  pattern => "#{C_FILE_SUBST}\n#{pattern}"
@@ -347,19 +139,12 @@ module Tebako
347
139
  end
348
140
 
349
141
  def template_makefile_in_patch(ostype, deps_lib_dir, ruby_ver)
350
- base_patch = {
351
- "MAINLIBS = @MAINLIBS@" => mlibs(ostype, deps_lib_dir),
352
- "LIBS = @LIBS@ $(EXTLIBS)" => <<~SUBST
353
- # -- Start of tebako patch --
354
- LIBS = $(MAINLIBS) @LIBS@
355
- # -- End of tebako patch --
356
- SUBST
357
- }
142
+ base_patch = TEMPLATE_MAKEFILE_IN_BASE_PATCH_ONE.merge(mlibs_subst(ostype, deps_lib_dir, ruby_ver))
358
143
  base_patch.merge!(template_makefile_in_patch_two(ruby_ver))
359
144
  end
360
145
 
361
146
  def template_makefile_in_patch_two(ruby_ver)
362
- if ruby_ver[0] == "3" && ruby_ver[2] != "0"
147
+ if PatchHelpers.ruby31?(ruby_ver)
363
148
  { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_TWO => TEMPLATE_MAKEFILE_IN_BASE_PATCH_TWO }
364
149
  else
365
150
  { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_TWO_PRE_3_1 => TEMPLATE_MAKEFILE_IN_BASE_PATCH_TWO_PRE_3_1 }
@@ -368,5 +153,4 @@ module Tebako
368
153
  end
369
154
  end
370
155
  end
371
- # rubocop:enable Metrics/ModuleLength
372
156
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2022-2023, [Ribose Inc](https://www.ribose.com).
3
+ # Copyright (c) 2023 [Ribose Inc](https://www.ribose.com).
4
4
  # All rights reserved.
5
5
  # This file is a part of tebako
6
6
  #
@@ -25,9 +25,38 @@
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
- # This test is inspired packed-mn
29
- # https://github.com/metanorma/packed-mn
28
+ require "open3"
29
+ require_relative "patch_literals"
30
30
 
31
- require "expressir/express/parser"
31
+ # Tebako - an executable packager
32
+ module Tebako
33
+ module Packager
34
+ # Ruby patching helpers (pass2)
35
+ module PatchHelpers
36
+ class << self
37
+ def get_prefix(package)
38
+ out, st = Open3.capture2("brew --prefix #{package}")
39
+ raise Tebako::Error, "brew --prefix #{package} failed with code #{st.exitstatus}" unless st.exitstatus.zero?
32
40
 
33
- puts "Hello! Expressir gem welcomes you to the magic world of ruby gems."
41
+ out
42
+ end
43
+
44
+ def ruby3x?(ruby_ver)
45
+ ruby_ver[0] == "3"
46
+ end
47
+
48
+ def ruby31?(ruby_ver)
49
+ ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 1
50
+ end
51
+
52
+ def ruby32?(ruby_ver)
53
+ ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 2
54
+ end
55
+
56
+ def yaml_reference(ruby_ver)
57
+ ruby32?(ruby_ver) ? "-l:libyaml.a" : ""
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end