aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-08 12:36:05 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-08 12:36:05 +0200
commitb66d30af9fb5c50966183820f8ed7af6b8791a2e (patch)
tree510a691f6e393e91b3fe870c5ccf0465e72c76d5
parent18af73df698e560b847e46d524d059d2921876d5 (diff)
Move context-dependent functions from diagnostics to context
-rw-r--r--build/context26
-rw-r--r--build/context.cxx153
-rw-r--r--build/diagnostics31
-rw-r--r--build/diagnostics.cxx155
-rw-r--r--build/path-io.cxx1
-rw-r--r--build/spec.cxx1
6 files changed, 183 insertions, 184 deletions
diff --git a/build/context b/build/context
index 920ad1f..ffe88bc 100644
--- a/build/context
+++ b/build/context
@@ -131,6 +131,32 @@ namespace build
// returns the original path.
//
extern const dir_path* relative_base;
+
+ // In addition to calling relative(), this function also uses shorter
+ // notations such as '~/'.
+ //
+ std::string
+ diag_relative (const path&);
+
+ // As above but also adds trailing '/'. If the path is the same as
+ // base, returns "./" if current is true and empty string otherwise.
+ //
+ std::string
+ diag_relative (const dir_path&, bool current = true);
+
+ // Action phrases, e.g., "configure update exe{foo}", "updating exe{foo}",
+ // and "updating exe{foo} is configured".
+ //
+ class target;
+
+ std::string
+ diag_do (const action&, const target&);
+
+ std::string
+ diag_doing (const action&, const target&);
+
+ std::string
+ diag_done (const action&, const target&);
}
#include <build/context.txx>
diff --git a/build/context.cxx b/build/context.cxx
index 5a801b0..a20a7e2 100644
--- a/build/context.cxx
+++ b/build/context.cxx
@@ -5,6 +5,7 @@
#include <build/context>
#include <ostream>
+#include <sstream>
#include <cassert>
#include <system_error>
@@ -226,5 +227,157 @@ namespace build
return out_root / s.leaf (src_root);
}
+ // relative()
+ //
const dir_path* relative_base = &work;
+
+ string
+ diag_relative (const path& p)
+ {
+ const path& b (*relative_base);
+
+ if (p.absolute ())
+ {
+ if (p == b)
+ return ".";
+
+#ifndef _WIN32
+ if (p == home)
+ return "~";
+#endif
+
+ path rb (relative (p));
+
+#ifndef _WIN32
+ if (rb.relative ())
+ {
+ // See if the original path with the ~/ shortcut is better
+ // that the relative to base.
+ //
+ if (p.sub (home))
+ {
+ path rh (p.leaf (home));
+ if (rb.string ().size () > rh.string ().size () + 2) // 2 for '~/'
+ return "~/" + rh.string ();
+ }
+ }
+ else if (rb.sub (home))
+ return "~/" + rb.leaf (home).string ();
+#endif
+
+ return rb.string ();
+ }
+
+ return p.string ();
+ }
+
+ string
+ diag_relative (const dir_path& d, bool cur)
+ {
+ string r (diag_relative (static_cast<const path&> (d)));
+
+ // Translate "." to empty.
+ //
+ if (!cur && d.absolute () && r == ".")
+ r.clear ();
+
+ // Add trailing '/'.
+ //
+ if (!r.empty () && !dir_path::traits::is_separator (r.back ()))
+ r += '/';
+
+ return r;
+ }
+
+ // diag_do(), etc.
+ //
+ string
+ diag_do (const action&, const target& t)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ ostringstream os;
+
+ // perform(update(x)) -> "update x"
+ // configure(update(x)) -> "configure updating x"
+ //
+ if (m.name_do.empty ())
+ os << io.name_do << ' ';
+ else
+ {
+ os << m.name_do << ' ';
+
+ if (!io.name_doing.empty ())
+ os << io.name_doing << ' ';
+ }
+
+ if (oo != nullptr)
+ os << "(for " << oo->name << ") ";
+
+ os << t;
+ return os.str ();
+ }
+
+ string
+ diag_doing (const action&, const target& t)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ ostringstream os;
+
+ // perform(update(x)) -> "updating x"
+ // configure(update(x)) -> "configuring updating x"
+ //
+ if (!m.name_doing.empty ())
+ os << m.name_doing << ' ';
+
+ if (!io.name_doing.empty ())
+ os << io.name_doing << ' ';
+
+ if (oo != nullptr)
+ os << "(for " << oo->name << ") ";
+
+ os << t;
+ return os.str ();
+ }
+
+ string
+ diag_done (const action&, const target& t)
+ {
+ const meta_operation_info& m (*current_mif);
+ const operation_info& io (*current_inner_oif);
+ const operation_info* oo (current_outer_oif);
+
+ ostringstream os;
+
+ // perform(update(x)) -> "x is up to date"
+ // configure(update(x)) -> "updating x is configured"
+ //
+ if (m.name_done.empty ())
+ {
+ os << t;
+
+ if (!io.name_done.empty ())
+ os << " " << io.name_done;
+
+ if (oo != nullptr)
+ os << "(for " << oo->name << ") ";
+ }
+ else
+ {
+ if (!io.name_doing.empty ())
+ os << io.name_doing << ' ';
+
+ if (oo != nullptr)
+ os << "(for " << oo->name << ") ";
+
+ os << t << " " << m.name_done;
+ }
+
+ return os.str ();
+ }
}
diff --git a/build/diagnostics b/build/diagnostics
index 6e54f56..d5b0b3d 100644
--- a/build/diagnostics
+++ b/build/diagnostics
@@ -28,19 +28,8 @@ namespace build
//
class failed: public std::exception {};
- // In addition to calling relative(), this function also uses shorter
- // notations such as '~/'.
- //
- std::string
- diag_relative (const path&);
-
- // As above but also adds trailing '/'. If the path is the same as
- // base, returns "./" if current is true and empty string otherwise.
- //
- std::string
- diag_relative (const dir_path&, bool current = true);
-
- //
+ // Flag that indicates whether paths should be inserted relative
+ // into this stream.
//
extern const int relative_index;
@@ -50,22 +39,6 @@ namespace build
inline void
relative (std::ostream& os, bool v) {os.iword (relative_index) = v ? 1 : 0;}
-
- // Action phrases, e.g., "configure update exe{foo}", "updating exe{foo}",
- // and "updating exe{foo} is configured".
- //
- struct action;
- class target;
-
- std::string
- diag_do (const action&, const target&);
-
- std::string
- diag_doing (const action&, const target&);
-
- std::string
- diag_done (const action&, const target&);
-
// Print process commmand line. If the number of elements is specified
// (or the second version is used), then it will print the piped multi-
// process command line, if present. In this case, the expected format
diff --git a/build/diagnostics.cxx b/build/diagnostics.cxx
index 075dbab..70dfe07 100644
--- a/build/diagnostics.cxx
+++ b/build/diagnostics.cxx
@@ -4,173 +4,18 @@
#include <build/diagnostics>
-#include <sstream>
#include <iostream>
-#include <build/scope>
-#include <build/target>
-#include <build/operation>
-#include <build/context>
#include <build/utility>
using namespace std;
namespace build
{
- string
- diag_relative (const path& p)
- {
- const path& b (*relative_base);
-
- if (p.absolute ())
- {
- if (p == b)
- return ".";
-
-#ifndef _WIN32
- if (p == home)
- return "~";
-#endif
-
- path rb (relative (p));
-
-#ifndef _WIN32
- if (rb.relative ())
- {
- // See if the original path with the ~/ shortcut is better
- // that the relative to base.
- //
- if (p.sub (home))
- {
- path rh (p.leaf (home));
- if (rb.string ().size () > rh.string ().size () + 2) // 2 for '~/'
- return "~/" + rh.string ();
- }
- }
- else if (rb.sub (home))
- return "~/" + rb.leaf (home).string ();
-#endif
-
- return rb.string ();
- }
-
- return p.string ();
- }
-
- string
- diag_relative (const dir_path& d, bool cur)
- {
- string r (diag_relative (static_cast<const path&> (d)));
-
- // Translate "." to empty.
- //
- if (!cur && d.absolute () && r == ".")
- r.clear ();
-
- // Add trailing '/'.
- //
- if (!r.empty () && !dir_path::traits::is_separator (r.back ()))
- r += '/';
-
- return r;
- }
-
// Relative stream.
//
const int relative_index = ostream::xalloc ();
- // diag_do(), etc.
- //
- string
- diag_do (const action&, const target& t)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- ostringstream os;
-
- // perform(update(x)) -> "update x"
- // configure(update(x)) -> "configure updating x"
- //
- if (m.name_do.empty ())
- os << io.name_do << ' ';
- else
- {
- os << m.name_do << ' ';
-
- if (!io.name_doing.empty ())
- os << io.name_doing << ' ';
- }
-
- if (oo != nullptr)
- os << "(for " << oo->name << ") ";
-
- os << t;
- return os.str ();
- }
-
- string
- diag_doing (const action&, const target& t)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- ostringstream os;
-
- // perform(update(x)) -> "updating x"
- // configure(update(x)) -> "configuring updating x"
- //
- if (!m.name_doing.empty ())
- os << m.name_doing << ' ';
-
- if (!io.name_doing.empty ())
- os << io.name_doing << ' ';
-
- if (oo != nullptr)
- os << "(for " << oo->name << ") ";
-
- os << t;
- return os.str ();
- }
-
- string
- diag_done (const action&, const target& t)
- {
- const meta_operation_info& m (*current_mif);
- const operation_info& io (*current_inner_oif);
- const operation_info* oo (current_outer_oif);
-
- ostringstream os;
-
- // perform(update(x)) -> "x is up to date"
- // configure(update(x)) -> "updating x is configured"
- //
- if (m.name_done.empty ())
- {
- os << t;
-
- if (!io.name_done.empty ())
- os << " " << io.name_done;
-
- if (oo != nullptr)
- os << "(for " << oo->name << ") ";
- }
- else
- {
- if (!io.name_doing.empty ())
- os << io.name_doing << ' ';
-
- if (oo != nullptr)
- os << "(for " << oo->name << ") ";
-
- os << t << " " << m.name_done;
- }
-
- return os.str ();
- }
-
void
print_process (const char* const* args, size_t n)
{
diff --git a/build/path-io.cxx b/build/path-io.cxx
index ae28143..b6fd9e7 100644
--- a/build/path-io.cxx
+++ b/build/path-io.cxx
@@ -6,6 +6,7 @@
#include <ostream>
+#include <build/context>
#include <build/diagnostics>
using namespace std;
diff --git a/build/spec.cxx b/build/spec.cxx
index bdca763..b08cdb3 100644
--- a/build/spec.cxx
+++ b/build/spec.cxx
@@ -6,6 +6,7 @@
#include <ostream>
+#include <build/context>
#include <build/diagnostics>
using namespace std;