tebako 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/common.env CHANGED
@@ -1,5 +1,5 @@
1
1
  BUILD_TYPE=Release
2
2
  DEPS=deps
3
3
  INCBIN_TAG=348e36b
4
- DWARFS_WR_TAG=v0.7.1
4
+ DWARFS_WR_TAG=v0.8.3
5
5
  RUBY_VER=3.2.5
data/exe/tebako-packager CHANGED
@@ -27,6 +27,7 @@
27
27
  # POSSIBILITY OF SUCH DAMAGE.
28
28
 
29
29
  require_relative "../lib/tebako/packager"
30
+ require_relative "../lib/tebako/ruby_version"
30
31
  require_relative "../lib/tebako/stripper"
31
32
  require_relative "../lib/tebako/build_helpers"
32
33
 
@@ -73,31 +74,6 @@ begin
73
74
  ruby_ver = Tebako::RubyVersion.new(ARGV[6])
74
75
  Tebako::Packager.stash(ARGV[4], ARGV[5])
75
76
  Tebako::Packager.pass2(ARGV[1], ARGV[2], ARGV[3], ruby_ver)
76
- when "deploy"
77
- # ARGV[0] -- command
78
- # ARGV[1] -- OSTYPE
79
- # ARGV[2] -- RUBY_SOURCE_DIR
80
- # ARGV[3] -- FS_STASH_DIR
81
- # ARGV[4] -- DATA_SRC_DIR
82
- # ARGV[5] -- DATA_PRE_DIR
83
- # ARGV[6] -- DATA_BIN_DIR
84
- # ARGV[7] -- FS_ROOT
85
- # ARGV[8] -- FS_ENTRANCE
86
- # ARGV[9] -- FS_MOUNT_POINT
87
- # ARGV[10] -- APP_NAME
88
- # ARGV[11] -- RUBY_VER
89
- # ARGV[12] -- CWD
90
- unless ARGV.length == 13 || ARGV.length == 12
91
- raise Tebako::Error,
92
- "tebako-packager deploy command expects 12 or 13 arguments, #{ARGV.length} has been provided."
93
- end
94
- ruby_ver = Tebako::RubyVersion.new(ARGV[11])
95
- Tebako::Packager.init(ARGV[3], ARGV[4], ARGV[5], ARGV[6])
96
- Tebako::Packager.create_implib(ARGV[2], ARGV[4], File.basename(ARGV[10]), ruby_ver) if ARGV[1] =~ /msys/
97
- # Assume that "<TARGET_BIN_DIR (TBD)>" is <DATA_SRC_DIR>/bin"
98
- # That shall match CMakeLists.txt settings
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)
101
77
 
102
78
  when "finalize"
103
79
  # ARGV[0] -- command
@@ -81,43 +81,4 @@ module Tebako
81
81
  end
82
82
  end
83
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
84
  end
