aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-30 19:55:33 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-30 19:55:33 +0000
commitfb9f37336d6208fb60074b762fed2a772375b872 (patch)
treec820744e13e70e524eb17adb84c6f7a294fe0637
parentafc95e1d3d45d0b66213cc93a404dd11be83544c (diff)
downloadpaludis-fb9f37336d6208fb60074b762fed2a772375b872.tar.gz
paludis-fb9f37336d6208fb60074b762fed2a772375b872.tar.xz
Prefix output from third party hooks with the hook name.
-rw-r--r--paludis/environments/paludis/paludis_environment.cc31
-rw-r--r--paludis/environments/portage/portage_environment.cc14
-rw-r--r--paludis/hooker.cc18
-rw-r--r--paludis/hooker.hh2
4 files changed, 42 insertions, 23 deletions
diff --git a/paludis/environments/paludis/paludis_environment.cc b/paludis/environments/paludis/paludis_environment.cc
index 4f20d65..7709c8f 100644
--- a/paludis/environments/paludis/paludis_environment.cc
+++ b/paludis/environments/paludis/paludis_environment.cc
@@ -50,7 +50,7 @@ namespace paludis
{
mutable bool done_hooks;
mutable std::tr1::shared_ptr<Hooker> hooker;
- mutable std::list<FSEntry> hook_dirs;
+ mutable std::list<std::pair<FSEntry, bool> > hook_dirs;
std::tr1::shared_ptr<PaludisConfig> config;
std::string paludis_command;
@@ -63,7 +63,7 @@ namespace paludis
{
}
- void add_one_hook(const FSEntry & r) const
+ void add_one_hook(const FSEntry & r, const bool v) const
{
try
{
@@ -71,7 +71,7 @@ namespace paludis
{
Log::get_instance()->message(ll_debug, lc_no_context, "Adding hook directory '"
+ stringify(r) + "'");
- hook_dirs.push_back(r);
+ hook_dirs.push_back(std::make_pair(r, v));
}
else
Log::get_instance()->message(ll_debug, lc_no_context, "Skipping hook directory candidate '"
@@ -89,11 +89,11 @@ namespace paludis
{
if (! done_hooks)
{
- add_one_hook(c / "hooks");
+ add_one_hook(c / "hooks", true);
if (getenv_with_default("PALUDIS_NO_GLOBAL_HOOKS", "").empty())
{
- add_one_hook(FSEntry(LIBEXECDIR) / "paludis" / "hooks");
- add_one_hook(FSEntry(DATADIR) / "paludis" / "hooks");
+ add_one_hook(FSEntry(LIBEXECDIR) / "paludis" / "hooks", false);
+ add_one_hook(FSEntry(DATADIR) / "paludis" / "hooks", true);
}
done_hooks = true;
}
@@ -588,14 +588,13 @@ PaludisEnvironment::set_paludis_command(const std::string & s)
int
PaludisEnvironment::perform_hook(const Hook & hook) const
{
- using namespace std::tr1::placeholders;
-
if (! _imp->hooker)
{
_imp->need_hook_dirs(_imp->config->config_dir());
_imp->hooker.reset(new Hooker(this));
- std::for_each(_imp->hook_dirs.begin(), _imp->hook_dirs.end(),
- std::tr1::bind(std::tr1::mem_fn(&Hooker::add_dir), _imp->hooker.get(), _1));
+ for (std::list<std::pair<FSEntry, bool> >::const_iterator h(_imp->hook_dirs.begin()),
+ h_end(_imp->hook_dirs.end()) ; h != h_end ; ++h)
+ _imp->hooker->add_dir(h->first, h->second);
}
return _imp->hooker->perform_hook(hook);
@@ -605,7 +604,17 @@ std::string
PaludisEnvironment::hook_dirs() const
{
_imp->need_hook_dirs(_imp->config->config_dir());
- return join(_imp->hook_dirs.begin(), _imp->hook_dirs.end(), " ");
+
+ std::string result;
+ for (std::list<std::pair<FSEntry, bool> >::const_iterator h(_imp->hook_dirs.begin()),
+ h_end(_imp->hook_dirs.end()) ; h != h_end ; ++h)
+ {
+ if (! result.empty())
+ result.append(" ");
+ result.append(stringify(h->first));
+ }
+
+ return result;
}
std::string
diff --git a/paludis/environments/portage/portage_environment.cc b/paludis/environments/portage/portage_environment.cc
index 077bd66..deba902 100644
--- a/paludis/environments/portage/portage_environment.cc
+++ b/paludis/environments/portage/portage_environment.cc
@@ -213,6 +213,8 @@ template<typename I_>
void
PortageEnvironment::_load_atom_file(const FSEntry & f, I_ i, const std::string & def_value)
{
+ using namespace std::tr1::placeholders;
+
Context context("When loading '" + stringify(f) + "':");
if (! f.exists())
@@ -220,8 +222,8 @@ PortageEnvironment::_load_atom_file(const FSEntry & f, I_ i, const std::string &
if (f.is_directory())
{
- for (DirIterator d(f), d_end ; d != d_end ; ++d)
- _load_atom_file(*d, i, def_value);
+ std::for_each(DirIterator(f), DirIterator(), std::tr1::bind(std::tr1::mem_fn(
+ &PortageEnvironment::_load_atom_file<I_>), this, _1, i, def_value));
}
else
{
@@ -255,6 +257,8 @@ template<typename I_>
void
PortageEnvironment::_load_lined_file(const FSEntry & f, I_ i)
{
+ using namespace std::tr1::placeholders;
+
Context context("When loading '" + stringify(f) + "':");
if (! f.exists())
@@ -262,8 +266,8 @@ PortageEnvironment::_load_lined_file(const FSEntry & f, I_ i)
if (f.is_directory())
{
- for (DirIterator d(f), d_end ; d != d_end ; ++d)
- _load_lined_file(*d, i);
+ std::for_each(DirIterator(f), DirIterator(), std::tr1::bind(std::tr1::mem_fn(
+ &PortageEnvironment::_load_lined_file<I_>), this, _1, i));
}
else
{
@@ -554,7 +558,7 @@ PortageEnvironment::perform_hook(const Hook & hook) const
_imp->need_hook_dirs();
_imp->hooker.reset(new Hooker(this));
std::for_each(_imp->hook_dirs.begin(), _imp->hook_dirs.end(),
- std::tr1::bind(std::tr1::mem_fn(&Hooker::add_dir), _imp->hooker.get(), _1));
+ std::tr1::bind(std::tr1::mem_fn(&Hooker::add_dir), _imp->hooker.get(), _1, false));
}
return _imp->hooker->perform_hook(hook);
diff --git a/paludis/hooker.cc b/paludis/hooker.cc
index a774e89..9ad8b9d 100644
--- a/paludis/hooker.cc
+++ b/paludis/hooker.cc
@@ -26,6 +26,7 @@
#include <paludis/util/fs_entry.hh>
#include <paludis/util/is_file_with_extension.hh>
#include <paludis/util/system.hh>
+#include <paludis/util/strip.hh>
#include <list>
using namespace paludis;
@@ -39,7 +40,7 @@ namespace paludis
{
const Environment * const env;
mutable HookPresentCache hook_cache;
- std::list<FSEntry> dirs;
+ std::list<std::pair<FSEntry, bool> > dirs;
Implementation(const Environment * const e) :
env(e)
@@ -58,10 +59,10 @@ Hooker::~Hooker()
}
void
-Hooker::add_dir(const FSEntry & dir)
+Hooker::add_dir(const FSEntry & dir, const bool v)
{
_imp->hook_cache.clear();
- _imp->dirs.push_back(dir);
+ _imp->dirs.push_back(std::make_pair(dir, v));
}
int
@@ -78,10 +79,10 @@ Hooker::perform_hook(const Hook & hook) const
bool had_hook(false);
int max_exit_status(0);
- for (std::list<FSEntry>::const_iterator h(_imp->dirs.begin()), h_end(_imp->dirs.end()) ;
+ for (std::list<std::pair<FSEntry, bool> >::const_iterator h(_imp->dirs.begin()), h_end(_imp->dirs.end()) ;
h != h_end ; ++h)
{
- FSEntry hh(*h / hook.name());
+ FSEntry hh(h->first / hook.name());
if (! hh.is_directory())
continue;
@@ -95,7 +96,7 @@ Hooker::perform_hook(const Hook & hook) const
for (std::list<FSEntry>::const_iterator hk(hooks.begin()),
hk_end(hooks.end()) ; hk != hk_end ; ++hk)
{
- Context c("When running hook script '" + stringify(hh) +
+ Context c("When running hook script '" + stringify(*hk) +
"' for hook '" + hook.name() + "':");
Log::get_instance()->message(ll_debug, lc_no_context, "Starting hook script '" +
stringify(hh) + "' for '" + hook.name() + "'");
@@ -109,6 +110,11 @@ Hooker::perform_hook(const Hook & hook) const
.with_setenv("PALUDIS_REDUCED_UID", stringify(_imp->env->reduced_uid()))
.with_setenv("PALUDIS_COMMAND", _imp->env->paludis_command()));
+ if (h->second)
+ cmd
+ .with_stdout_prefix(strip_trailing_string(hk->basename(), ".bash") + "> ")
+ .with_stderr_prefix(strip_trailing_string(hk->basename(), ".bash") + "> ");
+
for (Hook::Iterator x(hook.begin()), x_end(hook.end()) ; x != x_end ; ++x)
cmd.with_setenv(x->first, x->second);
diff --git a/paludis/hooker.hh b/paludis/hooker.hh
index e02877b..e303921 100644
--- a/paludis/hooker.hh
+++ b/paludis/hooker.hh
@@ -38,7 +38,7 @@ namespace paludis
~Hooker();
int perform_hook(const Hook &) const;
- void add_dir(const FSEntry &);
+ void add_dir(const FSEntry &, const bool output_prefixed);
};
}