aboutsummaryrefslogtreecommitdiff
path: root/build2/dump.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-11-20 13:11:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-11-20 18:29:45 +0200
commit9964a9aca03b38c2959994e0fdc91014da252cb8 (patch)
tree4c263c8f9ee422de9f27aecdb05a040ee116ddae /build2/dump.cxx
parent4184f61e2b795dd4c4b4a974a890bdaf98906b82 (diff)
Implement dump directive
It can be used to print (to stderr) a human-readable representation of the current scope or a list of targets. For example: dump # Dump current scope. dump lib{foo} details/exe{bar} # Dump two targets. This is primarily useful for debugging as well as to write build system tests.
Diffstat (limited to 'build2/dump.cxx')
-rw-r--r--build2/dump.cxx61
1 files changed, 49 insertions, 12 deletions
diff --git a/build2/dump.cxx b/build2/dump.cxx
index ab2e73f..7e2676d 100644
--- a/build2/dump.cxx
+++ b/build2/dump.cxx
@@ -184,16 +184,27 @@ namespace build2
}
static void
- dump_target (ostream& os, string& ind, const target& t, const scope& s)
+ dump_target (ostream& os,
+ string& ind,
+ const target& t,
+ const scope& s,
+ bool relative)
{
- // Print the target and its prerequisites relative to the scope. To achieve
- // this we are going to temporarily lower the stream verbosity to level 1.
- // The drawback of doing this is that we also lower the verbosity of
- // extension printing (it wouldn't have been bad at all to get 'foo.?' for
- // unassigned and 'foo.' for empty).
+ // If requested, print the target and its prerequisites relative to the
+ // scope. To achieve this we are going to temporarily lower the stream
+ // verbosity to level 1. The drawback of doing this is that we also lower
+ // the verbosity of extension printing (it wouldn't have been bad at all
+ // to get 'foo.?' for unassigned and 'foo.' for empty).
//
- uint16_t sv (stream_verb (os));
- stream_verb (os, 1);
+ // @@ Actually, all those foo.? look rather hairy...
+ // @@ Can't we change level to a bit mask?
+ //
+ uint16_t sv;
+ if (relative)
+ {
+ sv = stream_verb (os);
+ stream_verb (os, 1);
+ }
os << ind << t;
@@ -234,7 +245,8 @@ namespace build2
}
}
- stream_verb (os, sv); // We want variable values in full.
+ if (relative)
+ stream_verb (os, sv); // We want variable values in full.
// Print target-specific variables.
//
@@ -265,7 +277,10 @@ namespace build2
if (d.empty ())
os << ind << dir_path::traits::directory_separator;
else
- os << ind << relative (d);
+ {
+ dir_path rd (relative (d));
+ os << ind << (rd.empty () ? dir_path (".") : rd);
+ }
os << ":" << endl << ind << '{';
@@ -329,7 +344,7 @@ namespace build2
}
os << endl;
- dump_target (os, ind, t, p);
+ dump_target (os, ind, t, p, true /* relative */);
}
ind.resize (ind.size () - 2);
@@ -346,11 +361,33 @@ namespace build2
assert (&i->second == global_scope);
// We don't lock diag_stream here as dump() is supposed to be called from
- // the main thread prior to any other threads being spawned.
+ // the main thread prior/after to any other threads being spawned.
//
string ind;
ostream& os (*diag_stream);
dump_scope (os, ind, i);
os << endl;
}
+
+ void
+ dump (const scope& s, const char* cind)
+ {
+ const scope_map_base& m (scopes); // Iterator interface.
+ auto i (m.find (s.out_path ()));
+ assert (i != m.end () && &i->second == &s);
+
+ string ind (cind);
+ ostream& os (*diag_stream);
+ dump_scope (os, ind, i);
+ os << endl;
+ }
+
+ void
+ dump (const target& t, const char* cind)
+ {
+ string ind (cind);
+ ostream& os (*diag_stream);
+ dump_target (os, ind, t, t.base_scope (), false /* relative */);
+ os << endl;
+ }
}