create requisite output directories for build targets; refactor common buile functionality into Builder#standard_build()

This commit is contained in:
Josh Holtrop 2013-09-15 15:27:16 -04:00
parent 17c7bf1d31
commit f13664331f
4 changed files with 19 additions and 11 deletions

View File

@ -1,3 +1,5 @@
require "fileutils"
module Rscons
# Class to hold an object that knows how to build a certain type of file.
class Builder
@ -16,5 +18,18 @@ module Rscons
def produces?(target, source, env)
false
end
# 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)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.rm_f(target)
return false unless env.execute(short_cmd_string, command)
cache.register_build(target, command, sources)
end
target
end
end
end

View File

@ -21,12 +21,7 @@ module Rscons
'SOURCES' => objects,
})
command = env.build_command(env['ARCOM'], vars)
unless cache.up_to_date?(target, command, objects)
FileUtils.rm_f(target)
return false unless env.execute("AR #{target}", command)
cache.register_build(target, command, objects)
end
target
standard_build("AR #{target}", target, command, objects, env, cache)
end
end
end

View File

@ -55,6 +55,8 @@ module Rscons
end
command = env.build_command(env["#{com_prefix}COM"], vars)
unless cache.up_to_date?(target, command, sources)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.rm_f(target)
return false unless env.execute("#{com_prefix} #{target}", command)
deps = sources
if File.exists?(vars['DEPFILE'])

View File

@ -28,11 +28,7 @@ module Rscons
'LD' => env['LD'] || ld_alt,
})
command = env.build_command(env['LDCOM'], vars)
unless cache.up_to_date?(target, command, objects)
return false unless env.execute("LD #{target}", command)
cache.register_build(target, command, objects)
end
target
standard_build("LD #{target}", target, command, objects, env, cache)
end
end
end