Compare commits

..
5 Commits
4 changed files with 62 additions and 16 deletions

No files matched your search

+9
View File
@@ -329,6 +329,15 @@ http://rubydoc.info/github/holtrop/rscons/frames.
## Release Notes ## Release Notes
### v1.4.2
- add Environment#expand_path
- expand construction variable references in builder targets and sources before invoking builder
### v1.4.1
- fix invoking a builder with no sources while a build root defined
### v1.4.0 ### v1.4.0
- add CFile builder - add CFile builder
+26 -15
View File
@@ -172,7 +172,7 @@ module Rscons
# called after the block returns. # called after the block returns.
def process def process
unless @targets.empty? unless @targets.empty?
clean_target_paths! expand_paths!
cache = Cache.instance cache = Cache.instance
cache.clear_checksum_cache! cache.clear_checksum_cache!
targets_processed = {} targets_processed = {}
@@ -337,24 +337,35 @@ module Rscons
builder.run(target, sources, cache, self, vars) builder.run(target, sources, cache, self, vars)
end end
private # Expand a path to be relative to the Environment's build root.
#
# Expand all target paths that begin with ^/ to be relative to the # Paths beginning with "^/" are expanded by replacing "^" with the
# Environment's build root, if present # Environment's build root.
def clean_target_paths! #
if @build_root # @param path [String] The path to expand.
expand = lambda do |path| #
# @return [String] The expanded path.
def expand_path(path)
path.sub(%r{^\^(?=[\\/])}, @build_root) path.sub(%r{^\^(?=[\\/])}, @build_root)
end end
new_targets = {} private
@targets.each_pair do |target, target_params|
target_params[:sources].map! do |source| # Expand target and source paths before invoking builders.
expand[source] #
# This method expand construction variable references in the target and
# source file names before passing them to the builder. It also expands
# "^/" prefixes to the Environment's build root if a build root is defined.
def expand_paths!
@targets = @targets.reduce({}) do |result, (target, target_params)|
sources = target_params[:sources].map do |source|
source = expand_path(source) if @build_root
expand_varref(source)
end end
new_targets[expand[target]] = target_params target = expand_path(target) if @build_root
end target = expand_varref(target)
@targets = new_targets result[target] = target_params.merge(sources: sources)
result
end end
end end
+1 -1
View File
@@ -1,4 +1,4 @@
module Rscons module Rscons
# gem version # gem version
VERSION = "1.4.1" VERSION = "1.4.2"
end end
+26
View File
@@ -498,4 +498,30 @@ EOF
env.TestBuilder("file") env.TestBuilder("file")
end end
end end
it "expands construction variables in builder target and sources before invoking the builder" do
test_dir('custom_builder')
class MySource < Rscons::Builder
def run(target, sources, cache, env, vars)
File.open(target, 'w') do |fh|
fh.puts <<EOF
#define THE_VALUE 678
EOF
end
target
end
end
Rscons::Environment.new do |env|
env["hdr"] = "inc.h"
env["src"] = "program.c"
env.add_builder(MySource.new)
env.MySource('${hdr}')
env.Program('program', "${src}")
end
lines.should == ['CC program.o', 'LD program']
File.exists?('inc.h').should be_true
`./program`.should == "The value is 678\n"
end
end end