From e416c54b985832c25f0e7861a3c295303ffb9da1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 21 May 2024 12:22:16 +0200 Subject: Use new thread-specific current working directory in testscript implementation In particular, this makes sure functions like $path.complete() work correctly from testscripts. --- libbuild2/test/script/parser.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libbuild2') diff --git a/libbuild2/test/script/parser.cxx b/libbuild2/test/script/parser.cxx index b712c21..337b162 100644 --- a/libbuild2/test/script/parser.cxx +++ b/libbuild2/test/script/parser.cxx @@ -1609,6 +1609,17 @@ namespace build2 { runner_->enter (*scope_, scope_->start_loc_); + // Set thread-specific current directory override. In particular, this + // makes sure functions like $path.complete() work correctly. + // + auto wdg = make_guard ( + [old = path_traits::thread_current_directory ()] () + { + path_traits::thread_current_directory (old); + }); + + path_traits::thread_current_directory (&scope_->work_dir.path->string ()); + // Note that we rely on "small function object" optimization for the // exec_*() lambdas. // -- cgit v1.1