Remove BuildTarget, Builder#create_build_target, and Builder#setup - close #90
This commit is contained in:
parent
aac32d20b0
commit
3f8b4d616f
@ -6,7 +6,7 @@ build do
|
|||||||
Rscons.glob("src/*.c"),
|
Rscons.glob("src/*.c"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine.to_s)
|
env.build_after("test-shared.exe", libmine)
|
||||||
env.Program("test-static.exe",
|
env.Program("test-static.exe",
|
||||||
Rscons.glob("src/**/*.c"))
|
Rscons.glob("src/**/*.c"))
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ build do
|
|||||||
Rscons.glob("src/*.cc"),
|
Rscons.glob("src/*.cc"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine.to_s)
|
env.build_after("test-shared.exe", libmine)
|
||||||
env.Program("test-static.exe",
|
env.Program("test-static.exe",
|
||||||
Rscons.glob("src/**/*.cc"))
|
Rscons.glob("src/**/*.cc"))
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,6 @@ build do
|
|||||||
Rscons.glob("src/*.c"),
|
Rscons.glob("src/*.c"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine.to_s)
|
env.build_after("test-shared.exe", libmine)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ build do
|
|||||||
Rscons.glob("src/*.c"),
|
Rscons.glob("src/*.c"),
|
||||||
"LIBPATH" => %w[.],
|
"LIBPATH" => %w[.],
|
||||||
"LIBS" => %w[mine])
|
"LIBS" => %w[mine])
|
||||||
env.build_after("test-shared.exe", libmine.to_s)
|
env.build_after("test-shared.exe", libmine)
|
||||||
env.Program("test-static.exe",
|
env.Program("test-static.exe",
|
||||||
Rscons.glob("src/**/*.c"))
|
Rscons.glob("src/**/*.c"))
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class MyObject < Rscons::Builder
|
class MyObject < Rscons::Builder
|
||||||
def run(options)
|
def run(options)
|
||||||
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||||
env.run_builder(env.builders["Object"].new, target, sources, cache, vars)
|
env.run_builder(env.builders["Object"].new(env: env, target: target, sources: sources, cache: cache, vars: vars), target, sources, cache, vars)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ end
|
|||||||
build do
|
build do
|
||||||
Environment.new do |env|
|
Environment.new do |env|
|
||||||
env.add_builder(TestBuilder)
|
env.add_builder(TestBuilder)
|
||||||
env.TestBuilder("one", [], "wait_time" => "3")
|
one = env.TestBuilder("one", [], "wait_time" => "3")
|
||||||
env.TestBuilder("two", [], "wait_time" => "0")
|
two = env.TestBuilder("two", [], "wait_time" => "0")
|
||||||
env.depends("two", "one")
|
env.depends(two, one)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class MyObject < Rscons::Builder
|
class MyObject < Rscons::Builder
|
||||||
def run(target, sources, cache, env, vars)
|
def run(target, sources, cache, env, vars)
|
||||||
env.run_builder(env.builders["Object"].new, target, sources, cache, vars)
|
env.run_builder(env.builders["Object"].new(target: target, sources: sources, cache: cache, env: env, vars: vars), target, sources, cache, vars)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
require_relative "rscons/ansi"
|
require_relative "rscons/ansi"
|
||||||
require_relative "rscons/application"
|
require_relative "rscons/application"
|
||||||
require_relative "rscons/basic_environment"
|
require_relative "rscons/basic_environment"
|
||||||
require_relative "rscons/build_target"
|
|
||||||
require_relative "rscons/builder"
|
require_relative "rscons/builder"
|
||||||
require_relative "rscons/builder_builder"
|
require_relative "rscons/builder_builder"
|
||||||
require_relative "rscons/cache"
|
require_relative "rscons/cache"
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
module Rscons
|
|
||||||
# The BuildTarget class represents a single build target.
|
|
||||||
class BuildTarget
|
|
||||||
# Create a BuildTarget object.
|
|
||||||
#
|
|
||||||
# @param options [Hash] Options to create the BuildTarget with.
|
|
||||||
# @option options [Environment] :env
|
|
||||||
# The Environment.
|
|
||||||
# @option options [String] :target
|
|
||||||
# The user-supplied target name.
|
|
||||||
# @option options [Array<String>] :sources
|
|
||||||
# The user-supplied source file name(s).
|
|
||||||
def initialize(options)
|
|
||||||
@env = options[:env]
|
|
||||||
@target = options[:target]
|
|
||||||
end
|
|
||||||
|
|
||||||
# Manually record a given target as depending on the specified files.
|
|
||||||
#
|
|
||||||
# @param user_deps [Array<String>] Dependency files.
|
|
||||||
#
|
|
||||||
# @return [void]
|
|
||||||
def depends(*user_deps)
|
|
||||||
@env.depends(@target, *user_deps)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Convert the BuildTarget to a String.
|
|
||||||
#
|
|
||||||
# This method always returns the target file name.
|
|
||||||
#
|
|
||||||
# @return [String] Target file name.
|
|
||||||
def to_s
|
|
||||||
@target
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -42,6 +42,29 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String, Symbol]
|
||||||
|
# Target file name.
|
||||||
|
attr_reader :target
|
||||||
|
|
||||||
|
# Create an instance of the Builder to build a target.
|
||||||
|
#
|
||||||
|
# @param options [Hash]
|
||||||
|
# Options.
|
||||||
|
# @option options [String, Symbol] :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)
|
||||||
|
@target = options[:target]
|
||||||
|
@sources = options[:sources]
|
||||||
|
@env = options[:env]
|
||||||
|
@vars = options[:vars]
|
||||||
|
end
|
||||||
|
|
||||||
# Return the name of the builder.
|
# Return the name of the builder.
|
||||||
#
|
#
|
||||||
# If not overridden this defaults to the last component of the class name.
|
# If not overridden this defaults to the last component of the class name.
|
||||||
@ -51,55 +74,14 @@ module Rscons
|
|||||||
self.class.name
|
self.class.name
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a BuildTarget object for this build target.
|
# Manually record a given build target as depending on the specified files.
|
||||||
#
|
#
|
||||||
# Builder sub-classes can override this method to manipulate parameters
|
# @param user_deps [Array<String>]
|
||||||
# (for example, add a suffix to the user-given target file name).
|
# Dependency files.
|
||||||
#
|
#
|
||||||
# @param options [Hash] Options to create the BuildTarget with.
|
# @return [void]
|
||||||
# @option options [Environment] :env
|
def depends(*user_deps)
|
||||||
# The Environment.
|
@env.depends(@target, *user_deps)
|
||||||
# @option options [String] :target
|
|
||||||
# The user-supplied target name.
|
|
||||||
# @option options [Array<String>] :sources
|
|
||||||
# The user-supplied source file name(s).
|
|
||||||
# @option options [Hash,VarSet] :vars
|
|
||||||
# Extra construction variables.
|
|
||||||
#
|
|
||||||
# @return [BuildTarget]
|
|
||||||
def create_build_target(options)
|
|
||||||
BuildTarget.new(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Set up a build operation using this builder.
|
|
||||||
#
|
|
||||||
# This method is called when a build target is registered using this
|
|
||||||
# builder. This method should not do any building, but should perform any
|
|
||||||
# setup needed and register any prerequisite build targets that need to be
|
|
||||||
# built before the target being requested here.
|
|
||||||
#
|
|
||||||
# If the builder needs no special setup, it does not need to override this
|
|
||||||
# method. If there is any information produced in this method that will be
|
|
||||||
# needed later in the build, it can be stored in the return value from this
|
|
||||||
# method, which will be passed to the {#run} method.
|
|
||||||
#
|
|
||||||
# @since 1.10.0
|
|
||||||
#
|
|
||||||
# @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.
|
|
||||||
#
|
|
||||||
# @return [Object]
|
|
||||||
# Any object that the builder author wishes to be saved and passed back
|
|
||||||
# in to the {#run} method.
|
|
||||||
def setup(options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
@ -139,8 +121,6 @@ module Rscons
|
|||||||
# The Environment executing the builder.
|
# The Environment executing the builder.
|
||||||
# @option options [Hash,VarSet] :vars
|
# @option options [Hash,VarSet] :vars
|
||||||
# Extra construction variables.
|
# Extra construction variables.
|
||||||
# @option options [Object] :setup_info
|
|
||||||
# Whatever value was returned from this builder's {#setup} method call.
|
|
||||||
#
|
#
|
||||||
# @return [ThreadedCommand,String,false]
|
# @return [ThreadedCommand,String,false]
|
||||||
# Name of the target file on success or false on failure.
|
# Name of the target file on success or false on failure.
|
||||||
@ -177,8 +157,6 @@ module Rscons
|
|||||||
# The Environment executing the builder.
|
# The Environment executing the builder.
|
||||||
# @option options [Hash,VarSet] :vars
|
# @option options [Hash,VarSet] :vars
|
||||||
# Extra construction variables.
|
# Extra construction variables.
|
||||||
# @option options [Object] :setup_info
|
|
||||||
# Whatever value was returned from this builder's {#setup} method call.
|
|
||||||
# @option options [true,false,nil] :command_status
|
# @option options [true,false,nil] :command_status
|
||||||
# If the {#run} method returns a {ThreadedCommand}, this field will
|
# If the {#run} method returns a {ThreadedCommand}, this field will
|
||||||
# contain the return value from executing the command with
|
# contain the return value from executing the command with
|
||||||
|
@ -10,18 +10,23 @@ module Rscons
|
|||||||
'ARCMD' => ['${AR}', '${ARFLAGS}', '${_TARGET}', '${_SOURCES}']
|
'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.
|
# @param options [Hash]
|
||||||
#
|
# Options.
|
||||||
# @return [Object]
|
# @option options [String] :target
|
||||||
# Any object that the builder author wishes to be saved and passed back
|
# Target file name.
|
||||||
# in to the {#run} method.
|
# @option options [Array<String>] :sources
|
||||||
def setup(options)
|
# Source file name(s).
|
||||||
target, sources, env, vars = options.values_at(:target, :sources, :env, :vars)
|
# @option options [Environment] :env
|
||||||
suffixes = env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], vars)
|
# 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.
|
# 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
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
@ -31,14 +36,14 @@ module Rscons
|
|||||||
# @return [String,false]
|
# @return [String,false]
|
||||||
# Name of the target file on success or false on failure.
|
# Name of the target file on success or false on failure.
|
||||||
def run(options)
|
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({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => objects,
|
'_SOURCES' => @objects,
|
||||||
})
|
})
|
||||||
options[:sources] = objects
|
options[:sources] = @objects
|
||||||
command = env.build_command("${ARCMD}", vars)
|
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
|
end
|
||||||
|
|
||||||
# Finalize a build.
|
# Finalize a build.
|
||||||
|
@ -17,41 +17,26 @@ module Rscons
|
|||||||
'LDCMD' => ['${LD}', '-o', '${_TARGET}', '${LDFLAGS}', '${_SOURCES}', '${LIBDIRPREFIX}${LIBPATH}', '${LIBLINKPREFIX}${LIBS}']
|
'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
|
# @param options [Hash]
|
||||||
# executing on a Windows platform and no other suffix is given.
|
# Options.
|
||||||
#
|
|
||||||
# @param options [Hash] Options to create the BuildTarget with.
|
|
||||||
# @option options [Environment] :env
|
|
||||||
# The Environment.
|
|
||||||
# @option options [String] :target
|
# @option options [String] :target
|
||||||
# The user-supplied target name.
|
# Target file name.
|
||||||
# @option options [Array<String>] :sources
|
# @option options [Array<String>] :sources
|
||||||
# The user-supplied source file name(s).
|
# Source file name(s).
|
||||||
#
|
# @option options [Environment] :env
|
||||||
# @return [BuildTarget]
|
# The Environment executing the builder.
|
||||||
def create_build_target(options)
|
# @option options [Hash,VarSet] :vars
|
||||||
env, target, vars = options.values_at(:env, :target, :vars)
|
# Extra construction variables.
|
||||||
my_options = options.dup
|
def initialize(options)
|
||||||
unless File.basename(target)["."]
|
super(options)
|
||||||
my_options[:target] += env.expand_varref("${PROGSUFFIX}", vars)
|
unless File.basename(@target)["."]
|
||||||
|
@target += @env.expand_varref("${PROGSUFFIX}", @vars)
|
||||||
end
|
end
|
||||||
super(my_options)
|
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
||||||
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)
|
|
||||||
# Register builders to build each source to an object file or library.
|
# 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
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
@ -61,7 +46,7 @@ module Rscons
|
|||||||
# @return [String,false]
|
# @return [String,false]
|
||||||
# Name of the target file on success or false on failure.
|
# Name of the target file on success or false on failure.
|
||||||
def run(options)
|
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 = env.expand_varref("${LD}", vars)
|
||||||
ld = if ld != ""
|
ld = if ld != ""
|
||||||
ld
|
ld
|
||||||
@ -74,12 +59,12 @@ module Rscons
|
|||||||
end
|
end
|
||||||
vars = vars.merge({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => objects,
|
'_SOURCES' => @objects,
|
||||||
'LD' => ld,
|
'LD' => ld,
|
||||||
})
|
})
|
||||||
options[:sources] = objects
|
options[:sources] = @objects
|
||||||
command = env.build_command("${LDCMD}", vars)
|
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
|
end
|
||||||
|
|
||||||
# Finalize a build.
|
# Finalize a build.
|
||||||
|
@ -24,47 +24,31 @@ module Rscons
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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 platform-dependent suffix if no
|
|
||||||
# other suffix is given.
|
|
||||||
#
|
#
|
||||||
# @param options [Hash]
|
# @param options [Hash]
|
||||||
# Options to create the BuildTarget with.
|
# Options.
|
||||||
# @option options [Environment] :env
|
|
||||||
# The Environment.
|
|
||||||
# @option options [String] :target
|
# @option options [String] :target
|
||||||
# The user-supplied target name.
|
# Target file name.
|
||||||
# @option options [Array<String>] :sources
|
# @option options [Array<String>] :sources
|
||||||
# The user-supplied source file name(s).
|
# Source file name(s).
|
||||||
#
|
# @option options [Environment] :env
|
||||||
# @return [BuildTarget]
|
# The Environment executing the builder.
|
||||||
def create_build_target(options)
|
# @option options [Hash,VarSet] :vars
|
||||||
env, target, vars = options.values_at(:env, :target, :vars)
|
# Extra construction variables.
|
||||||
my_options = options.dup
|
def initialize(options)
|
||||||
libprefix = env.expand_varref("${SHLIBPREFIX}", vars)
|
super(options)
|
||||||
unless File.basename(target).start_with?(libprefix)
|
libprefix = @env.expand_varref("${SHLIBPREFIX}", @vars)
|
||||||
my_options[:target].sub!(%r{^(.*/)?([^/]+)$}, "\\1#{libprefix}\\2")
|
unless File.basename(@target).start_with?(libprefix)
|
||||||
|
@target = @target.sub!(%r{^(.*/)?([^/]+)$}, "\\1#{libprefix}\\2")
|
||||||
end
|
end
|
||||||
unless File.basename(target)["."]
|
unless File.basename(@target)["."]
|
||||||
my_options[:target] += env.expand_varref("${SHLIBSUFFIX}", vars)
|
@target += @env.expand_varref("${SHLIBSUFFIX}", @vars)
|
||||||
end
|
end
|
||||||
super(my_options)
|
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
||||||
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)
|
|
||||||
# Register builders to build each source to an object file or library.
|
# 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,
|
||||||
features: %w[shared])
|
features: %w[shared])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the builder to produce a build target.
|
# Run the builder to produce a build target.
|
||||||
@ -74,7 +58,7 @@ module Rscons
|
|||||||
# @return [String,false]
|
# @return [String,false]
|
||||||
# Name of the target file on success or false on failure.
|
# Name of the target file on success or false on failure.
|
||||||
def run(options)
|
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 = env.expand_varref("${SHLD}", vars)
|
||||||
ld = if ld != ""
|
ld = if ld != ""
|
||||||
ld
|
ld
|
||||||
@ -87,12 +71,12 @@ module Rscons
|
|||||||
end
|
end
|
||||||
vars = vars.merge({
|
vars = vars.merge({
|
||||||
'_TARGET' => target,
|
'_TARGET' => target,
|
||||||
'_SOURCES' => objects,
|
'_SOURCES' => @objects,
|
||||||
'SHLD' => ld,
|
'SHLD' => ld,
|
||||||
})
|
})
|
||||||
options[:sources] = objects
|
options[:sources] = @objects
|
||||||
command = env.build_command("${SHLDCMD}", vars)
|
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
|
end
|
||||||
|
|
||||||
# Finalize a build.
|
# Finalize a build.
|
||||||
|
@ -5,12 +5,23 @@ module Rscons
|
|||||||
# @since 1.8.0
|
# @since 1.8.0
|
||||||
class SimpleBuilder < Builder
|
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]
|
# @param run_proc [Proc]
|
||||||
# A Proc to execute when the builder runs. The provided block must
|
# A Proc to execute when the builder runs. The provided block must
|
||||||
# provide the have the same signature as {Builder#run}.
|
# provide the have the same signature as {Builder#run}.
|
||||||
def initialize(&run_proc)
|
def initialize(options, &run_proc)
|
||||||
|
super(options)
|
||||||
@run_proc = run_proc
|
@run_proc = run_proc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -282,8 +282,7 @@ module Rscons
|
|||||||
job[:sources],
|
job[:sources],
|
||||||
cache,
|
cache,
|
||||||
job[:vars],
|
job[:vars],
|
||||||
allow_delayed_execution: true,
|
allow_delayed_execution: true)
|
||||||
setup_info: job[:setup_info])
|
|
||||||
unless result
|
unless result
|
||||||
failure = "Failed to build #{job[:target]}"
|
failure = "Failed to build #{job[:target]}"
|
||||||
Ansi.write($stderr, :red, failure, :reset, "\n")
|
Ansi.write($stderr, :red, failure, :reset, "\n")
|
||||||
@ -342,9 +341,9 @@ module Rscons
|
|||||||
# @param method [Symbol] Method name.
|
# @param method [Symbol] Method name.
|
||||||
# @param args [Array] Method arguments.
|
# @param args [Array] Method arguments.
|
||||||
#
|
#
|
||||||
# @return [BuildTarget]
|
# @return [Builder]
|
||||||
# The {BuildTarget} object registered, if the method called is a
|
# The {Builder} object registered, if the method called is the name of a
|
||||||
# {Builder}.
|
# registered {Builder}.
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
if @builders.has_key?(method.to_s)
|
if @builders.has_key?(method.to_s)
|
||||||
target, sources, vars, *rest = args
|
target, sources, vars, *rest = args
|
||||||
@ -352,14 +351,13 @@ module Rscons
|
|||||||
unless vars.is_a?(Hash) or vars.is_a?(VarSet)
|
unless vars.is_a?(Hash) or vars.is_a?(VarSet)
|
||||||
raise "Unexpected construction variable set: #{vars.inspect}"
|
raise "Unexpected construction variable set: #{vars.inspect}"
|
||||||
end
|
end
|
||||||
builder = @builders[method.to_s].new
|
|
||||||
target = expand_path(expand_varref(target))
|
target = expand_path(expand_varref(target))
|
||||||
sources = Array(sources).map do |source|
|
sources = Array(sources).map do |source|
|
||||||
expand_path(expand_varref(source))
|
expand_path(expand_varref(source))
|
||||||
end.flatten
|
end.flatten
|
||||||
build_target = builder.create_build_target(env: self, target: target, sources: sources, vars: vars)
|
builder = @builders[method.to_s].new(env: self, target: target, sources: sources, vars: vars)
|
||||||
add_target(build_target.to_s, builder, sources, vars, rest)
|
add_target(builder.target, builder, sources, vars, rest)
|
||||||
build_target
|
builder
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
@ -367,13 +365,21 @@ module Rscons
|
|||||||
|
|
||||||
# Manually record a given target as depending on the specified files.
|
# Manually record a given target as depending on the specified files.
|
||||||
#
|
#
|
||||||
# @param target [String,BuildTarget] Target file.
|
# @param target [String, Builder] Target file.
|
||||||
# @param user_deps [Array<String>] Dependency files.
|
# @param user_deps [Array<String, Builder>] Dependency files.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def depends(target, *user_deps)
|
def depends(target, *user_deps)
|
||||||
|
if target.is_a?(Builder)
|
||||||
|
target = target.target
|
||||||
|
end
|
||||||
target = expand_varref(target.to_s)
|
target = expand_varref(target.to_s)
|
||||||
user_deps = user_deps.map {|ud| expand_varref(ud)}
|
user_deps = user_deps.map do |ud|
|
||||||
|
if ud.is_a?(Builder)
|
||||||
|
ud = ud.target
|
||||||
|
end
|
||||||
|
expand_varref(ud)
|
||||||
|
end
|
||||||
@user_deps[target] ||= []
|
@user_deps[target] ||= []
|
||||||
@user_deps[target] = (@user_deps[target] + user_deps).uniq
|
@user_deps[target] = (@user_deps[target] + user_deps).uniq
|
||||||
build_after(target, user_deps)
|
build_after(target, user_deps)
|
||||||
@ -400,7 +406,7 @@ module Rscons
|
|||||||
# @param targets [String, Array<String>]
|
# @param targets [String, Array<String>]
|
||||||
# Target files to wait to build until the prerequisites are finished
|
# Target files to wait to build until the prerequisites are finished
|
||||||
# building.
|
# building.
|
||||||
# @param prerequisites [String, Array<String>]
|
# @param prerequisites [String, Builder, Array<String, Builder>]
|
||||||
# Files that must be built before building the specified targets.
|
# Files that must be built before building the specified targets.
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
@ -411,6 +417,9 @@ module Rscons
|
|||||||
target = expand_path(expand_varref(target))
|
target = expand_path(expand_varref(target))
|
||||||
@registered_build_dependencies[target] ||= Set.new
|
@registered_build_dependencies[target] ||= Set.new
|
||||||
prerequisites.each do |prerequisite|
|
prerequisites.each do |prerequisite|
|
||||||
|
if prerequisite.is_a?(Builder)
|
||||||
|
prerequisite = prerequisite.target
|
||||||
|
end
|
||||||
prerequisite = expand_path(expand_varref(prerequisite))
|
prerequisite = expand_path(expand_varref(prerequisite))
|
||||||
@registered_build_dependencies[target] << prerequisite
|
@registered_build_dependencies[target] << prerequisite
|
||||||
end
|
end
|
||||||
@ -451,8 +460,8 @@ module Rscons
|
|||||||
# Find and register builders to build source files into files containing
|
# Find and register builders to build source files into files containing
|
||||||
# one of the suffixes given by suffixes.
|
# one of the suffixes given by suffixes.
|
||||||
#
|
#
|
||||||
# This method is used internally by Rscons builders. It should be called
|
# This method is used internally by Rscons builders. It can be called
|
||||||
# from the builder's #setup method.
|
# from the builder's #initialize method.
|
||||||
#
|
#
|
||||||
# @since 1.10.0
|
# @since 1.10.0
|
||||||
#
|
#
|
||||||
@ -510,8 +519,6 @@ module Rscons
|
|||||||
# @since 1.10.0
|
# @since 1.10.0
|
||||||
# Allow a threaded command to be scheduled but not yet completed before
|
# Allow a threaded command to be scheduled but not yet completed before
|
||||||
# this method returns.
|
# this method returns.
|
||||||
# @option options [Object] :setup_info
|
|
||||||
# Arbitrary builder info returned by Builder#setup.
|
|
||||||
#
|
#
|
||||||
# @return [String,false] Return value from the {Builder}'s +run+ method.
|
# @return [String,false] Return value from the {Builder}'s +run+ method.
|
||||||
def run_builder(builder, target, sources, cache, vars, options = {})
|
def run_builder(builder, target, sources, cache, vars, options = {})
|
||||||
@ -523,7 +530,6 @@ module Rscons
|
|||||||
cache: cache,
|
cache: cache,
|
||||||
env: self,
|
env: self,
|
||||||
vars: vars,
|
vars: vars,
|
||||||
setup_info: options[:setup_info]
|
|
||||||
}
|
}
|
||||||
call_build_hooks = lambda do |sec|
|
call_build_hooks = lambda do |sec|
|
||||||
@build_hooks[sec].each do |build_hook_block|
|
@build_hooks[sec].each do |build_hook_block|
|
||||||
@ -672,17 +678,11 @@ module Rscons
|
|||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def add_target(target, builder, sources, vars, args)
|
def add_target(target, builder, sources, vars, args)
|
||||||
setup_info = builder.setup(
|
|
||||||
target: target,
|
|
||||||
sources: sources,
|
|
||||||
env: self,
|
|
||||||
vars: vars)
|
|
||||||
@job_set.add_job(
|
@job_set.add_job(
|
||||||
builder: builder,
|
builder: builder,
|
||||||
target: target,
|
target: target,
|
||||||
sources: sources,
|
sources: sources,
|
||||||
vars: vars,
|
vars: vars)
|
||||||
setup_info: setup_info)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start a threaded command in a new thread.
|
# Start a threaded command in a new thread.
|
||||||
|
@ -2,7 +2,7 @@ module Rscons
|
|||||||
describe Builder do
|
describe Builder do
|
||||||
describe "#run" do
|
describe "#run" do
|
||||||
it "raises an error if called directly and not through a subclass" do
|
it "raises an error if called directly and not through a subclass" do
|
||||||
expect{subject.run({})}.to raise_error /This method must be overridden in a subclass/
|
expect{Builder.new({}).run({})}.to raise_error /This method must be overridden in a subclass/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ module Rscons
|
|||||||
let(:env) {Environment.new}
|
let(:env) {Environment.new}
|
||||||
|
|
||||||
it "should create a new builder with the given action" do
|
it "should create a new builder with the given action" do
|
||||||
builder = Rscons::Builders::SimpleBuilder.new { 0x1234 }
|
builder = Rscons::Builders::SimpleBuilder.new({}) { 0x1234 }
|
||||||
expect(builder.run(1,2,3,4,5)).to eq(0x1234)
|
expect(builder.run(1,2,3,4,5)).to eq(0x1234)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user