From c08a2243b9f1752e3c16a69518729c160cb91f2c Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 5 May 2014 16:22:07 -0400 Subject: [PATCH] add Environment#expand_path --- lib/rscons/environment.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/rscons/environment.rb b/lib/rscons/environment.rb index 563c037..a2de2d9 100644 --- a/lib/rscons/environment.rb +++ b/lib/rscons/environment.rb @@ -337,22 +337,30 @@ module Rscons builder.run(target, sources, cache, self, vars) end + # Expand a path to be relative to the Environment's build root. + # + # Paths beginning with "^/" are expanded by replacing "^" with the + # Environment's build root. + # + # @param path [String] The path to expand. + # + # @return [String] The expanded path. + def expand_path(path) + path.sub(%r{^\^(?=[\\/])}, @build_root) + end + private # Expand all target paths that begin with ^/ to be relative to the # Environment's build root, if present def clean_target_paths! if @build_root - expand = lambda do |path| - path.sub(%r{^\^(?=[\\/])}, @build_root) - end - new_targets = {} @targets.each_pair do |target, target_params| target_params[:sources].map! do |source| - expand[source] + expand_path(source) end - new_targets[expand[target]] = target_params + new_targets[expand_path(target)] = target_params end @targets = new_targets end