tebako 0.8.2 → 0.8.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3ce7f498e5f82482a720d99b95c4f5e405c595f4ded4d5dffa5ac3030679530
4
- data.tar.gz: 7fb7a07898f02dad4bcffe7f058c142311f6c9873dfb1accb460cd9442390064
3
+ metadata.gz: cf7f343e3ed1cef12b766eaa2cc0834c31882f7cf78629b5079856d9c5b94765
4
+ data.tar.gz: 852554fa13a1c95a22bef4234a2063f0879b66ffd53b0cc2635b232c8dbfa1bd
5
5
  SHA512:
6
- metadata.gz: e089f8dc1edd455cb028b3ca888285b260df832228296891167bc248f2e39df650696b031c7201db0f2115e26242f2edfada4045dec1d42e82e8635cf01dd57d
7
- data.tar.gz: 632d3337eae51876bfa9bf48a77d33a80e16b86439c66f0b406a7cf3bcb004d7f18f8a9f46bb858f8bc76cda2565078ea9883a5f1d1279ef6e3c80ff3f2808e0
6
+ metadata.gz: ad25d6a39cb8a2b3ff00d2f109299682da1cdceda1b852e9ea6b144b6bfbc4e087a70e9441295196623e10f5f9281390fefa2c9d9b40858e7beb622d6a860275
7
+ data.tar.gz: fdcf01004d51fafd178f76fc7684140653cdf84dc8ea400c2956713c7034e0b8f99b7ff46f236babc1b8b313ac4f199b128d0c6fb8d5f71af93baa215c23e743
data/CMakeLists.txt CHANGED
@@ -246,6 +246,14 @@ else(${IS_MSYS})
246
246
  set(FS_MOUNT_POINT "/__tebako_memfs__")
247
247
  endif(${IS_MSYS})
248
248
 
249
+ if(PACKAGE_NEEDS_CWD)
250
+ set(NEEDS_CWD true)
251
+ set(PACKAGE_CWD_FULL ${FS_MOUNT_POINT}/${PACKAGE_CWD})
252
+ else(PACKAGE_NEEDS_CWD)
253
+ set(NEEDS_CWD false)
254
+ set(PACKAGE_CWD "")
255
+ set(PACKAGE_CWD_FULL "")
256
+ endif(PACKAGE_NEEDS_CWD)
249
257
 
250
258
  message(STATUS "DATA_SRC_DIR: ${DATA_SRC_DIR}")
251
259
  message(STATUS "DATA_PRE_DIR: ${DATA_PRE_DIR}")
@@ -435,6 +443,7 @@ else (${SETUP_MODE})
435
443
  COMMAND ruby ${EXE}/tebako-packager deploy ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${RUBY_STASH_DIR}
436
444
  ${DATA_SRC_DIR} ${DATA_PRE_DIR} ${DATA_BIN_DIR}
437
445
  ${FS_ROOT} ${FS_ENTRANCE} ${FS_MOUNT_POINT} ${APP_NAME} ${RUBY_VER}
446
+ ${PACKAGE_CWD}
438
447
  DEPENDS ${RUBY_PRJ}
439
448
  )
440
449
 
@@ -481,19 +490,7 @@ else (${SETUP_MODE})
481
490
 
482
491
  add_dependencies(tebako-fs packaged_filesystem)
483
492
 
484
- if (${RUBY_VER} VERSION_LESS "3.0.0")
485
- add_custom_target(tebako
486
- COMMAND ${CMAKE_COMMAND} -E chdir ${RUBY_SOURCE_DIR} make -j${NCORES}
487
- COMMAND ruby ${EXE}/tebako-packager finalize ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${APP_NAME}
488
- )
489
- else()
490
- add_custom_target(tebako
491
- COMMAND ${CMAKE_COMMAND} -E chdir ${RUBY_SOURCE_DIR} make ruby -j${NCORES}
492
- COMMAND ${CMAKE_COMMAND} -E chdir ${RUBY_SOURCE_DIR} make -j${NCORES}
493
- COMMAND ruby ${EXE}/tebako-packager finalize ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${APP_NAME}
494
- )
495
- endif()
496
-
493
+ add_custom_target(tebako COMMAND ruby ${EXE}/tebako-packager finalize ${OSTYPE_TXT} ${RUBY_SOURCE_DIR} ${APP_NAME} ${RUBY_VER})
497
494
  add_dependencies(tebako setup tebako-fs)
498
495
 
499
496
  endif(${SETUP_MODE})
data/README.adoc CHANGED
@@ -88,7 +88,7 @@ with debug information unstripped. You can opt to run 'strip -S' manually, it mo
88
88
  | 2.7.8 | Linux, macOS
89
89
  | 3.0.7 | Linux, macOS
90
90
  | 3.1.6 | Linux, macOS, Windows
91
- | 3.2.4 | Linux, macOS, Windows
91
+ | 3.2.{4,5} | Linux, macOS, Windows
92
92
  | 3.3.{3,4} | Linux, macOS, Windows
93
93
 
94
94
  |===
@@ -655,6 +655,7 @@ tebako press \
655
655
  [-R|--Ruby=<ruby-version>] \
656
656
  [-o|--output=<packaged-file-name>] \
657
657
  [-l|--log-level=<error|warn|debug|trace>] \
658
+ [-c|--cwd=<package current working directory>]
658
659
  [-D|--devmode] \
659
660
  [-t|--tebafile=<path-to-tebafile>]
660
661
  ----
@@ -668,10 +669,10 @@ the Tebako root folder (see details in the Tebako Root Folder Selection section)
668
669
  this parameter defines Ruby version that will be packaged (optional, defaults to
669
670
  `3.1.6`)
670
671
 
671
- `<project-root>`::
672
+ `project-root`::
672
673
  a folder at the host source file system where project files are located
673
674
 
674
- `<entry-point>`::
675
+ `entry-point`::
675
676
  an executable file (binary executable or script) that shall be started when
676
677
  packaged file is called
677
678
 
@@ -682,6 +683,12 @@ the output file name (optional, defaults to `<current folder>/<entry point base
682
683
  logging level for the Tebako built-in memory filesystem driver
683
684
  (optional, defaults to `error`)
684
685
 
686
+ `cwd`::
687
+ a folder within Tebako memfs where the packaged application will start. This folder should be specified relative to the memfs root.
688
+ If not provided, the application will start within the current folder of the host (i.e., at $PWD).
689
+ This option is required because it is not possible to change the directory to a memfs folder until the package is started, as opposed to any host folder
690
+ that can be set as the current directory before Tebako package invocation. Tebako saves original working directory in a global Ruby variable `$tebako_original_pwd`.
691
+
685
692
  `tebafile`::
686
693
  the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`).
