aboutsummaryrefslogtreecommitdiff
path: root/build2/name.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-12-16 12:00:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-12-16 12:00:53 +0200
commit44e1022f8141bd57756c2be4277c728ca7443eb3 (patch)
tree4b3d7e4be8c79d00acc52aec7f1cf64d184f9f73 /build2/name.cxx
parent497353a7eeec26d35741afd45b7cd759105f0246 (diff)
Redo string/stream representation of dir{} name/target
Now instead of: dir{foo/bar/} We get: foo/dir{bar/} Which feels more consistent with how we print other names/targets. That is, "directory bar/ in directory foo/" similar how foo/exe{bar} is "executable bar in directory foo/".
Diffstat (limited to 'build2/name.cxx')
-rw-r--r--build2/name.cxx72
1 files changed, 44 insertions, 28 deletions
diff --git a/build2/name.cxx b/build2/name.cxx
index d1f3bd7..f71c7c1 100644
--- a/build2/name.cxx
+++ b/build2/name.cxx
@@ -6,8 +6,6 @@
#include <string.h> // strchr()
-#include <sstream>
-
#include <build2/diagnostics.hxx>
namespace build2
@@ -31,15 +29,18 @@ namespace build2
r += '%';
}
- // If the value is empty, then we want to put the directory inside {},
- // e.g., dir{bar/}, not bar/dir{}.
+ // If the value is empty, then we want to put the last component of the
+ // directory inside {}, e.g., dir{bar/}, not bar/dir{}.
//
- bool d (!n.dir.empty ());
bool v (!n.value.empty ());
bool t (!n.type.empty ());
- if (v && d)
- r += n.dir.representation ();
+ const dir_path& pd (v ? n.dir :
+ t ? n.dir.directory () :
+ dir_path ());
+
+ if (!pd.empty ())
+ r += pd.representation ();
if (t)
{
@@ -50,7 +51,7 @@ namespace build2
if (v)
r += n.value;
else
- r += n.dir.representation ();
+ r += (pd.empty () ? n.dir : n.dir.leaf ()).representation ();
if (t)
r += '}';
@@ -95,18 +96,17 @@ namespace build2
os << v;
};
- auto write_dir = [quote, &os, &write_string](const dir_path& d)
+ uint16_t dv (stream_verb (os)); // Directory verbosity.
+
+ auto write_dir = [dv, quote, &os, &write_string] (const dir_path& d)
{
+ const string& s (dv < 2
+ ? diag_relative (d)
+ : d.representation ());
if (quote)
- {
- std::ostringstream s;
- stream_verb (s, stream_verb (os));
- s << d;
-
- write_string (s.str ());
- }
+ write_string (s);
else
- os << d;
+ os << s;
};
// Note: similar to to_string() below.
@@ -123,29 +123,45 @@ namespace build2
os << '%';
}
- // If the value is empty, then we want to print the directory inside {},
- // e.g., dir{bar/}, not bar/dir{}. We also want to print {} for an empty
- // name (unless quoted).
+ // If the value is empty, then we want to print the last component of the
+ // directory inside {}, e.g., dir{bar/}, not bar/dir{}. We also want to
+ // print {} for an empty name (unless quoted, which is handled above).
//
bool d (!n.dir.empty ());
bool v (!n.value.empty ());
- bool t (!n.type.empty () || (!d && !v));
+ bool t (!n.type.empty ());
- if (v)
- write_dir (n.dir);
+ // Note: relative() may return empty.
+ //
+ const dir_path& rd (dv < 2 ? relative (n.dir) : n.dir); // Relative.
+ const dir_path& pd (v ? rd :
+ t ? rd.directory () :
+ dir_path ());
- if (t)
+ if (!pd.empty ())
+ write_dir (pd);
+
+ if (t || (!d && !v))
{
- write_string (n.type);
+ if (t)
+ write_string (n.type);
+
os << '{';
}
if (v)
write_string (n.value);
- else
- write_dir (n.dir);
+ else if (d)
+ {
+ if (rd.empty ())
+ write_string (dir_path (".").representation ());
+ else if (!pd.empty ())
+ write_string (rd.leaf ().representation ());
+ else
+ write_dir (rd);
+ }
- if (t)
+ if (t || (!d && !v))
os << '}';
return os;