Compare commits

...
3 Commits
Author SHA1 Message Date
josh 4d7ed373e7 v0.2.0 2013-11-08 15:45:35 -05:00
josh 72558391a2 clarify documentation about cloning Environments 2013-11-08 15:45:24 -05:00
josh d01767981c add Environment#build_root to be used if no build directories match 2013-11-08 14:52:39 -05:00
4 changed files with 40 additions and 10 deletions

No files matched your search

+3 -3
View File
@@ -127,9 +127,9 @@ An Rscons::Environment consists of:
* a collection of targets to build * a collection of targets to build
* a collection of build hooks * a collection of build hooks
When cloning an environment, the construction variables, builders, and build When cloning an environment, the construction variables and builders are
directories are cloned, but the new environment does not inherit any of the cloned, but the new environment does not inherit any of the targets, build
targets or build hooks from the source environment. hooks, build directories, or the build root from the source environment.
Cloned environments contain "deep copies" of construction variables. Cloned environments contain "deep copies" of construction variables.
For example, in: For example, in:
+14 -6
View File
@@ -9,6 +9,9 @@ module Rscons
# Hash of +{"builder_name" => builder_object}+ pairs. # Hash of +{"builder_name" => builder_object}+ pairs.
attr_reader :builders attr_reader :builders
# String or +nil+
attr_accessor :build_root
# Create an Environment object. # Create an Environment object.
# @param variables [Hash] # @param variables [Hash]
# The variables hash can contain construction variables, which are # The variables hash can contain construction variables, which are
@@ -42,10 +45,10 @@ module Rscons
# Make a copy of the Environment object. # Make a copy of the Environment object.
# The cloned environment will contain a copy of all environment options, # The cloned environment will contain a copy of all environment options,
# construction variables, builders, and build directories. It will not # construction variables, and builders. It will not contain a copy of the
# contain a copy of the targets or build hooks. # targets, build hooks, build directories, or the build root. If a block
# If a block is given, the Environment object is yielded to the block and # is given, the Environment object is yielded to the block and when the
# when the block returns, the {#process} method is automatically called. # block returns, the {#process} method is automatically called.
def clone(variables = {}) def clone(variables = {})
env = Environment.new() env = Environment.new()
@builders.each do |builder_name, builder| @builders.each do |builder_name, builder|
@@ -88,14 +91,19 @@ module Rscons
# This method takes into account the Environment's build directories. # This method takes into account the Environment's build directories.
def get_build_fname(source_fname, suffix) def get_build_fname(source_fname, suffix)
build_fname = source_fname.set_suffix(suffix).gsub('\\', '/') build_fname = source_fname.set_suffix(suffix).gsub('\\', '/')
@build_dirs.each do |src_dir, obj_dir| found_match = @build_dirs.find do |src_dir, obj_dir|
if src_dir.is_a?(Regexp) if src_dir.is_a?(Regexp)
build_fname.sub!(src_dir, obj_dir) build_fname.sub!(src_dir, obj_dir)
else else
build_fname.sub!(%r{^#{src_dir}/}, "#{obj_dir}/") build_fname.sub!(%r{^#{src_dir}/}, "#{obj_dir}/")
end end
build_fname.gsub!('\\', '/')
end end
if @build_root and not found_match
unless source_fname.start_with?('/') or source_fname =~ %r{^\w:[\\/]}
build_fname = "#{@build_root}/#{build_fname}"
end
end
build_fname.gsub!('\\', '/')
build_fname build_fname
end end
+1 -1
View File
@@ -1,4 +1,4 @@
module Rscons module Rscons
# gem version # gem version
VERSION = "0.1.0" VERSION = "0.2.0"
end end
+22
View File
@@ -158,6 +158,28 @@ describe Rscons do
File.exists?('build_two/two.o').should be_true File.exists?('build_two/two.o').should be_true
end end
it 'uses build directories before build root' do
test_dir('build_dir')
Rscons::Environment.new do |env|
env.append('CPPPATH' => Dir['src/**/*/'])
env.build_dir("src", "build")
env.build_root = "build_root"
env.Program('build_dir', Dir['src/**/*.c'])
end
lines.should == ["CC build/one/one.o", "CC build/two/two.o", "LD build_dir"]
end
it 'uses build_root if no build directories match' do
test_dir('build_dir')
Rscons::Environment.new do |env|
env.append('CPPPATH' => Dir['src/**/*/'])
env.build_dir("src2", "build")
env.build_root = "build_root"
env.Program('build_dir', Dir['src/**/*.c'])
end
lines.should == ["CC build_root/src/one/one.o", "CC build_root/src/two/two.o", "LD build_dir"]
end
it 'cleans built files' do it 'cleans built files' do
test_dir('build_dir') test_dir('build_dir')
Rscons::Environment.new do |env| Rscons::Environment.new do |env|