move clean logic to Application
This commit is contained in:
parent
de46bb0cc1
commit
e29ec5a126
@ -57,25 +57,6 @@ module Rscons
|
|||||||
@application ||= Application.new
|
@application ||= Application.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove all generated files.
|
|
||||||
#
|
|
||||||
# @return [void]
|
|
||||||
def clean
|
|
||||||
cache = Cache.instance
|
|
||||||
# remove all built files
|
|
||||||
cache.targets.each do |target|
|
|
||||||
FileUtils.rm_f(target)
|
|
||||||
end
|
|
||||||
# remove all created directories if they are empty
|
|
||||||
cache.directories.sort {|a, b| b.size <=> a.size}.each do |directory|
|
|
||||||
next unless File.directory?(directory)
|
|
||||||
if (Dir.entries(directory) - ['.', '..']).empty?
|
|
||||||
Dir.rmdir(directory) rescue nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
cache.clear
|
|
||||||
end
|
|
||||||
|
|
||||||
# Return whether the given path is an absolute filesystem path.
|
# Return whether the given path is an absolute filesystem path.
|
||||||
#
|
#
|
||||||
# @param path [String] the path to examine.
|
# @param path [String] the path to examine.
|
||||||
|
@ -29,11 +29,34 @@ module Rscons
|
|||||||
# Process exit code (0 on success).
|
# Process exit code (0 on success).
|
||||||
def run(operation)
|
def run(operation)
|
||||||
# TODO
|
# TODO
|
||||||
|
case operation
|
||||||
|
when "clean"
|
||||||
|
clean
|
||||||
|
end
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Remove all generated files.
|
||||||
|
#
|
||||||
|
# @return [void]
|
||||||
|
def clean
|
||||||
|
cache = Cache.instance
|
||||||
|
# remove all built files
|
||||||
|
cache.targets.each do |target|
|
||||||
|
FileUtils.rm_f(target)
|
||||||
|
end
|
||||||
|
# remove all created directories if they are empty
|
||||||
|
cache.directories.sort {|a, b| b.size <=> a.size}.each do |directory|
|
||||||
|
next unless File.directory?(directory)
|
||||||
|
if (Dir.entries(directory) - ['.', '..']).empty?
|
||||||
|
Dir.rmdir(directory) rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
cache.clear
|
||||||
|
end
|
||||||
|
|
||||||
# Determine the number of threads to use by default.
|
# Determine the number of threads to use by default.
|
||||||
#
|
#
|
||||||
# @return [Integer]
|
# @return [Integer]
|
||||||
|
@ -1,6 +1,31 @@
|
|||||||
module Rscons
|
module Rscons
|
||||||
describe Application do
|
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
|
||||||
|
|
||||||
describe ".determine_n_threads" do
|
describe ".determine_n_threads" do
|
||||||
context "when specified by environment variable" do
|
context "when specified by environment variable" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
@ -1,29 +1,4 @@
|
|||||||
describe Rscons do
|
describe Rscons 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.clean
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".absolute_path?" do
|
describe ".absolute_path?" do
|
||||||
context "on Windows" do
|
context "on Windows" do
|
||||||
it "returns whether a path is absolute" do
|
it "returns whether a path is absolute" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user