diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-21 16:21:07 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-07-21 16:21:07 +0200 |
commit | a1cec9e0df14f3c1a833e2a447b5324ff9c430d3 (patch) | |
tree | e61c7e1cb3fa27ba435053761f5a2a3fb670f728 /build/test | |
parent | bead742dbac51088e89cdd4dd7a55aaa1d8c98d7 (diff) |
Test module genesis
Diffstat (limited to 'build/test')
-rw-r--r-- | build/test/module | 21 | ||||
-rw-r--r-- | build/test/module.cxx | 72 | ||||
-rw-r--r-- | build/test/operation | 18 | ||||
-rw-r--r-- | build/test/operation.cxx | 34 | ||||
-rw-r--r-- | build/test/rule | 32 | ||||
-rw-r--r-- | build/test/rule.cxx | 49 |
6 files changed, 226 insertions, 0 deletions
diff --git a/build/test/module b/build/test/module new file mode 100644 index 0000000..0b6af78 --- /dev/null +++ b/build/test/module @@ -0,0 +1,21 @@ +// file : build/test/module -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_TEST_MODULE +#define BUILD_TEST_MODULE + +#include <build/types> +#include <build/module> + +namespace build +{ + namespace test + { + extern "C" void + test_init ( + scope&, scope&, const location&, std::unique_ptr<module>&, bool); + } +} + +#endif // BUILD_TEST_MODULE diff --git a/build/test/module.cxx b/build/test/module.cxx new file mode 100644 index 0000000..d5ba754 --- /dev/null +++ b/build/test/module.cxx @@ -0,0 +1,72 @@ +// file : build/test/module.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <build/test/module> + +#include <build/scope> +#include <build/target> +#include <build/rule> +#include <build/diagnostics> + +#include <build/test/operation> +#include <build/test/rule> + +using namespace std; +using namespace butl; + +namespace build +{ + namespace test + { + class module: public build::module + { + public: + module (operation_id test_id): rule (test_id) {} + + test::rule rule; + }; + + extern "C" void + test_init (scope& root, + scope& base, + const location& l, + unique_ptr<build::module>& r, + bool first) + { + tracer trace ("test::init"); + + if (&root != &base) + fail (l) << "test module must be initialized in bootstrap.build"; + + if (!first) + { + warn (l) << "multiple test module initializations"; + return; + } + + const dir_path& out_root (root.path ()); + level4 ([&]{trace << "for " << out_root;}); + + // Register the test operation. + // + operation_id test_id (root.operations.insert (test)); + + unique_ptr<module> m (new module (test_id)); + + { + auto& rs (base.rules); + + // Register the standard alias rule for the test operation. + // + rs.insert<alias> (test_id, "alias", alias_rule::instance); + + // Register our test running rule. + // + rs.insert<target> (test_id, "test", m->rule); + } + + r = move (m); + } + } +} diff --git a/build/test/operation b/build/test/operation new file mode 100644 index 0000000..1942936 --- /dev/null +++ b/build/test/operation @@ -0,0 +1,18 @@ +// file : build/test/operation -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_TEST_OPERATION +#define BUILD_TEST_OPERATION + +#include <build/operation> + +namespace build +{ + namespace test + { + extern operation_info test; + } +} + +#endif // BUILD_TEST_OPERATION diff --git a/build/test/operation.cxx b/build/test/operation.cxx new file mode 100644 index 0000000..75e3e80 --- /dev/null +++ b/build/test/operation.cxx @@ -0,0 +1,34 @@ +// file : build/test/operation.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <build/test/operation> + +#include <build/config/operation> + +using namespace std; +using namespace butl; + +namespace build +{ + namespace test + { + static operation_id + test_pre (meta_operation_id mo) + { + // Run update as a pre-operation, unless we are disfiguring. + // + return mo != config::disfigure_id ? update_id : 0; + } + + operation_info test { + "test", + "test", + "testing", + "tested", + execution_mode::first, + &test_pre, + nullptr + }; + } +} diff --git a/build/test/rule b/build/test/rule new file mode 100644 index 0000000..db10606 --- /dev/null +++ b/build/test/rule @@ -0,0 +1,32 @@ +// file : build/test/rule -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_TEST_RULE +#define BUILD_TEST_RULE + +#include <build/rule> +#include <build/operation> + +namespace build +{ + namespace test + { + class rule: public build::rule + { + public: + rule (operation_id o): test_id (o) {} + + virtual match_result + match (action, target&, const std::string&) const; + + virtual recipe + apply (action, target&, const match_result&) const; + + private: + operation_id test_id; + }; + } +} + +#endif // BUILD_TEST_RULE diff --git a/build/test/rule.cxx b/build/test/rule.cxx new file mode 100644 index 0000000..3fd3a16 --- /dev/null +++ b/build/test/rule.cxx @@ -0,0 +1,49 @@ +// file : build/test/rule.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <build/test/rule> + +#include <build/scope> +#include <build/target> +#include <build/algorithm> +#include <build/diagnostics> + +using namespace std; + +namespace build +{ + namespace test + { + match_result rule:: + match (action a, target& t, const std::string&) const + { + // First determine if this is a test. + // + auto v (t.vars["test"]); + + if (!v) + v.rebind (t.base_scope ()[string("test.") + t.type ().name]); + + if (!v || !v.as<bool> ()) + return match_result (t, false); // "Not a test" result. + + // If this is the update pre-operation, make someone else do + // the job. + // + if (a.operation () != test_id) + return nullptr; + + return match_result (t, true); + } + + recipe rule:: + apply (action, target&, const match_result& mr) const + { + if (!mr.value) // Not a test. + return noop_recipe; + + return noop_recipe; //@@ TMP + } + } +} |