From f13664331ff2b11e85685b1105b1b337ee8e96d5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 15 Sep 2013 15:27:16 -0400 Subject: [PATCH] create requisite output directories for build targets; refactor common buile functionality into Builder#standard_build() --- lib/rscons/builder.rb | 15 +++++++++++++++ lib/rscons/builders/library.rb | 7 +------ lib/rscons/builders/object.rb | 2 ++ lib/rscons/builders/program.rb | 6 +----- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/rscons/builder.rb b/lib/rscons/builder.rb index 1b77f20..f122001 100644 --- a/lib/rscons/builder.rb +++ b/lib/rscons/builder.rb @@ -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 diff --git a/lib/rscons/builders/library.rb b/lib/rscons/builders/library.rb index cfaa76a..6461c75 100644 --- a/lib/rscons/builders/library.rb +++ b/lib/rscons/builders/library.rb @@ -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 diff --git a/lib/rscons/builders/object.rb b/lib/rscons/builders/object.rb index 08a5f52..00c4f78 100644 --- a/lib/rscons/builders/object.rb +++ b/lib/rscons/builders/object.rb @@ -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']) diff --git a/lib/rscons/builders/program.rb b/lib/rscons/builders/program.rb index 64ef954..5fd6192 100644 --- a/lib/rscons/builders/program.rb +++ b/lib/rscons/builders/program.rb @@ -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