remove a few deprecated methods - #84
This commit is contained in:
parent
31ef45258f
commit
12f1909d35
@ -1,30 +0,0 @@
|
||||
class MyObject < Rscons::Builder
|
||||
def produces?(target, source, env)
|
||||
target.end_with?(".o") and source.end_with?(".xyz")
|
||||
end
|
||||
|
||||
def run(target, sources, cache, env, vars)
|
||||
cflags = env.expand_varref("${CFLAGS}", vars)
|
||||
vars = vars.merge(
|
||||
"CFLAGS" => cflags + %w[-x c],
|
||||
"CSUFFIX" => ".xyz")
|
||||
env.run_builder(env.builders["Object"], target, sources, cache, vars)
|
||||
end
|
||||
end
|
||||
|
||||
build do
|
||||
Environment.new do |env|
|
||||
env.add_builder(MyObject.new)
|
||||
File.open("test.xyz", "w") do |fh|
|
||||
fh.puts <<EOF
|
||||
#include <stdio.h>
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
printf("XYZ!\\n");
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
env.Program("test", "test.xyz")
|
||||
end
|
||||
end
|
||||
end
|
@ -1,24 +0,0 @@
|
||||
class MyProgram < Rscons::Builder
|
||||
def run(options)
|
||||
target, sources, cache, env, vars = options.values_at(:target, :sources, :cache, :env, :vars)
|
||||
objects = env.build_sources(sources, [".o"], cache, vars)
|
||||
command = %W[gcc -o #{target}] + objects
|
||||
return false unless env.execute("#{name} #{target}", command)
|
||||
target
|
||||
end
|
||||
end
|
||||
|
||||
build do
|
||||
Environment.new do |env|
|
||||
env.add_builder(MyProgram.new)
|
||||
env.Object("simple.o", "simple.c")
|
||||
File.open("two.c", "wb") do |fh|
|
||||
fh.puts <<-EOF
|
||||
void two(void)
|
||||
{
|
||||
}
|
||||
EOF
|
||||
end
|
||||
env.MyProgram("simple.exe", ["simple.o", "two.c"])
|
||||
end
|
||||
end
|
@ -16,12 +16,15 @@ class DebugBuilder < Rscons::Builder
|
||||
sources = ["extra"] + sources
|
||||
strict_deps = true
|
||||
end
|
||||
unless cache.up_to_date?(target, command, sources, env, debug: true, strict_deps: strict_deps)
|
||||
desc = "#{name} #{target}"
|
||||
return false unless env.execute(desc, command)
|
||||
cache.register_build(target, command, sources, env)
|
||||
if cache.up_to_date?(target, command, sources, env, debug: true, strict_deps: strict_deps)
|
||||
target
|
||||
else
|
||||
ThreadedCommand.new(command, short_description: "#{name} #{target}")
|
||||
end
|
||||
target
|
||||
end
|
||||
|
||||
def finalize(options)
|
||||
standard_finalize(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
build do
|
||||
class MyCommand < Rscons::Builder
|
||||
def run(target, sources, cache, env, vars)
|
||||
vars = vars.merge({
|
||||
"_TARGET" => target,
|
||||
"_SOURCES" => sources,
|
||||
})
|
||||
command = env.build_command("${CMD}", vars)
|
||||
cmd_desc = vars["CMD_DESC"] || "MyCommand"
|
||||
standard_build("#{cmd_desc} #{target}", target, command, sources, env, cache)
|
||||
end
|
||||
end
|
||||
|
||||
Environment.new do |env|
|
||||
env.add_builder(MyCommand.new)
|
||||
command = %w[gcc -c -o ${_TARGET} ${_SOURCES}]
|
||||
env.MyCommand("simple.o", "simple.c", "CMD" => command)
|
||||
end
|
||||
end
|
@ -2,11 +2,15 @@ class StrictBuilder < Rscons::Builder
|
||||
def run(options)
|
||||
target, sources, cache, env = options.values_at(:target, :sources, :cache, :env)
|
||||
command = %W[gcc -o #{target}] + sources.sort
|
||||
unless cache.up_to_date?(target, command, sources, env, strict_deps: true)
|
||||
return false unless env.execute("StrictBuilder #{target}", command)
|
||||
cache.register_build(target, command, sources, env)
|
||||
if cache.up_to_date?(target, command, sources, env, strict_deps: true)
|
||||
target
|
||||
else
|
||||
ThreadedCommand.new(command, short_description: "#{name} #{target}")
|
||||
end
|
||||
target
|
||||
end
|
||||
|
||||
def finalize(options)
|
||||
standard_finalize(options)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -180,33 +180,6 @@ module Rscons
|
||||
def finalize(options)
|
||||
end
|
||||
|
||||
# Check if the cache is up to date for the target and if not execute the
|
||||
# build command. This method does not support parallelization.
|
||||
#
|
||||
# @param short_cmd_string [String]
|
||||
# Short description of build action to be printed when env.echo ==
|
||||
# :short.
|
||||
# @param target [String] Name of the target file.
|
||||
# @param command [Array<String>]
|
||||
# The command to execute to build the target.
|
||||
# @param sources [Array<String>] Source file name(s).
|
||||
# @param env [Environment] The Environment executing the builder.
|
||||
# @param cache [Cache] The Cache object.
|
||||
#
|
||||
# @return [String,false]
|
||||
# The name of the target on success or false on failure.
|
||||
def standard_build(short_cmd_string, target, command, sources, env, cache)
|
||||
unless cache.up_to_date?(target, command, sources, env)
|
||||
unless Rscons.phony_target?(target)
|
||||
cache.mkdir_p(File.dirname(target))
|
||||
FileUtils.rm_f(target)
|
||||
end
|
||||
return false unless env.execute(short_cmd_string, command)
|
||||
cache.register_build(target, command, sources, env)
|
||||
end
|
||||
target
|
||||
end
|
||||
|
||||
# Check if the cache is up to date for the target and if not create a
|
||||
# {ThreadedCommand} object to execute the build command in a thread.
|
||||
#
|
||||
|
@ -336,27 +336,6 @@ module Rscons
|
||||
@job_set.clear!
|
||||
end
|
||||
|
||||
# Execute a builder command.
|
||||
#
|
||||
# @param short_desc [String] Message to print if the Environment's echo
|
||||
# mode is set to :short
|
||||
# @param command [Array] The command to execute.
|
||||
# @param options [Hash] Optional options, possible keys:
|
||||
# - :env - environment Hash to pass to Kernel#system.
|
||||
# - :options - options Hash to pass to Kernel#system.
|
||||
#
|
||||
# @return [true,false,nil] Return value from Kernel.system().
|
||||
def execute(short_desc, command, options = {})
|
||||
print_builder_run_message(short_desc, command)
|
||||
env_args = options[:env] ? [options[:env]] : []
|
||||
options_args = options[:options] ? [options[:options]] : []
|
||||
system(*env_args, *Rscons.command_executer, *command, *options_args).tap do |result|
|
||||
unless result or @echo == :command
|
||||
print_failed_command(command)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Define a build target.
|
||||
#
|
||||
# @param method [Symbol] Method name.
|
||||
@ -468,39 +447,6 @@ module Rscons
|
||||
@user_deps[target]
|
||||
end
|
||||
|
||||
# Build a list of source files into files containing one of the suffixes
|
||||
# given by suffixes.
|
||||
#
|
||||
# This method is used internally by Rscons builders.
|
||||
#
|
||||
# @deprecated Use {#register_builds} instead.
|
||||
#
|
||||
# @param sources [Array<String>] List of source files to build.
|
||||
# @param suffixes [Array<String>]
|
||||
# List of suffixes to try to convert source files into.
|
||||
# @param cache [Cache] The Cache.
|
||||
# @param vars [Hash] Extra variables to pass to the builder.
|
||||
#
|
||||
# @return [Array<String>] List of the converted file name(s).
|
||||
def build_sources(sources, suffixes, cache, vars)
|
||||
sources.map do |source|
|
||||
if source.end_with?(*suffixes)
|
||||
source
|
||||
else
|
||||
converted = nil
|
||||
suffixes.each do |suffix|
|
||||
converted_fname = get_build_fname(source, suffix)
|
||||
if builder = find_builder_for(converted_fname, source, [])
|
||||
converted = run_builder(builder, converted_fname, [source], cache, vars)
|
||||
return nil unless converted
|
||||
break
|
||||
end
|
||||
end
|
||||
converted or raise "Could not find a builder to handle #{source.inspect}."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Find and register builders to build source files into files containing
|
||||
# one of the suffixes given by suffixes.
|
||||
#
|
||||
|
@ -842,32 +842,6 @@ EOF
|
||||
]
|
||||
end
|
||||
|
||||
it "allows a builder to call Environment#build_sources in a non-threaded manner" do
|
||||
test_dir("simple")
|
||||
result = run_rscons(rsconscript: "build_sources.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(lines(result.stdout)).to include *[
|
||||
"CC simple.o",
|
||||
"CC build/e.1/two.o",
|
||||
"MyProgram simple.exe",
|
||||
]
|
||||
end
|
||||
|
||||
it "prints the failed build command for a non-threaded builder" do
|
||||
test_dir("simple")
|
||||
File.open("simple.c", "wb") do |fh|
|
||||
fh.write(<<EOF)
|
||||
void one()
|
||||
{
|
||||
}
|
||||
EOF
|
||||
end
|
||||
result = run_rscons(rsconscript: "build_sources.rb")
|
||||
expect(result.status).to_not eq 0
|
||||
expect(result.stderr).to match /main/
|
||||
expect(result.stdout).to match /Failed command was: gcc/
|
||||
end
|
||||
|
||||
it "prints the failed build command for a threaded builder when called via Environment#run_builder without delayed execution" do
|
||||
test_dir("simple")
|
||||
File.open("simple.c", "wb") do |fh|
|
||||
@ -878,19 +852,6 @@ EOF
|
||||
expect(result.stdout).to match /Failed command was: gcc/
|
||||
end
|
||||
|
||||
it "supports builders that call Builder#standard_build" do
|
||||
test_dir("simple")
|
||||
result = run_rscons(rsconscript: "standard_build.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
expect(lines(result.stdout)).to include *["MyCommand simple.o"]
|
||||
end
|
||||
|
||||
it "supports the old 3-parameter signature to Builder#produces?" do
|
||||
test_dir("simple")
|
||||
result = run_rscons(rsconscript: "bc_produces.rb")
|
||||
expect(result.stderr).to eq ""
|
||||
end
|
||||
|
||||
it 'supports build hooks to override construction variables' do
|
||||
test_dir("typical")
|
||||
result = run_rscons(rsconscript: "backward_compatible_build_hooks.rb")
|
||||
|
Loading…
x
Reference in New Issue
Block a user