tebako 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,6 +34,7 @@ require_relative "codegen"
34
34
  require_relative "error"
35
35
  require_relative "options_manager"
36
36
  require_relative "scenario_manager"
37
+ require_relative "packager_lite"
37
38
 
38
39
  # Tebako - an executable packager
39
40
  # Command-line interface methods
@@ -41,10 +42,27 @@ module Tebako
41
42
  # Cli helpers
42
43
  module CliHelpers
43
44
  def do_press(options_manager)
44
- puts options_manager.press_announce
45
+ scenario_manager = Tebako::ScenarioManager.new(options_manager.root, options_manager.fs_entrance)
46
+ puts options_manager.press_announce(scenario_manager.msys?)
47
+
48
+ if options_manager.mode == "both" || options_manager.mode == "runtime" || options_manager.mode == "bundle"
49
+ do_press_runtime(options_manager, scenario_manager)
50
+ end
51
+
52
+ if options_manager.mode == "both" || options_manager.mode == "application"
53
+ do_press_application(options_manager, scenario_manager)
54
+ end
55
+
56
+ true
57
+ end
45
58
 
46
- generate_files(options_manager)
59
+ def do_press_application(options_manager, scenario_manager)
60
+ packager = Tebako::PackagerLite.new(options_manager, scenario_manager)
61
+ packager.create_package
62
+ end
47
63
 
64
+ def do_press_runtime(options_manager, scenario_manager)
65
+ generate_files(options_manager, scenario_manager)
48
66
  cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{options_manager.cfg_options} #{options_manager.press_options}"
49
67
  build_cmd = "cmake --build #{options_manager.output_folder} --target tebako --parallel #{Etc.nprocessors}"
50
68
  merged_env = ENV.to_h.merge(options_manager.b_env)
@@ -64,20 +82,18 @@ module Tebako
64
82
  true
65
83
  end
66
84
 
67
- def generate_files(options_manager)
85
+ def generate_files(options_manager, scenario_manager)
68
86
  puts "-- Generating files"
69
- scenario_manager = Tebako::ScenarioManager.new(options_manager.root, options_manager.fs_entrance)
70
87
  scenario_manager.configure_scenario
71
88
 
72
- puts " ... tebako-version.h"
73
89
  v_parts = Tebako::VERSION.split(".")
74
90
  Tebako::Codegen.generate_tebako_version_h(options_manager, v_parts)
75
-
76
- puts " ... tebako-fs.cpp"
77
91
  Tebako::Codegen.generate_tebako_fs_cpp(options_manager, scenario_manager)
78
-
79
- puts " ... deploy.rb"
80
92
  Tebako::Codegen.generate_deploy_rb(options_manager, scenario_manager)
93
+
94
+ return unless options_manager.mode == "both" || options_manager.mode == "runtime"
95
+
96
+ Tebako::Codegen.generate_stub_rb(options_manager)
81
97
  end
82
98
 
83
99
  def options_from_tebafile(tebafile)
@@ -28,6 +28,8 @@
28
28
  require "pathname"
29
29
  require "fileutils"
30
30
 
31
+ require_relative "package_descriptor"
32
+
31
33
  # Tebako - an executable packager
32
34
  module Tebako
33
35
  # Code geberation
@@ -47,20 +49,42 @@ module Tebako
47
49
 
48
50
  SUBST
49
51
 
50
- class << self
52
+ class << self # rubocop:disable Metrics/ClassLength
51
53
  def deploy_crt_implib(opt, scm)
52
54
  crt = ""
53
55
  if scm.msys?
54
56
  crt = <<~SUBST
55
57
  Tebako::Packager.create_implib("#{opt.ruby_src_dir}", "#{opt.data_src_dir}",
56
- "#{File.basename(opt.package)}", rv)
58
+ "#{opt.package}", rv)
57
59
  SUBST
58
60
  end
59
61
  crt
60
62
  end
61
63
 