@@ -0,0 +1,112 @@
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_relative "version"
30
+
31
+ # Tebako - an executable packager
32
+ module Tebako
33
+ # Cache management
34
+ class CacheManager
35
+ E_VERSION_FILE = ".environment.version"
36
+
37
+ def initialize(deps, src_dir, out_dir)
38
+ @deps = deps
39
+ @src_dir = src_dir
40
+ @out_dir = out_dir
41
+ end
42
+
43
+ def clean_cache
44
+ puts "Cleaning tebako packaging environment"
45
+ # Using File.join(deps, "") to ensure that the slashes are appropriate
46
+ FileUtils.rm_rf([File.join(@deps, ""), File.join(@out_dir, "")], secure: true)
47
+ end
48
+
49
+ def clean_output
50
+ puts "Cleaning CMake cache and Ruby build files"
51
+
52
+ nmr = "src/_ruby_*"
53
+ nms = "stash_*"
54
+ FileUtils.rm_rf(Dir.glob(File.join(@deps, nmr)), secure: true)
55
+ FileUtils.rm_rf(Dir.glob(File.join(@deps, nms)), secure: true)
56
+
57
+ # Using File.join(output_folder, "") to ensure that the slashes are appropriate
58
+ FileUtils.rm_rf(File.join(@out_dir, ""), secure: true)
59
+ end
60
+
61
+ def ensure_version_file
62
+ version_file_path = File.join(@deps, E_VERSION_FILE)
63
+
64
+ begin
65
+ File.write(version_file_path, version_key)
66
+ # puts "Set version information for tebako packaging environment to #{Tebako::VERSION}"
67
+ rescue StandardError => e
68
+ puts "#{Tebako::PACKAGING_ERRORS[201]} #{E_VERSION_FILE}: #{e.message}"
69
+ end
70
+ end
71
+
72
+ def version_key
73
+ @version_key ||= "#{Tebako::VERSION} at #{@src_dir}"
74
+ end
75
+
76
+ def version_cache
77
+ version_file_path = File.join(@deps, E_VERSION_FILE)
78
+ file_version = File.open(version_file_path, &:readline).strip
79
+ file_version.match(/(?<version>.+) at (?<source>.+)/)
80
+ end
81
+
82
+ def version_cache_check
83
+ match_data = version_cache
84
+ return version_unknown unless match_data
85
+
86
+ if match_data[:version] != Tebako::VERSION
87
+ version_mismatch(match_data[:version])
88
+ elsif match_data[:source] != @src_dir
89
+ version_source_mismatch(match_data[:source])
90
+ end
91
+ rescue StandardError
92
+ version_unknown
93
+ end
94
+
95
+ def version_mismatch(cached_version)
96
+ puts "Tebako cache was created by a gem version #{cached_version} " \
97
+ "and cannot be used for gem version #{Tebako::VERSION}"
98
+ clean_cache
99
+ end
100
+
101
+ def version_source_mismatch(cached_source)
102
+ puts "CMake cache was created for a different source directory '#{cached_source}' " \
103
+ "and cannot be used for '#{@src_dir}'"
104
+ clean_output
105
+ end
106
+
107
+ def version_unknown
108
+ puts "CMake cache version was not recognized, cleaning up"
109
+ clean_cache
110
+ end
111
+ end
112
+ end
data/lib/tebako/cli.rb CHANGED
@@ -32,9 +32,10 @@ require "open3"
32
32
  require "thor"
33
33
  require "yaml"
34
34
 
35
+ require_relative "cache_manager"
35
36
  require_relative "cli_helpers"
36
- require_relative "cli_rubies"
37
37
  require_relative "error"
38
+ require_relative "ruby_version"
38
39
  require_relative "version"
39
40
 
40
41
  # Tebako - an executable packager
@@ -52,20 +53,23 @@ module Tebako
52
53
  desc: "tebako configuration file 'tebafile', '$PWD/.tebako.yml' by default"
53
54
  desc "clean", "Clean tebako packaging environment"
54
55
  def clean
55
- clean_cache
56
+ (_, cm) = bootstrap
57
+ cm.clean_cache
56
58
  end
57
59
 
58
60
  desc "clean_ruby", "Clean Ruby source from tebako packaging environment"
59
61
  method_option :Ruby, type: :string, aliases: "-R", required: false,
60
- enum: Tebako::CliRubies::RUBY_VERSIONS.keys,
62
+ enum: Tebako::RubyVersion::RUBY_VERSIONS.keys,
61
63
  desc: "Ruby version to clean, all available versions by default"
62
64
  def clean_ruby
63
65
  puts "Cleaning Ruby sources from tebako packaging environment"
66
+ (om,) = bootstrap
67
+
64
68
  suffix = options["Ruby"].nil? ? "" : "_#{options["Ruby"]}"
65
69
  nmr = "src/_ruby#{suffix}*"
66
70
  nms = "stash#{suffix}*"
