modify Cache to store user-specified extra dependencies

This commit is contained in:
josh committed 2013-12-27 14:20:32 -05:00
1 parent a28cef9eb7
commit 7330e74ab8
9 files changed
+105 -46

No files matched your search

+3 -3
View File
@@ -22,12 +22,12 @@ module Rscons
# Check if the cache is up to date for the target and if not execute the
# build command.
# Return the name of the target or false on failure.
def standard_build(short_cmd_string, target, command, sources, env, cache)
unless cache.up_to_date?(target, command, sources)
def standard_build(short_cmd_string, target, command, sources, user_deps, env, cache)
unless cache.up_to_date?(target, command, sources, user_deps)
cache.mkdir_p(File.dirname(target))
FileUtils.rm_f(target)
return false unless env.execute(short_cmd_string, command)
cache.register_build(target, command, sources)
cache.register_build(target, command, sources, user_deps)
end
target
end
+2 -2
View File
@@ -12,7 +12,7 @@ module Rscons
}
end
def run(target, sources, cache, env, vars)
def run(target, sources, user_deps, cache, env, vars)
# build sources to linkable objects
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
if objects
@@ -21,7 +21,7 @@ module Rscons
'_SOURCES' => objects,
})
command = env.build_command(env['ARCMD'], vars)
standard_build("AR #{target}", target, command, objects, env, cache)
standard_build("AR #{target}", target, command, objects, user_deps, env, cache)
end
end
end
+3 -3
View File
@@ -50,7 +50,7 @@ module Rscons
end
end
def run(target, sources, cache, env, vars)
def run(target, sources, user_deps, cache, env, vars)
vars = vars.merge({
'_TARGET' => target,
'_SOURCES' => sources,
@@ -62,7 +62,7 @@ module Rscons
v.nil? and raise "Error: unknown input file type: #{sources.first.inspect}"
end.first
command = env.build_command(env["#{com_prefix}CMD"], vars)
unless cache.up_to_date?(target, command, sources)
unless cache.up_to_date?(target, command, sources, user_deps)
cache.mkdir_p(File.dirname(target))
FileUtils.rm_f(target)
return false unless env.execute("#{com_prefix} #{target}", command)
@@ -71,7 +71,7 @@ module Rscons
deps += Environment.parse_makefile_deps(vars['_DEPFILE'], target)
FileUtils.rm_f(vars['_DEPFILE'])
end
cache.register_build(target, command, deps.uniq)
cache.register_build(target, command, deps.uniq, user_deps)
end
target
end
+2 -2
View File
@@ -14,7 +14,7 @@ module Rscons
}
end
def run(target, sources, cache, env, vars)
def run(target, sources, user_deps, cache, env, vars)
# build sources to linkable objects
objects = env.build_sources(sources, [env['OBJSUFFIX'], env['LIBSUFFIX']].flatten, cache, vars)
return false unless objects
@@ -33,7 +33,7 @@ module Rscons
'LD' => ld,
})
command = env.build_command(env['LDCMD'], vars)
standard_build("LD #{target}", target, command, objects, env, cache)
standard_build("LD #{target}", target, command, objects, user_deps, env, cache)
end
end
end
+28 -10
View File
@@ -18,9 +18,15 @@ module Rscons
# {
# 'fname' => 'program.o',
# 'checksum' => '87654321',
# }
# },
# ],
# }
# 'user_deps' => [
# {
# 'fname' => 'lscript.ld',
# 'checksum' => '77551133',
# },
# ],
# },
# 'program.o' => {
# 'checksum' => '87654321',
# 'command' => ['gcc', '-c', '-o', 'program.o', 'program.c'],
@@ -32,15 +38,16 @@ module Rscons
# {
# 'fname' => 'program.h',
# 'checksum' => '7979764643',
# }
# ]
# },
# ],
# 'user_deps' => [],
# }
# }
# },
# directories: {
# 'build' => true,
# 'build/one' => true,
# 'build/two' => true,
# }
# },
# }
class Cache
#### Constants
@@ -82,6 +89,7 @@ module Rscons
# @param target [String] The name of the target file.
# @param command [Array] The command used to build the target.
# @param deps [Array] List of the target's dependency files.
# @param user_deps [Array] List of user-specified extra dependencies.
# @param options [Hash] Optional options. Can contain the following keys:
# :strict_deps::
# Only consider a target up to date if its list of dependencies is
@@ -96,7 +104,7 @@ module Rscons
# exactly equal to those cached
# - each cached dependency file's current checksum matches the checksum
# stored in the cache file
def up_to_date?(target, command, deps, options = {})
def up_to_date?(target, command, deps, user_deps, options = {})
# target file must exist on disk
return false unless File.exists?(target)
@@ -118,8 +126,11 @@ module Rscons
return false unless (Set.new(deps) - Set.new(cached_deps)).empty?
end
# set of user dependencies must match
return false unless user_deps == @cache[:targets][target][:user_deps].map { |dc| dc[:fname] }
# all cached dependencies must have their checksums match
@cache[:targets][target][:deps].each do |dep_cache|
(@cache[:targets][target][:deps] + @cache[:targets][target][:user_deps]).each do |dep_cache|
return false unless dep_cache[:checksum] == lookup_checksum(dep_cache[:fname])
end
@@ -130,7 +141,8 @@ module Rscons
# @param target [String] The name of the target.
# @param command [Array] The command used to build the target.
# @param deps [Array] List of dependencies for the target.
def register_build(target, command, deps)
# @param user_deps [Array] List of user-specified extra dependencies.
def register_build(target, command, deps, user_deps)
@cache[:targets][target.encode(__ENCODING__)] = {
command: command,
checksum: calculate_checksum(target),
@@ -139,7 +151,13 @@ module Rscons
fname: dep.encode(__ENCODING__),
checksum: lookup_checksum(dep),
}
end
end,
user_deps: user_deps.map do |dep|
{
fname: dep.encode(__ENCODING__),
checksum: lookup_checksum(dep),
}
end,
}
end
+5 -3
View File
@@ -147,6 +147,7 @@ module Rscons
result = run_builder(@targets[target][:builder],
target,
@targets[target][:source],
[],
cache,
@targets[target][:vars] || {})
unless result
@@ -238,7 +239,7 @@ module Rscons
converted_fname = get_build_fname(source, suffix)
builder = @builders.values.find { |b| b.produces?(converted_fname, source, self) }
if builder
converted = run_builder(builder, converted_fname, [source], cache, vars)
converted = run_builder(builder, converted_fname, [source], [], cache, vars)
return nil unless converted
break
end
@@ -255,18 +256,19 @@ module Rscons
# @param cache [Cache] The Cache.
# @param vars [Hash] Extra variables to pass to the builder.
# Return the result of the builder's run() method.
def run_builder(builder, target, sources, cache, vars)
def run_builder(builder, target, sources, user_deps, cache, vars)
vars = @varset.merge(vars)
@build_hooks.each do |build_hook_block|
build_operation = {
builder: builder,
target: target,
sources: sources,
user_deps: user_deps,
vars: vars,
}
build_hook_block.call(build_operation)
end
builder.run(target, sources, cache, self, vars)
builder.run(target, sources, user_deps, cache, self, vars)
end
# Parse dependencies for a given target from a Makefile.