diff options
-rw-r--r-- | build2/buildfile | 1 | ||||
-rw-r--r-- | build2/test/init.cxx | 23 | ||||
-rw-r--r-- | build2/test/target | 29 | ||||
-rw-r--r-- | build2/test/target.cxx | 47 |
4 files changed, 93 insertions, 7 deletions
diff --git a/build2/buildfile b/build2/buildfile index 28d9b38..03c0dd3 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -75,6 +75,7 @@ exe{b}: \ test/{hxx cxx}{ init } \ test/{hxx cxx}{ operation } \ test/{hxx cxx}{ rule } \ + test/{hxx cxx}{ target } \ test/script/{hxx cxx}{ lexer } \ test/script/{hxx cxx}{ parser } \ test/script/{hxx cxx}{ runner } \ diff --git a/build2/test/init.cxx b/build2/test/init.cxx index 5b01bce..296ae69 100644 --- a/build2/test/init.cxx +++ b/build2/test/init.cxx @@ -9,8 +9,9 @@ #include <build2/rule> #include <build2/diagnostics> -#include <build2/test/operation> #include <build2/test/rule> +#include <build2/test/target> +#include <build2/test/operation> using namespace std; using namespace butl; @@ -22,15 +23,15 @@ namespace build2 static rule rule_; void - boot (scope& root, const location&, unique_ptr<module_base>&) + boot (scope& rs, const location&, unique_ptr<module_base>&) { tracer trace ("test::boot"); - l5 ([&]{trace << "for " << root.out_path ();}); + l5 ([&]{trace << "for " << rs.out_path ();}); // Register the test operation. // - root.operations.insert (test_id, test); + rs.operations.insert (test_id, test); // Enter module variables. Do it during boot in case they get assigned // in bootstrap.build. @@ -50,7 +51,7 @@ namespace build2 } bool - init (scope& root, + init (scope& rs, scope&, const location& l, unique_ptr<module_base>&, @@ -66,7 +67,7 @@ namespace build2 return true; } - const dir_path& out_root (root.out_path ()); + const dir_path& out_root (rs.out_path ()); l5 ([&]{trace << "for " << out_root;}); assert (config_hints.empty ()); // We don't known any hints. @@ -80,10 +81,18 @@ namespace build2 // if (s) // config::save_module (r, "test", INT32_MAX); + // Register target types. + // + { + auto& t (rs.target_types); + + t.insert<testscript> (); + } + // Register rules. // { - auto& r (root.rules); + auto& r (rs.rules); // Register our test running rule. // diff --git a/build2/test/target b/build2/test/target new file mode 100644 index 0000000..fe1d25f --- /dev/null +++ b/build2/test/target @@ -0,0 +1,29 @@ +// file : build2/test/target -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD2_TEST_TARGET +#define BUILD2_TEST_TARGET + +#include <build2/types> +#include <build2/utility> + +#include <build2/target> + +namespace build2 +{ + namespace test + { + class testscript: public file + { + public: + using file::file; + + public: + static const target_type static_type; + virtual const target_type& dynamic_type () const {return static_type;} + }; + } +} + +#endif // BUILD2_TEST_TARGET diff --git a/build2/test/target.cxx b/build2/test/target.cxx new file mode 100644 index 0000000..1a215ca --- /dev/null +++ b/build2/test/target.cxx @@ -0,0 +1,47 @@ +// file : build2/test/target.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <build2/test/target> + +using namespace std; +using namespace butl; + +namespace build2 +{ + namespace test + { + static target* + testscript_factory (const target_type&, + dir_path d, + dir_path o, + string n, + const string* e) + { + if (e == nullptr) + e = &extension_pool.find (n == "testscript" ? "" : "test"); + + return new testscript (move (d), move (o), move (n), e); + } + + static const string* + testscript_target_extension (const target_key& tk, scope&) + { + // If the name is special 'testscript', then there is no extension, + // otherwise it is .test. + // + return &extension_pool.find (*tk.name == "testscript" ? "" : "test"); + } + + const target_type testscript::static_type + { + "test", + &file::static_type, + &testscript_factory, + &testscript_target_extension, + nullptr, + &search_file, + false + }; + } +} |