From 64eecc0f7ba15b1733bbc713a2f197dda590e12d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 14 Oct 2016 10:41:48 +0200 Subject: Add test{} testscript target type --- build2/buildfile | 1 + build2/test/init.cxx | 23 ++++++++++++++++------- build2/test/target | 29 +++++++++++++++++++++++++++++ build2/test/target.cxx | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 build2/test/target create mode 100644 build2/test/target.cxx (limited to 'build2') 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 #include -#include #include +#include +#include using namespace std; using namespace butl; @@ -22,15 +23,15 @@ namespace build2 static rule rule_; void - boot (scope& root, const location&, unique_ptr&) + boot (scope& rs, const location&, unique_ptr&) { 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&, @@ -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 (); + } + // 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 +#include + +#include + +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 + +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 + }; + } +} -- cgit v1.1