67
- FileUtils.rm_rf(Dir.glob(File.join(deps, nmr)), secure: true)
68
- FileUtils.rm_rf(Dir.glob(File.join(deps, nms)), secure: true)
71
+ FileUtils.rm_rf(Dir.glob(File.join(om.deps, nmr)), secure: true)
72
+ FileUtils.rm_rf(Dir.glob(File.join(om.deps, nms)), secure: true)
69
73
  end
70
74
 
71
75
  desc "hash", "Print build script hash (ci cache key)"
@@ -95,16 +99,15 @@ module Tebako
95
99
  desc: "Tebako package file name, entry point base file name in the current folder by default"
96
100
  method_option :root, type: :string, aliases: "-r", required: true, desc: "Root folder of the Ruby application"
97
101
  method_option :Ruby, type: :string, aliases: "-R", required: false,
98
- enum: Tebako::CliRubies::RUBY_VERSIONS.keys,
99
- desc: "Tebako package Ruby version, #{Tebako::CliRubies::DEFAULT_RUBY_VERSION} by default"
102
+ enum: Tebako::RubyVersion::RUBY_VERSIONS.keys,
103
+ desc: "Tebako package Ruby version, #{Tebako::RubyVersion::DEFAULT_RUBY_VERSION} by default"
100
104
  method_option :patchelf, aliases: "-P", type: :boolean,
101
105
  desc: RGP_DESCRIPTION
102
106
  def press
103
- version_cache_check unless options[:devmode]
107
+ (om, cm) = bootstrap
104
108
 
105
- puts press_announce
106
- do_press
107
- ensure_version_file
109
+ do_press(om)
110
+ cm.ensure_version_file
108
111
  rescue Tebako::Error => e
109
112
  puts "Tebako script failed: #{e.message} [#{e.error_code}]"
110
113
  exit e.error_code
@@ -112,14 +115,13 @@ module Tebako
112
115
 
113
116
  desc "setup", "Set up tebako packaging environment"
114
117
  method_option :Ruby, type: :string, aliases: "-R", required: false,
115
- enum: Tebako::CliRubies::RUBY_VERSIONS.keys,
116
- desc: "Tebako package Ruby version, #{Tebako::CliRubies::DEFAULT_RUBY_VERSION} by default."
118
+ enum: Tebako::RubyVersion::RUBY_VERSIONS.keys,
119
+ desc: "Tebako package Ruby version, #{Tebako::RubyVersion::DEFAULT_RUBY_VERSION} by default."
117
120
  def setup
118
- version_cache_check unless options[:devmode]
121
+ (om, cm) = bootstrap
119
122
 
120
- puts "Setting up tebako packaging environment"
121
- do_setup
122
- ensure_version_file
123
+ do_setup(om)
124
+ cm.ensure_version_file
123
125
  rescue Tebako::Error => e
124
126
  puts "Tebako script failed: #{e.message} [#{e.error_code}]"
125
127
  exit e.error_code
@@ -130,6 +132,14 @@ module Tebako
130
132
  end
131
133
 
132
134
  no_commands do
135
+ def bootstrap
136
+ options_manager = Tebako::OptionsManager.new(options)
137
+ cache_manager = Tebako::CacheManager.new(options_manager.deps, options_manager.source,
138
+ options_manager.output_folder)
139
+ cache_manager.version_cache_check unless options[:devmode]
140
+ [options_manager, cache_manager]
141
+ end
142
+
133
143
  def initialize(*args)
134
144
  super
135
145
  return if args[2][:current_command].name.include?("hash")
@@ -151,7 +161,6 @@ module Tebako
151
161
 
152
162
  no_commands do
153
163
  include Tebako::CliHelpers
154
- include Tebako::CliRubies
155
164
  end
156
165
  end
157
166
  end
@@ -30,123 +30,56 @@ require "fileutils"
30
30
  require "pathname"
