tebako 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/CMakeLists.txt +694 -0
  3. data/Gemfile +35 -0
  4. data/README.adoc +389 -0
  5. data/Rakefile +33 -0
  6. data/bin/console +15 -0
  7. data/bin/setup +8 -0
  8. data/cmake/copy_dir.cmake +29 -0
  9. data/cmake/def_tty_colours.cmake +19 -0
  10. data/common.env +6 -0
  11. data/exe/tebako +31 -0
  12. data/include/tebako/tebako-fs.h +40 -0
  13. data/include/tebako/tebako-main.h +40 -0
  14. data/lib/cli.rb +28 -0
  15. data/lib/tebako/cli.rb +137 -0
  16. data/lib/tebako/cli_helpers.rb +147 -0
  17. data/lib/tebako/error.rb +39 -0
  18. data/lib/tebako/packager/pass1.rb +155 -0
  19. data/lib/tebako/packager/pass2.rb +374 -0
  20. data/lib/tebako/packager.rb +210 -0
  21. data/lib/tebako/version.rb +30 -0
  22. data/resources/tebako-fs.cpp.in +37 -0
  23. data/resources/tebako-version.h.in +37 -0
  24. data/src/tebako-main.cpp +188 -0
  25. data/tebako.gemspec +63 -0
  26. data/tests/scripts/cross-tests.sh +34 -0
  27. data/tests/scripts/functional-tests.sh +335 -0
  28. data/tests/test-00/test.rb +4 -0
  29. data/tests/test-01/tebako-test-run.rb +5 -0
  30. data/tests/test-09/tebako-test-0.0.1.gem +0 -0
  31. data/tests/test-11/bin/tebako-test-run.rb +10 -0
  32. data/tests/test-11/lib/tebako-test.rb +20 -0
  33. data/tests/test-11/tebako-test.gemspec +15 -0
  34. data/tests/test-12/tebako-test-a.gemspec +15 -0
  35. data/tests/test-12/tebako-test-b.gemspec +15 -0
  36. data/tests/test-13/bin/tebako-test-run.rb +10 -0
  37. data/tests/test-13/lib/tebako-test.rb +20 -0
  38. data/tests/test-13/tebako-test.gemspec +15 -0
  39. data/tests/test-15/Gemfile +8 -0
  40. data/tests/test-15/Rakefile +4 -0
  41. data/tests/test-15/bin/tebako-test-run.rb +10 -0
  42. data/tests/test-15/lib/tebako/bundle/test/version.rb +9 -0
  43. data/tests/test-15/lib/tebako/bundle/test.rb +29 -0
  44. data/tests/test-15/tebako-bundle-test.gemspec +30 -0
  45. data/tests/test-16/Gemfile +8 -0
  46. data/tests/test-16/Rakefile +4 -0
  47. data/tests/test-16/bin/tebako-test-run.rb +10 -0
  48. data/tests/test-16/lib/tebako/bundle/test/version.rb +9 -0
  49. data/tests/test-16/lib/tebako/bundle/test.rb +29 -0
  50. data/tests/test-16/tebako-bundle-test.gemspec +24 -0
  51. data/tests/test-18/Gemfile +5 -0
  52. data/tests/test-18/tebako-test-run.rb +12 -0
  53. data/tests/test-19/Gemfile +6 -0
  54. data/tests/test-19/tebako-test-run.rb +11 -0
  55. data/tests-2/fixtures/gems-bundler/Gemfile +4 -0
  56. data/tests-2/fixtures/gems-bundler/gems-bundler.rb +34 -0
  57. data/tests-2/fixtures/gems-byebug/Gemfile +5 -0
  58. data/tests-2/fixtures/gems-byebug/gems-byebug.rb +31 -0
  59. data/tests-2/fixtures/gems-expressir/Gemfile +7 -0
  60. data/tests-2/fixtures/gems-expressir/gems-expressir.rb +33 -0
  61. data/tests-2/fixtures/gems-libmspack/Gemfile +5 -0
  62. data/tests-2/fixtures/gems-libmspack/gems-libmspack.rb +91 -0
  63. data/tests-2/fixtures/gems-sassc/Gemfile +6 -0
  64. data/tests-2/fixtures/gems-sassc/base_style/all.scss +1 -0
  65. data/tests-2/fixtures/gems-sassc/base_style/reset.scss +100 -0
  66. data/tests-2/fixtures/gems-sassc/gems-sassc.rb +129 -0
  67. data/tests-2/fixtures/gems-seven-zip/Gemfile +7 -0
  68. data/tests-2/fixtures/gems-seven-zip/gems-seven-zip.rb +53 -0
  69. data/tests-2/fixtures/launcher-coreincl/launcher-coreincl.rb +29 -0
  70. data/tests-2/fixtures/launcher-package/launcher-package.rb +29 -0
  71. data/tests-2/fixtures/launcher-pwd/launcher-pwd.rb +28 -0
  72. data/tests-2/fixtures/launcher-stdinredir/input.txt +1 -0
  73. data/tests-2/fixtures/launcher-stdinredir/launcher-stdinredir.rb +31 -0
  74. data/tests-2/fixtures/launcher-stdoutredir/launcher-stdoutredir.rb +28 -0
  75. data/tests-2/fixtures/patches-dir/level-1/level-2/file-1.txt +1 -0
  76. data/tests-2/fixtures/patches-dir/level-1/level-2/file-2.txt +1 -0
  77. data/tests-2/fixtures/patches-dir/level-1/level-2/file-3.txt +1 -0
  78. data/tests-2/fixtures/patches-dir/patches-dir.rb +154 -0
  79. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-1.txt +1 -0
  80. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-2.txt +2 -0
  81. data/tests-2/fixtures/patches-io-and-file/level-1/level-2/file-3.txt +1 -0
  82. data/tests-2/fixtures/patches-io-and-file/level-1/link-3 +1 -0
  83. data/tests-2/fixtures/patches-io-and-file/patches-io-and-file.rb +87 -0
  84. data/tests-2/fixtures/patches-main/patches-main.rb +6 -0
  85. data/tests-2/tebako-test.rb +312 -0
  86. metadata +170 -0
