diff --git a/new/path.jam b/new/path.jam index 6d00c60cf..f35a434d1 100644 --- a/new/path.jam +++ b/new/path.jam @@ -260,34 +260,35 @@ rule glob ( dir : patterns + ) rule all-parents ( path : upper_limit ? : cwd ? ) { cwd ?= [ pwd ] ; - local rpath = [ root $(path) $(cwd) ] ; + local path_ele = [ regex.split [ root $(path) $(cwd) ] "/" ] ; if ! $(upper_limit) { upper_limit = / ; - } - upper_limit = [ root $(upper_limit) $(cwd) ] ; - - # Leave only directory names below 'upper_limits' - # Assure pruned_path[2] will have no leading '/' - local pruned_path = [ regex.match "($(upper_limit))/*(.*)" : $(rpath) : 1 2 ] ; - if ! $(pruned_path) { - error "$(upper_limit) is not prefix of $(path)" ; } + local upper_ele = [ regex.split [ root $(upper_limit) $(cwd) ] "/" ] ; - if $(pruned_path[2]) - { - # Length of 'tokens' is equal to the number of paths to check. - local tokens = [ regex.split $(pruned_path[2]) "/" ] ; - + # Leave only elements in 'path_ele' below 'upper_ele' + while $(path_ele) && $(upper_ele[1]) = $(path_ele[1]) { + upper_ele = $(upper_ele[2-]) ; + path_ele = $(path_ele[2-]) ; + } + + # All upper elements removed ? + if ! $(upper_ele) { + # Create the relative paths to parents, number of elements in 'path_ele' local result ; - for local i in $(tokens) { + for local i in $(path_ele) { path = [ parent $(path) ] ; result += $(path) ; } return $(result) ; } + else { + error "$(upper_limit) is not prefix of $(path)" ; + } } + # # Search for 'pattern' in parent directories of 'dir', up till and including # 'upper_limit', if it is specified, or till the filesystem root otherwise. diff --git a/test/bad_dirname.py b/test/bad_dirname.py new file mode 100644 index 000000000..57e43abd7 --- /dev/null +++ b/test/bad_dirname.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + + +# Regression test: when directory of project root contained regex metacharacters, +# Boost.Build failed to work. Bug reported by Michael Stevens + +from BoostBuild import Tester, List + +t = Tester() + +t.write("bad[abc]dirname/Jamfile", """ +""") + +t.write("bad[abc]dirname/project-root.jam", """ +""") + +t.run_build_system(subdir="bad[abc]dirname") + +t.cleanup() + diff --git a/test/test_all.py b/test/test_all.py index 6428f0b90..2b1386cd0 100644 --- a/test/test_all.py +++ b/test/test_all.py @@ -95,6 +95,7 @@ tests = [ "project_test1", "absolute_sources", "dependency_property", "custom_generator", + "bad_dirname", ] if os.name == 'posix': diff --git a/v2/test/bad_dirname.py b/v2/test/bad_dirname.py new file mode 100644 index 000000000..57e43abd7 --- /dev/null +++ b/v2/test/bad_dirname.py @@ -0,0 +1,25 @@ +#!/usr/bin/python + +# Copyright (C) Vladimir Prus 2003. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + + +# Regression test: when directory of project root contained regex metacharacters, +# Boost.Build failed to work. Bug reported by Michael Stevens + +from BoostBuild import Tester, List + +t = Tester() + +t.write("bad[abc]dirname/Jamfile", """ +""") + +t.write("bad[abc]dirname/project-root.jam", """ +""") + +t.run_build_system(subdir="bad[abc]dirname") + +t.cleanup() + diff --git a/v2/test/test_all.py b/v2/test/test_all.py index 6428f0b90..2b1386cd0 100644 --- a/v2/test/test_all.py +++ b/v2/test/test_all.py @@ -95,6 +95,7 @@ tests = [ "project_test1", "absolute_sources", "dependency_property", "custom_generator", + "bad_dirname", ] if os.name == 'posix': diff --git a/v2/util/path.jam b/v2/util/path.jam index 6d00c60cf..f35a434d1 100644 --- a/v2/util/path.jam +++ b/v2/util/path.jam @@ -260,34 +260,35 @@ rule glob ( dir : patterns + ) rule all-parents ( path : upper_limit ? : cwd ? ) { cwd ?= [ pwd ] ; - local rpath = [ root $(path) $(cwd) ] ; + local path_ele = [ regex.split [ root $(path) $(cwd) ] "/" ] ; if ! $(upper_limit) { upper_limit = / ; - } - upper_limit = [ root $(upper_limit) $(cwd) ] ; - - # Leave only directory names below 'upper_limits' - # Assure pruned_path[2] will have no leading '/' - local pruned_path = [ regex.match "($(upper_limit))/*(.*)" : $(rpath) : 1 2 ] ; - if ! $(pruned_path) { - error "$(upper_limit) is not prefix of $(path)" ; } + local upper_ele = [ regex.split [ root $(upper_limit) $(cwd) ] "/" ] ; - if $(pruned_path[2]) - { - # Length of 'tokens' is equal to the number of paths to check. - local tokens = [ regex.split $(pruned_path[2]) "/" ] ; - + # Leave only elements in 'path_ele' below 'upper_ele' + while $(path_ele) && $(upper_ele[1]) = $(path_ele[1]) { + upper_ele = $(upper_ele[2-]) ; + path_ele = $(path_ele[2-]) ; + } + + # All upper elements removed ? + if ! $(upper_ele) { + # Create the relative paths to parents, number of elements in 'path_ele' local result ; - for local i in $(tokens) { + for local i in $(path_ele) { path = [ parent $(path) ] ; result += $(path) ; } return $(result) ; } + else { + error "$(upper_limit) is not prefix of $(path)" ; + } } + # # Search for 'pattern' in parent directories of 'dir', up till and including # 'upper_limit', if it is specified, or till the filesystem root otherwise.