// file : build2/test/init.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2017 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #include #include #include #include #include #include #include #include #include using namespace std; using namespace butl; namespace build2 { namespace test { void boot (scope& rs, const location&, unique_ptr&) { tracer trace ("test::boot"); l5 ([&]{trace << "for " << rs.out_path ();}); // Register the test operation. // rs.operations.insert (test_id, test); // Enter module variables. Do it during boot in case they get assigned // in bootstrap.build. // 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); // Test working directory before/after cleanup (see Testscript spec for // semantics). // vp.insert ("config.test.output", 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); // 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))); if (!v || v.empty ()) v = cast ((*global_scope)["build.host"]); } } bool init (scope& rs, scope&, const location& l, unique_ptr& mod, bool first, bool, const variable_map& config_hints) { tracer trace ("test::init"); if (!first) { warn (l) << "multiple test module initializations"; return true; } const dir_path& out_root (rs.out_path ()); l5 ([&]{trace << "for " << out_root;}); assert (mod == nullptr); mod.reset (new module ()); module& m (static_cast (*mod)); // Configure. // assert (config_hints.empty ()); // We don't known any hints. // Adjust module priority so that the config.test.* values are saved at // the end of config.build. // config::save_module (rs, "test", INT32_MAX); // config.test // if (lookup l = config::omitted (rs, "config.test").first) { // Figure out which root scope it came from. // scope* s (&rs); for (; s != nullptr && !l.belongs (*s); s = s->parent_scope ()->root_scope ()) assert (s != nullptr); m.test_ = &cast (l); m.root_ = s; } // config.test.output // if (lookup l = config::omitted (rs, "config.test.output").first) { const name_pair& p (cast (l)); // If second half is empty, then first is the after value. // const name& a (p.second.empty () ? p.first : p.second); // after const name& b (p.second.empty () ? p.second : p.first); // before // Parse and validate. // if (!b.simple ()) fail << "invalid config.test.output before value '" << b << "'"; if (!a.simple ()) fail << "invalid config.test.output after value '" << a << "'"; if (a.value == "clean") m.after = output_after::clean; else if (a.value == "keep") m.after = output_after::keep; else fail << "invalid config.test.output after value '" << a << "'"; if (b.value == "fail") m.before = output_before::fail; else if (b.value == "warn") m.before = output_before::warn; else if (b.value == "clean") m.before = output_before::clean; else if (b.value == "") m.before = output_before::clean; else fail << "invalid config.test.output before value '" << b << "'"; } //@@ TODO: Need ability to specify extra diff options (e.g., // --strip-trailing-cr, now hardcoded). // //@@ TODO: Pring report. // Register target types. // { auto& t (rs.target_types); t.insert (); } // Register rules. // { const rule& r (m); const alias_rule& ar (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); } return true; } } }