Remove BuildTarget, Builder#create_build_target, and Builder#setup - close #90

This commit is contained in:
josh committed 2019-02-10 18:24:49 -05:00
1 parent aac32d20b0
commit 3f8b4d616f
17 files changed
+138 -212

No files matched your search

+19 -14
View File
@@ -10,18 +10,23 @@ module Rscons
'ARCMD' => ['${AR}', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}']
)
# Set up a build operation using this builder.
# Create an instance of the Builder to build a target.
#
# @param options [Hash] Builder setup options.
#
# @return [Object]
# Any object that the builder author wishes to be saved and passed back
# in to the {#run} method.
def setup(options)
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
# @param options [Hash]
# Options.
# @option options [String] :target
# Target file name.
# @option options [Array<String>] :sources
# Source file name(s).
# @option options [Environment] :env
# The Environment executing the builder.
# @option options [Hash,VarSet] :vars
# Extra construction variables.
def initialize(options)
super(options)
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
# Register builders to build each source to an object file or library.
env.register_builds(target, sources, suffixes, vars)
@objects = @env.register_builds(@target, @sources, suffixes, @vars)
end
# Run the builder to produce a build target.
@@ -31,14 +36,14 @@ module Rscons
# @return [String,false]
# Name of the target file on success or false on failure.
def run(options)
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
vars = vars.merge({
'_TARGET' => target,
'_SOURCES' => objects,
'_SOURCES' => @objects,
})
options[:sources] = objects
options[:sources] = @objects
command = env.build_command("${ARCMD}", vars)
standard_threaded_build("AR #{target}", target, command, objects, env, cache)
standard_threaded_build("AR #{target}", target, command, @objects, env, cache)
end
# Finalize a build.
+19 -34
View File
@@ -17,41 +17,26 @@ module Rscons
'LDCMD' => ['${LD}', '-o', '${_TARGET}', '${LDFLAGS}', '${_SOURCES}', '${LIBDIRPREFIX}${LIBPATH}', '${LIBLINKPREFIX}${LIBS}']
)
# Create a BuildTarget object for this build target.
# Create an instance of the Builder to build a target.
#
# The build target filename is given a ".exe" suffix if Rscons is
# executing on a Windows platform and no other suffix is given.
#
# @param options [Hash] Options to create the BuildTarget with.
# @option options [Environment] :env
# The Environment.
# @param options [Hash]
# Options.
# @option options [String] :target
# The user-supplied target name.
# Target file name.
# @option options [Array<String>] :sources
# The user-supplied source file name(s).
#
# @return [BuildTarget]
def create_build_target(options)
env, target, vars = options.values_at(:env, :target, :vars)
my_options = options.dup
unless File.basename(target)["."]
my_options[:target] += env.expand_varref("${PROGSUFFIX}", vars)
# Source file name(s).
# @option options [Environment] :env
# The Environment executing the builder.
# @option options [Hash,VarSet] :vars
# Extra construction variables.
def initialize(options)
super(options)
unless File.basename(@target)["."]
@target += @env.expand_varref("${PROGSUFFIX}", @vars)
end
super(my_options)
end
# Set up a build operation using this builder.
#
# @param options [Hash] Builder setup options.
#
# @return [Object]
# Any object that the builder author wishes to be saved and passed back
# in to the {#run} method.
def setup(options)
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
# Register builders to build each source to an object file or library.
env.register_builds(target, sources, suffixes, vars)
@objects = @env.register_builds(@target, @sources, suffixes, @vars)
end
# Run the builder to produce a build target.
@@ -61,7 +46,7 @@ module Rscons
# @return [String,false]
# Name of the target file on success or false on failure.
def run(options)
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
ld = env.expand_varref("${LD}", vars)
ld = if ld != ""
ld
@@ -74,12 +59,12 @@ module Rscons
end
vars = vars.merge({
'_TARGET' => target,
'_SOURCES' => objects,
'_SOURCES' => @objects,
'LD' => ld,
})
options[:sources] = objects
options[:sources] = @objects
command = env.build_command("${LDCMD}", vars)
standard_threaded_build("LD #{target}", target, command, objects, env, cache)
standard_threaded_build("LD #{target}", target, command, @objects, env, cache)
end
# Finalize a build.
+22 -38
View File
@@ -24,47 +24,31 @@ module Rscons
end
end
# Create a BuildTarget object for this build target.
#
# The build target filename is given a platform-dependent suffix if no
# other suffix is given.
# Create an instance of the Builder to build a target.
#
# @param options [Hash]
# Options to create the BuildTarget with.
# @option options [Environment] :env
# The Environment.
# Options.
# @option options [String] :target
# The user-supplied target name.
# Target file name.
# @option options [Array<String>] :sources
# The user-supplied source file name(s).
#
# @return [BuildTarget]
def create_build_target(options)
env, target, vars = options.values_at(:env, :target, :vars)
my_options = options.dup
libprefix = env.expand_varref("${SHLIBPREFIX}", vars)
unless File.basename(target).start_with?(libprefix)
my_options[:target].sub!(%r{^(.*/)?([^/]+)$}, "\\1#{libprefix}\\2")
# Source file name(s).
# @option options [Environment] :env
# The Environment executing the builder.
# @option options [Hash,VarSet] :vars
# Extra construction variables.
def initialize(options)
super(options)
libprefix = @env.expand_varref("${SHLIBPREFIX}", @vars)
unless File.basename(@target).start_with?(libprefix)
@target = @target.sub!(%r{^(.*/)?([^/]+)$}, "\\1#{libprefix}\\2")
end
unless File.basename(target)["."]
my_options[:target] += env.expand_varref("${SHLIBSUFFIX}", vars)
unless File.basename(@target)["."]
@target += @env.expand_varref("${SHLIBSUFFIX}", @vars)
end
super(my_options)
end
# Set up a build operation using this builder.
#
# @param options [Hash] Builder setup options.
#
# @return [Object]
# Any object that the builder author wishes to be saved and passed back
# in to the {#run} method.
def setup(options)
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
# Register builders to build each source to an object file or library.
env.register_builds(target, sources, suffixes, vars,
features: %w[shared])
@objects = @env.register_builds(@target, @sources, suffixes, @vars,
features: %w[shared])
end
# Run the builder to produce a build target.
@@ -74,7 +58,7 @@ module Rscons
# @return [String,false]
# Name of the target file on success or false on failure.
def run(options)
target, sources, cache, env, vars, objects = options.values_at(:target, :sources, :cache, :env, :vars, :setup_info)
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
ld = env.expand_varref("${SHLD}", vars)
ld = if ld != ""
ld
@@ -87,12 +71,12 @@ module Rscons
end
vars = vars.merge({
'_TARGET' => target,
'_SOURCES' => objects,
'_SOURCES' => @objects,
'SHLD' => ld,
})
options[:sources] = objects
options[:sources] = @objects
command = env.build_command("${SHLDCMD}", vars)
standard_threaded_build("SHLD #{target}", target, command, objects, env, cache)
standard_threaded_build("SHLD #{target}", target, command, @objects, env, cache)
end
# Finalize a build.
+13 -2
View File
@@ -5,12 +5,23 @@ module Rscons
# @since 1.8.0
class SimpleBuilder < Builder
# Create a new builder with the given action.
# Create an instance of the Builder to build a target.
#
# @param options [Hash]
# Options.
# @option options [String] :target
# Target file name.
# @option options [Array<String>] :sources
# Source file name(s).
# @option options [Environment] :env
# The Environment executing the builder.
# @option options [Hash,VarSet] :vars
# Extra construction variables.
# @param run_proc [Proc]
# A Proc to execute when the builder runs. The provided block must
# provide the have the same signature as {Builder#run}.
def initialize(&run_proc)
def initialize(options, &run_proc)
super(options)
@run_proc = run_proc
end