From 12f1909d35226b21ac007887c128f0b03c37120e Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 4 Jan 2019 13:35:38 -0500 Subject: [PATCH] remove a few deprecated methods - #84 --- build_tests/simple/bc_produces.rb | 30 ----------- build_tests/simple/build_sources.rb | 24 --------- build_tests/simple/cache_debugging.rb | 13 +++-- build_tests/simple/standard_build.rb | 19 ------- build_tests/two_sources/cache_strict_deps.rb | 12 +++-- lib/rscons/builder.rb | 27 ---------- lib/rscons/environment.rb | 54 -------------------- spec/build_tests_spec.rb | 39 -------------- 8 files changed, 16 insertions(+), 202 deletions(-) delete mode 100644 build_tests/simple/bc_produces.rb delete mode 100644 build_tests/simple/build_sources.rb delete mode 100644 build_tests/simple/standard_build.rb diff --git a/build_tests/simple/bc_produces.rb b/build_tests/simple/bc_produces.rb deleted file mode 100644 index 7638379..0000000 --- a/build_tests/simple/bc_produces.rb +++ /dev/null @@ -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 < -int main(int argc, char * argv[]) -{ - printf("XYZ!\\n"); - return 0; -} -EOF - env.Program("test", "test.xyz") - end - end -end diff --git a/build_tests/simple/build_sources.rb b/build_tests/simple/build_sources.rb deleted file mode 100644 index b0013ed..0000000 --- a/build_tests/simple/build_sources.rb +++ /dev/null @@ -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 diff --git a/build_tests/simple/cache_debugging.rb b/build_tests/simple/cache_debugging.rb index ba1969d..6fcdd3a 100644 --- a/build_tests/simple/cache_debugging.rb +++ b/build_tests/simple/cache_debugging.rb @@ -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 diff --git a/build_tests/simple/standard_build.rb b/build_tests/simple/standard_build.rb deleted file mode 100644 index 5914cb3..0000000 --- a/build_tests/simple/standard_build.rb +++ /dev/null @@ -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 diff --git a/build_tests/two_sources/cache_strict_deps.rb b/build_tests/two_sources/cache_strict_deps.rb index a1b90ab..df8c4ff 100644 --- a/build_tests/two_sources/cache_strict_deps.rb +++ b/build_tests/two_sources/cache_strict_deps.rb @@ -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 diff --git a/lib/rscons/builder.rb b/lib/rscons/builder.rb index 06da747..d40b970 100644 --- a/lib/rscons/builder.rb +++ b/lib/rscons/builder.rb @@ -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] - # The command to execute to build the target. - # @param sources [Array] 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. # diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 634f87b..9e3cb20 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -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] List of source files to build. - # @param suffixes [Array] - # 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] 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. # diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb index 53603ca..6e81607 100644 --- a/spec/build_tests_spec.rb +++ b/spec/build_tests_spec.rb @@ -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(<