tebako 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CMakeLists.txt +21 -29
- data/README.adoc +53 -28
- data/Rakefile +10 -0
- data/common.env +1 -1
- data/lib/tebako/cli.rb +23 -8
- data/lib/tebako/cli_helpers.rb +3 -3
- data/lib/tebako/packager/pass1.rb +3 -1
- data/lib/tebako/packager/pass2.rb +64 -274
- data/{tests-2/fixtures/gems-expressir/gems-expressir.rb → lib/tebako/packager/patch_helpers.rb} +30 -5
- data/lib/tebako/packager/patch_literals.rb +255 -0
- data/lib/tebako/version.rb +1 -1
- data/tebako.gemspec +4 -1
- data/version.txt +1 -0
- metadata +5 -62
- data/tests/scripts/cross-tests.sh +0 -34
- data/tests/scripts/functional-tests.sh +0 -335
- data/tests/test-00/test.rb +0 -4
- data/tests/test-01/tebako-test-run.rb +0 -5
- data/tests/test-09/tebako-test-0.0.1.gem +0 -0
- data/tests/test-11/bin/tebako-test-run.rb +0 -10
- data/tests/test-11/lib/tebako-test.rb +0 -20
- data/tests/test-11/tebako-test.gemspec +0 -15
- data/tests/test-12/tebako-test-a.gemspec +0 -15
- data/tests/test-12/tebako-test-b.gemspec +0 -15
- data/tests/test-13/bin/tebako-test-run.rb +0 -10
- data/tests/test-13/lib/tebako-test.rb +0 -20
- data/tests/test-13/tebako-test.gemspec +0 -15
- data/tests/test-15/Gemfile +0 -8
- data/tests/test-15/Rakefile +0 -4
- data/tests/test-15/bin/tebako-test-run.rb +0 -10
- data/tests/test-15/lib/tebako/bundle/test/version.rb +0 -9
- data/tests/test-15/lib/tebako/bundle/test.rb +0 -29
- data/tests/test-15/tebako-bundle-test.gemspec +0 -30
- data/tests/test-16/Gemfile +0 -8
- data/tests/test-16/Rakefile +0 -4
- data/tests/test-16/bin/tebako-test-run.rb +0 -10
- data/tests/test-16/lib/tebako/bundle/test/version.rb +0 -9
- data/tests/test-16/lib/tebako/bundle/test.rb +0 -29
- data/tests/test-16/tebako-bundle-test.gemspec +0 -24
- data/tests/test-18/Gemfile +0 -5
- data/tests/test-18/tebako-test-run.rb +0 -12
- data/tests/test-19/Gemfile +0 -6
- data/tests/test-19/tebako-test-run.rb +0 -11
- data/tests-2/fixtures/gems-bundler/Gemfile +0 -4
- data/tests-2/fixtures/gems-bundler/gems-bundler.rb +0 -34
- data/tests-2/fixtures/gems-byebug/Gemfile +0 -5
- data/tests-2/fixtures/gems-byebug/gems-byebug.rb +0 -31
- data/tests-2/fixtures/gems-expressir/Gemfile +0 -7
- data/tests-2/fixtures/gems-libmspack/Gemfile +0 -5
- data/tests-2/fixtures/gems-libmspack/gems-libmspack.rb +0 -91
- data/tests-2/fixtures/gems-sassc/Gemfile +0 -6
- data/tests-2/fixtures/gems-sassc/base_style/all.scss +0 -1
- data/tests-2/fixtures/gems-sassc/base_style/reset.scss +0 -100
- data/tests-2/fixtures/gems-sassc/gems-sassc.rb +0 -129
- data/tests-2/fixtures/gems-seven-zip/Gemfile +0 -7
- data/tests-2/fixtures/gems-seven-zip/gems-seven-zip.rb +0 -53
- data/tests-2/fixtures/launcher-coreincl/launcher-coreincl.rb +0 -29
- data/tests-2/fixtures/launcher-package/launcher-package.rb +0 -29
- data/tests-2/fixtures/launcher-pwd/launcher-pwd.rb +0 -28
- data/tests-2/fixtures/launcher-stdinredir/input.txt +0 -1
- data/tests-2/fixtures/launcher-stdinredir/launcher-stdinredir.rb +0 -31
- data/tests-2/fixtures/launcher-stdoutredir/launcher-stdoutredir.rb +0 -28
- data/tests-2/fixtures/patches-dir/level-1/level-2/file-1.txt +0 -1
- data/tests-2/fixtures/patches-dir/level-1/level-2/file-2.txt +0 -1
- data/tests-2/fixtures/patches-dir/level-1/level-2/file-3.txt +0 -1
- data/tests-2/fixtures/patches-dir/patches-dir.rb +0 -154
- data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-1.txt +0 -1
- data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-2.txt +0 -2
- data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-3.txt +0 -1
- data/tests-2/fixtures/patches-io-and-file/level-1/link-3 +0 -1
- data/tests-2/fixtures/patches-io-and-file/patches-io-and-file.rb +0 -87
- data/tests-2/fixtures/patches-main/patches-main.rb +0 -6
- data/tests-2/tebako-test.rb +0 -312
@@ -25,321 +25,112 @@
|
|
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
|
-
|
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
|
230
|
-
|
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
|
-
}
|
266
|
-
|
267
|
-
}.freeze
|
268
|
-
|
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
|
278
|
-
|
279
|
-
DARWIN_DEP_LIBS = ["glog", "gflags"].freeze
|
280
|
-
# rubocop:enable Style/WordArray
|
281
|
-
|
282
36
|
class << self
|
283
|
-
|
284
|
-
def get_patch_map(ostype, deps_lib_dir, ruby_ver)
|
37
|
+
def get_dir_c_patch(ostype)
|
285
38
|
dir_c_patch = patch_c_file(ostype =~ /msys/ ? "/* define system APIs */" : "#ifdef HAVE_GETATTRLIST")
|
286
39
|
dir_c_patch.merge!(DIR_C_BASE_PATCH)
|
40
|
+
end
|
287
41
|
|
42
|
+
def get_patch_map(ostype, deps_lib_dir, ruby_ver)
|
288
43
|
patch_map = {
|
289
44
|
"template/Makefile.in" => template_makefile_in_patch(ostype, deps_lib_dir, ruby_ver),
|
290
45
|
"main.c" => MAIN_C_PATCH,
|
291
46
|
"tool/mkconfig.rb" => TOOL_MKCONFIG_RB_PATCH,
|
292
|
-
"dir.c" =>
|
47
|
+
"dir.c" => get_dir_c_patch(ostype)
|
293
48
|
}
|
294
49
|
|
295
50
|
C_FILES_TO_PATCH.each { |patch| patch_map.store(patch[0], patch_c_file(patch[1])) }
|
296
51
|
patch_map.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if ostype =~ /linux-musl/
|
297
|
-
patch_map.
|
298
|
-
|
299
|
-
patch_map.store("common.mk", COMMON_MK_PATCH) if ruby_ver[0] == "3"
|
52
|
+
patch_map.store("common.mk", COMMON_MK_PATCH) if PatchHelpers.ruby3x?(ruby_ver)
|
300
53
|
|
301
|
-
patch_map
|
54
|
+
ostype =~ /msys/ ? patch_map.merge!(MSYS_PATCHES) : patch_map
|
302
55
|
end
|
303
|
-
# rubocop:enable Metrics/MethodLength
|
304
56
|
|
305
57
|
private
|
306
58
|
|
307
|
-
|
308
|
-
out, st = Open3.capture2("brew --prefix #{package}")
|
309
|
-
raise Tebako::Error, "brew --prefix #{package} failed with code #{st.exitstatus}" unless st.exitstatus.zero?
|
59
|
+
include Tebako::Packager::PatchLiterals
|
310
60
|
|
311
|
-
|
61
|
+
def process_brew_libs!(libs, brew_libs)
|
62
|
+
brew_libs.each { |lib| libs << "#{PatchHelpers.get_prefix(lib[0]).chop}/lib/lib#{lib[1]}.a " }
|
312
63
|
end
|
313
64
|
|
314
|
-
def darwin_libs(deps_lib_dir)
|
65
|
+
def darwin_libs(deps_lib_dir, ruby_ver)
|
315
66
|
libs = String.new
|
316
|
-
|
317
|
-
|
67
|
+
process_brew_libs!(libs, DARWIN_BREW_LIBS)
|
68
|
+
process_brew_libs!(libs, DARWIN_BREW_LIBS_32) if PatchHelpers.ruby32?(ruby_ver)
|
69
|
+
DARWIN_DEP_LIBS.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
|
318
70
|
<<~SUBST
|
319
|
-
|
320
|
-
MAINLIBS = -ltebako-fs -ldwarfs-wr -ldwarfs -lfolly -lfsst -lmetadata_thrift -lthrift_light -lxxhash \
|
71
|
+
-ltebako-fs -ldwarfs-wr -ldwarfs -lfolly -lfsst -lmetadata_thrift -lthrift_light -lxxhash \
|
321
72
|
-lzstd #{libs} -ljemalloc -lc++
|
322
|
-
|
73
|
+
SUBST
|
74
|
+
end
|
75
|
+
|
76
|
+
def yaml_reference(ruby_ver)
|
77
|
+
PatchHelpers.ruby32?(ruby_ver) ? "-l:libyaml.a" : ""
|
78
|
+
end
|
79
|
+
|
80
|
+
def linux_gnu_libs(ruby_ver)
|
81
|
+
<<~SUBST
|
82
|
+
-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 \
|
83
|
+
-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 \
|
84
|
+
-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 \
|
85
|
+
#{yaml_reference(ruby_ver)} -l:libboost_system.a -l:libstdc++.a -l:librt.a -ldl -lpthread
|
86
|
+
SUBST
|
87
|
+
end
|
88
|
+
|
89
|
+
def linux_musl_libs(ruby_ver)
|
90
|
+
<<~SUBST
|
91
|
+
-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 \
|
92
|
+
-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 \
|
93
|
+
-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 \
|
94
|
+
#{yaml_reference(ruby_ver)} -l:libboost_system.a -l:libstdc++.a -l:librt.a -ldl -lpthread
|
95
|
+
SUBST
|
96
|
+
end
|
97
|
+
|
98
|
+
def msys_libs(ruby_ver)
|
99
|
+
<<~SUBST
|
100
|
+
-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 \
|
101
|
+
-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 \
|
102
|
+
-l:libzstd.a -l:libffi.a -l:libgdbm.a -l:libncurses.a -l:libjemalloc.a -l:libunwind.a -l:liblzma.a -l:libiberty.a \
|
103
|
+
#{yaml_reference(ruby_ver)} -l:libstdc++.a -l:libdl.a -lole32 -loleaut32 -luuid
|
323
104
|
SUBST
|
324
105
|
end
|
325
106
|
|
326
107
|
# rubocop:disable Metrics/MethodLength
|
327
|
-
def mlibs(ostype, deps_lib_dir)
|
108
|
+
def mlibs(ostype, deps_lib_dir, ruby_ver)
|
328
109
|
case ostype
|
329
110
|
when /linux-gnu/
|
330
|
-
|
111
|
+
linux_gnu_libs(ruby_ver)
|
331
112
|
when /linux-musl/
|
332
|
-
|
113
|
+
linux_musl_libs(ruby_ver)
|
333
114
|
when /darwin/
|
334
|
-
darwin_libs(deps_lib_dir)
|
115
|
+
darwin_libs(deps_lib_dir, ruby_ver)
|
335
116
|
when /msys/
|
336
|
-
|
117
|
+
msys_libs(ruby_ver)
|
337
118
|
else
|
338
119
|
raise Tebako::Error, "Unknown ostype #{ostype}"
|
339
120
|
end
|
340
121
|
end
|
341
122
|
# rubocop:enable Metrics/MethodLength
|
342
123
|
|
124
|
+
def mlibs_subst(ostype, deps_lib_dir, ruby_ver)
|
125
|
+
yjit_libs = PatchHelpers.ruby32?(ruby_ver) ? "$(YJIT_LIBS) " : ""
|
126
|
+
{
|
127
|
+
"MAINLIBS = #{yjit_libs}@MAINLIBS@" =>
|
128
|
+
"# -- Start of tebako patch -- \n" \
|
129
|
+
"MAINLIBS = #{yjit_libs}#{mlibs(ostype, deps_lib_dir, ruby_ver)}" \
|
130
|
+
"# -- End of tebako patch -- \n"
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
343
134
|
def patch_c_file(pattern)
|
344
135
|
{
|
345
136
|
pattern => "#{C_FILE_SUBST}\n#{pattern}"
|
@@ -348,18 +139,18 @@ module Tebako
|
|
348
139
|
|
349
140
|
def template_makefile_in_patch(ostype, deps_lib_dir, ruby_ver)
|
350
141
|
base_patch = {
|
351
|
-
"MAINLIBS = @MAINLIBS@" => mlibs(ostype, deps_lib_dir),
|
352
142
|
"LIBS = @LIBS@ $(EXTLIBS)" => <<~SUBST
|
353
143
|
# -- Start of tebako patch --
|
354
144
|
LIBS = $(MAINLIBS) @LIBS@
|
355
145
|
# -- End of tebako patch --
|
356
146
|
SUBST
|
357
147
|
}
|
148
|
+
base_patch.merge!(mlibs_subst(ostype, deps_lib_dir, ruby_ver))
|
358
149
|
base_patch.merge!(template_makefile_in_patch_two(ruby_ver))
|
359
150
|
end
|
360
151
|
|
361
152
|
def template_makefile_in_patch_two(ruby_ver)
|
362
|
-
if ruby_ver
|
153
|
+
if PatchHelpers.ruby31?(ruby_ver)
|
363
154
|
{ TEMPLATE_MAKEFILE_IN_BASE_PATTERN_TWO => TEMPLATE_MAKEFILE_IN_BASE_PATCH_TWO }
|
364
155
|
else
|
365
156
|
{ TEMPLATE_MAKEFILE_IN_BASE_PATTERN_TWO_PRE_3_1 => TEMPLATE_MAKEFILE_IN_BASE_PATCH_TWO_PRE_3_1 }
|
@@ -368,5 +159,4 @@ module Tebako
|
|
368
159
|
end
|
369
160
|
end
|
370
161
|
end
|
371
|
-
# rubocop:enable Metrics/ModuleLength
|
372
162
|
end
|
data/{tests-2/fixtures/gems-expressir/gems-expressir.rb → lib/tebako/packager/patch_helpers.rb}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c)
|
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,34 @@
|
|
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
|
-
|
29
|
-
|
28
|
+
require "open3"
|
29
|
+
require_relative "patch_literals"
|
30
30
|
|
31
|
-
|
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
|
-
|
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
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|