31
31
  require "rbconfig"
32
32
 
33
- require_relative "cli_rubies"
33
+ require_relative "codegen"
34
34
  require_relative "error"
35
- require_relative "version"
35
+ require_relative "options_manager"
36
+ require_relative "scenario_manager"
36
37
 
37
38
  # Tebako - an executable packager
38
39
  # Command-line interface methods
39
40
  module Tebako
40
- E_VERSION_FILE = ".environment.version"
41
41
  # Cli helpers
42
42
  module CliHelpers
43
- def b_env
44
- u_flags = if RbConfig::CONFIG["host_os"] =~ /darwin/
45
- "-DTARGET_OS_SIMULATOR=0 -DTARGET_OS_IPHONE=0 #{ENV.fetch("CXXFLAGS", nil)}"
46
- else
47
- ENV.fetch("CXXFLAGS", nil)
48
- end
49
- @b_env ||= { "CXXFLAGS" => u_flags }
50
- end
51
-
52
- def cfg_options
53
- ruby_ver, ruby_hash = extend_ruby_version
54
- # Cannot use 'xxx' as parameters because it does not work in Windows shells
55
- # So we have to use \"xxx\"
56
- @cfg_options ||=
57
- "-DCMAKE_BUILD_TYPE=Release -DRUBY_VER:STRING=\"#{ruby_ver}\" -DRUBY_HASH:STRING=\"#{ruby_hash}\" " \
58
- "-DDEPS:STRING=\"#{deps}\" -G \"#{m_files}\" -B \"#{output_folder}\" -S \"#{source}\" " \
59
- "#{remove_glibc_private} -DTEBAKO_VERSION:STRING=\"#{Tebako::VERSION}\""
60
- end
43
+ def do_press(options_manager)
44
+ puts options_manager.press_announce
61
45
 
62
- def clean_cache
63
- puts "Cleaning tebako packaging environment"
64
- # Using File.join(deps, "") to ensure that the slashes are appropriate
65
- FileUtils.rm_rf([File.join(deps, ""), File.join(output_folder, "")], secure: true)
66
- end
46
+ generate_files(options_manager)
67
47
 
68
- def clean_output
69
- puts "Cleaning CMake cache and Ruby build files"
70
-
71
- nmr = "src/_ruby_*"
72
- nms = "stash_*"
73
- FileUtils.rm_rf(Dir.glob(File.join(deps, nmr)), secure: true)
74
- FileUtils.rm_rf(Dir.glob(File.join(deps, nms)), secure: true)
75
-
76
- # Using File.join(output_folder, "") to ensure that the slashes are appropriate
77
- FileUtils.rm_rf(File.join(output_folder, ""), secure: true)
78
- end
79
-
80
- def deps
81
- @deps ||= File.join(prefix, "deps")
82
- end
83
-
84
- def do_press
85
- cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{cfg_options} #{press_options}"
86
- build_cmd = "cmake --build #{output_folder} --target tebako --parallel #{Etc.nprocessors}"
87
- merged_env = ENV.to_h.merge(b_env)
48
+ cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{options_manager.cfg_options} #{options_manager.press_options}"
49
+ build_cmd = "cmake --build #{options_manager.output_folder} --target tebako --parallel #{Etc.nprocessors}"
50
+ merged_env = ENV.to_h.merge(options_manager.b_env)
88
51
  Tebako.packaging_error(103) unless system(merged_env, cfg_cmd)
89
52
  Tebako.packaging_error(104) unless system(merged_env, build_cmd)
90
53
  true
91
54
  end
92
55
 
