Class: Tebako::OptionsManager
- Inherits:
-
Object
- Object
- Tebako::OptionsManager
- Defined in:
- lib/tebako/options_manager.rb
Overview
Cli helpers
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
- #cfg_options ⇒ 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
- #deps ⇒ Object
- #deps_bin_dir ⇒ Object
- #deps_lib_dir ⇒ Object
- #folder_within_root?(folder) ⇒ Boolean
- #fs_current ⇒ Object
- #fs_entrance ⇒ Object
- #handle_nil_prefix ⇒ Object
-
#initialize(options) ⇒ OptionsManager
constructor
rubocop:disable Metrics/ClassLength.
- #l_level ⇒ Object
- #mode ⇒ Object
- #output_folder ⇒ Object
- #output_type_first ⇒ Object
- #output_type_second ⇒ Object
- #package ⇒ 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
- #root ⇒ Object
- #ruby_src_dir ⇒ Object
- #source ⇒ Object
- #stash_dir(rver = nil) ⇒ Object
- #stash_dir_all ⇒ Object
Constructor Details
#initialize(options) ⇒ OptionsManager
rubocop:disable Metrics/ClassLength
43 44 45 46 47 48 |
# File 'lib/tebako/options_manager.rb', line 43 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.
50 51 52 |
# File 'lib/tebako/options_manager.rb', line 50 def ruby_ver @ruby_ver end |
#rv ⇒ Object (readonly)
Returns the value of attribute rv.
50 51 52 |
# File 'lib/tebako/options_manager.rb', line 50 def rv @rv end |
Instance Method Details
#cfg_options ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tebako/options_manager.rb', line 52 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}\" " \ "#{remove_glibc_private} -DTEBAKO_VERSION:STRING=\"#{v_parts[0]}.#{v_parts[1]}.#{v_parts[2]}\"" end |
#cwd ⇒ Object
63 64 65 66 |
# File 'lib/tebako/options_manager.rb', line 63 def cwd f_cwd = @options["cwd"]&.gsub("\\", "/") @cwd ||= f_cwd end |
#cwd_announce ⇒ Object
68 69 70 |
# File 'lib/tebako/options_manager.rb', line 68 def cwd_announce @cwd_announce ||= cwd.nil? ? "<Host current directory>" : cwd end |
#data_app_file ⇒ Object
92 93 94 |
# File 'lib/tebako/options_manager.rb', line 92 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)
74 75 76 |
# File 'lib/tebako/options_manager.rb', line 74 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
84 85 86 |
# File 'lib/tebako/options_manager.rb', line 84 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)
98 99 100 |
# File 'lib/tebako/options_manager.rb', line 98 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)
104 105 106 |
# File 'lib/tebako/options_manager.rb', line 104 def data_src_dir @data_src_dir ||= File.join(output_folder, "s") end |
#data_stub_file ⇒ Object
88 89 90 |
# File 'lib/tebako/options_manager.rb', line 88 def data_stub_file @data_stub_file ||= File.join(data_bin_dir, "fs.bin") end |
#deps ⇒ Object
108 109 110 |
# File 'lib/tebako/options_manager.rb', line 108 def deps @deps ||= File.join(prefix, "deps") end |
#deps_bin_dir ⇒ Object
112 113 114 |
# File 'lib/tebako/options_manager.rb', line 112 def deps_bin_dir @deps_bin_dir ||= File.join(deps, "bin") end |
#deps_lib_dir ⇒ Object
116 117 118 |
# File 'lib/tebako/options_manager.rb', line 116 def deps_lib_dir @deps_lib_dir ||= File.join(deps, "lib") end |
#folder_within_root?(folder) ⇒ Boolean
120 121 122 123 124 125 126 127 |
# File 'lib/tebako/options_manager.rb', line 120 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
129 130 131 132 133 134 135 136 137 |
# File 'lib/tebako/options_manager.rb', line 129 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
139 140 141 |
# File 'lib/tebako/options_manager.rb', line 139 def fs_entrance @fs_entrance ||= @options["entry-point"]&.gsub("\\", "/") end |
#handle_nil_prefix ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/tebako/options_manager.rb', line 143 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
154 155 156 |
# File 'lib/tebako/options_manager.rb', line 154 def l_level @l_level ||= @options["log-level"].nil? ? "error" : @options["log-level"] end |
#mode ⇒ Object
158 159 160 |
# File 'lib/tebako/options_manager.rb', line 158 def mode @mode ||= @options["mode"].nil? ? "bundle" : @options["mode"] end |
#output_folder ⇒ Object
162 163 164 |
# File 'lib/tebako/options_manager.rb', line 162 def output_folder @output_folder ||= File.join(prefix, "o") end |
#output_type_first ⇒ Object
166 167 168 |
# File 'lib/tebako/options_manager.rb', line 166 def output_type_first @output_type_first ||= %w[both runtime].include?(mode) ? "runtime package" : "package" end |
#output_type_second ⇒ Object
170 171 172 |
# File 'lib/tebako/options_manager.rb', line 170 def output_type_second "application package" end |
#package ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/tebako/options_manager.rb', line 174 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_within_root? ⇒ Boolean
187 188 189 |
# File 'lib/tebako/options_manager.rb', line 187 def package_within_root? folder_within_root?(package) end |
#patchelf? ⇒ Boolean
191 192 193 |
# File 'lib/tebako/options_manager.rb', line 191 def patchelf? @options["patchelf"] end |
#prefix ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/tebako/options_manager.rb', line 195 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
205 206 207 |
# File 'lib/tebako/options_manager.rb', line 205 def prefix_within_root? folder_within_root?(prefix) end |
#press_announce(is_msys) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/tebako/options_manager.rb', line 209 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
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/tebako/options_manager.rb', line 230 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
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/tebako/options_manager.rb', line 242 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
256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/tebako/options_manager.rb', line 256 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
222 223 224 225 226 227 228 |
# File 'lib/tebako/options_manager.rb', line 222 def press_announce_ref(is_msys) if is_msys " referencing runtime at '#{ref}'" else "" end end |
#press_announce_runtime ⇒ Object
269 270 271 272 273 274 275 276 277 |
# File 'lib/tebako/options_manager.rb', line 269 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
279 280 281 |
# File 'lib/tebako/options_manager.rb', line 279 def @press_options ||= "-DPCKG:STRING='#{package}' -DLOG_LEVEL:STRING='#{l_level}' " \ end |
#process_gemfile(gemfile_path) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/tebako/options_manager.rb', line 283 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
300 301 302 |
# File 'lib/tebako/options_manager.rb', line 300 def ref @ref ||= @options["ref"].nil? ? "tebako-runtime" : @options["ref"].gsub("\\", "/") end |
#relative?(path) ⇒ Boolean
296 297 298 |
# File 'lib/tebako/options_manager.rb', line 296 def relative?(path) Pathname.new(path).relative? end |
#remove_glibc_private ⇒ Object
304 305 306 307 308 309 310 |
# File 'lib/tebako/options_manager.rb', line 304 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 |
#root ⇒ Object
312 313 314 315 316 317 318 319 |
# File 'lib/tebako/options_manager.rb', line 312 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
321 322 323 |
# File 'lib/tebako/options_manager.rb', line 321 def ruby_src_dir @ruby_src_dir ||= File.join(deps, "src", "_ruby_#{@ruby_ver}") end |
#source ⇒ Object
325 326 327 328 |
# File 'lib/tebako/options_manager.rb', line 325 def source c_path = Pathname.new(__FILE__).realpath @source ||= File.("../../..", c_path) end |
#stash_dir(rver = nil) ⇒ Object
330 331 332 |
# File 'lib/tebako/options_manager.rb', line 330 def stash_dir(rver = nil) @stash_dir ||= "#{stash_dir_all}_#{rver || @ruby_ver}" end |
#stash_dir_all ⇒ Object
334 335 336 |
# File 'lib/tebako/options_manager.rb', line 334 def stash_dir_all @stash_dir_all ||= File.join(deps, "stash") end |