62
- def deploy_cwd(opt)
63
- opt.cwd.nil? ? "nil" : "\"#{opt.cwd}\""
64
+ def deploy_mk(opt, scm)
65
+ case opt.mode
66
+ when "bundle"
67
+ deploy_mk_bundle(opt, scm)
68
+ when /runtime|both/
69
+ deploy_mk_stub(opt)
70
+ end
71
+ end
72
+
73
+ def deploy_mk_bundle(opt, scm)
74
+ <<~SUBST
75
+ Tebako::Packager.deploy("#{opt.data_src_dir}", "#{opt.data_pre_dir}",
76
+ rv , "#{opt.root}", "#{scm.fs_entrance}", "#{opt.cwd}")
77
+ Tebako::Packager.mkdwarfs("#{opt.deps_bin_dir}", "#{opt.data_bundle_file}",
78
+ "#{opt.data_src_dir}")
79
+ SUBST
80
+ end
81
+
82
+ def deploy_mk_stub(opt)
83
+ <<~SUBST
84
+ Tebako::Packager.deploy("#{opt.data_src_dir}", "#{opt.data_pre_dir}",
85
+ rv, "#{File.join(opt.deps, "src", "tebako", "local")}", "stub.rb", nil)
86
+ Tebako::Packager.mkdwarfs("#{opt.deps_bin_dir}", "#{opt.data_stub_file}", "#{opt.data_src_dir}")
87
+ SUBST
64
88
  end
65
89
 
66
90
  def deploy_rb(opt, scm)
@@ -71,22 +95,41 @@ module Tebako
71
95
  Tebako::Packager::init("#{opt.stash_dir}", "#{opt.data_src_dir}",
72
96
  "#{opt.data_pre_dir}", "#{opt.data_bin_dir}")
73
97
  #{deploy_crt_implib(opt, scm)}
