aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-03-07 14:37:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-03-07 14:37:08 +0200
commit4854da9ba94fc107ff3dcd7eac4e12cecacd9b2e (patch)
tree44c7dceeb85132c65008f94b24888b8cfc7985e7
parentb7c0293598d45f052a41c3ed6580d98801280cd7 (diff)
Remove the depdb (.d) files when cleaning
-rw-r--r--build2/algorithm7
-rw-r--r--build2/algorithm.cxx36
-rw-r--r--build2/context14
-rw-r--r--build2/context.txx15
-rw-r--r--build2/cxx/compile.cxx2
5 files changed, 60 insertions, 14 deletions
diff --git a/build2/algorithm b/build2/algorithm
index f0f2fbf..7c9239d 100644
--- a/build2/algorithm
+++ b/build2/algorithm
@@ -209,10 +209,15 @@ namespace build2
default_action (action, target&);
// Standard perform(clean) action implementation for the file target
- // or derived.
+ // (or derived).
//
target_state
perform_clean (action, target&);
+
+ // As above, but also removes the auxiliary dependency database (.d file).
+ //
+ target_state
+ perform_clean_depdb (action, target&);
}
#include <build2/algorithm.ixx>
diff --git a/build2/algorithm.cxx b/build2/algorithm.cxx
index dab12c9..89dd029 100644
--- a/build2/algorithm.cxx
+++ b/build2/algorithm.cxx
@@ -473,7 +473,7 @@ namespace build2
target_state
perform_clean (action a, target& t)
{
- // The reverse order of update: first delete the file, then clean
+ // The reverse order of update: first remove the file, then clean
// prerequisites.
//
file& ft (dynamic_cast<file&> (t));
@@ -493,4 +493,38 @@ namespace build2
return r;
}
+
+ target_state
+ perform_clean_depdb (action a, target& t)
+ {
+ // Normally the .d file is created/updated before the target so remove it
+ // first. Also, don't print the command at verbosity level below 3.
+ //
+ file& ft (dynamic_cast<file&> (t));
+
+ path df (ft.path () + ".d");
+ target_state dr (rmfile (df, false)
+ ? target_state::changed
+ : target_state::unchanged);
+
+ // Factor the result of removing the .d file into the target state. While
+ // strictly speaking removing it doesn't change the target state, if we
+ // don't do this, then we may end up removing the file but still saying
+ // that everything is clean (e.g., if someone removes the target file but
+ // leaves .d laying around). That would be confusing.
+ //
+ target_state tr (perform_clean (a, t));
+
+ // What would also be confusing is if we didn't print any commands in
+ // this case.
+ //
+ if (tr == target_state::unchanged && dr == target_state::changed)
+ {
+ if (verb > 0 && verb < 3)
+ text << "rm " << df;
+ }
+
+ tr |= dr;
+ return tr;
+ }
}
diff --git a/build2/context b/build2/context
index d7ca3d3..d5b55d3 100644
--- a/build2/context
+++ b/build2/context
@@ -69,17 +69,19 @@ namespace build2
fs_status<butl::mkdir_status>
mkdir_p (const dir_path&);
- // Remove the file and print the standard diagnostics. The second
- // argument is only used in diagnostics, to print the target name.
- // Passing the path for target will result in the relative path
- // being printed.
+ // Remove the file and print the standard diagnostics. The second argument
+ // is only used in diagnostics, to print the target name. Passing the path
+ // for target will result in the relative path being printed.
+ //
+ // If verbose is false, then only print the command at verbosity level 3
+ // or higher.
//
template <typename T>
fs_status<butl::rmfile_status>
- rmfile (const path&, const T& target);
+ rmfile (const path&, const T& target, bool verbose = true);
inline fs_status<butl::rmfile_status>
- rmfile (const path& f) {return rmfile (f, f);}
+ rmfile (const path& f, bool verbose = true) {return rmfile (f, f, verbose);}
// Similar to rmfile() but for directories.
//
diff --git a/build2/context.txx b/build2/context.txx
index 566beb1..3233092 100644
--- a/build2/context.txx
+++ b/build2/context.txx
@@ -8,10 +8,15 @@ namespace build2
{
template <typename T>
fs_status<butl::rmfile_status>
- rmfile (const path& f, const T& t)
+ rmfile (const path& f, const T& t, bool verbose)
{
using namespace butl;
+ // Verbosity thresholds.
+ //
+ uint16_t l1 (verbose ? 2 : 3);
+ uint16_t l2 (verbose ? 1 : 3);
+
// We don't want to print the command if we couldn't remove the
// file because it does not exist (just like we don't print the
// update command if the file is up to date). This makes the
@@ -25,9 +30,9 @@ namespace build2
}
catch (const system_error& e)
{
- if (verb >= 2)
+ if (verb >= l1)
text << "rm " << f;
- else if (verb)
+ else if (verb >= l2)
text << "rm " << t;
fail << "unable to remove file " << f << ": " << e.what ();
@@ -35,9 +40,9 @@ namespace build2
if (rs == rmfile_status::success)
{
- if (verb >= 2)
+ if (verb >= l1)
text << "rm " << f;
- else if (verb)
+ else if (verb >= l2)
text << "rm " << t;
}
diff --git a/build2/cxx/compile.cxx b/build2/cxx/compile.cxx
index e8cbb99..70ff4a0 100644
--- a/build2/cxx/compile.cxx
+++ b/build2/cxx/compile.cxx
@@ -234,7 +234,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_depdb;
default: return noop_recipe; // Configure update.
}
}