tebako 0.5.0 → 0.5.2

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