From 5058b155076b004f4abf21be6cf657a3f2cc4d1b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 20 Aug 2017 15:56:26 +0200 Subject: Add support for not cleaning generated version file --- build2/context.cxx | 4 ++++ build2/context.hxx | 4 +++- build2/variable.hxx | 14 +++++++++----- build2/variable.ixx | 9 +++++++++ build2/version/rule.cxx | 5 +++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/build2/context.cxx b/build2/context.cxx index 11c2c63..f7f2448 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -191,6 +191,8 @@ namespace build2 const variable* var_import_target; + const variable* var_clean; + const string* current_mname; const string* current_oname; @@ -538,6 +540,8 @@ namespace build2 var_project_summary = &vp.insert ("project.summary", pv); var_import_target = &vp.insert ("import.target"); + + var_clean = &vp.insert ("clean", variable_visibility::target); } // Register builtin rules. diff --git a/build2/context.hxx b/build2/context.hxx index bf31887..dbb41ae 100644 --- a/build2/context.hxx +++ b/build2/context.hxx @@ -254,7 +254,9 @@ namespace build2 extern const variable* var_project_url; // project.url extern const variable* var_project_summary; // project.summary - extern const variable* var_import_target; // import.target + extern const variable* var_import_target; // import.target + + extern const variable* var_clean; // [bool] target visibility // Current action (meta/operation). // diff --git a/build2/variable.hxx b/build2/variable.hxx index decc300..5ef67fd 100644 --- a/build2/variable.hxx +++ b/build2/variable.hxx @@ -283,12 +283,16 @@ namespace build2 template const T* cast_null (const value&); template const T* cast_null (const lookup&); - // As above but returns false if the value is NULL (or not defined, in case - // of lookup). Note that the template argument is only for documentation and - // should be bool (or semantically compatible). + // As above but returns false/true if the value is NULL (or not defined, + // in case of lookup). Note that the template argument is only for + // documentation and should be bool (or semantically compatible). // - template T cast_false (const value& v); - template T cast_false (const lookup& l); + template T cast_false (const value&); + template T cast_false (const lookup&); + + template T cast_true (const value&); + template T cast_true (const lookup&); + // Assign value type to the value. In the second version the variable is // optional and is only used for diagnostics. diff --git a/build2/variable.ixx b/build2/variable.ixx index 8656a04..04cf6dc 100644 --- a/build2/variable.ixx +++ b/build2/variable.ixx @@ -193,6 +193,15 @@ namespace build2 cast_false (const lookup& l) {return l && cast (l);} template + inline T + cast_true (const value& v) {return !v || cast (v);} + + template + inline T + cast_true (const lookup& l) {return !l || cast (l);} + + + template inline void typify (value& v, const variable& var) { diff --git a/build2/version/rule.cxx b/build2/version/rule.cxx index a9d62ba..3c9723e 100644 --- a/build2/version/rule.cxx +++ b/build2/version/rule.cxx @@ -81,6 +81,11 @@ namespace build2 { doc& t (static_cast (xt)); + // If this is clean check if we were asked not to remove it. + // + if (a == perform_clean_id && !cast_true (t[var_clean])) + return noop_recipe; + // Derive the file name. // t.derive_path (); -- cgit v1.1