imbue Cache with knowledge of whether a target or directory is for a build or install operation
This commit is contained in:
parent
c60589a9c9
commit
328babe1f4
@ -94,11 +94,11 @@ module Rscons
|
|||||||
def clean
|
def clean
|
||||||
cache = Cache.instance
|
cache = Cache.instance
|
||||||
# remove all built files
|
# remove all built files
|
||||||
cache.targets.each do |target|
|
cache.targets(false).each do |target|
|
||||||
FileUtils.rm_f(target)
|
FileUtils.rm_f(target)
|
||||||
end
|
end
|
||||||
# remove all created directories if they are empty
|
# remove all created directories if they are empty
|
||||||
cache.directories.sort {|a, b| b.size <=> a.size}.each do |directory|
|
cache.directories(false).sort {|a, b| b.size <=> a.size}.each do |directory|
|
||||||
next unless File.directory?(directory)
|
next unless File.directory?(directory)
|
||||||
if (Dir.entries(directory) - ['.', '..']).empty?
|
if (Dir.entries(directory) - ['.', '..']).empty?
|
||||||
Dir.rmdir(directory) rescue nil
|
Dir.rmdir(directory) rescue nil
|
||||||
|
@ -236,9 +236,12 @@ module Rscons
|
|||||||
# trigger a rebuild.
|
# trigger a rebuild.
|
||||||
# @param deps [Array<String>] List of dependencies for the target.
|
# @param deps [Array<String>] List of dependencies for the target.
|
||||||
# @param env [Environment] The {Rscons::Environment}.
|
# @param env [Environment] The {Rscons::Environment}.
|
||||||
|
# @param options [Hash] Optional arguments.
|
||||||
|
# @option options [Boolean] :install
|
||||||
|
# Whether the target is for an install operation.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def register_build(targets, command, deps, env)
|
def register_build(targets, command, deps, env, options = {})
|
||||||
Array(targets).each do |target|
|
Array(targets).each do |target|
|
||||||
target_checksum = Rscons.phony_target?(target) ? "" : calculate_checksum(target)
|
target_checksum = Rscons.phony_target?(target) ? "" : calculate_checksum(target)
|
||||||
@cache["targets"][get_cache_key(target)] = {
|
@cache["targets"][get_cache_key(target)] = {
|
||||||
@ -256,41 +259,65 @@ module Rscons
|
|||||||
"checksum" => lookup_checksum(dep),
|
"checksum" => lookup_checksum(dep),
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
|
"install" => !!options[:install],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a list of targets that have been built.
|
# Return a list of targets that have been built or installed.
|
||||||
#
|
#
|
||||||
# @return [Array<String>] List of targets that have been built.
|
# @param install [Boolean]
|
||||||
def targets
|
# Whether to return installed targets. If false, will only return normal
|
||||||
@cache["targets"].keys
|
# build targets and not install targets.
|
||||||
|
#
|
||||||
|
# @return [Array<String>]
|
||||||
|
# List of build targets that have been built or installed.
|
||||||
|
def targets(install)
|
||||||
|
install = !!install
|
||||||
|
@cache["targets"].select do |key, target|
|
||||||
|
target["install"] == install
|
||||||
|
end.map(&:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make any needed directories and record the ones that are created for
|
# Create any needed directory components for a build or install operation.
|
||||||
# removal upon a "clean" operation.
|
|
||||||
#
|
#
|
||||||
# @param path [String] Directory to create.
|
# Build directories will be removed if empty upon a "clean" operation.
|
||||||
|
# Install directories will be removed if empty upon an "uninstall"
|
||||||
|
# operation.
|
||||||
|
#
|
||||||
|
# @param path [String]
|
||||||
|
# Directory to create.
|
||||||
|
# @param options [Hash]
|
||||||
|
# Optional arguments.
|
||||||
|
# @option options [Boolean] :install
|
||||||
|
# Whether the directory is for an install operation.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def mkdir_p(path)
|
def mkdir_p(path, options = {})
|
||||||
parts = path.split(/[\\\/]/)
|
parts = path.split(/[\\\/]/)
|
||||||
parts.each_index do |i|
|
parts.each_index do |i|
|
||||||
next if parts[i] == ""
|
next if parts[i] == ""
|
||||||
subpath = File.join(*parts[0, i + 1])
|
subpath = File.join(*parts[0, i + 1])
|
||||||
unless File.exists?(subpath)
|
unless File.exists?(subpath)
|
||||||
FileUtils.mkdir_p(subpath)
|
FileUtils.mkdir_p(subpath)
|
||||||
@cache["directories"][subpath] = true
|
@cache["directories"][subpath] = !!options[:install]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a list of directories which were created as a part of the build.
|
# Return a list of directories which were created as a part of the build.
|
||||||
#
|
#
|
||||||
|
# @param install [Boolean]
|
||||||
|
# Whether to return installed directories. If false, will only return
|
||||||
|
# normal build directories and not install targets.
|
||||||
|
#
|
||||||
# @return [Array<String>]
|
# @return [Array<String>]
|
||||||
# List of directories which were created as a part of the build.
|
# List of directories which were created as a part of the build.
|
||||||
def directories
|
def directories(install)
|
||||||
@cache["directories"].keys
|
install = !!install
|
||||||
|
@cache["directories"].select do |key, d_install|
|
||||||
|
d_install == install
|
||||||
|
end.map(&:first)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -13,13 +13,6 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#targets" do
|
|
||||||
it "returns a list of targets that are cached" do
|
|
||||||
cache = {"targets" => {"t1" => {}, "t2" => {}, "t3" => {}}}
|
|
||||||
expect(build_from(cache).targets).to eq ["t1", "t2", "t3"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#mkdir_p" do
|
describe "#mkdir_p" do
|
||||||
it "makes directories and records any created in the cache" do
|
it "makes directories and records any created in the cache" do
|
||||||
_cache = {}
|
_cache = {}
|
||||||
@ -35,7 +28,7 @@ module Rscons
|
|||||||
expect(FileUtils).to receive(:mkdir_p).with("one/two/four")
|
expect(FileUtils).to receive(:mkdir_p).with("one/two/four")
|
||||||
cache.mkdir_p("one/two/three")
|
cache.mkdir_p("one/two/three")
|
||||||
cache.mkdir_p("one\\two\\four")
|
cache.mkdir_p("one\\two\\four")
|
||||||
expect(cache.directories).to eq ["one/two", "one/two/three", "one/two/four"]
|
expect(cache.directories(false)).to eq ["one/two", "one/two/three", "one/two/four"]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "handles absolute paths" do
|
it "handles absolute paths" do
|
||||||
@ -45,14 +38,7 @@ module Rscons
|
|||||||
expect(File).to receive(:exists?).with("/one/two").and_return(false)
|
expect(File).to receive(:exists?).with("/one/two").and_return(false)
|
||||||
expect(FileUtils).to receive(:mkdir_p).with("/one/two")
|
expect(FileUtils).to receive(:mkdir_p).with("/one/two")
|
||||||
cache.mkdir_p("/one/two")
|
cache.mkdir_p("/one/two")
|
||||||
expect(cache.directories).to eq ["/one/two"]
|
expect(cache.directories(false)).to eq ["/one/two"]
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#directories" do
|
|
||||||
it "returns a list of directories that are cached" do
|
|
||||||
_cache = {"directories" => {"dir1" => true, "dir2" => true}}
|
|
||||||
expect(build_from(_cache).directories).to eq ["dir1", "dir2"]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user