Class: Rscons::Builders::Copy
- Inherits:
-
Rscons::Builder
- Object
- Rscons::Builder
- Rscons::Builders::Copy
- Defined in:
- lib/rscons/builders/copy.rb
Overview
The Copy builder copies files/directories to new locations.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Rscons::Builder
#build_step, #cache, #env, #preferred_ld, #side_effects, #sources, #target, #vars
Instance Method Summary collapse
-
#initialize(*args) ⇒ Copy
constructor
Construct builder.
-
#run(options) ⇒ Object
Run the builder to produce a build target.
Methods inherited from Rscons::Builder
#depends, extra_path, #finalize_command, name, #name, #print_run_message, #produces, #register_command, #standard_command, #wait_for
Constructor Details
#initialize(*args) ⇒ Copy
Construct builder.
9 10 11 12 |
# File 'lib/rscons/builders/copy.rb', line 9 def initialize(*args) super @install_builder = self.class.name == "Install" end |
Instance Method Details
#run(options) ⇒ Object
Run the builder to produce a build target.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rscons/builders/copy.rb', line 15 def run() target_is_dir = (@sources.length > 1) || Dir.exist?(@sources.first) || Dir.exist?(@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.exist? 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 = false file_map.each do |src, dest| # Check the cache and copy if necessary unless @cache.up_to_date?(dest, :Copy, [src], @env) unless = "#{name} <source>#{Util.short_format_paths(@sources)}<reset> => <target>#{@target}<reset>" (, nil) = 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.exist?(@target) : File.exist?(@target)) ? true : false end |