add Builders::Mixins::ObjectDeps to commonize some builder functionality
This commit is contained in:
parent
3ff09978f4
commit
1efee50b2c
@ -165,6 +165,9 @@ module Rscons
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# builder mixins
|
||||||
|
require_relative "rscons/builders/mixins/object_deps"
|
||||||
|
|
||||||
# default builders
|
# default builders
|
||||||
require_relative "rscons/builders/cfile"
|
require_relative "rscons/builders/cfile"
|
||||||
require_relative "rscons/builders/command"
|
require_relative "rscons/builders/command"
|
||||||
|
@ -3,17 +3,12 @@ module Rscons
|
|||||||
# A default Rscons builder that produces a static library archive.
|
# A default Rscons builder that produces a static library archive.
|
||||||
class Library < Builder
|
class Library < Builder
|
||||||
|
|
||||||
|
include Mixins::ObjectDeps
|
||||||
|
|
||||||
# Create an instance of the Builder to build a target.
|
# Create an instance of the Builder to build a target.
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
super(options)
|
super(options)
|
||||||
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
@objects = register_object_deps(Object)
|
||||||
@objects = @sources.map do |source|
|
|
||||||
if source.end_with?(*suffixes)
|
|
||||||
source
|
|
||||||
else
|
|
||||||
@env.register_dependency_build(@target, source, suffixes.first, @vars, Object)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
|
30
lib/rscons/builders/mixins/object_deps.rb
Normal file
30
lib/rscons/builders/mixins/object_deps.rb
Normal 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
|
@ -4,6 +4,8 @@ module Rscons
|
|||||||
# executable program.
|
# executable program.
|
||||||
class Program < Builder
|
class Program < Builder
|
||||||
|
|
||||||
|
include Mixins::ObjectDeps
|
||||||
|
|
||||||
# Create an instance of the Builder to build a target.
|
# Create an instance of the Builder to build a target.
|
||||||
#
|
#
|
||||||
# @param options [Hash]
|
# @param options [Hash]
|
||||||
@ -21,14 +23,7 @@ module Rscons
|
|||||||
unless File.basename(@target)["."]
|
unless File.basename(@target)["."]
|
||||||
@target += @env.expand_varref("${PROGSUFFIX}", @vars)
|
@target += @env.expand_varref("${PROGSUFFIX}", @vars)
|
||||||
end
|
end
|
||||||
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
@objects = register_object_deps(Object)
|
||||||
@objects = @sources.map do |source|
|
|
||||||
if source.end_with?(*suffixes)
|
|
||||||
source
|
|
||||||
else
|
|
||||||
@env.register_dependency_build(@target, source, suffixes.first, @vars, Object)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
|
@ -4,6 +4,8 @@ module Rscons
|
|||||||
# shared library.
|
# shared library.
|
||||||
class SharedLibrary < Builder
|
class SharedLibrary < Builder
|
||||||
|
|
||||||
|
include Mixins::ObjectDeps
|
||||||
|
|
||||||
# Create an instance of the Builder to build a target.
|
# Create an instance of the Builder to build a target.
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
super(options)
|
super(options)
|
||||||
@ -14,14 +16,7 @@ module Rscons
|
|||||||
unless File.basename(@target)["."]
|
unless File.basename(@target)["."]
|
||||||
@target += @env.expand_varref("${SHLIBSUFFIX}", @vars)
|
@target += @env.expand_varref("${SHLIBSUFFIX}", @vars)
|
||||||
end
|
end
|
||||||
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
@objects = register_object_deps(SharedObject)
|
||||||
@objects = @sources.map do |source|
|
|
||||||
if source.end_with?(*suffixes)
|
|
||||||
source
|
|
||||||
else
|
|
||||||
@env.register_dependency_build(@target, source, suffixes.first, @vars, SharedObject)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user