tebako 0.9.2 → 0.10.0

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.
@@ -0,0 +1,119 @@
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 "pathname"
29
+
30
+ require_relative "error"
31
+
32
+ # Tebako - an executable packager
33
+ module Tebako
34
+ # Manages packaging scenario based on input files (gemfile, gemspec, etc)
35
+ class ScenarioManager
36
+ def initialize(fs_root, fs_entrance)
37
+ initialize_root(fs_root)
38
+ initialize_entry_point(fs_entrance)
39
+ end
40
+
41
+ attr_reader :fs_entry_point, :fs_mount_point, :fs_entrance
42
+
43
+ def configure_scenario
44
+ @fs_mount_point = if msys?
45
+ "A:/__tebako_memfs__"
46
+ else
47
+ "/__tebako_memfs__"
48
+ end
49
+
50
+ lookup_files
51
+ configure_scenario_inner
52
+ end
53
+
54
+ def exe_suffix
55
+ @exe_suffix ||= msys? ? ".exe" : ""
56
+ end
57
+
58
+ def macos?
59
+ @macos ||= RUBY_PLATFORM =~ /darwin/ ? true : false
60
+ end
61
+
62
+ def msys?
63
+ @msys ||= RUBY_PLATFORM =~ /msys|mingw|cygwin/ ? true : false
64
+ end
65
+
66
+ private
67
+
68
+ def initialize_entry_point(fs_entrance)
69
+ @fs_entrance = Pathname.new(fs_entrance).cleanpath.to_s
70
+
71
+ if Pathname.new(@fs_entrance).absolute?
72
+ Tebako.packaging_error 114 unless @fs_entrance.start_with?(@fs_root)
73
+
74
+ fetmp = @fs_entrance
75
+ @fs_entrance = Pathname.new(@fs_entrance).relative_path_from(Pathname.new(@fs_root)).to_s
76
+ puts "-- Absolute path to entry point '#{fetmp}' will be reduced to '#{@fs_entrance}' relative to '#{@fs_root}'"
77
+ end
78
+ # Can check after deploy, because entry point can be generated during bundle install or gem install
79
+ # Tebako.packaging_error 106 unless File.file?(File.join(@fs_root, @fs_entrance))
80
+ @fs_entry_point = "/bin/#{@fs_entrance}"
81
+ end
82
+
83
+ def initialize_root(fs_root)
84
+ Tebako.packaging_error 107 unless Dir.exist?(fs_root)
85
+ p_root = Pathname.new(fs_root).cleanpath
86
+ Tebako.packaging_error 113 unless p_root.absolute?
87
+ @fs_root = p_root.realpath.to_s
88
+ end
89
+
90
+ def configure_scenario_inner
91
+ case @gs_length
92
+ when 0
93
+ configure_scenario_no_gemspec
94
+ when 1
95
+ @scenario = @gf_length.positive? ? :gemspec_and_gemfile : :gemspec
96
+ else
97
+ raise Tebako::Error, "Multiple Ruby gemspecs found in #{@fs_root}"
98
+ end
99
+ end
100
+
101
+ def configure_scenario_no_gemspec
102
+ @fs_entry_point = "/local/#{@fs_entrance}" if @gf_length.positive? || @g_length.zero?
103
+
104
+ @scenario = if @gf_length.positive?
105
+ :gemfile
106
+ elsif @g_length.positive?
107
+ :gem
108
+ else
109
+ :simple_script
110
+ end
111
+ end
112
+
113
+ def lookup_files
114
+ @gs_length = Dir.glob(File.join(@fs_root, "*.gemspec")).length
115
+ @gf_length = Dir.glob(File.join(@fs_root, "Gemfile")).length
116
+ @g_length = Dir.glob(File.join(@fs_root, "*.gem")).length
117
+ end
118
+ end
119
+ end
@@ -46,11 +46,11 @@ module Tebako
46
46
  # Removes build artefacts, strip shared objects
47
47
  # [TODO] We probably need debug option/flag to say whether we shall delete ruby binaries
48
48
  # from memfs or not. For debugging purposes it is very handy to have it here
