From 934f2a9a90c5cad3cdc8a66b50c17827a3ddbcee Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 20 Jan 2018 13:46:11 +0200 Subject: Get rid of action rule override semantics Instead we now have two more or less separate match states for outer and inner parts of an action. --- build2/test/init.cxx | 111 +++++++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 48 deletions(-) (limited to 'build2/test/init.cxx') diff --git a/build2/test/init.cxx b/build2/test/init.cxx index 6119ae0..556de00 100644 --- a/build2/test/init.cxx +++ b/build2/test/init.cxx @@ -23,7 +23,7 @@ namespace build2 namespace test { bool - boot (scope& rs, const location&, unique_ptr&) + boot (scope& rs, const location&, unique_ptr& mod) { tracer trace ("test::boot"); @@ -38,53 +38,78 @@ namespace build2 // auto& vp (var_pool.rw (rs)); - // Tests to execute. - // - // Specified as @ pairs with both sides being optional. - // The variable is untyped (we want a list of name-pairs), overridable, - // and inheritable. The target is relative (in essence a prerequisite) - // which is resolved from the (root) scope where the config.test value - // is defined. - // - vp.insert ("config.test", true); + common_data d { - // Test working directory before/after cleanup (see Testscript spec for - // semantics). - // - vp.insert ("config.test.output", true); + // Tests to execute. + // + // Specified as @ pairs with both sides being + // optional. The variable is untyped (we want a list of name-pairs), + // overridable, and inheritable. The target is relative (in essence a + // prerequisite) which is resolved from the (root) scope where the + // config.test value is defined. + // + vp.insert ("config.test", true), - // Note: none are overridable. - // - // The test variable is a name which can be a path (with the - // true/false special values) or a target name. - // - vp.insert ("test", variable_visibility::target); - vp.insert ("test.input", variable_visibility::project); - vp.insert ("test.output", variable_visibility::project); - vp.insert ("test.roundtrip", variable_visibility::project); - vp.insert ("test.options", variable_visibility::project); - vp.insert ("test.arguments", variable_visibility::project); + // Test working directory before/after cleanup (see Testscript spec + // for semantics). + // + vp.insert ("config.test.output", true), + + // The test variable is a name which can be a path (with the + // true/false special values) or a target name. + // + // Note: none are overridable. + // + vp.insert ("test", variable_visibility::target), + vp.insert ("test.options", variable_visibility::project), + vp.insert ("test.arguments", variable_visibility::project), + + // Prerequisite-specific. + // + // test.stdin and test.stdout can be used to mark a prerequisite as a + // file to redirect stdin from and to compare stdout to, respectively. + // test.roundtrip is a shortcut to mark a prerequisite as both stdin + // and stdout. + // + // Prerequisites marked with test.input are treated as additional test + // inputs: they are made sure to be up to date and their paths are + // passed as additional command line arguments (after test.options and + // test.arguments). Their primary use is to pass inputs that may have + // varying file names/paths, for example: + // + // exe{parent}: exe{child}: test.input = true + // + // Note that currently this mechanism is only available to simple + // tests though we could also support it for testscript (e.g., by + // appending the input paths to test.arguments or by passing them in a + // separate test.inputs variable). + // + vp.insert ("test.stdin", variable_visibility::target), + vp.insert ("test.stdout", variable_visibility::target), + vp.insert ("test.roundtrip", variable_visibility::target), + vp.insert ("test.input", variable_visibility::target), + + // Test target platform. + // + vp.insert ("test.target", variable_visibility::project) + }; // These are only used in testscript. // vp.insert ("test.redirects", variable_visibility::project); vp.insert ("test.cleanups", variable_visibility::project); - // Test target platform. - // // Unless already set, default test.target to build.host. Note that it // can still be overriden by the user, e.g., in root.build. // { - value& v ( - rs.assign ( - vp.insert ( - "test.target", variable_visibility::project))); + value& v (rs.assign (d.test_target)); if (!v || v.empty ()) v = cast ((*global_scope)["build.host"]); } + mod.reset (new module (move (d))); return false; } @@ -108,8 +133,7 @@ namespace build2 const dir_path& out_root (rs.out_path ()); l5 ([&]{trace << "for " << out_root;}); - assert (mod == nullptr); - mod.reset (new module ()); + assert (mod != nullptr); module& m (static_cast (*mod)); // Configure. @@ -123,7 +147,7 @@ namespace build2 // config.test // - if (lookup l = config::omitted (rs, "config.test").first) + if (lookup l = config::omitted (rs, m.config_test).first) { // Figure out which root scope it came from. // @@ -139,7 +163,7 @@ namespace build2 // config.test.output // - if (lookup l = config::omitted (rs, "config.test.output").first) + if (lookup l = config::omitted (rs, m.config_test_output).first) { const name_pair& p (cast (l)); @@ -180,22 +204,13 @@ namespace build2 t.insert (); } - // Register rules. + // Register our test running rule. // { - const rule& r (m); - const alias_rule& ar (m); + default_rule& dr (m); - // Register our test running rule. - // - rs.rules.insert (perform_test_id, "test", r); - rs.rules.insert (perform_test_id, "test", ar); - - // Register our rule for the dist meta-operation. We need to do this - // because we may have ad hoc prerequisites (test input/output files) - // that need to be entered into the target list. - // - rs.rules.insert (dist_id, test_id, "test", r); + rs.rules.insert (perform_test_id, "test", dr); + rs.rules.insert (perform_test_id, "test", dr); } return true; -- cgit v1.1