aboutsummaryrefslogtreecommitdiff
path: root/build/context.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-03-25 14:48:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-03-25 14:48:36 +0200
commitcd75e06a87aa74aa6968113107afa53d401d20bc (patch)
tree1e104829d10f375a783d6efbbf7eef3e2c6d2ef5 /build/context.txx
parenta94dcda7f00b10cb22b5f2138b1c29bcfbe7de37 (diff)
Configure/disfigure src_root saving/removing support; fsdir{} injection
We can now build out-of-tree.
Diffstat (limited to 'build/context.txx')
-rw-r--r--build/context.txx100
1 files changed, 100 insertions, 0 deletions
diff --git a/build/context.txx b/build/context.txx
new file mode 100644
index 0000000..cae1ce8
--- /dev/null
+++ b/build/context.txx
@@ -0,0 +1,100 @@
+// file : build/context.txx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <system_error>
+
+#include <build/diagnostics>
+
+namespace build
+{
+ template <typename T>
+ rmfile_status
+ rmfile (const path& f, const T& t)
+ {
+ // 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
+ // below code a bit ugly.
+ //
+ rmfile_status rs;
+
+ try
+ {
+ rs = try_rmfile (f);
+ }
+ catch (const std::system_error& e)
+ {
+ if (verb >= 1)
+ text << "rm " << f.string ();
+ else
+ text << "rm " << t;
+
+ fail << "unable to remove file " << f.string () << ": " << e.what ();
+ }
+
+ if (rs == rmfile_status::success)
+ {
+ if (verb >= 1)
+ text << "rm " << f.string ();
+ else
+ text << "rm " << t;
+ }
+
+ return rs;
+ }
+
+ template <typename T>
+ rmdir_status
+ rmdir (const path& d, const T& t)
+ {
+ bool w (d == work); // Don't try to remove working directory.
+ rmdir_status rs;
+
+ // We don't want to print the command if we couldn't remove the
+ // directory because it does not exist (just like we don't print
+ // mkdir if it already exists) or if it is not empty. This makes
+ // the below code a bit ugly.
+ //
+ try
+ {
+ rs = !w ? try_rmdir (d) : rmdir_status::not_empty;
+ }
+ catch (const std::system_error& e)
+ {
+ if (verb >= 1)
+ text << "rmdir " << d.string ();
+ else
+ text << "rmdir " << t;
+
+ fail << "unable to remove directory " << d.string () << ": "
+ << e.what ();
+ }
+
+ switch (rs)
+ {
+ case rmdir_status::success:
+ {
+ if (verb >= 1)
+ text << "rmdir " << d.string ();
+ else
+ text << "rmdir " << t;
+
+ break;
+ }
+ case rmdir_status::not_empty:
+ {
+ if (verb >= 1)
+ text << "directory " << d.string () << " is "
+ << (w ? "current working directory" : "not empty")
+ << ", not removing";
+
+ break;
+ }
+ case rmdir_status::not_exist:
+ break;
+ }
+
+ return rs;
+ }
+}