687
694
  Please refer to the separate section below for tebafile description.
data/common.env CHANGED
@@ -2,4 +2,4 @@ BUILD_TYPE=Release
2
2
  DEPS=deps
3
3
  INCBIN_TAG=348e36b
4
4
  DWARFS_WR_TAG=v0.5.8
5
- RUBY_VER=3.1.6
5
+ RUBY_VER=3.2.5
data/exe/tebako-packager CHANGED
@@ -28,6 +28,7 @@
28
28
 
29
29
  require_relative "../lib/tebako/packager"
30
30
  require_relative "../lib/tebako/stripper"
31
+ require_relative "../lib/tebako/build_helpers"
31
32
 
32
33
  begin
33
34
  unless ARGV.length.positive?
@@ -46,8 +47,8 @@ begin
46
47
  raise Tebako::Error,
47
48
  "tebako-packager pass1 command expects 6 arguments, #{ARGV.length} has been provided."
48
49
  end
49
-
50
- Tebako::Packager.pass1(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5])
50
+ ruby_ver = Tebako::RubyVersion.new(ARGV[5])
51
+ Tebako::Packager.pass1(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ruby_ver)
51
52
 
52
53
  when "pass1a"
53
54
  # ARGV[0] -- command
@@ -69,9 +70,9 @@ begin
69
70
  raise Tebako::Error,
70
71
  "tebako-packager pass2 command expects 7 arguments, #{ARGV.length} has been provided."
71
72
  end
72
-
73
+ ruby_ver = Tebako::RubyVersion.new(ARGV[6])
73
74
  Tebako::Packager.stash(ARGV[4], ARGV[5])
74
- Tebako::Packager.pass2(ARGV[1], ARGV[2], ARGV[3], ARGV[6])
75
+ Tebako::Packager.pass2(ARGV[1], ARGV[2], ARGV[3], ruby_ver)
75
76
  when "deploy"
76
77
  # ARGV[0] -- command
77
78
  # ARGV[1] -- OSTYPE
@@ -85,26 +86,31 @@ begin
85
86
  # ARGV[9] -- FS_MOUNT_POINT
86
87
  # ARGV[10] -- APP_NAME
87
88
  # ARGV[11] -- RUBY_VER
88
- unless ARGV.length == 12
89
+ # ARGV[12] -- CWD
90
+ unless ARGV.length == 13 || ARGV.length == 12
89
91
  raise Tebako::Error,
90
- "tebako-packager deploy command expects 12 arguments, #{ARGV.length} has been provided."
92
+ "tebako-packager deploy command expects 12 or 13 arguments, #{ARGV.length} has been provided."
91
93
  end
94
+ ruby_ver = Tebako::RubyVersion.new(ARGV[11])
92
95
  Tebako::Packager.init(ARGV[3], ARGV[4], ARGV[5], ARGV[6])
93
- Tebako::Packager.create_implib(ARGV[2], ARGV[4], File.basename(ARGV[10]), ARGV[11]) if ARGV[1] =~ /msys/
96
+ Tebako::Packager.create_implib(ARGV[2], ARGV[4], File.basename(ARGV[10]), ruby_ver) if ARGV[1] =~ /msys/
94
97
  # Assume that "<TARGET_BIN_DIR (TBD)>" is <DATA_SRC_DIR>/bin"
95
98
  # That shall match CMakeLists.txt settings
96
- Tebako::Packager.deploy(ARGV[1], ARGV[4], ARGV[5], ARGV[11], ARGV[7], ARGV[8], ARGV[9])
99
+ Tebako::Packager.deploy(ARGV[1], ARGV[4], ARGV[5], ruby_ver, ARGV[7], ARGV[8], ARGV[9],
100
+ ARGV.length == 13 ? ARGV[12] : nil)
97
101
 
98
102
  when "finalize"
99
103
  # ARGV[0] -- command
100
104
  # ARGV[1] -- OSTYPE
101
105
  # ARGV[2] -- RUBY_SOURCE_DIR
102
106
  # ARGV[3] -- APP_NAME
103
- unless ARGV.length == 4
107
+ # ARGV[4] -- RUBY_VER
108
+ unless ARGV.length == 5
104
109
  raise Tebako::Error,
105
- "tebako-packager finalize command expects 4 arguments, #{ARGV.length} has been provided."
110
+ "tebako-packager finalize command expects 5 arguments, #{ARGV.length} has been provided."
106
111
  end
107
- Tebako::Packager.finalize(ARGV[1], ARGV[2], ARGV[3])
112
+ ruby_ver = Tebako::RubyVersion.new(ARGV[4])
113
+ Tebako::Packager.finalize(ARGV[1], ARGV[2], ARGV[3], ruby_ver)
108
114
  else
109
115
  raise Tebako::Error, "tebako-packager cannot process #{ARGV[0]} command"
