From 4402d5fc6002769210bf06c97f6a3cc97f6e30ee Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 23 Aug 2017 20:07:26 +0200 Subject: Add perform_clean_group(), use instead of ad hoc implementation in cli rule --- build2/algorithm.cxx | 28 ++++++++++++++++++++++++++-- build2/algorithm.hxx | 6 ++++++ build2/cli/rule.cxx | 31 +------------------------------ build2/cli/rule.hxx | 3 --- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/build2/algorithm.cxx b/build2/algorithm.cxx index 174c395..14c1960 100644 --- a/build2/algorithm.cxx +++ b/build2/algorithm.cxx @@ -1425,12 +1425,36 @@ namespace build2 target_state perform_clean (action a, const target& t) { - return clean_extra (a, dynamic_cast (t), {nullptr}); + return clean_extra (a, t.as (), {nullptr}); } target_state perform_clean_depdb (action a, const target& t) { - return clean_extra (a, dynamic_cast (t), {".d"}); + return clean_extra (a, t.as (), {".d"}); + } + + target_state + perform_clean_group (action a, const target& xg) + { + const mtime_target& g (xg.as ()); + const group_view& gv (g.group_members (a)); + + // Similar logic to clean_extra() above. + // + target_state r (target_state::unchanged); + for (size_t i (0); i != gv.count; ++i) + { + if (const target* m = gv.members[i]) + { + if (rmfile (m->as ().path (), *m)) + r |= target_state::changed; + } + } + + g.mtime (timestamp_nonexistent); + + r |= reverse_execute_prerequisites (a, g); + return r; } } diff --git a/build2/algorithm.hxx b/build2/algorithm.hxx index 76e9d76..e8b9823 100644 --- a/build2/algorithm.hxx +++ b/build2/algorithm.hxx @@ -467,6 +467,12 @@ namespace build2 target_state perform_clean_depdb (action, const target&); + // As above but clean the target group. The group should be an mtime_target + // and members should be files. + // + target_state + perform_clean_group (action, const target&); + // Helper for custom perform(clean) implementations that cleans extra files // and directories (recursively) specified as a list of either absolute // paths or "path derivation directives". The directive string can be NULL, diff --git a/build2/cli/rule.cxx b/build2/cli/rule.cxx index 9e925b3..83774a3 100644 --- a/build2/cli/rule.cxx +++ b/build2/cli/rule.cxx @@ -174,7 +174,7 @@ namespace build2 switch (a) { case perform_update_id: return &perform_update; - case perform_clean_id: return &perform_clean; + case perform_clean_id: return &perform_clean_group; // Standard impl. default: return noop_recipe; // Configure update. } } @@ -304,34 +304,5 @@ namespace build2 return target_state::changed; } - - target_state compile:: - perform_clean (action a, const target& xt) - { - const cli_cxx& t (xt.as ()); - - // The reverse order of update: first delete the files, then clean - // prerequisites. Also update timestamp in case there are operations - // after us that could use the information. - // - // @@ Can't we use clean_extra() for this? - // - bool r (false); - - if (t.i != nullptr) - r = rmfile (t.i->path (), *t.i) || r; - r = rmfile (t.c->path (), *t.c) || r; - r = rmfile (t.h->path (), *t.h) || r; - - t.mtime (timestamp_nonexistent); - - target_state ts (r ? target_state::changed : target_state::unchanged); - - // Clean prerequisites. - // - ts |= reverse_execute_prerequisites (a, t); - - return ts; - } } } diff --git a/build2/cli/rule.hxx b/build2/cli/rule.hxx index 6798a6b..9af1da4 100644 --- a/build2/cli/rule.hxx +++ b/build2/cli/rule.hxx @@ -29,9 +29,6 @@ namespace build2 static target_state perform_update (action, const target&); - - static target_state - perform_clean (action, const target&); }; } } -- cgit v1.1