93
- def do_setup
94
- cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{cfg_options}"
95
- build_cmd = "cmake --build \"#{output_folder}\" --target setup --parallel #{Etc.nprocessors}"
96
- merged_env = ENV.to_h.merge(b_env)
56
+ def do_setup(options_manager)
57
+ puts "Setting up tebako packaging environment"
58
+
59
+ cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{options_manager.cfg_options}"
60
+ build_cmd = "cmake --build \"#{options_manager.output_folder}\" --target setup --parallel #{Etc.nprocessors}"
61
+ merged_env = ENV.to_h.merge(options_manager.b_env)
97
62
  Tebako.packaging_error(101) unless system(merged_env, cfg_cmd)
98
63
  Tebako.packaging_error(102) unless system(merged_env, build_cmd)
99
64
  true
100
65
  end
101
66
 
102
- def ensure_version_file
103
- version_file_path = File.join(deps, E_VERSION_FILE)
67
+ def generate_files(options_manager)
68
+ puts "-- Generating files"
69
+ scenario_manager = Tebako::ScenarioManager.new(options_manager.root, options_manager.fs_entrance)
70
+ scenario_manager.configure_scenario
104
71
 
105
- begin
106
- File.write(version_file_path, version_key)
107
- # puts "Set version information for tebako packaging environment to #{Tebako::VERSION}"
108
- rescue StandardError => e
109
- puts "An error occurred while creating or updating #{E_VERSION_FILE}: #{e.message}"
110
- end
111
- end
72
+ puts " ... tebako-version.h"
73
+ v_parts = Tebako::VERSION.split(".")
74
+ Tebako::Codegen.generate_tebako_version_h(options_manager, v_parts)
112
75
 
113
- def fs_current
114
- fs_current = Dir.pwd
115
- if RUBY_PLATFORM =~ /msys|mingw|cygwin/
116
- fs_current, cygpath_res = Open3.capture2e("cygpath", "-w", fs_current)
117
- Tebako.packaging_error(101) unless cygpath_res.success?
118
- fs_current.strip!
119
- end
120
- @fs_current ||= fs_current
121
- end
76
+ puts " ... tebako-fs.cpp"
77
+ Tebako::Codegen.generate_tebako_fs_cpp(options_manager, scenario_manager)
122
78
 
123
- def l_level
124
- @l_level ||= if options["log-level"].nil?
125
- "error"
126
- else
127
- options["log-level"]
128
- end
79
+ puts " ... deploy.rb"
80
+ Tebako::Codegen.generate_deploy_rb(options_manager, scenario_manager)
129
81
  end
130
82
 
131
- # rubocop:disable Metrics/MethodLength
132
- def m_files
133
- # [TODO]
134
- # Ninja generates incorrect script fot tebako press target -- gets lost in a chain custom targets
135
- # Using makefiles has negative performance impact so it needs to be fixed
136
- @m_files ||= case RUBY_PLATFORM
137
- when /linux/, /darwin/
138
- "Unix Makefiles"
139
- when /msys|mingw|cygwin/
140
- "MinGW Makefiles"
141
- else
142
- raise Tebako::Error.new(
143
- "#{RUBY_PLATFORM} is not supported, exiting",
144
- 254
145
- )
146
- end
147
- end
148
- # rubocop:enable Metrics/MethodLength
149
-
150
83
  def options_from_tebafile(tebafile)
151
84
  ::YAML.load_file(tebafile)["options"] || {}
152
85
  rescue Psych::SyntaxError => e
@@ -158,134 +91,5 @@ module Tebako
158
91
  puts e.message
159
92
  {}
160
93
  end
