From b3df37e9ea2d9bfad0b8e8df0561f16914eb6195 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 13 Mar 2022 22:15:55 -0400 Subject: [PATCH] Do not configure for clean tasks when not yet configured - close #158 --- lib/rscons/application.rb | 15 ++++++++++++--- lib/rscons/cache.rb | 1 + spec/build_tests_spec.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index d90549b..f745fb0 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -81,8 +81,10 @@ module Rscons end end @script = Script.new - @script.load(rsconscript) - enable_variants + if should_load_script + @script.load(rsconscript) + enable_variants + end if show_tasks show_script_tasks(all_tasks) return 0 @@ -170,8 +172,8 @@ module Rscons def distclean cache = Cache.instance clean - FileUtils.rm_rf(@build_dir) cache.clear + FileUtils.rm_rf(@build_dir) end # Check if the project needs to be configured. @@ -394,6 +396,13 @@ module Rscons end end + def should_load_script + return true if @tasks_and_params.empty? + return true if Cache.instance["configuration_data"]["configured"] + return false if (@tasks_and_params.keys - %w[distclean clean uninstall]).empty? + true + end + end end diff --git a/lib/rscons/cache.rb b/lib/rscons/cache.rb index 3cc8e04..36946f7 100644 --- a/lib/rscons/cache.rb +++ b/lib/rscons/cache.rb @@ -101,6 +101,7 @@ module Rscons # # @return [void] def write + return unless Dir.exist?(File.dirname(cache_file)) @cache["version"] = VERSION File.open(cache_file, "w") do |fh| fh.puts(JSON.dump(@cache)) diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index eb9095b..e487715 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -1854,6 +1854,33 @@ EOF expect(result.stdout).to match "Prefix is /yodabob" end + it "does not configure for distclean operation" do + test_dir "configure" + + result = run_rscons(args: %w[-f configure_with_top_level_env.rb distclean]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to_not match %r{Configuring project} + end + + it "does not configure for clean operation" do + test_dir "configure" + + result = run_rscons(args: %w[-f configure_with_top_level_env.rb clean]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to_not match %r{Configuring project} + end + + it "does not configure for uninstall operation" do + test_dir "configure" + + result = run_rscons(args: %w[-f configure_with_top_level_env.rb uninstall]) + expect(result.stderr).to eq "" + expect(result.status).to eq 0 + expect(result.stdout).to_not match %r{Configuring project} + end + it "automatically runs the configure task if the project is not yet configured in the given build directory" do test_dir "configure"