Class: Tebako::OptionsManager
- Inherits:
-
Object
- Object
- Tebako::OptionsManager
- Defined in:
- lib/tebako/options_manager.rb
Overview
Cli helpers
Constant Summary collapse
- DEFAULT_COMPRESSION_LEVEL =
rubocop:disable Metrics/ClassLength
5
Instance Attribute Summary collapse
-
#ruby_ver ⇒ Object
readonly
Returns the value of attribute ruby_ver.
-
#rv ⇒ Object
readonly
Returns the value of attribute rv.
Instance Method Summary collapse
- #application_cache_dir ⇒ Object
- #bundle_cache_dir ⇒ Object
- #bundle_format ⇒ Object
- #cfg_options ⇒ Object
- #compression_level ⇒ Object
- #cwd ⇒ Object
- #cwd_announce ⇒ Object
- #data_app_file ⇒ Object
-
#data_bin_dir ⇒ Object
DATA_BIN_DIR folder is used to create packaged filesystem set(DATA_BIN_DIR $CMAKE_CURRENT_BINARY_DIR/p).
-
#data_bundle_file ⇒ Object
Mode File(s) Content bundle fs.bin Application both fs.bin, fs2.bin Stub, application respectively runtime fs.bin Stub app fs2.bin Application.
-
#data_pre_dir ⇒ Object
DATA_PRE_DIR folder is used to build gems that need to be packaged set(DATA_PRE_DIR $CMAKE_CURRENT_BINARY_DIR/r).
-
#data_src_dir ⇒ Object
DATA_SRC_DIR folder is used to collect all files that need to be packaged set(DATA_SRC_DIR $CMAKE_CURRENT_BINARY_DIR/s).
- #data_stub_file ⇒ Object
- #deployment_cache? ⇒ Boolean
- #deployment_cache_dir ⇒ Object
- #deps ⇒ Object
- #deps_bin_dir ⇒ Object
- #deps_lib_dir ⇒ Object
- #derive(overrides) ⇒ Object
- #explain? ⇒ Boolean
- #filesystem_cache_dir ⇒ Object
- #finalized_runtime_cache_dir ⇒ Object
- #folder_within_root?(folder) ⇒ Boolean
- #fs_current ⇒ Object
- #fs_entrance ⇒ Object
- #handle_nil_prefix ⇒ Object
-
#initialize(options) ⇒ OptionsManager
constructor
A new instance of OptionsManager.
- #l_level ⇒ Object
- #layer_plan_dir ⇒ Object
- #layer_strategy ⇒ Object
- #mode ⇒ Object
- #native_gem_cache_dir ⇒ Object
- #output_folder ⇒ Object
- #output_type_first ⇒ Object
- #output_type_second ⇒ Object
- #package ⇒ Object
- #package_manifest ⇒ Object
- #package_within_root? ⇒ Boolean
- #patchelf? ⇒ Boolean
- #prefix ⇒ Object
- #prefix_within_root? ⇒ Boolean
- #press_announce(is_msys) ⇒ Object
- #press_announce_application(is_msys) ⇒ Object
- #press_announce_both ⇒ Object
- #press_announce_bundle ⇒ Object
- #press_announce_ref(is_msys) ⇒ Object
- #press_announce_runtime ⇒ Object
- #press_options ⇒ Object
- #process_gemfile(gemfile_path) ⇒ Object
- #ref ⇒ Object
- #relative?(path) ⇒ Boolean
- #remove_glibc_private ⇒ Object
- #report_format ⇒ Object
- #root ⇒ Object
- #ruby_src_dir ⇒ Object
- #runtime_deployment_cache_dir ⇒ Object
- #source ⇒ Object
- #stash_dir(rver = nil) ⇒ Object
- #stash_dir_all ⇒ Object
Constructor Details
#initialize(options) ⇒ OptionsManager
Returns a new instance of OptionsManager.
46 47 48 49 50 51 |
# File 'lib/tebako/options_manager.rb', line 46 def initialize() @options = @rv = Tebako::RubyVersion.new(@options["Ruby"]) @ruby_ver, @ruby_hash = @rv.extend_ruby_version @scmb = ScenarioManagerBase.new end |
Instance Attribute Details
#ruby_ver ⇒ Object (readonly)
Returns the value of attribute ruby_ver.
53 54 55 |
# File 'lib/tebako/options_manager.rb', line 53 def ruby_ver @ruby_ver end |
#rv ⇒ Object (readonly)
Returns the value of attribute rv.
53 54 55 |
# File 'lib/tebako/options_manager.rb', line 53 def rv @rv end |
Instance Method Details
#application_cache_dir ⇒ Object
88 89 90 |
# File 'lib/tebako/options_manager.rb', line 88 def application_cache_dir @application_cache_dir ||= File.join(deps, "application-cache") end |
#bundle_cache_dir ⇒ Object
84 85 86 |
# File 'lib/tebako/options_manager.rb', line 84 def bundle_cache_dir @bundle_cache_dir ||= File.join(deps, "bundle-cache") end |
#bundle_format ⇒ Object
218 219 220 |
# File 'lib/tebako/options_manager.rb', line 218 def bundle_format @options.fetch("bundle-format", "layered") end |
#cfg_options ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/tebako/options_manager.rb', line 59 def ## {v_parts[3]} may be something like rc1 that won't work with CMake v_parts = Tebako::VERSION.split(".") # Cannot use 'xxx' as parameters because it does not work in Windows shells # So we have to use \"xxx\" @cfg_options ||= "-DCMAKE_BUILD_TYPE=Release -DRUBY_VER:STRING=\"#{@ruby_ver}\" -DRUBY_HASH:STRING=\"#{@ruby_hash}\" " \ "-DDEPS:STRING=\"#{deps}\" -G \"#{@scmb.m_files}\" -B \"#{output_folder}\" -S \"#{source}\" " \ "-DPACKAGE_MANIFEST:FILEPATH=\"#{package_manifest}\" " \ "#{remove_glibc_private} -DTEBAKO_VERSION:STRING=\"#{v_parts[0]}.#{v_parts[1]}.#{v_parts[2]}\"" end |
#compression_level ⇒ Object
80 81 82 |
# File 'lib/tebako/options_manager.rb', line 80 def compression_level @compression_level ||= @options.fetch("compression-level", DEFAULT_COMPRESSION_LEVEL) end |
#cwd ⇒ Object
71 72 73 74 |
# File 'lib/tebako/options_manager.rb', line 71 def cwd f_cwd = @options["cwd"]&.gsub("\\", "/") @cwd ||= f_cwd end |
#cwd_announce ⇒ Object
76 77 78 |
# File 'lib/tebako/options_manager.rb', line 76 def cwd_announce @cwd_announce ||= cwd.nil? ? "<Host current directory>" : cwd end |
#data_app_file ⇒ Object
148 149 150 |
# File 'lib/tebako/options_manager.rb', line 148 def data_app_file @data_app_file ||= File.join(data_bin_dir, "fs2.bin") end |
#data_bin_dir ⇒ Object
DATA_BIN_DIR folder is used to create packaged filesystem set(DATA_BIN_DIR $CMAKE_CURRENT_BINARY_DIR/p)
130 131 132 |
# File 'lib/tebako/options_manager.rb', line 130 def data_bin_dir @data_bin_dir ||= File.join(output_folder, "p") end |
#data_bundle_file ⇒ Object
Mode File(s) Content bundle fs.bin Application both fs.bin, fs2.bin Stub, application respectively runtime fs.bin Stub app fs2.bin Application
140 141 142 |
# File 'lib/tebako/options_manager.rb', line 140 def data_bundle_file @data_bundle_file ||= File.join(data_bin_dir, "fs.bin") end |
#data_pre_dir ⇒ Object
DATA_PRE_DIR folder is used to build gems that need to be packaged set(DATA_PRE_DIR $CMAKE_CURRENT_BINARY_DIR/r)
154 155 156 |
# File 'lib/tebako/options_manager.rb', line 154 def data_pre_dir @data_pre_dir ||= File.join(output_folder, "r") end |
#data_src_dir ⇒ Object
DATA_SRC_DIR folder is used to collect all files that need to be packaged set(DATA_SRC_DIR $CMAKE_CURRENT_BINARY_DIR/s)
160 161 162 |
# File 'lib/tebako/options_manager.rb', line 160 def data_src_dir @data_src_dir ||= File.join(output_folder, "s") end |
#data_stub_file ⇒ Object
144 145 146 |
# File 'lib/tebako/options_manager.rb', line 144 def data_stub_file @data_stub_file ||= File.join(data_bin_dir, "fs.bin") end |
#deployment_cache? ⇒ Boolean
112 113 114 |
# File 'lib/tebako/options_manager.rb', line 112 def deployment_cache? @options.fetch("deployment-cache", true) end |
#deployment_cache_dir ⇒ Object
96 97 98 |
# File 'lib/tebako/options_manager.rb', line 96 def deployment_cache_dir @deployment_cache_dir ||= File.join(deps, "deployment-cache") end |
#deps ⇒ Object
164 165 166 |
# File 'lib/tebako/options_manager.rb', line 164 def deps @deps ||= File.join(prefix, "deps") end |
#deps_bin_dir ⇒ Object
168 169 170 |
# File 'lib/tebako/options_manager.rb', line 168 def deps_bin_dir @deps_bin_dir ||= File.join(deps, "bin") end |
#deps_lib_dir ⇒ Object
172 173 174 |
# File 'lib/tebako/options_manager.rb', line 172 def deps_lib_dir @deps_lib_dir ||= File.join(deps, "lib") end |
#derive(overrides) ⇒ Object
55 56 57 |
# File 'lib/tebako/options_manager.rb', line 55 def derive(overrides) Tebako::OptionsManager.new(@options.merge(overrides)) end |
#explain? ⇒ Boolean
116 117 118 |
# File 'lib/tebako/options_manager.rb', line 116 def explain? @options["explain"] || false end |
#filesystem_cache_dir ⇒ Object
92 93 94 |
# File 'lib/tebako/options_manager.rb', line 92 def filesystem_cache_dir @filesystem_cache_dir ||= File.join(deps, "filesystem-cache") end |
#finalized_runtime_cache_dir ⇒ Object
108 109 110 |
# File 'lib/tebako/options_manager.rb', line 108 def finalized_runtime_cache_dir @finalized_runtime_cache_dir ||= File.join(deps, "finalized-runtime-cache") end |
#folder_within_root?(folder) ⇒ Boolean
176 177 178 179 180 181 182 183 |
# File 'lib/tebako/options_manager.rb', line 176 def folder_within_root?(folder) folder_path = Pathname.new(folder.chomp("/")) root_path = Pathname.new(root.chomp("/")) folder_path.ascend do |path| return true if path == root_path end false end |
#fs_current ⇒ Object
185 186 187 188 189 190 191 192 193 |
# File 'lib/tebako/options_manager.rb', line 185 def fs_current fs_current = Dir.pwd if @scmb.msys? fs_current, cygpath_res = Open3.capture2e("cygpath", "-w", fs_current) Tebako.packaging_error(101) unless cygpath_res.success? fs_current.strip! end @fs_current ||= fs_current&.gsub("\\", "/") end |
#fs_entrance ⇒ Object
195 196 197 |
# File 'lib/tebako/options_manager.rb', line 195 def fs_entrance @fs_entrance ||= @options["entry-point"]&.gsub("\\", "/") end |
#handle_nil_prefix ⇒ Object
199 200 201 202 203 204 205 206 207 208 |
# File 'lib/tebako/options_manager.rb', line 199 def handle_nil_prefix env_prefix = ENV.fetch("TEBAKO_PREFIX", nil) if env_prefix.nil? puts "No prefix specified, using ~/.tebako" File.("~/.tebako") else puts "Using TEBAKO_PREFIX environment variable as prefix" File.(env_prefix.gsub("\\", "/")) end end |
#l_level ⇒ Object
210 211 212 |
# File 'lib/tebako/options_manager.rb', line 210 def l_level @l_level ||= @options["log-level"].nil? ? "error" : @options["log-level"] end |
#layer_plan_dir ⇒ Object
222 223 224 |
# File 'lib/tebako/options_manager.rb', line 222 def layer_plan_dir @layer_plan_dir ||= File.join(output_folder, "layer-plan") end |
#layer_strategy ⇒ Object
214 215 216 |
# File 'lib/tebako/options_manager.rb', line 214 def layer_strategy @options.fetch("layer-strategy", "coarse") end |
#mode ⇒ Object
226 227 228 |
# File 'lib/tebako/options_manager.rb', line 226 def mode @mode ||= @options["mode"].nil? ? "bundle" : @options["mode"] end |
#native_gem_cache_dir ⇒ Object
104 105 106 |
# File 'lib/tebako/options_manager.rb', line 104 def native_gem_cache_dir @native_gem_cache_dir ||= File.join(deps, "native-gem-cache") end |
#output_folder ⇒ Object
230 231 232 |
# File 'lib/tebako/options_manager.rb', line 230 def output_folder @output_folder ||= File.join(prefix, "o") end |
#output_type_first ⇒ Object
234 235 236 |
# File 'lib/tebako/options_manager.rb', line 234 def output_type_first @output_type_first ||= %w[both runtime].include?(mode) ? "runtime package" : "package" end |
#output_type_second ⇒ Object
238 239 240 |
# File 'lib/tebako/options_manager.rb', line 238 def output_type_second "application package" end |
#package ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/tebako/options_manager.rb', line 242 def package package = if @options["output"].nil? File.join(Dir.pwd, mode == "runtime" ? "tebako-runtime" : File.basename(fs_entrance, ".*")) else @options["output"]&.gsub("\\", "/") end @package ||= if relative?(package) File.join(fs_current, package) else package end end |
#package_manifest ⇒ Object
124 125 126 |
# File 'lib/tebako/options_manager.rb', line 124 def package_manifest @package_manifest ||= File.join(output_folder, "package.manifest") end |
#package_within_root? ⇒ Boolean
255 256 257 |
# File 'lib/tebako/options_manager.rb', line 255 def package_within_root? folder_within_root?(package) end |
#patchelf? ⇒ Boolean
259 260 261 |
# File 'lib/tebako/options_manager.rb', line 259 def patchelf? @options["patchelf"] end |
#prefix ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/tebako/options_manager.rb', line 263 def prefix @prefix ||= if @options["prefix"].nil? handle_nil_prefix elsif @options["prefix"] == "PWD" Dir.pwd else File.(@options["prefix"]&.gsub("\\", "/")) end end |
#prefix_within_root? ⇒ Boolean
273 274 275 |
# File 'lib/tebako/options_manager.rb', line 273 def prefix_within_root? folder_within_root?(prefix) end |
#press_announce(is_msys) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/tebako/options_manager.rb', line 277 def press_announce(is_msys) case mode when "application" press_announce_application(is_msys) when "both" press_announce_both when "bundle" press_announce_bundle when "runtime" press_announce_runtime end end |
#press_announce_application(is_msys) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/tebako/options_manager.rb', line 298 def press_announce_application(is_msys) <<~ANN Running tebako press at #{prefix} Mode: 'application' Ruby version: '#{@ruby_ver}' Project root: '#{root}' Application entry point: '#{fs_entrance}' Package file name: '#{package}.tebako'#{press_announce_ref(is_msys)} Package working directory: '#{cwd_announce}' ANN end |
#press_announce_both ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/tebako/options_manager.rb', line 310 def press_announce_both <<~ANN Running tebako press at #{prefix} Mode: 'both' Ruby version: '#{@ruby_ver}' Project root: '#{root}' Application entry point: '#{fs_entrance}' Runtime file name: '#{package}' Package file name: '#{package}.tebako' Loging level: '#{l_level}' Package working directory: '#{cwd_announce}' ANN end |
#press_announce_bundle ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/tebako/options_manager.rb', line 324 def press_announce_bundle <<~ANN Running tebako press at #{prefix} Mode: 'bundle' Ruby version: '#{@ruby_ver}' Project root: '#{root}' Application entry point: '#{fs_entrance}' Package file name: '#{package}' Loging level: '#{l_level}' Package working directory: '#{cwd_announce}' ANN end |
#press_announce_ref(is_msys) ⇒ Object
290 291 292 293 294 295 296 |
# File 'lib/tebako/options_manager.rb', line 290 def press_announce_ref(is_msys) if is_msys " referencing runtime at '#{ref}'" else "" end end |
#press_announce_runtime ⇒ Object
337 338 339 340 341 342 343 344 345 |
# File 'lib/tebako/options_manager.rb', line 337 def press_announce_runtime <<~ANN Running tebako press at #{prefix} Mode: 'runtime' Ruby version: '#{@ruby_ver}' Runtime file name: '#{package}' Loging level: '#{l_level}' ANN end |
#press_options ⇒ Object
347 348 349 |
# File 'lib/tebako/options_manager.rb', line 347 def @press_options ||= "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{l_level}' " \ end |
#process_gemfile(gemfile_path) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/tebako/options_manager.rb', line 351 def process_gemfile(gemfile_path) folder = File.dirname(gemfile_path) filename = File.basename(gemfile_path) # Change directory to the folder containing the Gemfile # Because Bundler::Definition.build *sometimes* requires to be in # the Gemfile directory Dir.chdir(folder) do @rv = Tebako::RubyVersionWithGemfile.new(@options["Ruby"], filename) end @ruby_ver, @ruby_hash = @rv.extend_ruby_version @ruby_src_dir = nil end |
#ref ⇒ Object
368 369 370 |
# File 'lib/tebako/options_manager.rb', line 368 def ref @ref ||= @options["ref"].nil? ? "tebako-runtime" : @options["ref"].gsub("\\", "/") end |
#relative?(path) ⇒ Boolean
364 365 366 |
# File 'lib/tebako/options_manager.rb', line 364 def relative?(path) Pathname.new(path).relative? end |
#remove_glibc_private ⇒ Object
372 373 374 375 376 377 378 |
# File 'lib/tebako/options_manager.rb', line 372 def remove_glibc_private @remove_glibc_private ||= if RUBY_PLATFORM.end_with?("linux") || RUBY_PLATFORM.end_with?("linux-gnu") "-DREMOVE_GLIBC_PRIVATE=#{@options["patchelf"] ? "ON" : "OFF"}" else "" end end |
#report_format ⇒ Object
120 121 122 |
# File 'lib/tebako/options_manager.rb', line 120 def report_format @options["report"] end |
#root ⇒ Object
380 381 382 383 384 385 386 387 |
# File 'lib/tebako/options_manager.rb', line 380 def root f_root = @options["root"].nil? ? "" : @options["root"].gsub("\\", "/") @root ||= if relative?(f_root) File.join(fs_current, f_root) else File.join(f_root, "") end end |
#ruby_src_dir ⇒ Object
389 390 391 |
# File 'lib/tebako/options_manager.rb', line 389 def ruby_src_dir @ruby_src_dir ||= File.join(deps, "src", "_ruby_#{@ruby_ver}") end |
#runtime_deployment_cache_dir ⇒ Object
100 101 102 |
# File 'lib/tebako/options_manager.rb', line 100 def runtime_deployment_cache_dir @runtime_deployment_cache_dir ||= File.join(deps, "runtime-deployment-cache") end |
#source ⇒ Object
393 394 395 396 |
# File 'lib/tebako/options_manager.rb', line 393 def source c_path = Pathname.new(__FILE__).realpath @source ||= File.("../../..", c_path) end |
#stash_dir(rver = nil) ⇒ Object
398 399 400 |
# File 'lib/tebako/options_manager.rb', line 398 def stash_dir(rver = nil) @stash_dir ||= "#{stash_dir_all}_#{rver || @ruby_ver}" end |
#stash_dir_all ⇒ Object
402 403 404 |
# File 'lib/tebako/options_manager.rb', line 402 def stash_dir_all @stash_dir_all ||= File.join(deps, "stash") end |