diff --git a/v2/util/path.jam b/v2/util/path.jam index 29b1e96e3..9d007af14 100644 --- a/v2/util/path.jam +++ b/v2/util/path.jam @@ -204,20 +204,27 @@ rule pwd ( ) rule glob ( dirs * : patterns + ) { local result ; - if $(patterns:D) + for local d in $(dirs) { - # When a pattern has a directory element, we first glob for - # directory, and then glob for file name is the found directories. for local p in $(patterns) { - # First glob for directory part. - local globbed-dirs = [ glob $(dirs) : $(p:D) ] ; - result += [ glob $(globbed-dirs) : $(p:D="") ] ; + local pattern = [ path.root $(p) $(d) ] ; + result += [ glob-really $(pattern) ] ; } - } - else - { - # When a pattern has not directory, we glob directly. + } + + # Windows is not case-sensitive, so if you're globbing + # for Jamroot and jamroot, the result will include 'Jamroot' + # twice. Remove duplicates. + return [ sequence.unique $(result) ] ; +} + +# Looks for file matching 'pattern' in 'directory'. +# Does not recurse. +rule glob-one ( dir : p ) +{ + local result ; + # When a pattern has not directory, we glob directly. # Take care of special ".." value. The "GLOB" rule simply ignores # the ".." element (and ".") element in directory listings. This is # needed so that @@ -231,26 +238,54 @@ rule glob ( dirs * : patterns + ) # On the other hand, when ".." is explicitly present in the pattern # we need to return it. # - for local dir in $(dirs) + + if $(p) != ".." + { + result += [ sequence.transform make + : [ GLOB [ native $(dir) ] : $(p) ] ] ; + } + else + { + result += [ path.join $(dir) .. ] ; + } +} + + + +rule glob-really ( pattern ) +{ + local result ; + # The second condition protects again looping infinitely + # on '/' path. + if $(pattern:D) && $(pattern:D) != $(pattern) + { + # When the pattern has a directory element, we first glob for + # directory, and then glob for file name is the found directories. + + # First glob for directory part. + local globbed-dirs = [ glob-really $(pattern:D) ] ; + + for local dir in $(globbed-dirs) { - for local p in $(patterns) - { - if $(p) != ".." - { - result += [ sequence.transform make - : [ GLOB [ native $(dir) ] : $(p) ] ] ; - } - else - { - result += [ path.join $(dir) .. ] ; - } - } + local x = [ glob-one $(dir) : $(pattern:D="") ] ; + result += $(x) ; + } + } + else + { + if $(pattern:D) = $(pattern) + { + # Just return the result. + # FIXME: Maybe need to check that the directory + # is indeed present. + result = $(pattern) ; + } + else + { + result = [ glob-one . : $(pattern) ] ; } } - # Windows is not case-sensitive, so if you're globbing - # for Jamroot and jamroot, the result will include 'Jamroot' - # twice. Remove duplicates. - return [ sequence.unique $(result) ] ; + return $(result) ; } #