aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/script.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-16 13:29:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:21 +0200
commit4230333bc5b32d30e35264b1104240bb5e2247ff (patch)
tree0e3873c012dcf83281ecb43c4cfe2780a794a25c /build2/test/script/script.cxx
parentd81ad6a0b20613ac77e115ca273cd48eaeeae1c8 (diff)
Implement testscript $*, $NN, $~ special variables
Diffstat (limited to 'build2/test/script/script.cxx')
-rw-r--r--build2/test/script/script.cxx49
1 files changed, 31 insertions, 18 deletions
diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx
index b206e4f..2be023d 100644
--- a/build2/test/script/script.cxx
+++ b/build2/test/script/script.cxx
@@ -15,32 +15,45 @@ namespace build2
namespace script
{
script::
- script (target& tt, target& st)
- : test_target (tt), script_target (st)
+ script (target& tt, testscript& st)
+ : test_target (tt), script_target (st),
+
+ // Enter the test* variables with the same variable types as in
+ // buildfiles.
+ //
+ test_var (var_pool.insert<path> ("test")),
+ opts_var (var_pool.insert<strings> ("test.options")),
+ args_var (var_pool.insert<strings> ("test.arguments")),
+
+ cmd_var (var_pool.insert<strings> ("*")),
+ cwd_var (var_pool.insert<dir_path> ("~"))
{
// Unless we have the test variable set on the test or script target,
// set it at the script level to the test target's path.
//
+ if (!find (test_var))
{
- // Note: use the same variable type as in buildfile.
+ value& v (assign (test_var));
+
+ // If this is a path-based target, then we use the path. If this
+ // is a directory (alias) target, then we use the directory path.
+ // Otherwise, we leave it NULL expecting the testscript to set it
+ // to something appropriate, if used.
//
- const variable& var (var_pool.insert<path> ("test"));
+ if (auto* p = tt.is_a<path_target> ())
+ v = p->path ();
+ else if (tt.is_a<dir> ())
+ v = path (tt.dir.string ()); // Strip trailing slash.
+ }
- if (!find (var))
- {
- value& v (assign (var));
+ // Also add the NULL $* value that signals it needs to be recalculated
+ // on first access.
+ //
+ assign (cmd_var) = nullptr;
- // If this is a path-based target, then we use the path. If this
- // is a directory (alias) target, then we use the directory path.
- // Otherwise, we leave it NULL expecting the testscript to set it
- // to something appropriate, if used.
- //
- if (auto* p = tt.is_a<path_target> ())
- v = p->path ();
- else if (tt.is_a<dir> ())
- v = path (tt.dir.string ()); // Strip trailing slash.
- }
- }
+ // Set the script CWD ($~) which is the $out_base/<script-name>.
+ //
+ assign (cwd_var) = dir_path (tt.out_dir ()) /= st.name;
}
lookup scope::