110
116
  end
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  *
3
- * Copyright (c) 2021, [Ribose Inc](https://www.ribose.com).
3
+ * Copyright (c) 2021-2024, [Ribose Inc](https://www.ribose.com).
4
4
  * All rights reserved.
5
5
  * This file is a part of tebako
6
6
  *
@@ -37,4 +37,7 @@ namespace tebako {
37
37
  extern const char* fs_log_level;
38
38
  extern const char* fs_mount_point;
39
39
  extern const char* fs_entry_point;
40
+ extern bool needs_cwd;
41
+ extern const char* package_cwd;
42
+ extern char original_cwd[PATH_MAX];
40
43
  }
@@ -33,6 +33,7 @@ extern "C" {
33
33
  int tebako_main(int* argc, char*** argv);
34
34
  const char* tebako_mount_point(void);
35
35
  int tebako_is_running_miniruby(void);
36
+ const char* tebako_original_pwd(void);
36
37
  #ifdef RB_W32
37
38
  int tebako_file_load_ok(const char *path);
38
39
  #endif
@@ -0,0 +1,123 @@
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 "open3"
29
+
30
+ # Tebako - an executable packager
31
+ module Tebako
32
+ # Ruby build helpers
33
+ module BuildHelpers
34
+ class << self
35
+ def ncores
36
+ if RUBY_PLATFORM.include?("darwin")
37
+ out, st = Open3.capture2e("sysctl", "-n", "hw.ncpu")
38
+ else
39
+ out, st = Open3.capture2e("nproc", "--all")
40
+ end
41
+
42
+ if st.exitstatus.zero?
43
+ out.strip.to_i
44
+ else
45
+ 4
46
+ end
47
+ end
48
+
49
+ def run_with_capture(args)
50
+ puts " ... @ #{args.join(" ")}"
51
+ out, st = Open3.capture2e(*args)
52
+ raise Tebako::Error, "Failed to run #{args.join(" ")} (#{st}):\n #{out}" unless st.exitstatus.zero?
53
+
54
+ out
55
+ end
56
+
57
+ def run_with_capture_v(args)
58
+ if @verbose
59
+ args_v = args.dup
60
+ args_v.push("--verbose")
61
+ puts run_with_capture(args_v)
62
+ else
63
+ run_with_capture(args)
64
+ end
65
+ end
66
+
67
+ # Sets up temporary environment variables and yields to the
68
+ # block. When the block exits, the environment variables are set
69
+ # back to their original values.
70
+ def with_env(hash)
71
+ old = {}
72
+ hash.each do |k, v|
73
+ old[k] = ENV.fetch(k, nil)
74
+ ENV[k] = v
75
+ end
76
+ begin
77
+ yield
78
+ ensure
79
+ hash.each_key { |k| ENV[k] = old[k] }
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ # Ruby version checks
86
+ class RubyVersion
87
+ def initialize(ruby_ver)
88
+ unless ruby_ver =~ /^\d+\.\d+\.\d+$/
89
+ raise Tebako::Error, "Invalid Ruby version format '#{ruby_ver}'. Expected format: x.y.z"
90
+ end
91
+
92
+ @ruby_ver = ruby_ver
93
+ end
94
+
95
+ def ruby3x?
96
+ @ruby3x ||= @ruby_ver[0] == "3"
97
+ end
98
+
99
+ def ruby31?
100
+ @ruby31 ||= ruby3x? && @ruby_ver[2].to_i >= 1
101
+ end
102
+
103
+ def ruby32?
104
+ @ruby32 ||= ruby3x? && @ruby_ver[2].to_i >= 2
105
+ end
106
+
107
+ def ruby32only?
108
+ @ruby32only ||= ruby3x? && @ruby_ver[2] == "2"
109
+ end
110
+
111
+ def ruby33?
112
+ @ruby33 ||= ruby3x? && @ruby_ver[2].to_i >= 3
113
+ end
114
+
115
+ def api_version
116
+ @api_version ||= "#{@ruby_ver.split(".")[0..1].join(".")}.0"
117
+ end
118
+
119
+ def lib_version
120
+ @lib_version ||= "#{@ruby_ver.split(".")[0..1].join}0"
121
+ end
122
+ end
123
+ end
data/lib/tebako/cli.rb CHANGED
@@ -73,7 +73,14 @@ module Tebako
73
73
  print Digest::SHA256.hexdigest [File.read(File.join(source, "CMakeLists.txt")), Tebako::VERSION].join
74
74
  end
75
75
 
76
+ CWD_DESCRIPTION = <<~DESC
77
+ Current working directory for packaged application. This directory shall be specified relative to root.
78
+ #{" " * 62}# If this parameter is not set, the application will start in the current directory of the host file system.
79
+ DESC
80
+
76
81
  desc "press", "Press tebako image"
82
+ method_option :cwd, type: :string, aliases: "-c", required: false,
83
+ desc: CWD_DESCRIPTION
77
84
  method_option :"entry-point", type: :string, aliases: ["-e", "--entry"], required: true,
78
85
  desc: "Ruby application entry point"
79
86
  method_option :"log-level", type: :string, aliases: "-l", required: false, enum: %w[error warn debug trace],
@@ -137,7 +137,7 @@ module Tebako
137
137
  "MinGW Makefiles"
138
138
  else
139
139
  raise Tebako::Error.new(
140
- "#{RUBY_PLATFORM} is not supported yet, exiting",
140
+ "#{RUBY_PLATFORM} is not supported, exiting",
141
141
  254
142
142
  )
143
143
  end
@@ -195,20 +195,28 @@ module Tebako
195
195
  end
196
196
 
197
197
  def press_announce
198
+ cwd_announce = options["cwd"].nil? ? "<Host current directory>" : options["cwd"]
198
199
  @press_announce ||= <<~ANN
199
200
  Running tebako press at #{prefix}
200
- Ruby version: '#{extend_ruby_version[0]}'
201
- Project root: '#{root}'
202
- Application entry point: '#{options["entry-point"]}'
203
- Package file name: '#{package}'
204
- Loging level: '#{l_level}'
201
+ Ruby version: '#{extend_ruby_version[0]}'
202
+ Project root: '#{root}'
203
+ Application entry point: '#{options["entry-point"]}'
204
+ Package file name: '#{package}'
205
+ Loging level: '#{l_level}'
206
+ Package working directory: '#{cwd_announce}'
205
207
  ANN
206
208
  end
207
209
 
208
210
  def press_options
211
+ cwd_option = if options["cwd"].nil?
212
+ "-DPACKAGE_NEEDS_CWD:BOOL=OFF"
213
+ else
214
+ "-DPACKAGE_NEEDS_CWD:BOOL=ON -DPACKAGE_CWD:STRING='#{options["cwd"]}'"
215
+ end
209
216
  @press_options ||=
210
217
  "-DROOT:STRING='#{root}' -DENTRANCE:STRING='#{options["entry-point"]}' " \
211
- "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{options["log-level"]}' "
218
+ "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{options["log-level"]}' " \
219
+ "#{cwd_option}"
212
220
  end
213
221
 
214
222
  def relative?(path)
@@ -42,25 +42,27 @@ module Tebako
42
42
  "3.0.7" => "2a3411977f2850431136b0fab8ad53af09fb74df2ee2f4fb7f11b378fe034388",
43
43
  "3.1.6" => "0d0dafb859e76763432571a3109d1537d976266be3083445651dc68deed25c22",
44
44
  "3.2.4" => "c72b3c5c30482dca18b0f868c9075f3f47d8168eaf626d4e682ce5b59c858692",
45
+ "3.2.5" => "ef0610b498f60fb5cfd77b51adb3c10f4ca8ed9a17cb87c61e5bea314ac34a16",
45
46
  "3.3.3" => "83c05b2177ee9c335b631b29b8c077b4770166d02fa527f3a9f6a40d13f3cce2",
46
47
  "3.3.4" => "fe6a30f97d54e029768f2ddf4923699c416cdbc3a6e96db3e2d5716c7db96a34"
47
48
  }.freeze
48
49
 
49
- DEFAULT_RUBY_VERSION = "3.1.6"
50
+ MIN_RUBY_VERSION_WINDOWS = "3.1.6"
51
+ DEFAULT_RUBY_VERSION = "3.2.5"
50
52
 
51
53
  def version_check(version)
52
54
  return if RUBY_VERSIONS.key?(version)
53
55
 
54
56
  raise Tebako::Error.new(
55
- "Ruby version #{version} is not supported yet, exiting",
57
+ "Ruby version #{version} is not supported, exiting",
56
58
  253
57
59
  )
58
60
  end
59
61
 
60
62
  def version_check_msys(version)
61
- if Gem::Version.new(version) < Gem::Version.new(DEFAULT_RUBY_VERSION) && RUBY_PLATFORM =~ /msys|mingw|cygwin/
63
+ if Gem::Version.new(version) < Gem::Version.new(MIN_RUBY_VERSION_WINDOWS) && RUBY_PLATFORM =~ /msys|mingw|cygwin/
62
64
  raise Tebako::Error.new(
63
- "Windows packaging works for Ruby #{DEFAULT_RUBY_VERSION} or above, version #{version} is not supported",
65
+ "Windows packaging works for Ruby #{MIN_RUBY_VERSION_WINDOWS} or above, version #{version} is not supported",
64
66
  252
65
67
  )
66
68
  end
@@ -29,6 +29,7 @@ require "fileutils"
29
29
  require "find"
30
30
 
31
31
  require_relative "error"
32
+ require_relative "build_helpers"
32
33
  require_relative "packager/patch_helpers"
33
34
 
34
35
  # Tebako - an executable packager
@@ -48,16 +49,18 @@ module Tebako
48
49
  @target_dir = target_dir
49
50
  @pre_dir = pre_dir
50
51
  @verbose = ENV["VERBOSE"] == "yes" || ENV["VERBOSE"] == "true"
52
+ @ncores = BuildHelpers.ncores
51
53
  end
52
54
 
53
55
  attr_reader :bundler_command, :gem_command, :gem_home
54
56
 
55
- def config(os_type, ruby_ver)
57
+ def config(os_type, ruby_ver, cwd)
56
58
  @ruby_ver = ruby_ver
57
59
  @os_type = os_type
60
+ @cwd = cwd
58
61
 
59
62
  @tbd = File.join(@target_dir, "bin")
60
- @tgd = @gem_home = File.join(@target_dir, "lib", "ruby", "gems", ruby_api_version)
63
+ @tgd = @gem_home = File.join(@target_dir, "lib", "ruby", "gems", @ruby_ver.api_version)
61
64
  @tld = File.join(@target_dir, "local")
62
65
 
63
66
  lookup_files
@@ -66,15 +69,13 @@ module Tebako
66
69
  end
67
70
 
68
71
  def deploy
69
- Packager::PatchHelpers.with_env(deploy_env) do
70
- unless Packager::PatchHelpers.ruby31?(@ruby_ver)
71
- update_rubygems
72
- patch_after_rubygems_update(@target_dir, @ruby_api_version)
73
- end
72
+ BuildHelpers.with_env(deploy_env) do
73
+ update_rubygems
74
74
  system("#{gem_command} env")
75
75
  install_gem("tebako-runtime")
76
76
  install_gem("bundler", BUNDLER_VERSION) if needs_bundler?
77
77
  deploy_solution
78
+ check_cwd
78
79
  end
79
80
  end
80
81
 
@@ -95,11 +96,7 @@ module Tebako
95
96
  ["--no-document", "--install-dir", @tgd].each do |param|
96
97
  params.push(param)
97
98
  end
98
- run_with_capture_v(params)
99
- end
100
-
101
- def ruby_api_version
102
- @ruby_api_version ||= "#{@ruby_ver.split(".")[0..1].join(".")}.0"
99
+ BuildHelpers.run_with_capture_v(params)
103
100
  end
104
101
 
105
102
  def needs_bundler?
@@ -107,16 +104,23 @@ module Tebako
107
104
  end
108
105
 
109
106
  def update_rubygems
107
+ return if @ruby_ver.ruby31?
108
+
110
109
  puts " ... updating rubygems to #{Tebako::RUBYGEMS_VERSION}"
111
- run_with_capture_v([@gem_command, "update", "--no-doc", "--system", Tebako::RUBYGEMS_VERSION])
110
+ BuildHelpers.run_with_capture_v([@gem_command, "update", "--no-doc", "--system",
111
+ Tebako::RUBYGEMS_VERSION])
112
+ patch_after_rubygems_update(@target_dir, @ruby_ver.api_version)
112
113
  end
113
114
 
114
115
  private
115
116
 
116
117
  def bundle_config
117
- run_with_capture_v([@bundler_command, "config", "set", "--local", "build.ffi", "--disable-system-libffi"])
118
- run_with_capture_v([@bundler_command, "config", "set", "--local", "build.nokogiri", @nokogiri_option])
119
- run_with_capture_v([@bundler_command, "config", "set", "--local", "force_ruby_platform", @force_ruby_platform])
118
+ BuildHelpers.run_with_capture_v([@bundler_command, "config", "set", "--local", "build.ffi",
119
+ "--disable-system-libffi"])
120
+ BuildHelpers.run_with_capture_v([@bundler_command, "config", "set", "--local", "build.nokogiri",
121
+ @nokogiri_option])
122
+ BuildHelpers.run_with_capture_v([@bundler_command, "config", "set", "--local", "force_ruby_platform",
123
+ @force_ruby_platform])
120
124
  end
121
125
 
122
126
  def check_entry_point(entry_point_root)
@@ -128,13 +132,22 @@ module Tebako
128
132
  raise Tebako::Error.new("Entry point #{fs_entry_point} does not exist or is not accessible", 106)
129
133
  end
130
134
 
135
+ def check_cwd
136
+ return if @cwd.nil?
137
+
138
+ cwd_full = File.join(@target_dir, @cwd)
139
+ return if File.directory?(cwd_full)
140
+
141
+ raise Tebako::Error.new("Package working directory #{@cwd} does not exist", 108)
142
+ end
143
+
131
144
  def collect_and_deploy_gem(gemspec)
132
145
  puts " ... Collecting gem from gemspec #{gemspec}"
133
146
 
134
147
  copy_files(@pre_dir)
135
148
 
136
149
  Dir.chdir(@pre_dir) do
137
- run_with_capture_v([@gem_command, "build", gemspec])
150
+ BuildHelpers.run_with_capture_v([@gem_command, "build", gemspec])
138
151
  install_all_gems_or_fail
139
152
  end
140
153
 
@@ -149,8 +162,8 @@ module Tebako
149
162
  Dir.chdir(@pre_dir) do
150
163
  bundle_config
151
164
  puts " *** It may take a long time for a big project. It takes REALLY long time on Windows ***"
152
- run_with_capture_v([@bundler_command, "install", "--jobs=#{ncores}"])
153
- run_with_capture_v([@bundler_command, "exec", @gem_command, "build", gemspec])
165
+ BuildHelpers.run_with_capture_v([@bundler_command, "install", "--jobs=#{@ncores}"])
166
+ BuildHelpers.run_with_capture_v([@bundler_command, "exec", @gem_command, "build", gemspec])
154
167
  install_all_gems_or_fail
155
168
  end
156
169
 
@@ -216,7 +229,7 @@ module Tebako
216
229
  Dir.chdir(@tld) do
217
230
  bundle_config
218
231
  puts " *** It may take a long time for a big project. It takes REALLY long time on Windows ***"
219
- run_with_capture_v([@bundler_command, "install", "--jobs=#{ncores}"])
232
+ BuildHelpers.run_with_capture_v([@bundler_command, "install", "--jobs=#{@ncores}"])
220
233
  end
221
234
 
222
235
  check_entry_point("local")
@@ -256,43 +269,11 @@ module Tebako
256
269
  @g_length = Dir.glob(File.join(@fs_root, "*.gem")).length
257
270
  end
258
271
 
259
- def ncores
260
- if RUBY_PLATFORM.include?("darwin")
261
- out, st = Open3.capture2e("sysctl", "-n", "hw.ncpu")
262
- else
263
- out, st = Open3.capture2e("nproc", "--all")
264
- end
265
-
266
- @ncores ||= if st.exitstatus.zero?
267
- out.strip.to_i
268
- else
269
- 4
270
- end
271
- end
272
-
273
272
  def patch_after_rubygems_update(target_dir, ruby_api_ver)
274
273
  # Autoload cannot handle statically linked openssl extension
275
274
  # Changing it to require seems to be the simplest solution
276
275
  Packager::PatchHelpers.patch_file("#{target_dir}/lib/ruby/site_ruby/#{ruby_api_ver}/rubygems/openssl.rb",
277
276
  { "autoload :OpenSSL, \"openssl\"" => "require \"openssl\"" })
278
277
  end
279
-
280
- def run_with_capture(args)
281
- puts " ... @ #{args.join(" ")}"
282
- out, st = Open3.capture2e(*args)
283
- raise Tebako::Error, "Failed to run #{args.join(" ")} (#{st}):\n #{out}" unless st.exitstatus.zero?
284
-
285
- out
286
- end
287
-
288
- def run_with_capture_v(args)
289
- if @verbose
290
- args_v = args.dup
291
- args_v.push("--verbose")
292
- puts run_with_capture(args_v)
293
- else
294
- run_with_capture(args)
295
- end
296
- end
297
278
  end
298
279
  end
data/lib/tebako/error.rb CHANGED
@@ -34,7 +34,8 @@ module Tebako
34
34
  104 => "'tebako press' build step failed",
35
35
  105 => "Failed to map MSys path to Windows",
36
36
  106 => "Entry point does not exist or is not accessible",
37
- 107 => "Project root does not exist or is not accessible"
37
+ 107 => "Project root does not exist or is not accessible",
38
+ 108 => "Package working directory does not exist"
38
39
  }.freeze
39
40
 
40
41
  class << self
@@ -156,7 +156,7 @@ module Tebako
156
156
  # ....................................................
157
157
  # autoload :OpenSSL, "openssl"
158
158
  # fails to deal with a default gem from statically linked extension
159
- patch_map.store("lib/rubygems/openssl.rb", RUBYGEM_OPENSSL_RB_PATCH) if PatchHelpers.ruby3x?(ruby_ver)
159
+ patch_map.store("lib/rubygems/openssl.rb", RUBYGEM_OPENSSL_RB_PATCH) if ruby_ver.ruby3x?
160
160
 
161
161
  if ostype =~ /msys/
162
162
  # ....................................................
@@ -176,7 +176,7 @@ module Tebako
176
176
  include Tebako::Packager::PatchBuildsystem
177
177
 
178
178
  def get_gnumakefile_in_patch_p1(ruby_ver) # rubocop:disable Metrics/MethodLength
179
- objext = PatchHelpers.ruby32?(ruby_ver) ? "$(OBJEXT)" : "@OBJEXT@"
179
+ objext = ruby_ver.ruby32? ? "$(OBJEXT)" : "@OBJEXT@"
180
180
  {
181
181
  " DLLWRAP += -mno-cygwin" =>
182
182
  "# tebako patched DLLWRAP += -mno-cygwin",
@@ -26,6 +26,7 @@
26
26
  # POSSIBILITY OF SUCH DAMAGE.
27
27
 
28
28
  require_relative "patch_literals"
29
+ require_relative "patch_main"
29
30
  require_relative "patch_libraries"
30
31
  require_relative "patch_helpers"
31
32
  require_relative "patch_buildsystem"
@@ -41,7 +42,7 @@ module Tebako
41
42
  patch_map.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if ostype =~ /linux-musl/
42
43
  if PatchHelpers.msys?(ostype)
43
44
  patch_map.merge!(get_msys_patches(ruby_ver))
44
- elsif PatchHelpers.ruby3x?(ruby_ver)
45
+ elsif ruby_ver.ruby3x?
45
46
  patch_map.store("common.mk", COMMON_MK_PATCH)
46
47
  end
47
48
  extend_patch_map_r33(patch_map, ostype, deps_lib_dir, ruby_ver)
@@ -52,7 +53,7 @@ module Tebako
52
53
  include Tebako::Packager::PatchBuildsystem
53
54
  include Tebako::Packager::PatchLiterals
54
55
  def extend_patch_map_r33(patch_map, ostype, deps_lib_dir, ruby_ver)
55
- if PatchHelpers.ruby33?(ruby_ver) || PatchHelpers.msys?(ostype)
56
+ if ruby_ver.ruby33? || PatchHelpers.msys?(ostype)
56
57
  patch_map.store("config.status",
57
58
  get_config_status_patch(ostype, deps_lib_dir, ruby_ver))
58
59
  end
@@ -75,7 +76,7 @@ module Tebako
75
76
  }
76
77
 
77
78
  if PatchHelpers.msys?(ostype)
78
- patch = PatchHelpers.ruby32?(ruby_ver) ? DLN_C_MSYS_PATCH : DLN_C_MSYS_PATCH_PRE32
79
+ patch = ruby_ver.ruby32? ? DLN_C_MSYS_PATCH : DLN_C_MSYS_PATCH_PRE32
79
80
  dln_c_patch.merge!(patch)
80
81
  end
81
82
 
@@ -83,7 +84,7 @@ module Tebako
83
84
  end
84
85
 
85
86
  def get_io_c_msys_patch(ruby_ver)
86
- io_c_msys_patch = PatchHelpers.ruby32?(ruby_ver) ? IO_C_MSYS_PATCH : IO_C_MSYS_PATCH_PRE_32
87
+ io_c_msys_patch = ruby_ver.ruby32? ? IO_C_MSYS_PATCH : IO_C_MSYS_PATCH_PRE_32
87
88
  io_c_msys_patch.merge(IO_C_MSYS_BASE_PATCH)
88
89
  end
89
90
 
@@ -94,7 +95,7 @@ module Tebako
94
95
  end
95
96
 
96
97
  def get_util_c_patch(ruby_ver)
97
- if PatchHelpers.ruby31?(ruby_ver)
98
+ if ruby_ver.ruby31?
98
99
  PatchHelpers.patch_c_file_post("#endif /* !HAVE_GNU_QSORT_R */")
99
100
  else
100
101
  PatchHelpers.patch_c_file_pre("#ifndef S_ISDIR")
@@ -122,14 +123,14 @@ module Tebako
122
123
  "template/Makefile.in" => template_makefile_in_patch(ostype, deps_lib_dir, ruby_ver),
123
124
  "tool/mkconfig.rb" => get_tool_mkconfig_rb_patch(ostype),
124
125
  "dir.c" => get_dir_c_patch(ostype), "dln.c" => get_dln_c_patch(ostype, ruby_ver),
125
- "io.c" => get_io_c_patch(ostype, ruby_ver), "main.c" => MAIN_C_PATCH,
126
+ "io.c" => get_io_c_patch(ostype, ruby_ver), "main.c" => PatchMain.get_main_c_patch(ruby_ver),
126
127
  "file.c" => PatchHelpers.patch_c_file_pre("/* define system APIs */"),
127
128
  "util.c" => get_util_c_patch(ruby_ver)
128
129
  }
