aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-17 18:19:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-05-17 18:19:34 +0000
commitc37882eb4aa592435ba7847ebb8b7fe79f28d4f9 (patch)
treedec5ea1631cb461bba183cdd41d26ebf23cb0138
parentd76f3d55ab629e1f34c93ba73240249173804901 (diff)
downloadpaludis-c37882eb4aa592435ba7847ebb8b7fe79f28d4f9.tar.gz
paludis-c37882eb4aa592435ba7847ebb8b7fe79f28d4f9.tar.xz
Improve pkg_pretend output
-rw-r--r--paludis/repositories/gentoo/ebuild.cc6
-rw-r--r--paludis/util/output_wrapper.cc33
-rw-r--r--paludis/util/pstream.cc5
-rw-r--r--paludis/util/system.cc49
-rw-r--r--paludis/util/system.hh22
5 files changed, 107 insertions, 8 deletions
diff --git a/paludis/repositories/gentoo/ebuild.cc b/paludis/repositories/gentoo/ebuild.cc
index 7d27989..62669c7 100644
--- a/paludis/repositories/gentoo/ebuild.cc
+++ b/paludis/repositories/gentoo/ebuild.cc
@@ -613,6 +613,12 @@ Command
EbuildPretendCommand::extend_command(const Command & cmd)
{
Command result(Command(cmd)
+ .with_stdout_prefix(stringify(params.db_entry->name.package) + "-" +
+ stringify(params.db_entry->version) + "> ")
+ .with_stderr_prefix(stringify(params.db_entry->name.package) + "-" +
+ stringify(params.db_entry->version) + "> ")
+ .with_prefix_discard_blank_output()
+ .with_prefix_blank_lines()
.with_setenv("USE", pretend_params.use)
.with_setenv("USE_EXPAND", pretend_params.use_expand)
.with_setenv("ROOT", pretend_params.root)
diff --git a/paludis/util/output_wrapper.cc b/paludis/util/output_wrapper.cc
index 3278085..2ba19ae 100644
--- a/paludis/util/output_wrapper.cc
+++ b/paludis/util/output_wrapper.cc
@@ -32,6 +32,7 @@ main(int argc, char *argv[])
int argi(1);
std::string stdout_prefix, stderr_prefix;
bool wrap_blanks(false);
+ bool discard_blank_output(false);
for ( ; argi < argc ; ++argi)
{
@@ -43,6 +44,8 @@ main(int argc, char *argv[])
}
else if (s == "--wrap-blanks")
wrap_blanks = true;
+ else if (s == "--discard-blank-output")
+ discard_blank_output = true;
else if (s == "--stdout-prefix")
{
if (++argi >= argc)
@@ -120,7 +123,9 @@ main(int argc, char *argv[])
close(stdout_pipes[1]);
close(stderr_pipes[1]);
bool stdout_done(false), stdout_prefix_shown(false), stdout_had_interesting_char(false),
- stderr_done(false), stderr_prefix_shown(false), stderr_had_interesting_char(false);
+ stderr_done(false), stderr_prefix_shown(false), stderr_had_interesting_char(false),
+ stdout_had_non_blanks(! discard_blank_output), stderr_had_non_blanks(! discard_blank_output);
+ unsigned stdout_blanks(0), stderr_blanks(0);
while ((! stdout_done) || (! stderr_done))
{
fd_set fds;
@@ -151,7 +156,20 @@ main(int argc, char *argv[])
for (std::string::size_type p(0) ; p < to_write.length() ; ++p)
{
if (to_write.at(p) != '\n')
+ {
+ if (! stdout_had_non_blanks)
+ {
+ for (unsigned x(0) ; x < stdout_blanks ; ++x)
+ if (wrap_blanks)
+ std::cout << stdout_prefix << std::endl;
+ else
+ std::cout << std::endl;
+ stdout_had_non_blanks = true;
+ }
stdout_had_interesting_char = true;
+ }
+ else if (! stdout_had_non_blanks)
+ ++stdout_blanks;
if (! stdout_prefix_shown)
{
@@ -185,7 +203,20 @@ main(int argc, char *argv[])
for (std::string::size_type p(0) ; p < to_write.length() ; ++p)
{
if (to_write.at(p) != '\n')
+ {
+ if (! stderr_had_non_blanks)
+ {
+ for (unsigned x(0) ; x < stderr_blanks ; ++x)
+ if (wrap_blanks)
+ std::cerr << stderr_prefix << std::endl;
+ else
+ std::cerr << std::endl;
+ stderr_had_non_blanks = true;
+ }
stderr_had_interesting_char = true;
+ }
+ else if (! stderr_had_non_blanks)
+ ++stderr_blanks;
if (! stderr_prefix_shown)
{
diff --git a/paludis/util/pstream.cc b/paludis/util/pstream.cc
index f2687a5..a73af2d 100644
--- a/paludis/util/pstream.cc
+++ b/paludis/util/pstream.cc
@@ -128,7 +128,10 @@ PStreamInBuf::PStreamInBuf(const Command & cmd) :
if ((! cmd.stdout_prefix().empty()) || (! cmd.stderr_prefix().empty()))
c = getenv_with_default("PALUDIS_OUTPUTWRAPPER_DIR", LIBEXECDIR "/paludis/utils") + "/outputwrapper --stdout-prefix '"
- + cmd.stdout_prefix() + "' --stderr-prefix '" + cmd.stderr_prefix() + "' -- " + c;
+ + cmd.stdout_prefix() + "' --stderr-prefix '" + cmd.stderr_prefix() + "' "
+ + (cmd.prefix_discard_blank_output() ? " --discard-blank-output " : "")
+ + (cmd.prefix_blank_lines() ? " --wrap-blanks " : "")
+ + " -- " + c;
cmd.echo_to_stderr();
Log::get_instance()->message(ll_debug, lc_no_context, "execl /bin/sh -c " + c
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 6336c81..4c8a0d5 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -146,13 +146,16 @@ namespace paludis
std::tr1::shared_ptr<gid_t> gid;
std::string stdout_prefix;
std::string stderr_prefix;
+ bool prefix_discard_blank_output;
+ bool prefix_blank_lines;
Implementation(const std::string & c,
const std::map<std::string, std::string> & s = (std::map<std::string, std::string>()),
const std::string & d = "", bool e = false,
std::tr1::shared_ptr<uid_t> u = std::tr1::shared_ptr<uid_t>(),
std::tr1::shared_ptr<gid_t> g = std::tr1::shared_ptr<gid_t>(),
- const std::string & p = "", const std::string & q = "") :
+ const std::string & p = "", const std::string & q = "",
+ const bool b = false, const bool bb = false) :
command(c),
setenv_values(s),
chdir(d),
@@ -160,7 +163,9 @@ namespace paludis
uid(u),
gid(g),
stdout_prefix(p),
- stderr_prefix(q)
+ stderr_prefix(q),
+ prefix_discard_blank_output(b),
+ prefix_blank_lines(bb)
{
}
};
@@ -179,7 +184,9 @@ Command::Command(const char * const s) :
Command::Command(const Command & other) :
PrivateImplementationPattern<Command>(new Implementation<Command>(other._imp->command,
other._imp->setenv_values, other._imp->chdir, other._imp->echo_to_stderr,
- other._imp->uid, other._imp->gid, other._imp->stdout_prefix, other._imp->stderr_prefix))
+ other._imp->uid, other._imp->gid, other._imp->stdout_prefix, other._imp->stderr_prefix,
+ other._imp->prefix_discard_blank_output,
+ other._imp->prefix_blank_lines))
{
}
@@ -193,7 +200,9 @@ Command::operator= (const Command & other)
std::tr1::shared_ptr<uid_t>(),
std::tr1::shared_ptr<gid_t>(),
other._imp->stdout_prefix,
- other._imp->stderr_prefix));
+ other._imp->stderr_prefix,
+ other._imp->prefix_discard_blank_output,
+ other._imp->prefix_blank_lines));
if (other.uid() && other.gid())
with_uid_gid(*other.uid(), *other.gid());
}
@@ -323,8 +332,10 @@ paludis::run_command(const Command & cmd)
if ((! cmd.stdout_prefix().empty()) || (! cmd.stderr_prefix().empty()))
command = getenv_with_default("PALUDIS_OUTPUTWRAPPER_DIR", LIBEXECDIR "/paludis/utils") + "/outputwrapper --stdout-prefix '"
- + cmd.stdout_prefix() + "' --stderr-prefix '" + cmd.stderr_prefix() + "' -- "
- + command;
+ + cmd.stdout_prefix() + "' --stderr-prefix '" + cmd.stderr_prefix() + "' "
+ + (cmd.prefix_discard_blank_output() ? " --discard-blank-output " : "")
+ + (cmd.prefix_blank_lines() ? " --wrap-blanks " : "")
+ + " -- " + command;
cmd.echo_to_stderr();
Log::get_instance()->message(ll_debug, lc_no_context, "execl /bin/sh -c " + command
@@ -387,6 +398,20 @@ Command::with_echo_to_stderr()
}
Command &
+Command::with_prefix_discard_blank_output()
+{
+ _imp->prefix_discard_blank_output = true;
+ return *this;
+}
+
+Command &
+Command::with_prefix_blank_lines()
+{
+ _imp->prefix_blank_lines = true;
+ return *this;
+}
+
+Command &
Command::with_stdout_prefix(const std::string & s)
{
_imp->stdout_prefix = s;
@@ -412,6 +437,18 @@ Command::stderr_prefix() const
return _imp->stderr_prefix;
}
+bool
+Command::prefix_discard_blank_output() const
+{
+ return _imp->prefix_discard_blank_output;
+}
+
+bool
+Command::prefix_blank_lines() const
+{
+ return _imp->prefix_blank_lines;
+}
+
std::string
paludis::get_user_name(const uid_t u)
{
diff --git a/paludis/util/system.hh b/paludis/util/system.hh
index e65aaf7..4c1e4c3 100644
--- a/paludis/util/system.hh
+++ b/paludis/util/system.hh
@@ -153,6 +153,17 @@ namespace paludis
*/
Command & with_stderr_prefix(const std::string &);
+ /**
+ * If prefixing, and if the output contains only blanks, don't display
+ * any output.
+ */
+ Command & with_prefix_discard_blank_output();
+
+ /**
+ * If prefixing, prefix blank lines too.
+ */
+ Command & with_prefix_blank_lines();
+
///\}
///\name Fetch command execution options
@@ -193,6 +204,17 @@ namespace paludis
*/
std::string stderr_prefix() const;
+ /**
+ * If prefixing, and if the output contains only blanks, don't display
+ * any output?
+ */
+ bool prefix_discard_blank_output() const;
+
+ /**
+ * Prefix blank lines?
+ */
+ bool prefix_blank_lines() const;
+
///\}
///\name Iterate over our setenvs.