lib/rscons/environment.rb in rscons-1.1.0 vs lib/rscons/environment.rb in rscons-1.2.0

- old
+ new

@@ -1,10 +1,10 @@ require 'set' require 'fileutils' module Rscons - # The Environment class is the main programmatic interface to RScons. It + # The Environment class is the main programmatic interface to Rscons. It # contains a collection of construction variables, options, builders, and # rules for building targets. class Environment # Hash of +{"builder_name" => builder_object}+ pairs. attr_reader :builders @@ -13,11 +13,12 @@ attr_accessor :echo # String or +nil+ attr_reader :build_root def build_root=(build_root) - @build_root = build_root.gsub('\\', '/') + @build_root = build_root + @build_root.gsub!('\\', '/') if @build_root end # Create an Environment object. # @param options [Hash] # Possible options keys: @@ -48,28 +49,57 @@ self.process end end # Make a copy of the Environment object. - # The cloned environment will contain a copy of all environment options, - # construction variables, and builders (unless :exclude_builders => true is - # passed as an option). It will not contain a copy of the targets, build - # hooks, build directories, or the build root. If a block is given, the - # Environment object is yielded to the block and when the block returns, - # the {#process} method is automatically called. The possible options keys - # match those documented in the #initialize method. + # + # By default, a cloned environment will contain a copy of all environment + # options, construction variables, and builders, but not a copy of the + # targets, build hooks, build directories, or the build root. + # + # Exactly which items are cloned are controllable via the optional :clone + # parameter, which can be :none, :all, or a set or array of any of the + # following: + # - :variables to clone construction variables (on by default) + # - :builders to clone the builders (on by default) + # - :build_root to clone the build root (off by default) + # - :build_dirs to clone the build directories (off by default) + # - :build_hooks to clone the build hooks (off by default) + # + # If a block is given, the Environment object is yielded to the block and + # when the block returns, the {#process} method is automatically called. + # + # Any options that #initialize receives can also be specified here. + # + # @return a new {Environment} object. def clone(options = {}) + clone = options[:clone] || Set[:variables, :builders] + clone = Set[:variables, :builders, :build_root, :build_dirs, :build_hooks] if clone == :all + clone = Set[] if clone == :none + clone = Set.new(clone) if clone.is_a?(Array) + clone.delete(:builders) if options[:exclude_builders] env = self.class.new( echo: options[:echo] || @echo, build_root: options[:build_root], exclude_builders: true) - unless options[:exclude_builders] + if clone.include?(:builders) @builders.each do |builder_name, builder| env.add_builder(builder) end end - env.append(@varset.clone) + env.append(@varset.clone) if clone.include?(:variables) + env.build_root = @build_root if clone.include?(:build_root) + if clone.include?(:build_dirs) + @build_dirs.each do |src_dir, obj_dir| + env.build_dir(src_dir, obj_dir) + end + end + if clone.include?(:build_hooks) + @build_hooks.each do |build_hook_block| + env.add_build_hook(&build_hook_block) + end + end if block_given? yield env env.process end @@ -244,11 +274,11 @@ @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. + # This method is used internally by Rscons builders. # @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 a list of the converted file names. @@ -292,10 +322,10 @@ end builder.run(target, sources, cache, self, vars) end # Parse dependencies for a given target from a Makefile. - # This method is used internally by RScons builders. + # This method is used internally by Rscons builders. # @param mf_fname [String] File name of the Makefile to read. # @param target [String] Name of the target to gather dependencies for. def self.parse_makefile_deps(mf_fname, target) deps = [] buildup = ''