Module: Tebako::CliHelpers

Defined in:
lib/tebako/cli_helpers.rb

Overview

Cli helpers

Constant Summary collapse

WARN =
<<~WARN

  ******************************************************************************************************************
  *                                                                                                                *
  *  WARNING: You are packaging in-place, i.e.: tebako package will be placed inside application root.             *
  *  It is not an error but we do not recommend it because it is a way to keep packaging old versions recrsively.  *
  *                                                                                                                *
  *  For example, ensure that `--root=` differs from `--output=` as described in README.adoc:                      *
  *  tebako press --root='~/projects/myproject' --entry=start.rb --output=/temp/myproject.tebako                   *
  *                                                                                                                *
  ******************************************************************************************************************

WARN
WARN2 =
<<~WARN

  ******************************************************************************************************************
  *                                                                                                                *
  *  WARNING: You are creating packaging environment inside application root.                                      *
  *  It is not an error but it means that all build-time artifacts will ne included in tebako package.             *
  *  You do not need it unless under very special circumstances like tebako packaging tebako itself.               *
  *                                                                                                                *
  *  Please consider removing your exisitng `--prefix` folder abd use another one that points outside of `--root`  *
  *  like tebako press --r ~/projects/myproject -e start.rb -o /temp/myproject.tebako -p ~/.tebako                 *
  *                                                                                                                *
  ******************************************************************************************************************

WARN

Instance Method Summary collapse

Instance Method Details

#check_warnings(options_manager) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'lib/tebako/cli_helpers.rb', line 78

def check_warnings(options_manager)
  return if options_manager.mode == "runtime"

  package_warning = options_manager.package_within_root?
  prefix_warning = options_manager.prefix_within_root?
  puts WARN if package_warning
  puts WARN2 if prefix_warning
  sleep 5 if package_warning || prefix_warning
end

#do_press(options_manager) ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/tebako/cli_helpers.rb', line 88

def do_press(options_manager)
  scenario_manager = Tebako::ScenarioManager.new(options_manager.root, options_manager.fs_entrance)
  scenario_manager.configure_scenario
  options_manager.process_gemfile(scenario_manager.gemfile_path) if scenario_manager.with_gemfile
  check_warnings(options_manager)
  puts options_manager.press_announce(scenario_manager.msys?)

  do_press_build(options_manager, scenario_manager)
  do_press_application(options_manager, scenario_manager)
end

#do_press_application(options_manager, scenario_manager) ⇒ Object



112
113
114
115
116
# File 'lib/tebako/cli_helpers.rb', line 112

def do_press_application(options_manager, scenario_manager)
  return unless %w[both application].include?(options_manager.mode)

  Tebako::ApplicationBuilder.new(options_manager, scenario_manager).build
end

#do_press_build(options_manager, scenario_manager) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/tebako/cli_helpers.rb', line 99

def do_press_build(options_manager, scenario_manager)
  return do_press_runtime(options_manager, scenario_manager) unless options_manager.mode == "bundle"

  if options_manager.bundle_format == "layered"
    Tebako::SingleFileBundleBuilder.new(options_manager, scenario_manager).build
    return
  end

  Tebako::BundleBuilder.new(options_manager, scenario_manager).build do
    do_press_runtime(options_manager, scenario_manager)
  end
end

#do_press_runtime(options_manager, scenario_manager) ⇒ Object

rubocop:disable Metrics/MethodLength



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/tebako/cli_helpers.rb', line 118

def do_press_runtime(options_manager, scenario_manager) # rubocop:disable Metrics/MethodLength
  return unless %w[both runtime bundle].include?(options_manager.mode)

  runner = ->(environment, command) { system(environment, command) }
  file_generator = -> { generate_files(options_manager, scenario_manager) }
  finalizer = -> { finalize(options_manager, scenario_manager) }
  Tebako::RuntimeBuilder.new(
    options_manager,
    scenario_manager,
    command_runner: runner,
    file_generator: file_generator,
    finalizer: finalizer,
    configure_command: press_cfg_cmd(options_manager),
    build_command: press_build_cmd(options_manager)
  ).build
end

#do_setup(options_manager) ⇒ Object

rubocop:enable Metrics/MethodLength



135
136
137
138
139
140
141
# File 'lib/tebako/cli_helpers.rb', line 135

def do_setup(options_manager)
  puts "Setting up tebako packaging environment"

  merged_env = ENV.to_h.merge(Tebako::ScenarioManagerBase.new.b_env)
  Tebako.packaging_error(101) unless system(merged_env, setup_cfg_cmd(options_manager))
  Tebako.packaging_error(102) unless system(merged_env, setup_build_cmd(options_manager))
end

#finalize(options_manager, scenario_manager) ⇒ Object



154
155
156
157
158
159
# File 'lib/tebako/cli_helpers.rb', line 154

def finalize(options_manager, scenario_manager)
  use_patchelf = options_manager.patchelf? && scenario_manager.linux_gnu?
  patchelf = use_patchelf ? "#{options_manager.deps_bin_dir}/patchelf" : nil
  Tebako::Packager.finalize(options_manager.ruby_src_dir, options_manager.package,
                            options_manager.rv, patchelf, options_manager.output_type_first)
end

#generate_files(options_manager, scenario_manager) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/tebako/cli_helpers.rb', line 143

def generate_files(options_manager, scenario_manager)
  puts "-- Generating files"

  v_parts = Tebako::VERSION.split(".")
  Tebako::Codegen.generate_tebako_version_h(options_manager, v_parts)
  Tebako::Codegen.generate_tebako_fs_cpp(options_manager, scenario_manager)
  Tebako::Codegen.generate_deploy_rb(options_manager, scenario_manager)
  Tebako::Codegen.generate_stub_rb(options_manager) if %w[both runtime].include?(options_manager.mode)
  Tebako::Codegen.generate_package_manifest(options_manager, scenario_manager)
end

#options_from_tebafile(tebafile) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/tebako/cli_helpers.rb', line 161

def options_from_tebafile(tebafile)
  ::YAML.load_file(tebafile)["options"] || {}
rescue Psych::SyntaxError => e
  puts "Warning: The tebafile '#{tebafile}' contains invalid YAML syntax."
  puts e.message
  {}
rescue StandardError => e
  puts "An unexpected error occurred while loading the tebafile '#{tebafile}'."
  puts e.message
  {}
end

#press_build_cmd(options_manager) ⇒ Object



173
174
175
# File 'lib/tebako/cli_helpers.rb', line 173

def press_build_cmd(options_manager)
  "cmake --build #{options_manager.output_folder} --target tebako --parallel #{Etc.nprocessors}"
end

#press_cfg_cmd(options_manager) ⇒ Object



177
178
179
# File 'lib/tebako/cli_helpers.rb', line 177

def press_cfg_cmd(options_manager)
  "cmake -DSETUP_MODE:BOOLEAN=OFF #{options_manager.cfg_options} #{options_manager.press_options}"
end

#setup_build_cmd(options_manager) ⇒ Object



181
182
183
# File 'lib/tebako/cli_helpers.rb', line 181

def setup_build_cmd(options_manager)
  "cmake --build \"#{options_manager.output_folder}\" --target setup --parallel #{Etc.nprocessors}"
end

#setup_cfg_cmd(options_manager) ⇒ Object



185
186
187
# File 'lib/tebako/cli_helpers.rb', line 185

def setup_cfg_cmd(options_manager)
  "cmake -DSETUP_MODE:BOOLEAN=ON #{options_manager.cfg_options}"
end