diff --git a/boost-base.jam b/boost-base.jam index 6cf3edb6a..45a561f80 100644 --- a/boost-base.jam +++ b/boost-base.jam @@ -1363,6 +1363,33 @@ rule top-relative-tokens return [ simplify-path-tokens $(SUBDIR_TOKENS) [ split-path $(<) ] ] ; } +.project-root-tokens = [ split-path $(.boost-build-file:D) ] ; + +# try to make a potentially absolute path relative to the project +# root. Only works for paths below the project root right now; others +# will remain absolute. +rule relative-path ( path ) +{ + local path-tokens = [ split-path $(path) ] ; + + # try to strip the project root + local r = $(.project-root-tokens) ; + local p = $(path-tokens) ; + while $(r) && ( $(r[1]) = $(p[1]) ) + { + p = $(p[2-]) ; + r = $(r[2-]) ; + } + + # if successful, use the stripped project root + if ! $(r) + { + path-tokens = $(p) ; + } + + return [ tokens-to-simple-path $(path-tokens) ] ; +} + # dependent-include target-path... # # For each target-path, ensure that the appropriate Jamfile has been diff --git a/testing.jam b/testing.jam index d2d8d1b59..35f0503ee 100755 --- a/testing.jam +++ b/testing.jam @@ -48,28 +48,8 @@ rule boost-test ( sources + : target-type : requirements * : test-name ? : defau if ( --dump-tests in $(ARGV) ) { - local srcs = [ on $(result) get-var-value source-files ] ; - local source-files ; - for local s in $(srcs) - { - source-files += [ - SEARCH_FOR_TARGET $(s:G=) - : [ on $(s) get-var-value LOCATE SEARCH ] - ] ; - } - - # Extract values of the feature - local dump-test-info = [ get-values : $(requirements) ] ; - - # Format them into a single string of quoted strings - dump-test-info = \"$(dump-test-info:J=\"\ \")\" ; - - ECHO boost-test($(target-type)) \"$(test-name)\" - [$(dump-test-info)] - ":" \"$(source-files)\" - ; + dump-test ; } - } Clean clean : $(result) ; @@ -88,6 +68,54 @@ rule boost-test ( sources + : target-type : requirements * : test-name ? : defau } } + + + +# Helper for boost-test above. Uses dynamic scoping to access +# boost-test's locals. +local rule dump-test ( ) +{ + local srcs = [ on $(result) get-var-value source-files ] ; + + # locate each source file + local source-files ; + for local s in $(srcs) + { + # find out where to look for the file + local paths = [ on $(s) get-var-value LOCATE SEARCH ] ; + + s = $(s:G=) ; # strip grist + + # build all the potential full paths of the file + local full-paths = $(s:R=$(paths)) ; + + # look there + local files = [ GLOB $(full-paths:D) : $(s:D=) ] ; + + if $(files) + { + # make relative to the project root instead of "." + local file = $(files[1]:R=$(SUBDIR_TOKENS:J=/) ; + + # try to undo absolute paths + source-files += [ relative-path $(file)) ] ; + } + } + + # Extract values of the feature + local dump-test-info = [ get-values : $(requirements) ] ; + + # Format them into a single string of quoted strings + dump-test-info = \"$(dump-test-info:J=\"\ \")\" ; + + ECHO boost-test($(target-type)) \"$(test-name)\" + [$(dump-test-info)] + ":" \"$(source-files)\" + ; + +} + + ####### BOOST_TEST_SUFFIX ?= .test ; diff --git a/v1/boost-base.jam b/v1/boost-base.jam index 6cf3edb6a..45a561f80 100644 --- a/v1/boost-base.jam +++ b/v1/boost-base.jam @@ -1363,6 +1363,33 @@ rule top-relative-tokens return [ simplify-path-tokens $(SUBDIR_TOKENS) [ split-path $(<) ] ] ; } +.project-root-tokens = [ split-path $(.boost-build-file:D) ] ; + +# try to make a potentially absolute path relative to the project +# root. Only works for paths below the project root right now; others +# will remain absolute. +rule relative-path ( path ) +{ + local path-tokens = [ split-path $(path) ] ; + + # try to strip the project root + local r = $(.project-root-tokens) ; + local p = $(path-tokens) ; + while $(r) && ( $(r[1]) = $(p[1]) ) + { + p = $(p[2-]) ; + r = $(r[2-]) ; + } + + # if successful, use the stripped project root + if ! $(r) + { + path-tokens = $(p) ; + } + + return [ tokens-to-simple-path $(path-tokens) ] ; +} + # dependent-include target-path... # # For each target-path, ensure that the appropriate Jamfile has been diff --git a/v1/testing.jam b/v1/testing.jam index d2d8d1b59..35f0503ee 100755 --- a/v1/testing.jam +++ b/v1/testing.jam @@ -48,28 +48,8 @@ rule boost-test ( sources + : target-type : requirements * : test-name ? : defau if ( --dump-tests in $(ARGV) ) { - local srcs = [ on $(result) get-var-value source-files ] ; - local source-files ; - for local s in $(srcs) - { - source-files += [ - SEARCH_FOR_TARGET $(s:G=) - : [ on $(s) get-var-value LOCATE SEARCH ] - ] ; - } - - # Extract values of the feature - local dump-test-info = [ get-values : $(requirements) ] ; - - # Format them into a single string of quoted strings - dump-test-info = \"$(dump-test-info:J=\"\ \")\" ; - - ECHO boost-test($(target-type)) \"$(test-name)\" - [$(dump-test-info)] - ":" \"$(source-files)\" - ; + dump-test ; } - } Clean clean : $(result) ; @@ -88,6 +68,54 @@ rule boost-test ( sources + : target-type : requirements * : test-name ? : defau } } + + + +# Helper for boost-test above. Uses dynamic scoping to access +# boost-test's locals. +local rule dump-test ( ) +{ + local srcs = [ on $(result) get-var-value source-files ] ; + + # locate each source file + local source-files ; + for local s in $(srcs) + { + # find out where to look for the file + local paths = [ on $(s) get-var-value LOCATE SEARCH ] ; + + s = $(s:G=) ; # strip grist + + # build all the potential full paths of the file + local full-paths = $(s:R=$(paths)) ; + + # look there + local files = [ GLOB $(full-paths:D) : $(s:D=) ] ; + + if $(files) + { + # make relative to the project root instead of "." + local file = $(files[1]:R=$(SUBDIR_TOKENS:J=/) ; + + # try to undo absolute paths + source-files += [ relative-path $(file)) ] ; + } + } + + # Extract values of the feature + local dump-test-info = [ get-values : $(requirements) ] ; + + # Format them into a single string of quoted strings + dump-test-info = \"$(dump-test-info:J=\"\ \")\" ; + + ECHO boost-test($(target-type)) \"$(test-name)\" + [$(dump-test-info)] + ":" \"$(source-files)\" + ; + +} + + ####### BOOST_TEST_SUFFIX ?= .test ;