From fc17a14008082edd4e4d336fc6bb8019aa551309 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 25 Jan 2022 22:45:39 -0500 Subject: [PATCH] Remove "nop" builders; Install* builders always install --- lib/rscons/application.rb | 2 - lib/rscons/builder.rb | 8 --- lib/rscons/builder_set.rb | 2 +- lib/rscons/builders/copy.rb | 85 ++++++++++++++------------------ lib/rscons/builders/directory.rb | 27 +++------- lib/rscons/environment.rb | 4 +- 6 files changed, 45 insertions(+), 83 deletions(-) diff --git a/lib/rscons/application.rb b/lib/rscons/application.rb index 0bec85f..46f5483 100644 --- a/lib/rscons/application.rb +++ b/lib/rscons/application.rb @@ -41,8 +41,6 @@ module Rscons # List of task(s) to execute. # @param options [Hash] # Optional parameters. - # @option sub_op [Boolean] - # Whether this operation is not the top-level operation. # # @return [Integer] # Process exit code (0 on success). diff --git a/lib/rscons/builder.rb b/lib/rscons/builder.rb index 5fe5cbf..abdbf22 100644 --- a/lib/rscons/builder.rb +++ b/lib/rscons/builder.rb @@ -87,14 +87,6 @@ module Rscons self.class.name end - # Return whether the builder is a no-op. - # - # @return [Boolean] - # Whether the builder is a no-op. - def nop? - false - end - # Manually record a given build target as depending on the specified files. # # @param user_deps [Array] diff --git a/lib/rscons/builder_set.rb b/lib/rscons/builder_set.rb index c36e86e..8373d78 100644 --- a/lib/rscons/builder_set.rb +++ b/lib/rscons/builder_set.rb @@ -37,7 +37,7 @@ module Rscons # The number of remaining build steps. def build_steps_remaining self.reduce(0) do |result, (target, builders)| - result + builders.select {|b| not b.nop?}.size + result + builders.size end end diff --git a/lib/rscons/builders/copy.rb b/lib/rscons/builders/copy.rb index e0dad5a..6278dae 100644 --- a/lib/rscons/builders/copy.rb +++ b/lib/rscons/builders/copy.rb @@ -9,61 +9,48 @@ module Rscons def initialize(*args) super @install_builder = self.class.name == "Install" - @nop = @install_builder && !Rscons.application.operation("install") - end - - # Return whether the builder is a no-op. - # - # @return [Boolean] - # Whether the builder is a no-op. - def nop? - @nop end # Run the builder to produce a build target. def run(options) - if @nop - true + target_is_dir = (@sources.length > 1) || + Dir.exists?(@sources.first) || + Dir.exists?(@target) + outdir = target_is_dir ? @target : File.dirname(@target) + # Collect the list of files to copy over. + file_map = {} + if target_is_dir + @sources.each do |src| + if Dir.exists? src + Dir.glob("#{src}/**/*", File::FNM_DOTMATCH).select do |f| + File.file?(f) + end.each do |subfile| + subpath = Pathname.new(subfile).relative_path_from(Pathname.new(src)).to_s + file_map[subfile] = "#{outdir}/#{subpath}" + end + else + file_map[src] = "#{outdir}/#{File.basename(src)}" + end + end else - target_is_dir = (@sources.length > 1) || - Dir.exists?(@sources.first) || - Dir.exists?(@target) - outdir = target_is_dir ? @target : File.dirname(@target) - # Collect the list of files to copy over. - file_map = {} - if target_is_dir - @sources.each do |src| - if Dir.exists? src - Dir.glob("#{src}/**/*", File::FNM_DOTMATCH).select do |f| - File.file?(f) - end.each do |subfile| - subpath = Pathname.new(subfile).relative_path_from(Pathname.new(src)).to_s - file_map[subfile] = "#{outdir}/#{subpath}" - end - else - file_map[src] = "#{outdir}/#{File.basename(src)}" - end - end - else - file_map[sources.first] = target - end - printed_message = false - file_map.each do |src, dest| - # Check the cache and copy if necessary - unless @cache.up_to_date?(dest, :Copy, [src], @env) - unless printed_message - message = "#{name} #{Util.short_format_paths(@sources)} => #{@target}" - print_run_message(message, nil) - printed_message = true - end - @cache.mkdir_p(File.dirname(dest), install: @install_builder) - FileUtils.rm_f(dest) - FileUtils.cp(src, dest, :preserve => true) - end - @cache.register_build(dest, :Copy, [src], @env, install: @install_builder) - end - (target_is_dir ? Dir.exists?(@target) : File.exists?(@target)) ? true : false + file_map[sources.first] = target end + printed_message = false + file_map.each do |src, dest| + # Check the cache and copy if necessary + unless @cache.up_to_date?(dest, :Copy, [src], @env) + unless printed_message + message = "#{name} #{Util.short_format_paths(@sources)} => #{@target}" + print_run_message(message, nil) + printed_message = true + end + @cache.mkdir_p(File.dirname(dest), install: @install_builder) + FileUtils.rm_f(dest) + FileUtils.cp(src, dest, :preserve => true) + end + @cache.register_build(dest, :Copy, [src], @env, install: @install_builder) + end + (target_is_dir ? Dir.exists?(@target) : File.exists?(@target)) ? true : false end end diff --git a/lib/rscons/builders/directory.rb b/lib/rscons/builders/directory.rb index 10b61b9..c6e321f 100644 --- a/lib/rscons/builders/directory.rb +++ b/lib/rscons/builders/directory.rb @@ -8,32 +8,19 @@ module Rscons def initialize(*args) super @install_builder = self.class.name == "InstallDirectory" - @nop = @install_builder && !Rscons.application.operation("install") - end - - # Return whether the builder is a no-op. - # - # @return [Boolean] - # Whether the builder is a no-op. - def nop? - @nop end # Run the builder to produce a build target. def run(options) - if @nop + if File.directory?(@target) true + elsif File.exists?(@target) + Ansi.write($stderr, :red, "Error: `#{@target}' already exists and is not a directory", :reset, "\n") + false else - if File.directory?(@target) - true - elsif File.exists?(@target) - Ansi.write($stderr, :red, "Error: `#{@target}' already exists and is not a directory", :reset, "\n") - false - else - print_run_message("Creating directory #{@target}", nil) - @cache.mkdir_p(@target, install: @install_builder) - true - end + print_run_message("Creating directory #{@target}", nil) + @cache.mkdir_p(@target, install: @install_builder) + true end end diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 240aa40..560a2e4 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -586,9 +586,7 @@ module Rscons # # @return [void] def run_builder(builder) - unless builder.nop? - builder.build_step ||= Rscons.application.get_next_build_step - end + builder.build_step ||= Rscons.application.get_next_build_step case result = builder.run({}) when Array result.each do |waititem|