129
130
  end
130
131
 
131
132
  def mlibs_subst(ostype, deps_lib_dir, ruby_ver)
132
- yjit_libs = PatchHelpers.ruby32only?(ruby_ver) ? "$(YJIT_LIBS) " : ""
133
+ yjit_libs = ruby_ver.ruby32only? ? "$(YJIT_LIBS) " : ""
133
134
  {
134
135
  "MAINLIBS = #{yjit_libs}@MAINLIBS@" =>
135
136
  "# -- Start of tebako patch -- \n" \
@@ -80,7 +80,7 @@ module Tebako
80
80
  def template_makefile_in_subst(ostype, ruby_ver)
81
81
  if PatchHelpers.msys?(ostype)
82
82
  TEMPLATE_MAKEFILE_IN_BASE_PATCH_MSYS
83
- elsif !PatchHelpers.ruby31?(ruby_ver)
83
+ elsif !ruby_ver.ruby31?
84
84
  TEMPLATE_MAKEFILE_IN_BASE_PATCH_PRE_3_1
85
85
  else
86
86
  TEMPLATE_MAKEFILE_IN_BASE_PATCH
@@ -88,9 +88,9 @@ module Tebako
88
88
  end
89
89
 
90
90
  def template_makefile_in_patch_two(ostype, ruby_ver)
91
- if !PatchHelpers.ruby31?(ruby_ver)
91
+ if !ruby_ver.ruby31?
92
92
  { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_1 => template_makefile_in_subst(ostype, ruby_ver) }
93
- elsif !PatchHelpers.ruby33?(ruby_ver)
93
+ elsif !ruby_ver.ruby33?
94
94
  { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_3 => template_makefile_in_subst(ostype, ruby_ver) }
95
95
  else
96
96
  { TEMPLATE_MAKEFILE_IN_BASE_PATTERN => template_makefile_in_subst(ostype, ruby_ver) }
@@ -136,7 +136,7 @@ module Tebako
136
136
  # - Introduce LIBRUBY dependency on static extensions
137
137
  # This is an addition to COMMON_MK_PATCH specified above
138
138
  def get_gnumakefile_in_patch_p2(ruby_ver) # rubocop:disable Metrics/MethodLength
139
- objext = PatchHelpers.ruby32?(ruby_ver) ? "$(OBJEXT)" : "@OBJEXT@"
139
+ objext = ruby_ver.ruby32? ? "$(OBJEXT)" : "@OBJEXT@"
140
140
 
141
141
  {
142
142
  "$(WPROGRAM): $(RUBYW_INSTALL_NAME).res.#{objext}" =>
@@ -108,44 +108,8 @@ module Tebako
108
108
  end
109
109
  end
110
110
 
111
- def ruby3x?(ruby_ver)
112
- ruby_ver[0] == "3"
113
- end
114
-
115
- def ruby31?(ruby_ver)
116
- ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 1
117
- end
118
-
119
- def ruby32?(ruby_ver)
120
- ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 2
121
- end
122
-
123
- def ruby32only?(ruby_ver)
124
- ruby3x?(ruby_ver) && ruby_ver[2] == "2"
125
- end
126
-
127
- def ruby33?(ruby_ver)
128
- ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 3
129
- end
130
-
131
- # Sets up temporary environment variables and yields to the
132
- # block. When the block exits, the environment variables are set
133
- # back to their original values.
134
- def with_env(hash)
135
- old = {}
136
- hash.each do |k, v|
137
- old[k] = ENV.fetch(k, nil)
138
- ENV[k] = v
139
- end
140
- begin
141
- yield
142
- ensure
143
- hash.each_key { |k| ENV[k] = old[k] }
144
- end
145
- end
146
-
147
111
  def yaml_reference(ruby_ver)
148
- ruby32?(ruby_ver) ? "-l:libyaml.a" : ""
112
+ ruby_ver.ruby32? ? "-l:libyaml.a" : ""
149
113
  end
150
114
  end
151
115
  end
@@ -125,7 +125,7 @@ module Tebako
125
125
  libs = String.new
126
126
 
127
127
  DARWIN_DEP_LIBS_1.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
128
- process_brew_libs!(libs, PatchHelpers.ruby31?(ruby_ver) ? DARWIN_BREW_LIBS_31 : DARWIN_BREW_LIBS_PRE_31)
128
+ process_brew_libs!(libs, ruby_ver.ruby31? ? DARWIN_BREW_LIBS_31 : DARWIN_BREW_LIBS_PRE_31)
129
129
  process_brew_libs!(libs, DARWIN_BREW_LIBS)
130
130
 
131
131
  DARWIN_DEP_LIBS_2.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
@@ -125,21 +125,6 @@ module Tebako
125
125
  SUBST
126
126
  }.freeze
127
127
 
128
- MAIN_C_PATCH = {
129
- "int\nmain(int argc, char **argv)" =>
130
- "#include <tebako/tebako-main.h>\n\nint\nmain(int argc, char **argv)",
131
-
132
- " ruby_sysinit(&argc, &argv);" => <<~SUBST
133
- ruby_sysinit(&argc, &argv);
134
- /* -- Start of tebako patch -- */
135
- if (tebako_main(&argc, &argv) != 0) {
136
- printf("Tebako intialization failed.");
137
- return -1;
138
- }
139
- /* -- End of tebako patch -- */
140
- SUBST
141
- }.freeze
142
-
143
128
  # Compensate ruby incorrect processing of (f)getattrlist returning ENOTSUP
144
129
  # Note. We are not patching need_normalization function
145
130
  # In this function (f)getattrlist failure with ENOTSUP is processed correctly
@@ -0,0 +1,94 @@
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
+ # Tebako - an executable packager
29
+ module Tebako
30
+ module Packager
31
+ # Ruby patching literals (main.c)
32
+ module PatchMain
33
+ MAIN_C_SUBST_RB_MAIN = <<~SUBST
34
+ /* -- Start of tebako patch -- */
35
+ #include <tebako/tebako-main.h>
36
+ /* -- End of tebako patch -- */
37
+
38
+ static int
39
+ rb_main(int argc, char **argv)
40
+ SUBST
41
+
42
+ MAIN_C_SUBST_MAIN = <<~SUBST
43
+ /* -- Start of tebako patch -- */
44
+ #include <tebako/tebako-main.h>
45
+ /* -- End of tebako patch -- */
46
+
47
+ int
48
+ main(int argc, char **argv)
49
+ SUBST
50
+
51
+ MAIN_C_SUBST_RB_MAIN_INNER = <<~SUBST
52
+ ruby_init();
53
+ /* -- Start of tebako patch -- */
54
+ if (!tebako_is_running_miniruby())
55
+ {
56
+ VALUE cwd = rb_str_new_cstr(tebako_original_pwd());
57
+ rb_gv_set("$tebako_original_pwd", cwd);
58
+ }
59
+ /* -- End of tebako patch -- */
60
+ SUBST
61
+
62
+ MAIN_C_SUBST_MAIN_INNER = <<~SUBST
63
+ ruby_sysinit(&argc, &argv);
64
+ /* -- Start of tebako patch -- */
65
+ if (tebako_main(&argc, &argv) != 0) {
66
+ printf("Tebako intialization failed.");
67
+ return -1;
68
+ }
69
+ /* -- End of tebako patch -- */
70
+ SUBST
71
+
72
+ class << self
73
+ def get_main_c_patch(ruby_ver)
74
+ puts get_main_c_main_pattern(ruby_ver)
75
+ {
76
+ get_main_c_main_pattern(ruby_ver) => get_main_c_main_subst(ruby_ver),
77
+ "ruby_init();" => MAIN_C_SUBST_RB_MAIN_INNER,
78
+ " ruby_sysinit(&argc, &argv);" => MAIN_C_SUBST_MAIN_INNER
79
+ }
80
+ end
81
+
82
+ private
83
+
84
+ def get_main_c_main_pattern(ruby_ver)
85
+ ruby_ver.ruby32? ? "static int\nrb_main(int argc, char **argv)" : "int\nmain(int argc, char **argv)"
86
+ end
87
+
88
+ def get_main_c_main_subst(ruby_ver)
89
+ ruby_ver.ruby32? ? MAIN_C_SUBST_RB_MAIN : MAIN_C_SUBST_MAIN
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -31,6 +31,7 @@ require "pathname"
31
31
 
32
32
  require_relative "error"
33
33
  require_relative "deploy_helper"
34
+ require_relative "ruby_builder"
34
35
  require_relative "stripper"
35
36
  require_relative "packager/pass1"
36
37
  require_relative "packager/pass1a"
@@ -75,16 +76,17 @@ module Tebako
75
76
  end
76
77
 
77
78
  # Deploy
78
- def deploy(os_type, target_dir, pre_dir, ruby_ver, fs_root, fs_entrance, fs_mount_point) # rubocop:disable Metrics/ParameterLists
79
+ def deploy(os_type, target_dir, pre_dir, ruby_ver, fs_root, fs_entrance, fs_mount_point, cwd) # rubocop:disable Metrics/ParameterLists
79
80
  puts "-- Running deploy script"
80
81
 
81
82
  deploy_helper = Tebako::DeployHelper.new(fs_root, fs_entrance, fs_mount_point, target_dir, pre_dir)
82
- deploy_helper.config(os_type, ruby_ver)
83
+ deploy_helper.config(os_type, ruby_ver, cwd)
83
84
  deploy_helper.deploy
84
85
  Tebako::Stripper.strip(os_type, target_dir)
85
86
  end
86
87
 
87
- def finalize(os_type, src_dir, app_name)
88
+ def finalize(os_type, src_dir, app_name, ruby_ver)
89
+ RubyBuilder.new(ruby_ver, src_dir).final_build
88
90
  exe_suffix = Packager::PatchHelpers.exe_suffix(os_type)
89
91
  src_name = File.join(src_dir, "ruby#{exe_suffix}")
90
92
  package_name = "#{app_name}#{exe_suffix}"
@@ -177,7 +179,7 @@ module Tebako
177
179
  end
178
180
 
179
181
  def lib_fname(src_dir, ruby_ver)
180
- File.join(src_dir, "lib", "libx64-ucrt-ruby#{ruby_ver[0]}#{ruby_ver[2]}0.a")
182
+ File.join(src_dir, "lib", "libx64-ucrt-ruby#{ruby_ver.lib_version}.a")
181
183
  end
182
184
 
183
185
  def do_patch(patch_map, root)
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 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 "fileutils"
29
+ require "find"
30
+
31
+ require_relative "build_helpers"
32
+
33
+ # Tebako - an executable packager
34
+ module Tebako
35
+ # Tebako packaging support (ruby builder)
36
+ class RubyBuilder
37
+ def initialize(ruby_ver, src_dir)
38
+ @ruby_ver = ruby_ver
39
+ @src_dir = src_dir
40
+ @ncores = BuildHelpers.ncores
41
+ end
42
+
43
+ # Final build of tebako package
44
+ def final_build
45
+ puts " ... building tebako package"
46
+ Dir.chdir(@src_dir) do
47
+ BuildHelpers.run_with_capture(["make", "ruby", "-j#{@ncores}"]) if @ruby_ver.ruby3x?
48
+ BuildHelpers.run_with_capture(["make", "-j#{@ncores}"])
49
+ end
50
+ end
51
+ end
52
+ end
@@ -26,5 +26,5 @@
26
26
  # POSSIBILITY OF SUCH DAMAGE.
27
27
 
28
28
  module Tebako
29
- VERSION = "0.8.2"
29
+ VERSION = "0.8.3"
30
30
  end
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  *
3
- * Copyright (c) 2021-2023 [Ribose Inc](https://www.ribose.com).
3
+ * Copyright (c) 2021-2024 [Ribose Inc](https://www.ribose.com).
4
4
  * All rights reserved.
5
5
  * This file is a part of tebako
6
6
  *
@@ -30,8 +30,11 @@
30
30
  #include <incbin/incbin.h>
31
31
 
32
32
  namespace tebako {
33
- const char * fs_log_level = "@LOG_LEVEL@";
34
- const char * fs_mount_point = "@FS_MOUNT_POINT@";
35
- const char * fs_entry_point = "@FS_ENTRY_POINT@";
33
+ const char * fs_log_level = "@LOG_LEVEL@";
34
+ const char * fs_mount_point = "@FS_MOUNT_POINT@";
35
+ const char * fs_entry_point = "@FS_ENTRY_POINT@";
36
+ bool needs_cwd = @NEEDS_CWD@;
37
+ const char * package_cwd = "@PACKAGE_CWD_FULL@";
38
+ char original_cwd[PATH_MAX];
36
39
  INCBIN(fs, "@DATA_BIN_FILE@");
37
40
  }
data/src/tebako-main.cpp CHANGED
@@ -27,6 +27,7 @@
27
27
  *
28
28
  */
29
29
 
30
+ #include <unistd.h>
30
31
  #include <stdlib.h>
31
32
  #include <stdio.h>
32
33
  #include <string.h>
@@ -34,6 +35,7 @@
34
35
  #include <sys/stat.h>
35
36
  #include <fcntl.h>
36
37
 
38
+
37
39
  #include <string>
38
40
  #include <cstdint>
39
41
 
@@ -132,6 +134,20 @@ extern "C" int tebako_main(int* argc, char*** argv) {
132
134
 
133
135
  }
134
136
 
137
+ if (!tebako_is_running_miniruby()) {
138
+ if (getcwd(tebako::original_cwd, sizeof(tebako::original_cwd)) == NULL) {
139
+ printf("Failed to get current directory: %s\n", strerror(errno));
140
+ return -1;
141
+ }
142
+
143
+ if (tebako::needs_cwd) {
144
+ if (tebako_chdir(tebako::package_cwd) != 0) {
145
+ printf("Failed to chdir to '%s' : %s\n", tebako::package_cwd, strerror(errno));
146
+ ret = -1;
147
+ }
148
+ }
149
+ }
150
+
135
151
  if (ret != 0) {
136
152
  try {
137
153
  printf("Tebako initialization failed\n");
@@ -145,8 +161,6 @@ extern "C" int tebako_main(int* argc, char*** argv) {
145
161
  // Nested error, no recovery :(
146
162
  }
147
163
  }
148
-
149
- // tebako_chdir("/__tebako_memfs__/local");
150
164
  }
151
165
  return ret;
152
166
  }
@@ -155,6 +169,10 @@ extern "C" const char* tebako_mount_point(void) {
155
169
  return tebako::fs_mount_point;
156
170
  }
157
171
 
172
+ extern "C" const char* tebako_original_pwd(void) {
173
+ return tebako::original_cwd;
174
+ }
175
+
158
176
  extern "C" int tebako_is_running_miniruby(void) {
159
177
  return running_miniruby;
160
178
  }
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.8.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tebako
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-08 00:00:00.000000000 Z
11
+ date: 2024-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -161,6 +161,7 @@ files:
161
161
  - include/tebako/tebako-fs.h
162
162
  - include/tebako/tebako-main.h
163
163
  - lib/tebako.rb
164
+ - lib/tebako/build_helpers.rb
164
165
  - lib/tebako/cli.rb
165
166
  - lib/tebako/cli_helpers.rb
166
167
  - lib/tebako/cli_rubies.rb
@@ -174,6 +175,8 @@ files:
174
175
  - lib/tebako/packager/patch_helpers.rb
175
176
  - lib/tebako/packager/patch_libraries.rb
176
177
  - lib/tebako/packager/patch_literals.rb
178
+ - lib/tebako/packager/patch_main.rb
179
+ - lib/tebako/ruby_builder.rb
177
180
  - lib/tebako/stripper.rb
178
181
  - lib/tebako/version.rb
179
182
  - resources/tebako-fs.cpp.in
@@ -237,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
240
  - !ruby/object:Gem::Version
238
241
  version: '0'
239
242
  requirements: []
240
- rubygems_version: 3.3.27
243
+ rubygems_version: 3.4.19
241
244
  signing_key:
242
245
  specification_version: 4
243
246
  summary: Packager for Ruby executables