161
-
162
- def output_folder
163
- @output_folder ||= File.join(prefix, "o")
164
- end
165
-
166
- def package
167
- package = if options["output"].nil?
168
- File.join(Dir.pwd, File.basename(options["entry-point"], ".*"))
169
- else
170
- options["output"]
171
- end
172
- @package ||= if relative?(package)
173
- File.join(fs_current, package)
174
- else
175
- package
176
- end
177
- end
178
-
179
- def remove_glibc_private
180
- @remove_glibc_private ||= if RUBY_PLATFORM.end_with?("linux") || RUBY_PLATFORM.end_with?("linux-gnu")
181
- "-DREMOVE_GLIBC_PRIVATE=#{options["patchelf"] ? "ON" : "OFF"}"
182
- else
183
- ""
184
- end
185
- end
186
-
187
- def handle_nil_prefix
188
- env_prefix = ENV.fetch("TEBAKO_PREFIX", nil)
189
- if env_prefix.nil?
190
- puts "No prefix specified, using ~/.tebako"
191
- File.expand_path("~/.tebako")
192
- else
193
- puts "Using TEBAKO_PREFIX environment variable as prefix"
194
- File.expand_path(env_prefix)
195
- end
196
- end
197
-
198
- def prefix
199
- @prefix ||= if options["prefix"].nil?
200
- handle_nil_prefix
201
- elsif options["prefix"] == "PWD"
202
- Dir.pwd
203
- else
204
- File.expand_path(options["prefix"])
205
- end
206
- end
207
-
208
- def press_announce
209
- cwd_announce = options["cwd"].nil? ? "<Host current directory>" : options["cwd"]
210
- @press_announce ||= <<~ANN
211
- Running tebako press at #{prefix}
212
- Ruby version: '#{extend_ruby_version[0]}'
213
- Project root: '#{root}'
214
- Application entry point: '#{options["entry-point"]}'
215
- Package file name: '#{package}'
216
- Loging level: '#{l_level}'
217
- Package working directory: '#{cwd_announce}'
218
- ANN
219
- end
220
-
221
- def press_options
222
- cwd_option = if options["cwd"].nil?
223
- "-DPACKAGE_NEEDS_CWD:BOOL=OFF"
224
- else
225
- "-DPACKAGE_NEEDS_CWD:BOOL=ON -DPACKAGE_CWD:STRING='#{options["cwd"]}'"
226
- end
227
- @press_options ||=
228
- "-DROOT:STRING='#{root}' -DENTRANCE:STRING='#{options["entry-point"]}' " \
229
- "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{options["log-level"]}' " \
230
- "#{cwd_option}"
231
- end
232
-
233
- def relative?(path)
234
- Pathname.new(path).relative?
235
- end
236
-
237
- def root
238
- @root ||= if relative?(options["root"])
239
- File.join(fs_current, options["root"])
240
- else
241
- File.join(options["root"], "")
242
- end
243
- end
244
-
245
- def source
246
- c_path = Pathname.new(__FILE__).realpath
247
- @source ||= File.expand_path("../../..", c_path)
248
- end
249
-
250
- def version_key
251
- @version_key ||= "#{Tebako::VERSION} at #{source}"
252
- end
253
-
254
- def version_cache
255
- version_file_path = File.join(deps, E_VERSION_FILE)
256
- file_version = File.open(version_file_path, &:readline).strip
257
- file_version.match(/(?<version>.+) at (?<source>.+)/)
258
- end
259
-
260
- def version_cache_check
261
- match_data = version_cache
262
-
263
- return version_unknown unless match_data
264
-
265
- if match_data[:version] != Tebako::VERSION
266
- version_mismatch(match_data[:version])
267
- elsif match_data[:source] != source
268
- version_source_mismatch(match_data[:source])
269
- end
270
- rescue StandardError
271
- version_unknown
272
- end
273
-
274
- def version_mismatch(cached_version)
275
- puts "Tebako cache was created by a gem version #{cached_version} " \
276
- "and cannot be used for gem version #{Tebako::VERSION}"
277
- clean_cache
278
- end
279
-
280
- def version_source_mismatch(cached_source)
281
- puts "CMake cache was created for a different source directory '#{cached_source}' " \
282
- "and cannot be used for '#{source}'"
283
- clean_output
284
- end
285
-
286
- def version_unknown
287
- puts "CMake cache version was not recognized, cleaning up"
288
- clean_cache
289
- end
290
94
  end
291
95
  end