mirror of
https://github.com/boostorg/build.git
synced 2026-02-16 13:22:11 +00:00
Cleanup path.glob and make it handle absolute paths without infinite looping.
[SVN r28018]
This commit is contained in:
@@ -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) ;
|
||||
}
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user