Skip to content

Commit

Permalink
fix: no double clean if clean and wrong cache
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jan 9, 2025
1 parent 68aff35 commit c1332b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/tebako/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Cli < Thor # rubocop:disable Metrics/ClassLength
desc: "tebako configuration file 'tebafile', '$PWD/.tebako.yml' by default"
desc "clean", "Clean tebako packaging environment"
def clean
(_, cm) = bootstrap
(_, cm) = bootstrap(clean: true)
cm.clean_cache
end

Expand All @@ -63,7 +63,7 @@ def clean
desc: "Ruby version to clean, all available versions by default"
def clean_ruby
puts "Cleaning Ruby sources from tebako packaging environment"
(om,) = bootstrap
(om,) = bootstrap(clean: true)

suffix = options["Ruby"].nil? ? "" : "_#{options["Ruby"]}"
nmr = "src/_ruby#{suffix}*"
Expand Down Expand Up @@ -127,7 +127,7 @@ def press
def setup
(om, cm) = bootstrap

do_setup(om, cm)
do_setup(om)
cm.ensure_version_file
rescue Tebako::Error => e
puts "Tebako script failed: #{e.message} [#{e.error_code}]"
Expand All @@ -139,11 +139,11 @@ def self.exit_on_failure?
end

no_commands do
def bootstrap
def bootstrap(clean: false)
options_manager = Tebako::OptionsManager.new(options)
cache_manager = Tebako::CacheManager.new(options_manager.deps, options_manager.source,
options_manager.output_folder)
cache_manager.version_cache_check unless options[:devmode]
cache_manager.version_cache_check unless options[:devmode] || clean
[options_manager, cache_manager]
end

Expand Down
9 changes: 7 additions & 2 deletions lib/tebako/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def do_press_runtime(options_manager, scenario_manager)
true
end

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

cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{options_manager.cfg_options}"
Expand All @@ -80,7 +80,7 @@ def do_setup(options_manager, scenario_manager)
Tebako.packaging_error(101) unless system(merged_env, cfg_cmd)
Tebako.packaging_error(102) unless system(merged_env, build_cmd)

FileUtils.chmod("+x", File.join(options_manager.deps_bin_dir, "mkdwarfs#{scenario_manager.exe_suffix}"))
fix_mkdwarfs_permissions(options_manager)
true
end

Expand All @@ -98,6 +98,11 @@ def generate_files(options_manager, scenario_manager)
Tebako::Codegen.generate_stub_rb(options_manager)
end

def fix_mkdwarfs_permissions(options_manager)
scenario_manager = Tebako::ScenarioManager.new(options_manager.root, options_manager.fs_entrance)
FileUtils.chmod("+x", File.join(options_manager.deps_bin_dir, "mkdwarfs#{scenario_manager.exe_suffix}"))
end

def options_from_tebafile(tebafile)
::YAML.load_file(tebafile)["options"] || {}
rescue Psych::SyntaxError => e
Expand Down
5 changes: 2 additions & 3 deletions spec/cli_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@

describe "#do_setup" do
let(:options_manager) { Tebako::OptionsManager.new(options) }
let(:scenario_manager) { double("ScenarioManager", exe_suffix: "") }

context "when running on Gnu Linux" do
before do
Expand All @@ -126,13 +125,13 @@
it "executes the setup command successfully" do
allow(FileUtils).to receive(:rm_rf)
allow(self).to receive(:system).and_return(true)
expect(do_setup(options_manager, scenario_manager)).to be_truthy
expect(do_setup(options_manager)).to be_truthy
end

it "raises an error if the setup command fails" do
allow(FileUtils).to receive(:rm_rf)
allow(self).to receive(:system).and_return(false)
expect { do_setup(options_manager, scenario_manager) }.to raise_error(Tebako::Error)
expect { do_setup(options_manager) }.to raise_error(Tebako::Error)
end
end
end
Expand Down

0 comments on commit c1332b9

Please sign in to comment.