remove Builder.features and Builder.produces?
This commit is contained in:
parent
ac1fc6d106
commit
3ff09978f4
7
build_tests/library/library_from_object.rb
Normal file
7
build_tests/library/library_from_object.rb
Normal file
@ -0,0 +1,7 @@
|
||||
build do
|
||||
Environment.new do |env|
|
||||
env.Program("library.exe", ["lib.a", "three.c"])
|
||||
env.Object("two.o", "two.c")
|
||||
env.Library("lib.a", ["one.c", "two.o"], 'CPPFLAGS' => ['-Dmake_lib'])
|
||||
end
|
||||
end
|
7
build_tests/shared_library/shared_library_from_object.rb
Normal file
7
build_tests/shared_library/shared_library_from_object.rb
Normal file
@ -0,0 +1,7 @@
|
||||
build do
|
||||
Environment.new do |env|
|
||||
env["CPPPATH"] << "src/lib"
|
||||
env.SharedObject("one.o", "src/lib/one.c")
|
||||
libmine = env.SharedLibrary("mine", ["one.o", "src/lib/two.c"])
|
||||
end
|
||||
end
|
@ -16,31 +16,6 @@ module Rscons
|
||||
def name
|
||||
super.split(":").last
|
||||
end
|
||||
|
||||
# Return a set of build features that this builder provides.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
# Set of build features that this builder provides.
|
||||
def features
|
||||
[]
|
||||
end
|
||||
|
||||
# Return whether this builder object is capable of producing a given target
|
||||
# file name from a given source file name.
|
||||
#
|
||||
# @param target [String]
|
||||
# The target file name.
|
||||
# @param source [String]
|
||||
# The source file name.
|
||||
# @param env [Environment]
|
||||
# The Environment.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether this builder object is capable of producing a given target
|
||||
# file name from a given source file name.
|
||||
def produces?(target, source, env)
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# @return [String, Symbol]
|
||||
|
@ -7,8 +7,13 @@ module Rscons
|
||||
def initialize(options)
|
||||
super(options)
|
||||
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
||||
# Register builders to build each source to an object file or library.
|
||||
@objects = @env.register_builds(@target, @sources, suffixes, @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
|
||||
end
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
|
@ -12,28 +12,6 @@ module Rscons
|
||||
"DC" => "DSUFFIX",
|
||||
}
|
||||
|
||||
class << self
|
||||
# Return whether this builder object is capable of producing a given target
|
||||
# file name from a given source file name.
|
||||
#
|
||||
# @param target [String]
|
||||
# The target file name.
|
||||
# @param source [String]
|
||||
# The source file name.
|
||||
# @param env [Environment]
|
||||
# The Environment.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether this builder object is capable of producing a given target
|
||||
# file name from a given source file name.
|
||||
def produces?(target, source, env)
|
||||
target.end_with?(*env['OBJSUFFIX']) and
|
||||
KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||
source.end_with?(*env[suffix_var])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
if @command
|
||||
|
@ -22,8 +22,13 @@ module Rscons
|
||||
@target += @env.expand_varref("${PROGSUFFIX}", @vars)
|
||||
end
|
||||
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
||||
# Register builders to build each source to an object file or library.
|
||||
@objects = @env.register_builds(@target, @sources, suffixes, @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
|
||||
end
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
|
@ -4,16 +4,6 @@ module Rscons
|
||||
# shared library.
|
||||
class SharedLibrary < Builder
|
||||
|
||||
class << self
|
||||
# Return a set of build features that this builder provides.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
# Set of build features that this builder provides.
|
||||
def features
|
||||
%w[shared]
|
||||
end
|
||||
end
|
||||
|
||||
# Create an instance of the Builder to build a target.
|
||||
def initialize(options)
|
||||
super(options)
|
||||
@ -25,9 +15,13 @@ module Rscons
|
||||
@target += @env.expand_varref("${SHLIBSUFFIX}", @vars)
|
||||
end
|
||||
suffixes = @env.expand_varref(["${OBJSUFFIX}", "${LIBSUFFIX}"], @vars)
|
||||
# Register builders to build each source to an object file or library.
|
||||
@objects = @env.register_builds(@target, @sources, suffixes, @vars,
|
||||
features: %w[shared])
|
||||
@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
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
|
@ -13,36 +13,6 @@ module Rscons
|
||||
"SHDC" => "DSUFFIX",
|
||||
}
|
||||
|
||||
class << self
|
||||
# Return a set of build features that this builder provides.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
# Set of build features that this builder provides.
|
||||
def features
|
||||
%w[shared]
|
||||
end
|
||||
|
||||
# Return whether this builder object is capable of producing a given target
|
||||
# file name from a given source file name.
|
||||
#
|
||||
# @param target [String]
|
||||
# The target file name.
|
||||
# @param source [String]
|
||||
# The source file name.
|
||||
# @param env [Environment]
|
||||
# The Environment.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether this builder object is capable of producing a given target
|
||||
# file name from a given source file name.
|
||||
def produces?(target, source, env)
|
||||
target.end_with?(*env['OBJSUFFIX']) and
|
||||
KNOWN_SUFFIXES.find do |compiler, suffix_var|
|
||||
source.end_with?(*env[suffix_var])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Run the builder to produce a build target.
|
||||
def run(options)
|
||||
if @command
|
||||
|
@ -238,16 +238,13 @@ module Rscons
|
||||
# Source file name.
|
||||
# @param suffix [String]
|
||||
# Suffix, including "." if desired.
|
||||
# @param options [Hash]
|
||||
# Extra options.
|
||||
# @option options [Array<String>] :features
|
||||
# Builder features to be used for this build. See {#register_builds}.
|
||||
# @param builder_class [Class]
|
||||
# The builder in use.
|
||||
#
|
||||
# @return [String]
|
||||
# The file name to be built from +source_fname+ with suffix +suffix+.
|
||||
def get_build_fname(source_fname, suffix, options = {})
|
||||
options[:features] ||= []
|
||||
extra_path = options[:features].include?("shared") ? "/_shared" : ""
|
||||
def get_build_fname(source_fname, suffix, builder_class)
|
||||
extra_path = builder_class == Builders::SharedObject ? "/_shared" : ""
|
||||
"#{@build_root}#{extra_path}/#{Util.make_relative_path(Rscons.set_suffix(source_fname, suffix))}".gsub("\\", "/")
|
||||
end
|
||||
|
||||
@ -421,52 +418,31 @@ module Rscons
|
||||
@user_deps[target]
|
||||
end
|
||||
|
||||
# Find and register builders to build source files into files containing
|
||||
# one of the suffixes given by suffixes.
|
||||
# Register a builder to build a source file into an output with the given
|
||||
# suffix.
|
||||
#
|
||||
# This method is used internally by Rscons builders. It can be called
|
||||
# from the builder's #initialize method.
|
||||
#
|
||||
# @since 1.10.0
|
||||
#
|
||||
# @param target [String]
|
||||
# The target that depends on these builds.
|
||||
# @param sources [Array<String>]
|
||||
# List of source file(s) to build.
|
||||
# @param suffixes [Array<String>]
|
||||
# List of suffixes to try to convert source files into.
|
||||
# @param source [String]
|
||||
# Source file to build.
|
||||
# @param suffix [String]
|
||||
# Suffix to try to convert source files into.
|
||||
# @param vars [Hash]
|
||||
# Extra variables to pass to the builders.
|
||||
# @param options [Hash]
|
||||
# Extra options.
|
||||
# @option options [Array<String>] :features
|
||||
# Set of features the builder must provide. Each feature can be proceeded
|
||||
# by a "-" character to indicate that the builder must /not/ provide the
|
||||
# given feature.
|
||||
# * shared - builder builds a shared object/library
|
||||
# @param builder_class [Class]
|
||||
# The builder class to use.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
# List of the output file name(s).
|
||||
def register_builds(target, sources, suffixes, vars, options = {})
|
||||
options[:features] ||= []
|
||||
# @return [String]
|
||||
# Output file name.
|
||||
def register_dependency_build(target, source, suffix, vars, builder_class)
|
||||
output_fname = get_build_fname(source, suffix, builder_class)
|
||||
self.__send__(builder_class.name, output_fname, source, vars)
|
||||
@registered_build_dependencies[target] ||= Set.new
|
||||
sources.map do |source|
|
||||
if source.end_with?(*suffixes)
|
||||
source
|
||||
else
|
||||
output_fname = nil
|
||||
suffixes.each do |suffix|
|
||||
attempt_output_fname = get_build_fname(source, suffix, features: options[:features])
|
||||
if builder = find_builder_for(attempt_output_fname, source, options[:features])
|
||||
output_fname = attempt_output_fname
|
||||
self.__send__(builder.name, output_fname, source, vars)
|
||||
@registered_build_dependencies[target] << output_fname
|
||||
break
|
||||
end
|
||||
end
|
||||
output_fname or raise "Could not find a builder for #{source.inspect}."
|
||||
end
|
||||
end
|
||||
@registered_build_dependencies[target] << output_fname
|
||||
output_fname
|
||||
end
|
||||
|
||||
# Expand a path to be relative to the Environment's build root.
|
||||
@ -706,46 +682,6 @@ module Rscons
|
||||
end
|
||||
end
|
||||
|
||||
# Find a builder that meets the requested features and produces a target
|
||||
# of the requested name.
|
||||
#
|
||||
# @param target [String]
|
||||
# Target file name.
|
||||
# @param source [String]
|
||||
# Source file name.
|
||||
# @param features [Array<String>]
|
||||
# See {#register_builds}.
|
||||
#
|
||||
# @return [Builder, nil]
|
||||
# The builder found, if any.
|
||||
def find_builder_for(target, source, features)
|
||||
@builders.values.find do |builder_class|
|
||||
features_met?(builder_class, features) and builder_class.produces?(target, source, self)
|
||||
end
|
||||
end
|
||||
|
||||
# Determine if a builder meets the requested features.
|
||||
#
|
||||
# @param builder_class [Class]
|
||||
# The builder.
|
||||
# @param features [Array<String>]
|
||||
# See {#register_builds}.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the builder meets the requested features.
|
||||
def features_met?(builder_class, features)
|
||||
builder_features = builder_class.features
|
||||
features.all? do |feature|
|
||||
want_feature = true
|
||||
if feature =~ /^-(.*)$/
|
||||
want_feature = false
|
||||
feature = $1
|
||||
end
|
||||
builder_has_feature = builder_features.include?(feature)
|
||||
want_feature ? builder_has_feature : !builder_has_feature
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Environment.class_init
|
||||
|
@ -1410,6 +1410,14 @@ EOF
|
||||
expect(result.stderr).to eq ""
|
||||
expect(lines(result.stdout)).to include "ar rcf lib.a build/e.1/one.o build/e.1/three.o build/e.1/two.o"
|
||||
end
|
||||
|
||||
it "allows passing object files as sources" do
|
||||
test_dir("library")
|
||||
result = run_rscons(rsconscript: "library_from_object.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(File.exists?("two.o")).to be_truthy
|
||||
expect(lines(result.stdout)).to include "Building static library archive => lib.a"
|
||||
end
|
||||
end
|
||||
|
||||
context "SharedLibrary builder" do
|
||||
@ -1425,6 +1433,13 @@ EOF
|
||||
expect(slines).to include("Linking => libmine.so")
|
||||
end
|
||||
end
|
||||
|
||||
it "allows passing object files as sources" do
|
||||
test_dir "shared_library"
|
||||
result = run_rscons(rsconscript: "shared_library_from_object.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(File.exists?("one.o"))
|
||||
end
|
||||
end
|
||||
|
||||
context "multi-threading" do
|
||||
|
@ -233,27 +233,5 @@ module Rscons
|
||||
expect {env.__send__(:find_finished_thread, false)}.to raise_error /No threads to wait for/
|
||||
end
|
||||
end
|
||||
|
||||
describe "#features_met?" do
|
||||
it "returns true when the builder provides all requested features" do
|
||||
builder = Struct.new(:features).new(%w[shared other])
|
||||
expect(subject.__send__(:features_met?, builder, %w[shared])).to be_truthy
|
||||
end
|
||||
|
||||
it "returns true when no features are requested" do
|
||||
builder = Struct.new(:features).new([])
|
||||
expect(subject.__send__(:features_met?, builder, [])).to be_truthy
|
||||
end
|
||||
|
||||
it "returns false when a builder does not provide a requested feature" do
|
||||
builder = Struct.new(:features).new(%w[shared other])
|
||||
expect(subject.__send__(:features_met?, builder, %w[other2])).to be_falsey
|
||||
end
|
||||
|
||||
it "returns false when a builder provides a feature that is not desired" do
|
||||
builder = Struct.new(:features).new(%w[shared other])
|
||||
expect(subject.__send__(:features_met?, builder, %w[-shared])).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user