74
- Tebako::Packager.deploy("#{opt.data_src_dir}", "#{opt.data_pre_dir}",
75
- rv , "#{opt.root}",
76
- "#{scm.fs_entrance}", #{deploy_cwd(opt)})
77
- Tebako::Packager.mkdwarfs("#{opt.deps_bin_dir}", "#{opt.data_bin_file}",
78
- "#{opt.data_src_dir}")
98
+ #{deploy_mk(opt, scm)}
79
99
  SUBST
80
100
  end
81
101
 
82
102
  def deploy_rq
83
103
  <<~SUBST
104
+ require "#{File.join(__dir__, "package_descriptor.rb")}"
84
105
  require "#{File.join(__dir__, "packager.rb")}"
85
106
  require "#{File.join(__dir__, "ruby_version.rb")}"
86
107
  SUBST
87
108
  end
88
109
 
110
+ def stub_rb(opt)
111
+ <<~SUBST
112
+ puts "Copyright (c) 2024 Ribose Inc (https://www.ribose.com)"
113
+ puts "Tebako runtime stub v#{Tebako::VERSION}"
114
+ puts "To run your application please call #{File.basename(opt.package)} --tebako-run <your tebako package>"
115
+ SUBST
116
+ end
117
+
118
+ def generate_stub_rb(options_manager)
119
+ puts " ... stub.rb"
120
+
121
+ fname = File.join(options_manager.deps, "src", "tebako", "local", "stub.rb")
122
+ FileUtils.mkdir_p(File.dirname(fname))
123
+
124
+ File.open(fname, "w") do |file|
125
+ file.write(COMMON_RUBY_HEADER)
126
+ file.write(stub_rb(options_manager))
127
+ end
128
+ end
129
+
89
130
  def generate_deploy_rb(options_manager, scenario_manager)
131
+ puts " ... deploy.rb"
132
+
90
133
  fname = File.join(options_manager.deps, "bin", "deploy.rb")
91
134
  FileUtils.mkdir_p(File.dirname(fname))
92
135
 
@@ -96,7 +139,20 @@ module Tebako
96
139
  end
97
140
  end
98
141
 
142
+ def generate_package_descriptor(options_manager, scenario_manager)
143
+ puts " ... package_descriptor"
144
+ fname = File.join(options_manager.deps, "src", "tebako", "package_descriptor")
145
+ FileUtils.mkdir_p(File.dirname(fname))
146
+ descriptor = Tebako::PackageDescriptor.new(options_manager.ruby_ver, Tebako::VERSION,
147
+ scenario_manager.fs_mount_point, scenario_manager.fs_entry_point,
148
+ options_manager.cwd)
149
+ File.binwrite(fname, descriptor.serialize)
150
+ fname
151
+ end
152
+
99
153
  def generate_tebako_fs_cpp(options_manager, scenario_manager)
154
+ puts " ... tebako-fs.cpp"
155
+
100
156
  fname = File.join(options_manager.deps, "src", "tebako", "tebako-fs.cpp")
101
157
  FileUtils.mkdir_p(File.dirname(fname))
102
158
 
@@ -107,6 +163,8 @@ module Tebako
107
163
  end
108
164
 
109
165
  def generate_tebako_version_h(options_manager, v_parts)
166
+ puts " ... tebako-version.h"
167
+
110
168
  fname = File.join(options_manager.deps, "include", "tebako", "tebako-version.h")
111
169
  FileUtils.mkdir_p(File.dirname(fname))
112
170
 
@@ -125,7 +183,17 @@ module Tebako
125
183
  end
126
184
 
127
185
  def tebako_fs_cpp(options_manager, scenario_manager)
186
+ case options_manager.mode
187
+ when "bundle"
188
+ tebako_fs_cpp_bundle(options_manager, scenario_manager)
189
+ when /runtime|both/
190
+ tebako_fs_cpp_stub(options_manager, scenario_manager)
191
+ end
192
+ end
193
+
194
+ def tebako_fs_cpp_bundle(options_manager, scenario_manager)
128
195
  <<~SUBST
196
+ #include <limits.h>
129
197
  #include <incbin/incbin.h>
130
198
 
131
199
  namespace tebako {
@@ -135,7 +203,24 @@ module Tebako
135
203
  const char * package_cwd = #{package_cwd(options_manager, scenario_manager)};
136
204
  char original_cwd[PATH_MAX];
137
205
 
138
- INCBIN(fs, "#{options_manager.output_folder}/p/fs.bin");
206
+ INCBIN(fs, "#{options_manager.data_bundle_file}");
207
+ }
208
+ SUBST
209
+ end
210
+
211
+ def tebako_fs_cpp_stub(options_manager, scenario_manager)
212
+ <<~SUBST
213
+ #include <limits.h>
214
+ #include <incbin/incbin.h>
215
+
216
+ namespace tebako {
217
+ const char * fs_log_level = "#{options_manager.l_level}";
218
+ const char * fs_mount_point = "#{scenario_manager.fs_mount_point}";
219
+ const char * fs_entry_point = "/local/stub.rb";
220
+ const char * package_cwd = nullptr;
221
+ char original_cwd[PATH_MAX];
222
+
223
+ INCBIN(fs, "#{options_manager.data_stub_file}");
139
224
  }
140
225
  SUBST
141
226
  end
@@ -70,7 +70,7 @@ module Tebako
70
70
  def deploy
71
71
  BuildHelpers.with_env(deploy_env) do
72
72
  update_rubygems
73
- system("#{gem_command} env")
73
+ system("#{gem_command} env") if @verbose
74
74
  install_gem("tebako-runtime")
75
75
  install_gem("bundler", BUNDLER_VERSION) if needs_bundler?
76
76
  deploy_solution
@@ -73,16 +73,32 @@ module Tebako
73
73
  @cwd ||= f_cwd
74
74
  end
75
75
 
76
+ def cwd_announce
77
+ @cwd_announce ||= cwd.nil? ? "<Host current directory>" : cwd
78
+ end
79
+
76
80
  # DATA_BIN_DIR folder is used to create packaged filesystem
77
81
  # set(DATA_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/p)
78
82
  def data_bin_dir
79
83
  @data_bin_dir ||= File.join(output_folder, "p")
80
84
  end
81
85
 
82
- # DATA_BIN_FILE is packaged filesystem itself
83
- # set(DATA_BIN_FILE ${DATA_BIN_DIR}/fs.bin)
84
- def data_bin_file
85
- @data_bin_file ||= File.join(data_bin_dir, "fs.bin")
86
+ # Mode File(s) Content
87
+ # bundle fs.bin Application
88
+ # both fs.bin, fs2.bin Stub, application respectively
89
+ # runtime fs.bin Stub
90
+ # app fs2.bin Application
91
+
92
+ def data_bundle_file
93
+ @data_bundle_file ||= File.join(data_bin_dir, "fs.bin")
94
+ end
95
+
96
+ def data_stub_file
97
+ @data_stub_file ||= File.join(data_bin_dir, "fs.bin")
98
+ end
99
+
100
+ def data_app_file
101
+ @data_app_file ||= File.join(data_bin_dir, "fs2.bin")
86
102
  end
87
103
 
88
104
  # DATA_PRE_DIR folder is used to build gems that need to be packaged
@@ -131,11 +147,11 @@ module Tebako
131
147
  end
132
148
 
133
149
  def l_level
134
- @l_level ||= if @options["log-level"].nil?
135
- "error"
136
- else
137
- @options["log-level"]
138
- end
150
+ @l_level ||= @options["log-level"].nil? ? "error" : @options["log-level"]
151
+ end
152
+
153
+ def mode
154
+ @mode ||= @options["mode"].nil? ? "bundle" : @options["mode"]
139
155
  end
140
156
 
141
157
  def m_files
@@ -179,10 +195,57 @@ module Tebako
179
195
  end
180
196
  end
181
197
 
182
- def press_announce
183
- cwd_announce = cwd.nil? ? "<Host current directory>" : cwd
184
- @press_announce ||= <<~ANN
198
+ def press_announce(is_msys)
199
+ case mode
200
+ when "application"
201
+ press_announce_application(is_msys)
202
+ when "both"
203
+ press_announce_both
204
+ when "bundle"
205
+ press_announce_bundle
206
+ when "runtime"
207
+ press_announce_runtime
208
+ end
209
+ end
210
+
211
+ def press_announce_ref(is_msys)
212
+ if is_msys
213
+ " referencing runtime at '#{ref}'"
214
+ else
215
+ ""
216
+ end
217
+ end
218
+
219
+ def press_announce_application(is_msys)
220
+ <<~ANN
185
221
  Running tebako press at #{prefix}
222
+ Mode: 'application'
223
+ Ruby version: '#{@ruby_ver}'
224
+ Project root: '#{root}'
225
+ Application entry point: '#{fs_entrance}'
226
+ Package file name: '#{package}.tebako'#{press_announce_ref(is_msys)}
227
+ Package working directory: '#{cwd_announce}'
228
+ ANN
229
+ end
230
+
231
+ def press_announce_both
232
+ <<~ANN
233
+ Running tebako press at #{prefix}
234
+ Mode: 'both'
235
+ Ruby version: '#{@ruby_ver}'
236
+ Project root: '#{root}'
237
+ Application entry point: '#{fs_entrance}'
238
+ Runtime file name: '#{package}'
239
+ Package file name: '#{package}.tebako'
240
+ Loging level: '#{l_level}'
241
+ Package working directory: '#{cwd_announce}'
242
+ ANN
243
+ end
244
+
245
+ def press_announce_bundle
246
+ <<~ANN
247
+ Running tebako press at #{prefix}
248
+ Mode: 'bundle'
186
249
  Ruby version: '#{@ruby_ver}'
187
250
  Project root: '#{root}'
188
251
  Application entry point: '#{fs_entrance}'
@@ -192,6 +255,16 @@ module Tebako
192
255
  ANN
193
256
  end
194
257
 
258
+ def press_announce_runtime
259
+ <<~ANN
260
+ Running tebako press at #{prefix}
261
+ Mode: 'runtime'
262
+ Ruby version: '#{@ruby_ver}'
263
+ Runtime file name: '#{package}'
264
+ Loging level: '#{l_level}'
265
+ ANN
266
+ end
267
+
195
268
  def press_options
196
269
  @press_options ||= "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{l_level}' " \
197
270
  end
@@ -200,6 +273,10 @@ module Tebako
200
273
  Pathname.new(path).relative?
201
274
  end
202
275
 
276
+ def ref
277
+ @ref ||= @options["ref"].nil? ? "tebako-runtime" : @options["ref"].gsub("\\", "/")
278
+ end
279
+
203
280
  def remove_glibc_private
204
281
  @remove_glibc_private ||= if RUBY_PLATFORM.end_with?("linux") || RUBY_PLATFORM.end_with?("linux-gnu")
205
282
  "-DREMOVE_GLIBC_PRIVATE=#{@options["patchelf"] ? "ON" : "OFF"}"
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
4
+ # All rights reserved.
5
+ # This file is a part of tebako
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions
9
+ # are met:
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # 2. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
20
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ # POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ require "stringio"
29
+
30
+ module Tebako
31
+ # Tebako application package descriptor
32
+ class PackageDescriptor
33
+ SIGNATURE = "TAMATEBAKO"
34
+
35
+ attr_reader :ruby_version_major, :ruby_version_minor, :ruby_version_patch, :tebako_version_major,
36
+ :tebako_version_minor, :tebako_version_patch, :mount_point, :entry_point, :cwd
37
+
38
+ def initialize(*args)
39
+ if args.size == 1 && args[0].is_a?(Array)
40
+ deserialize(args[0])
41
+ elsif args.size == 5
42
+ construct_from_params(*args)
43
+ else
44
+ raise ArgumentError, "Invalid arguments"
45
+ end
46
+ end
47
+
48
+ def serialize
49
+ buffer = StringIO.new
50
+
51
+ buffer.write(SIGNATURE)
52
+ serialize_versions(buffer)
53
+
54
+ write_string(buffer, @mount_point)
55
+ write_string(buffer, @entry_point)
56
+
57
+ serialize_cwd(buffer)
58
+ buffer.string
59
+ end
60
+
61
+ private
62
+
63
+ def deserialize(buffer)
64
+ stream = StringIO.new(buffer.pack("C*"))
65
+
66
+ signature = stream.read(SIGNATURE.size)
67
+ raise ArgumentError, "Invalid or missing signature" if signature != SIGNATURE
68
+
69
+ deserialize_versions(stream)
70
+ @mount_point = read_string(stream)
71
+ @entry_point = read_string(stream)
72
+
73
+ cwd_present = stream.read(1).unpack1("C")
74
+ @cwd = cwd_present == 1 ? read_string(stream) : nil
75
+ end
76
+
77
+ def construct_from_params(ruby_version, tebako_version, mount_point, entry_point, cwd)
78
+ parse_version(ruby_version, :@ruby_version_major, :@ruby_version_minor, :@ruby_version_patch)
79
+ parse_version(tebako_version, :@tebako_version_major, :@tebako_version_minor, :@tebako_version_patch)
80
+
81
+ @mount_point = mount_point
82
+ @entry_point = entry_point
83
+ @cwd = cwd
84
+ end
85
+
86
+ def deserialize_versions(stream)
87
+ @ruby_version_major = read_uint16(stream)
88
+ @ruby_version_minor = read_uint16(stream)
89
+ @ruby_version_patch = read_uint16(stream)
90
+ @tebako_version_major = read_uint16(stream)
91
+ @tebako_version_minor = read_uint16(stream)
92
+ @tebako_version_patch = read_uint16(stream)
93
+ end
94
+
95
+ def parse_version(version, major_sym, minor_sym, patch_sym)
96
+ major, minor, patch = version.split(".").map(&:to_i)
97
+ raise ArgumentError, "Invalid version format" unless major && minor && patch
98
+
99
+ instance_variable_set(major_sym, major)
100
+ instance_variable_set(minor_sym, minor)
101
+ instance_variable_set(patch_sym, patch)
102
+ end
103
+
104
+ def write_uint16(buffer, value)
105
+ buffer.write([value].pack("v"))
106
+ end
107
+
108
+ def read_uint16(stream)
109
+ data = stream.read(2)
110
+ raise ArgumentError, "Unexpected end of stream" if data.nil?
111
+
112
+ data.unpack1("v")
113
+ end
114
+
115
+ def serialize_cwd(buffer)
116
+ if @cwd
117
+ buffer.write([1].pack("C"))
118
+ write_string(buffer, @cwd)
119
+ else
120
+ buffer.write([0].pack("C"))
121
+ end
122
+ end
123
+
124
+ def serialize_versions(buffer)
125
+ write_uint16(buffer, @ruby_version_major)
126
+ write_uint16(buffer, @ruby_version_minor)
127
+ write_uint16(buffer, @ruby_version_patch)
128
+ write_uint16(buffer, @tebako_version_major)
129
+ write_uint16(buffer, @tebako_version_minor)
130
+ write_uint16(buffer, @tebako_version_patch)
131
+ end
132
+
133
+ def write_string(buffer, str)
134
+ write_uint16(buffer, str.size)
135
+ buffer.write(str)
136
+ end
137
+
138
+ def read_string(stream)
139
+ size = read_uint16(stream)
140
+ stream.read(size)
141
+ end
142
+ end
143
+ end
@@ -67,9 +67,10 @@ module Tebako
67
67
  class << self
68
68
  # Create implib
69
69
  def create_implib(src_dir, package_src_dir, app_name, ruby_ver)
70
- create_def(src_dir, app_name)
70
+ a_name = File.basename(app_name, ".*")
71
+ create_def(src_dir, a_name)
71
72
  puts " ... creating Windows import library"
72
- params = ["dlltool", "-d", def_fname(src_dir, app_name), "-D", out_fname(app_name), "--output-lib",
73
+ params = ["dlltool", "-d", def_fname(src_dir, a_name), "-D", out_fname(a_name), "--output-lib",
73
74
  lib_fname(package_src_dir, ruby_ver)]
74
75
  BuildHelpers.run_with_capture(params)
75
76
  end
@@ -85,13 +86,12 @@ module Tebako
85
86
  end
86
87
 
87
88
  def finalize(os_type, src_dir, app_name, ruby_ver, patchelf)
89
+ puts "-- Running finalize script"
90
+
88
91
  RubyBuilder.new(ruby_ver, src_dir).final_build
89
92
  exe_suffix = Packager::PatchHelpers.exe_suffix(os_type)
90
93
  src_name = File.join(src_dir, "ruby#{exe_suffix}")
91
- unless patchelf.nil?
92
- params = [patchelf, "--remove-needed-version", "libpthread.so.0", "GLIBC_PRIVATE", src_name]
93
- BuildHelpers.run_with_capture(params)
94
- end
94
+ patchelf(src_name, patchelf)
95
95
  package_name = "#{app_name}#{exe_suffix}"
96
96
  strip_or_copy(os_type, src_name, package_name)
97
97
  puts "Created tebako package at \"#{package_name}\""
@@ -106,9 +106,10 @@ module Tebako
106
106
  FileUtils.cp_r "#{stash_dir}/.", src_dir
107
107
  end
108
108
 
109
- def mkdwarfs(deps_bin_dir, data_bin_file, data_src_dir)
109
+ def mkdwarfs(deps_bin_dir, data_bin_file, data_src_dir, descriptor = nil)
110
110
  puts "-- Running mkdwarfs script"
111
111
  params = [File.join(deps_bin_dir, "mkdwarfs"), "-o", data_bin_file, "-i", data_src_dir, "--no-progress"]
112
+ params << "--header" << descriptor if descriptor
112
113
  BuildHelpers.run_with_capture_v(params)
113
114
  end
114
115
 
@@ -189,18 +190,11 @@ module Tebako
189
190
  patch_map.each { |fname, mapping| PatchHelpers.patch_file("#{root}/#{fname}", mapping) }
190
191
  end
191
192
 
192
- def ruby_version(tbd)
193
- ruby_version = nil
194
- PatchHelpers.with_env(DEPLOY_ENV) do
195
- out, st = Open3.capture2e("#{tbd}/ruby", "--version")
196
- raise Tebako::Error, "Failed to run ruby --version" unless st.exitstatus.zero?
197
-
198
- match = out.match(/ruby (\d+\.\d+\.\d+)/)
199
- raise Tebako::Error, "Failed to parse Ruby version from #{out}" unless match
193
+ def patchelf(src_name, patchelf)
194
+ return if patchelf.nil?
200
195
 
201
- ruby_version = match[1]
202
- end
203
- ruby_version
196
+ params = [patchelf, "--remove-needed-version", "libpthread.so.0", "GLIBC_PRIVATE", src_name]
197
+ BuildHelpers.run_with_capture(params)
204
198
  end
205
199
 
206
200
  def strip_or_copy(os_type, src_name, package_name)
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023-2024 [Ribose Inc](https://www.ribose.com).
4
+ # All rights reserved.
5
+ # This file is a part of tebako
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions
9
+ # are met:
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # 2. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
20
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ # POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ require "pathname"
29
+ require "fileutils"
30
+
31
+ require_relative "options_manager"
32
+ require_relative "scenario_manager"
33
+ require_relative "package_descriptor"
34
+ require_relative "packager"
35
+
36
+ module Tebako
37
+ # Tebako application package descriptor
38
+ class PackagerLite
39
+ def initialize(options_manager, scenario_manager)
40
+ @opts = options_manager
41
+ @scm = scenario_manager
42
+ @scm.configure_scenario
43
+ end
44
+
45
+ def codegen
46
+ puts "-- Generating files"
47
+ Tebako::Codegen.generate_package_descriptor(@opts, @scm)
48
+ end
49
+
50
+ def create_implib
51
+ rv = Tebako::RubyVersion.new(@opts.ruby_ver)
52
+ bname = if @opts.mode == "application"
53
+ @opts.ref
54
+ else # @opts.mode == "both"
55
+ @opts.package
56
+ end
57
+ Tebako::Packager.create_implib(@opts.ruby_src_dir, @opts.data_src_dir, bname, rv)
58
+ end
59
+
60
+ def create_package
61
+ deploy
62
+ FileUtils.rm_f(name)
63
+ Tebako::Packager.mkdwarfs(@opts.deps_bin_dir, name, @opts.data_src_dir, codegen)
64
+ puts "Created tebako package at \"#{name}\""
65
+ end
66
+
67
+ def deploy
68
+ Tebako::Packager.init(@opts.stash_dir, @opts.data_src_dir, @opts.data_pre_dir, @opts.data_bin_dir)
69
+ create_implib if @scm.msys?
70
+ Tebako::Packager.deploy(@opts.data_src_dir, @opts.data_pre_dir, @opts.rv, @opts.root, @scm.fs_entrance, @opts.cwd)
71
+ end
72
+
73
+ def name
74
+ bname = Pathname.new(@opts.package).cleanpath.to_s
75
+ @name ||= "#{bname}.tebako"
76
+ end
77
+ end
78
+ end
@@ -35,7 +35,7 @@ module Tebako
35
35
  class ScenarioManager
36
36
  def initialize(fs_root, fs_entrance)
37
37
  initialize_root(fs_root)
38
- initialize_entry_point(fs_entrance)
38
+ initialize_entry_point(fs_entrance || "stub.rb")
39
39
  end
40
40
 
41
41
  attr_reader :fs_entry_point, :fs_mount_point, :fs_entrance