From f91468192ad7066a5e6fa63ddc4e4231e632a457 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 18 Nov 2020 12:51:49 +0300 Subject: Remove target files on ad hoc rule update buildscript error --- libbuild2/adhoc-rule-buildscript.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'libbuild2') diff --git a/libbuild2/adhoc-rule-buildscript.cxx b/libbuild2/adhoc-rule-buildscript.cxx index a09d2c7..9470d3c 100644 --- a/libbuild2/adhoc-rule-buildscript.cxx +++ b/libbuild2/adhoc-rule-buildscript.cxx @@ -10,7 +10,7 @@ #include #include #include -#include // path_perms() +#include // path_perms(), auto_rmfile #include #include // attributes @@ -563,6 +563,20 @@ namespace build2 if (!ctx.dry_run || verb >= 2) { + // On failure remove the target files that may potentially exist but + // be invalid. + // + small_vector rms; + + if (!ctx.dry_run) + { + for (const target* m (&t); m != nullptr; m = m->adhoc_member) + { + if (auto* f = m->is_a ()) + rms.emplace_back (f->path ()); + } + } + build::script::default_runner r; p.execute (*rs, *bs, e, script, r); @@ -588,6 +602,9 @@ namespace build2 } #endif dd.check_mtime (tp); + + for (auto& rm: rms) + rm.cancel (); } } } -- cgit v1.1