add Builders::Mixins::ObjectDeps to commonize some builder functionality

This commit is contained in:
Josh Holtrop 2019-03-16 22:34:07 -04:00
parent 3ff09978f4
commit 1efee50b2c
5 changed files with 42 additions and 24 deletions

View File

@ -165,6 +165,9 @@ module Rscons
end
# builder mixins
require_relative "rscons/builders/mixins/object_deps"
# default builders
require_relative "rscons/builders/cfile"
require_relative "rscons/builders/command"

View File

@ -3,17 +3,12 @@ module Rscons
# A default Rscons builder that produces a static library archive.
class Library < Builder
include Mixins::ObjectDeps
# Create an instance of the Builder to build a target.
def initialize(options)
super(options)
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
@objects = @sources.map do |source|
if source.end_with?(*suffixes)
source
else
@env.register_dependency_build(@target, source, suffixes.first, @vars, Object)
end
end
@objects = register_object_deps(Object)
end
# Run the builder to produce a build target.

View File

@ -0,0 +1,30 @@
module Rscons
module Builders
# Rscons::Buidlers::Mixins namespacing module.
module Mixins
# Functionality for builders which desire object or static library files
# as inputs.
module ObjectDeps
# Register dependency builders to generate object files from @sources.
#
# @param builder_class [Builder]
# Builder class to use to build the object dependencies.
#
# @return [Array<String>]
# List of paths to the object or static library dependencies.
def register_object_deps(builder_class)
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
@sources.map do |source|
if source.end_with?(*suffixes)
source
else
@env.register_dependency_build(@target, source, suffixes.first, @vars, builder_class)
end
end
end
end
end
end
end

View File

@ -4,6 +4,8 @@ module Rscons
# executable program.
class Program < Builder
include Mixins::ObjectDeps
# Create an instance of the Builder to build a target.
#
# @param options [Hash]
@ -21,14 +23,7 @@ module Rscons
unless File.basename(@target)["."]
@target += @env.expand_varref("${PROGSUFFIX}", @vars)
end
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
@objects = @sources.map do |source|
if source.end_with?(*suffixes)
source
else
@env.register_dependency_build(@target, source, suffixes.first, @vars, Object)
end
end
@objects = register_object_deps(Object)
end
# Run the builder to produce a build target.

View File

@ -4,6 +4,8 @@ module Rscons
# shared library.
class SharedLibrary < Builder
include Mixins::ObjectDeps
# Create an instance of the Builder to build a target.
def initialize(options)
super(options)
@ -14,14 +16,7 @@ module Rscons
unless File.basename(@target)["."]
@target += @env.expand_varref("${SHLIBSUFFIX}", @vars)
end
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
@objects = @sources.map do |source|
if source.end_with?(*suffixes)
source
else
@env.register_dependency_build(@target, source, suffixes.first, @vars, SharedObject)
end
end
@objects = register_object_deps(SharedObject)
end
# Run the builder to produce a build target.