data/lib/tebako/cli.rb ADDED
@@ -0,0 +1,137 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright (c) 2021-2023 [Ribose Inc](https://www.ribose.com).
5
+ # All rights reserved.
6
+ # This file is a part of tebako
7
+ #
8
+ # Redistribution and use in source and binary forms, with or without
9
+ # modification, are permitted provided that the following conditions
10
+ # are met:
11
+ # 1. Redistributions of source code must retain the above copyright
12
+ # notice, this list of conditions and the following disclaimer.
13
+ # 2. Redistributions in binary form must reproduce the above copyright
14
+ # notice, this list of conditions and the following disclaimer in the
15
+ # documentation and/or other materials provided with the distribution.
16
+ #
17
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
21
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ # POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ require "fileutils"
30
+ require "thor"
31
+ require "yaml"
32
+
33
+ require_relative "cli_helpers"
34
+ require_relative "error"
35
+ require_relative "version"
36
+
37
+ # Tebako - an executable packager
38
+ # Implementation of tebako command-line interface
39
+ module Tebako
40
+ OPTIONS_FILE = ".tebako.yml"
41
+ # Tebako packager front-end
42
+ class TebakoCli < Thor
43
+ package_name "Tebako"
44
+ class_option :prefix, type: :string, aliases: "-p", required: false,
45
+ desc: "A path to tebako packaging environment, '~/.tebako' ('$HOME/.tebako') by default"
46
+
47
+ desc "clean", "Clean tebako packaging environment"
48
+ def clean
49
+ puts "Cleaning tebako packaging environment"
50
+ FileUtils.rm_rf([deps, output], secure: true)
51
+ end
52
+
53
+ desc "press", "Press tebako image"
54
+ method_option :"entry-point", type: :string, aliases: ["-e", "--entry"], required: true,
55
+ desc: "Ruby application entry point"
56
+ method_option :"log-level", type: :string, aliases: "-l", required: false, enum: %w[error warn debug trace],
57
+ desc: "Tebako memfs logging level, 'error' by default"
58
+ method_option :output, type: :string, aliases: "-o", required: false,
59
+ desc: "Tebako package file name, entry point base file name in the current folder by default"
60
+ method_option :root, type: :string, aliases: "-r", required: true, desc: "Root folder of the Ruby application"
61
+ method_option :Ruby, type: :string, aliases: "-R", required: false,
62
+ enum: Tebako::CliHelpers::RUBY_VERSIONS.keys,
63
+ desc: "Tebako package Ruby version, #{Tebako::CliHelpers::DEFAULT_RUBY_VERSION} by default"
64
+ def press
65
+ puts press_announce
66
+ do_press
67
+ rescue TebakoError => e
68
+ puts "Tebako script failed: #{e.message} [#{e.error_code}]"
69
+ exit e.error_code
70
+ end
71
+
72
+ desc "setup", "Set up tebako packaging environment"
73
+ method_option :Ruby, type: :string, aliases: "-R", required: false,
74
+ enum: Tebako::CliHelpers::RUBY_VERSIONS.keys,
75
+ desc: "Tebako package Ruby version, #{Tebako::CliHelpers::DEFAULT_RUBY_VERSION} by default"
76
+ def setup
77
+ puts "Setting up tebako packaging environment"
78
+ do_setup
79
+ rescue TebakoError => e
80
+ puts "Tebako script failed: #{e.message} [#{e.error_code}]"
81
+ exit e.error_code
82
+ end
83
+
84
+ def self.exit_on_failure?
85
+ true
86
+ end
87
+
88
+ no_commands do
89
+ def options
90
+ original_options = super
91
+
92
+ return original_options unless File.exist?(OPTIONS_FILE)
93
+
94
+ defaults = ::YAML.load_file(OPTIONS_FILE) || {}
95
+ puts defaults.merge(original_options)
96
+ Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
97
+ end
98
+
99
+ def generate
100
+ FileUtils.mkdir_p(prefix)
101
+ File.write(File.join(prefix, "version.txt"), "#{Tebako::VERSION}\n")
102
+ puts("all: ")
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ no_commands do
109
+ def do_press
110
+ packaging_error(103) unless system(b_env, "cmake -DSETUP_MODE:BOOLEAN=OFF #{cfg_options} #{press_options}")
111
+ packaging_error(104) unless system(b_env,
112
+ "cmake --build #{output} --target tebako --parallel #{Etc.nprocessors}")
113
+ end
114
+
115
+ def do_setup
116
+ FileUtils.mkdir_p(prefix)
117
+ File.write(File.join(prefix, "version.txt"), "#{Tebako::VERSION}\n")
118
+ packaging_error(101) unless system(b_env, "cmake -DSETUP_MODE:BOOLEAN=ON #{cfg_options}")
119
+ packaging_error(102) unless system(b_env,
120
+ "cmake --build #{output} --target setup --parallel #{Etc.nprocessors}")
121
+ end
122
+
123
+ def press_announce
124
+ @press_announce ||= <<~ANN
125
+ Running tebako press at #{prefix}
126
+ Ruby version: '#{extend_ruby_version[0]}'
127
+ Project root: '#{options["root"]}'
128
+ Application entry point: '#{options["entry-point"]}'
129
+ Package file name: '#{package}'
130
+ Loging level: '#{l_level}'
131
+ ANN
132
+ end
133
+ end
134
+
135
+ include Tebako::CliHelpers
136
+ end
137
+ end
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023 [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 "etc"
29
+ require "fileutils"
30
+ require "pathname"
31
+ require "rbconfig"
32
+
33
+ require_relative "error"
34
+ require_relative "version"
35
+
36
+ # Tebako - an executable packager
37
+ # Command-line interface methods
38
+ module Tebako
39
+ # TebakoCli methods
40
+ module CliHelpers
41
+ def b_env
42
+ u_flags = if RbConfig::CONFIG["host_os"] =~ /darwin/
43
+ "-DTARGET_OS_SIMULATOR=0 -DTARGET_OS_IPHONE=0 #{ENV.fetch("CXXFLAGS", nil)}"
44
+ else
45
+ ENV.fetch("CXXFLAGS", nil)
46
+ end
47
+ # cc = ENV.fetch("CC", "gcc")
48
+ # cxx = ENV.fetch("CXX", "g++")
49
+ @b_env ||= { "CXXFLAGS" => u_flags }
50
+ end
51
+
52
+ def cfg_options
53
+ ruby_ver, ruby_hash = extend_ruby_version
54
+ @cfg_options ||=
55
+ "-DCMAKE_BUILD_TYPE=Release -DRUBY_VER:STRING='#{ruby_ver}' -DRUBY_HASH:STRING='#{ruby_hash}' " \
56
+ "-DDEPS:STRING='#{deps}' -G '#{m_files}' -B '#{output}' -S '#{source}'"
57
+ end
58
+
59
+ def deps
60
+ @deps ||= File.join(prefix, "deps")
61
+ end
62
+
63
+ RUBY_VERSIONS = {
64
+ "2.7.7" => "e10127db691d7ff36402cfe88f418c8d025a3f1eea92044b162dd72f0b8c7b90",
65
+ "3.0.6" => "6e6cbd490030d7910c0ff20edefab4294dfcd1046f0f8f47f78b597987ac683e",
66
+ "3.1.4" => "a3d55879a0dfab1d7141fdf10d22a07dbf8e5cdc4415da1bde06127d5cc3c7b6"
67
+ # "3.2.2" => "96c57558871a6748de5bc9f274e93f4b5aad06cd8f37befa0e8d94e7b8a423bc"
68
+ }.freeze
69
+
70
+ DEFAULT_RUBY_VERSION = "3.0.6"
71
+
72
+ def extend_ruby_version
73
+ version = options["Ruby"].nil? ? DEFAULT_RUBY_VERSION : options["Ruby"]
74
+ unless RUBY_VERSIONS.key?(version)
75
+ raise TebakoError.new "Ruby version #{version} is not supported yet, exiting",
76
+ 253
77
+ end
78
+
79
+ @extend_ruby_version ||= [version, RUBY_VERSIONS[version]]
80
+ end
81
+
82
+ def l_level
83
+ @l_level ||= if options["log-level"].nil?
84
+ "error"
85
+ else
86
+ options["log-level"]
87
+ end
88
+ end
89
+
90
+ def m_files
91
+ @m_files ||= case RbConfig::CONFIG["host_os"]
92
+ when /linux/, /darwin/
93
+ "Unix Makefiles"
94
+ when /msys/
95
+ "Ninja"
96
+ else
97
+ raise TebakoError.new "#{RbConfig::CONFIG["host_os"]} is not supported yet, exiting", 254
98
+ end
99
+ end
100
+
101
+ def output
102
+ @output ||= File.join(prefix, "output")
103
+ end
104
+
105
+ def package
106
+ @package ||= if options["output"].nil?
107
+ File.join(Dir.pwd, File.basename(options["entry-point"], ".*"))
108
+ else
109
+ options["output"]
110
+ end
111
+ end
112
+
113
+ PACKAGING_ERRORS = {
114
+ 101 => "'tebako setup' configure step failed",
115
+ 102 => "'tebako setup' build step failed",
116
+ 103 => "'tebako press' configure step failed",
117
+ 104 => "'tebako press' build step failed"
118
+ }.freeze
119
+
120
+ def packaging_error(code)
121
+ msg = PACKAGING_ERRORS[code]
122
+ msg = "Unknown packaging error" if msg.nil?
123
+ raise TebakoError.new msg, code
124
+ end
125
+
126
+ def prefix
127
+ @prefix ||= if options["prefix"].nil?
128
+ File.expand_path("~/.tebako")
129
+ elsif options["prefix"] == "PWD"
130
+ Dir.pwd
131
+ else
132
+ File.expand_path(options["prefix"])
133
+ end
134
+ end
135
+
136
+ def press_options
137
+ @press_options ||=
138
+ "-DROOT:STRING='#{options["root"]}' -DENTRANCE:STRING='#{options["entry-point"]}' " \
139
+ "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{options["log-level"]}'"
140
+ end
141
+
142
+ def source
143
+ c_path = Pathname.new(__FILE__).realpath
144
+ @source ||= File.expand_path("../../..", c_path)
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023 [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
+ # Tebako error class
30
+ module Tebako
31
+ # Tebako error class
32
+ class TebakoError < StandardError
33
+ def initialize(msg = "Unspecified error", code = 255)
34
+ @error_code = code
35
+ super(msg)
36
+ end
37
+ attr_accessor :error_code
38
+ end
39
+ end
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2021-2023 [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
+ # Ruby patching definitions (pass1)
31
+ module Pass1
32
+ TOOL_RBINSTALL_RB_PATCH = {
33
+ " next if files.empty?" => "# tebako patched next if files.empty?"
34
+ }.freeze
35
+
36
+ RUBYGEM_OPENSSL_RB_PATCH = {
37
+ 'autoload :OpenSSL, "openssl"' => "require \"openssl\"\nautoload :OpenSSL, \"openssl\""
38
+ }.freeze
39
+
40
+ EXT_SETUP_PATCH = {
41
+ "#option nodynamic" => "option nodynamic"
42
+ }.freeze
43
+
44
+ EXT_BIGDECIMAL_BIGDECIMAL_H_PATCH = {
45
+ "#include \"ruby/ruby.h\"" => <<~SUBST
46
+ #include "ruby/ruby.h"
47
+
48
+ /* -- Start of tebako patch -- */
49
+ #ifndef HAVE_RB_SYM2STR
50
+ #define HAVE_RB_SYM2STR 1
51
+ #endif
52
+
53
+ #ifndef HAVE_RB_ARRAY_CONST_PTR
54
+ #define HAVE_RB_ARRAY_CONST_PTR 1
55
+ #endif
56
+
57
+ #ifndef HAVE_RB_RATIONAL_NUM
58
+ #define HAVE_RB_RATIONAL_NUM 1
59
+ #endif
60
+
61
+ #ifndef HAVE_RB_RATIONAL_DEN
62
+ #define HAVE_RB_RATIONAL_DEN 1
63
+ #endif
64
+
65
+ #ifndef HAVE_RB_COMPLEX_REAL
66
+ #define HAVE_RB_COMPLEX_REAL
67
+ #endif
68
+
69
+ #ifndef HAVE_RB_COMPLEX_IMAG
70
+ #define HAVE_RB_COMPLEX_IMAG
71
+ #endif
72
+ /* -- End of tebako patch -- */
73
+
74
+ SUBST
75
+ }.freeze
76
+
77
+ CONFIGURE_PATCH = {
78
+ "EXTDLDFLAGS=\"-bundle_loader '\\$(BUILTRUBY)'\"" => ""
79
+ }.freeze
80
+
81
+ class << self
82
+ def get_patch_map(ostype, mount_point, ruby_ver)
83
+ patch_map = {
84
+ # ....................................................
85
+ # It won't install gems with no files defined in spec
86
+ # However if
87
+ # -- we are installing a default gem from extension
88
+ # -- extension is build statically
89
+ # there may be no files install in addition to spec
90
+ # Example: io/wait extension (and others)
91
+ "tool/rbinstall.rb" => TOOL_RBINSTALL_RB_PATCH,
92
+
93
+ # ....................................................
94
+ # This is something that I cannnot explain
95
+ # (this patch does not seem related to static compilation)
96
+ "ext/bigdecimal/bigdecimal.h" => EXT_BIGDECIMAL_BIGDECIMAL_H_PATCH,
97
+
98
+ # ....................................................
99
+ # Allow only packaged gems (from within memfs)
100
+ "lib/rubygems/path_support.rb" => rubygems_path_support_patch(mount_point),
101
+
102
+ # ....................................................
103
+ # Disable dynamic extensions
104
+ "ext/Setup" => EXT_SETUP_PATCH
105
+ }
106
+ # ....................................................
107
+ # Fixing (bypassing) configure script bug where a variable is used before initialization
108
+ patch_map.store("configure", CONFIGURE_PATCH) if ostype =~ /darwin/
109
+
110
+ # ....................................................
111
+ # autoload :OpenSSL, "openssl"
112
+ # fails to deal with a default gem from statically linked extension
113
+ patch_map.store("lib/rubygems/openssl.rb", RUBYGEM_OPENSSL_RB_PATCH) if ruby_ver[0] == "3"
114
+
115
+ patch_map
116
+ end
117
+
118
+ private
119
+
120
+ def rubygems_path_support_patch_one(mount_point)
121
+ <<~SUBST
122
+ @home = env["GEM_HOME"] || Gem.default_dir
123
+ # -- Start of tebako patch --
124
+ unless env["TEBAKO_PASS_THROUGH"]
125
+ @home = Gem.default_dir unless @home.index("#{mount_point}") == 0
126
+ end
127
+ # -- End of tebako patch --
128
+
129
+ SUBST
130
+ end
131
+
132
+ def rubygems_path_support_patch_two(mount_point)
133
+ <<~SUBST
134
+
135
+ @path = split_gem_path env["GEM_PATH"], @home
136
+ # -- Start of tebako patch --
137
+ unless env["TEBAKO_PASS_THROUGH"]
138
+ @path.keep_if do |xpath|
139
+ xpath.index("#{mount_point}") == 0
140
+ end
141
+ end
142
+ # -- End of tebako patch --
143
+
144
+ SUBST
145
+ end
146
+
147
+ def rubygems_path_support_patch(mount_point)
148
+ {
149
+ ' @home = env["GEM_HOME"] || Gem.default_dir' => rubygems_path_support_patch_one(mount_point),
150
+ ' @path = split_gem_path env["GEM_PATH"], @home' => rubygems_path_support_patch_two(mount_point)
151
+ }
152
+ end
153
+ end
154
+ end
155
+ end