diff --git a/src/tools/python.jam b/src/tools/python.jam index 66c05bb2b..e3cb287cc 100644 --- a/src/tools/python.jam +++ b/src/tools/python.jam @@ -613,7 +613,10 @@ rule capture-output ( target : sources * : properties * ) # over explicitly. RUN_PATH on $(sources[1]) = [ on $(sources[2]) return $(RUN_PATH) ] ; PYTHONPATH = [ on $(sources[2]) return $(LOCATE) ] ; - testing.capture-output $(target) : $(sources[1]) : $(properties) ; + # After test is run, we remove the Python module, but not the Python + # script. + testing.capture-output $(target) : $(sources[1]) : $(properties) + : $(sources[2]) ; local c = [ common.prepend-path-variable-command PYTHONPATH : $(PYTHONPATH) ] ; LAUNCHER on $(target) = $(c) [ on $(target) return $(PYTHON) ] ; } diff --git a/src/tools/testing.jam b/src/tools/testing.jam index f8d8b9076..53911b564 100644 --- a/src/tools/testing.jam +++ b/src/tools/testing.jam @@ -342,7 +342,14 @@ if --preserve-test-targets in $(argv) toolset.flags testing.capture-output ARGS ; toolset.flags testing.capture-output INPUT_FILES ; toolset.flags testing.capture-output LAUNCHER ; -rule capture-output ( target : source : properties * ) + +# Runs executable 'sources' and stores stdout in file 'target'. +# If --preserve-test-targets command line option, removes the executable. +# The 'target-to-remove' parameter controls what should be removed: +# - if 'none', does not remove anything, ever +# - if empty, removes 'source' +# - if non-empty and not 'none', contains a list of sources to remove. +rule capture-output ( target : source : properties * : targets-to-remove ? ) { output-file on $(target) = $(target:S=.output) ; LOCATE on $(target:S=.output) = [ on $(target) return $(LOCATE) ] ; @@ -358,13 +365,22 @@ rule capture-output ( target : source : properties * ) # before target is created. Therefore, they are bound using SEARCH setting # on them and not LOCATE setting of $(target), as in other case (due to jam bug). DEPENDS $(target) : [ on $(target) return $(INPUT_FILES) ] ; - + + if $(targets-to-remove) = none + { + targets-to-remove = ; + } + else if ! $(targets-to-remove) + { + targets-to-remove = $(source) ; + } + run-path-setup $(target) : $(source) : $(properties) ; if ! $(preserve-test-targets) { - TEMPORARY $(source) ; - RmTemps $(target) : $(source) ; + TEMPORARY $(targets-to-remove) ; + RmTemps $(target) : $(targets-to-remove) ; } }