49
- def strip(ostype, src_dir)
49
+ def strip(scm, src_dir)
50
50
  puts " ... stripping the output"
51
51
  strip_bs(src_dir)
52
- strip_fi(ostype, src_dir)
53
- strip_li(ostype, src_dir)
52
+ strip_fi(scm, src_dir)
53
+ strip_li(scm, src_dir)
54
54
  end
55
55
 
56
56
  def strip_file(file_in, file_out = nil)
@@ -69,8 +69,8 @@ module Tebako
69
69
 
70
70
  private
71
71
 
72
- def get_files(ostype)
73
- exe_suffix = Packager::PatchHelpers.exe_suffix(ostype)
72
+ def get_files(scm)
73
+ exe_suffix = scm.exe_suffix
74
74
  files = BIN_FILES.flat_map do |f|
75
75
  [f, "#{f}#{CMD_SUFFIX}", "#{f}#{BAT_SUFFIX}"]
76
76
  end
@@ -87,29 +87,29 @@ module Tebako
87
87
  ])
88
88
  end
89
89
 
90
- def strip_fi(ostype, src_dir)
91
- files = get_files(ostype).map { |f| "#{src_dir}/bin/#{f}" }
90
+ def strip_fi(scm, src_dir)
91
+ files = get_files(scm).map { |f| "#{src_dir}/bin/#{f}" }
92
92
  FileUtils.rm(files, force: true)
93
93
  end
94
94
 
95
- def strip_li(ostype, src_dir)
96
- sext = strip_extensions(ostype)
95
+ def strip_li(scm, src_dir)
96
+ sext = strip_extensions(scm)
97
97
  Find.find(src_dir) do |file|
98
98
  next if File.directory?(file)
99
99
 
100
100
  extension = File.extname(file).delete_prefix(".").downcase
101
101
  if DELETE_EXTENSIONS.include?(extension)
102
102
  FileUtils.rm(file)
103
- elsif sext.include?(extension) # && !Packager::PatchHelpers.msys?(ostype)
103
+ elsif sext.include?(extension)
104
104
  strip_file(file)
105
105
  end
106
106
  end
107
107
  end
108
108
 
109
- def strip_extensions(ostype)
109
+ def strip_extensions(scm)
110
110
  sext = ["so"]
111
- sext << "dll" if Packager::PatchHelpers.msys?(ostype)
112
- sext << "dylib" << "bundle" if Packager::PatchHelpers.macos?(ostype)
111
+ sext << "dll" if scm.msys?
112
+ sext << "dylib" << "bundle" if scm.macos?
113
113
  sext
114
114
  end
115
115
  end
@@ -26,5 +26,5 @@
26
26
  # POSSIBILITY OF SUCH DAMAGE.
27
27
 
28
28
  module Tebako
29
- VERSION = "0.9.2"
29
+ VERSION = "0.10.0"
30
30
  end
data/src/tebako-main.cpp CHANGED
@@ -34,6 +34,7 @@
34
34
  #include <memory.h>
35
35
  #include <sys/stat.h>
36
36
  #include <fcntl.h>
37
+ #include <stdint.h>
37
38
 
38
39
  #include <string>
39
40
  #include <cstdint>
@@ -70,9 +71,7 @@ extern "C" int tebako_main(int* argc, char*** argv)
70
71
  }
71
72
  else {
72
73
  try {
73
- fsret = load_fs(&gfsData[0], gfsSize, tebako::fs_log_level, nullptr /* cachesize*/, nullptr /* workers */,
74
- nullptr /* mlock */, nullptr /* decompress_ratio*/, nullptr /* image_offset */
75
- );
74
+ fsret = mount_root_memfs(&gfsData[0], gfsSize, tebako::fs_log_level, nullptr, nullptr, nullptr, nullptr, nullptr);
76
75
 
77
76
  if (fsret == 0) {
78
77
  if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract") == 0) {
@@ -88,7 +87,7 @@ extern "C" int tebako_main(int* argc, char*** argv)
88
87
  ret = 0;
89
88
  }
90
89
  }
91
- atexit(drop_fs);
90
+ atexit(unmount_root_memfs);
92
91
  }
