From 785e8e18fd2f7c981cb077ec714f37f9b32dc067 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 27 Apr 2019 21:39:52 -0400 Subject: [PATCH] a clean operation should preserve install target cache info - close #101 --- lib/rscons/application.rb | 4 +++- spec/build_tests_spec.rb | 32 ++++++++++++++++++++++---------- spec/rscons/application_spec.rb | 30 ------------------------------ 3 files changed, 25 insertions(+), 41 deletions(-) delete mode 100644 spec/rscons/application_spec.rb diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 921bc5b..a563b94 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -114,16 +114,18 @@ module Rscons cache = Cache.instance # remove all built files cache.targets(false).each do |target| + cache.remove_target(target) FileUtils.rm_f(target) end # remove all created directories if they are empty cache.directories(false).sort {|a, b| b.size <=> a.size}.each do |directory| + cache.remove_directory(directory) next unless File.directory?(directory) if (Dir.entries(directory) - ['.', '..']).empty? Dir.rmdir(directory) rescue nil end end - cache.clear + cache.write 0 end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 66c7d2c..0821545 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -350,6 +350,28 @@ EOF expect(File.exists?("build/e.1/src/one/one.o")).to be_falsey end end + + it "does not remove install cache entries" do + test_dir "typical" + + Dir.mktmpdir do |prefix| + result = run_rscons(rsconscript: "install.rb", op: %W[configure --prefix=#{prefix}]) + expect(result.stderr).to eq "" + + result = run_rscons(rsconscript: "install.rb", op: %W[install]) + expect(result.stderr).to eq "" + + result = run_rscons(rsconscript: "install.rb", op: %W[clean]) + expect(result.stderr).to eq "" + expect(File.exists?("#{prefix}/bin/program.exe")).to be_truthy + expect(File.exists?("build/e.1/src/one/one.o")).to be_falsey + + result = run_rscons(rsconscript: "install.rb", op: %W[uninstall -v]) + expect(result.stderr).to eq "" + expect(result.stdout).to match %r{Removing #{prefix}/bin/program.exe} + expect(Dir.entries(prefix)).to match_array %w[. ..] + end + end end it 'allows Ruby classes as custom builders to be used to construct files' do @@ -1175,16 +1197,6 @@ EOF expect(result.stderr).to match /Warning.*was corrupt. Contents:/ end - it "removes the cache file on a clean operation" do - test_dir("simple") - result = run_rscons - expect(result.stderr).to eq "" - expect(File.exists?(Rscons::Cache::CACHE_FILE)).to be_truthy - result = run_rscons(op: %w[clean]) - expect(result.stderr).to eq "" - expect(File.exists?(Rscons::Cache::CACHE_FILE)).to be_falsey - end - it "forces a build when the target file does not exist and is not in the cache" do test_dir("simple") expect(File.exists?("simple.exe")).to be_falsey diff --git a/spec/rscons/application_spec.rb b/spec/rscons/application_spec.rb deleted file mode 100644 index 05a0f68..0000000 --- a/spec/rscons/application_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Rscons - describe Application do - - describe ".clean" do - it "removes all build targets and created directories" do - cache = "cache" - expect(Rscons::Cache).to receive(:instance).and_return(cache) - expect(cache).to receive(:targets).and_return(["build/a.out", "build/main.o"]) - expect(FileUtils).to receive(:rm_f).with("build/a.out") - expect(FileUtils).to receive(:rm_f).with("build/main.o") - expect(cache).to receive(:directories).and_return(["build/one", "build/one/two", "build", "other"]) - expect(File).to receive(:directory?).with("build/one/two").and_return(true) - expect(Dir).to receive(:entries).with("build/one/two").and_return([".", ".."]) - expect(Dir).to receive(:rmdir).with("build/one/two") - expect(File).to receive(:directory?).with("build/one").and_return(true) - expect(Dir).to receive(:entries).with("build/one").and_return([".", ".."]) - expect(Dir).to receive(:rmdir).with("build/one") - expect(File).to receive(:directory?).with("build").and_return(true) - expect(Dir).to receive(:entries).with("build").and_return([".", ".."]) - expect(Dir).to receive(:rmdir).with("build") - expect(File).to receive(:directory?).with("other").and_return(true) - expect(Dir).to receive(:entries).with("other").and_return([".", "..", "other.file"]) - expect(cache).to receive(:clear) - - Rscons.application.__send__(:clean) - end - end - - end -end