93
92
 
94
93
  catch (std::exception e) {
@@ -100,7 +99,7 @@ extern "C" int tebako_main(int* argc, char*** argv)
100
99
  ret = -1;
101
100
  }
102
101
 
103
- if (tebako::needs_cwd) {
102
+ if (tebako::package_cwd != nullptr) {
104
103
  if (tebako_chdir(tebako::package_cwd) != 0) {
105
104
  printf("Failed to chdir to '%s' : %s\n", tebako::package_cwd, strerror(errno));
106
105
  ret = -1;
@@ -120,7 +119,7 @@ extern "C" int tebako_main(int* argc, char*** argv)
120
119
  argv_memory = nullptr;
121
120
  }
122
121
  if (fsret == 0) {
123
- drop_fs();
122
+ unmount_root_memfs();
124
123
  }
125
124
  }
126
125
  catch (...) {
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.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-06 00:00:00.000000000 Z
11
+ date: 2024-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -164,11 +164,13 @@ files:
164
164
  - include/tebako/tebako-main.h
165
165
  - lib/tebako.rb
166
166
  - lib/tebako/build_helpers.rb
167
+ - lib/tebako/cache_manager.rb
167
168
  - lib/tebako/cli.rb
168
169
  - lib/tebako/cli_helpers.rb
169
- - lib/tebako/cli_rubies.rb
170
+ - lib/tebako/codegen.rb
170
171
  - lib/tebako/deploy_helper.rb
171
172
  - lib/tebako/error.rb
173
+ - lib/tebako/options_manager.rb
172
174
  - lib/tebako/packager.rb
173
175
  - lib/tebako/packager/pass1.rb
174
176
  - lib/tebako/packager/pass1a.rb
@@ -179,10 +181,10 @@ files:
179
181
  - lib/tebako/packager/patch_literals.rb
180
182
  - lib/tebako/packager/patch_main.rb
181
183
  - lib/tebako/ruby_builder.rb
184
+ - lib/tebako/ruby_version.rb
185
+ - lib/tebako/scenario_manager.rb
182
186
  - lib/tebako/stripper.rb
183
187
  - lib/tebako/version.rb
184
- - resources/tebako-fs.cpp.in
185
- - resources/tebako-version.h.in
186
188
  - src/tebako-main.cpp
187
189
  - tebako.gemspec
188
190
  - tools/.gitattributes
@@ -217,7 +219,7 @@ licenses:
217
219
  metadata:
218
220
  homepage_uri: https://github.com/tamatebako/tebako
219
221
  source_code_uri: https://github.com/tamatebako/tebako
220
- post_install_message:
222
+ post_install_message:
221
223
  rdoc_options: []
222
224
  require_paths:
223
225
  - cmake
@@ -242,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
244
  version: '0'
243
245
  requirements: []
244
246
  rubygems_version: 3.4.19
245
- signing_key:
247
+ signing_key:
246
248
  specification_version: 4
247
249
  summary: Packager for Ruby executables
248
250
  test_files: []
@@ -1,40 +0,0 @@
1
- /**
2
- *
3
- * Copyright (c) 2021-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
- */
29
-
30
- #include <incbin/incbin.h>
31
-
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@";
36
- bool needs_cwd = @NEEDS_CWD@;
37
- const char * package_cwd = "@PACKAGE_CWD_FULL@";
38
- char original_cwd[PATH_MAX];
39
- INCBIN(fs, "@DATA_BIN_FILE@");
40
- }
@@ -1,37 +0,0 @@
1
- /**
2
- *
3
- * Copyright (c) 2021, [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
- */
29
-
30
-
31
- #pragma once
32
-
33
- const unsigned int tebako_version_major = @PROJECT_VERSION_MAJOR@;
34
- const unsigned int tebako_version_minor = @PROJECT_VERSION_MINOR@;
35
- const unsigned int tebako_version_teeny = @PROJECT_VERSION_PATCH@;
36
-
37
-