aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-15 23:23:25 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-04-15 23:23:25 +0000
commitfc47615e397f61f7f6d5e08003510f94fefd75d9 (patch)
tree0a3428e8747c051bb077fdd78220fd637b7b3ab5
parentc27a1dc3115a1c282c3ec010fe46128c119b5751 (diff)
downloadpaludis-fc47615e397f61f7f6d5e08003510f94fefd75d9.tar.gz
paludis-fc47615e397f61f7f6d5e08003510f94fefd75d9.tar.xz
Allow after as well as depend for hooks
-rwxr-xr-xpaludis/hooker.bash11
-rw-r--r--paludis/hooker.cc19
-rwxr-xr-xpaludis/hooker_TEST_setup.sh13
3 files changed, 38 insertions, 5 deletions
diff --git a/paludis/hooker.bash b/paludis/hooker.bash
index 67c4a07..9dbe7b1 100755
--- a/paludis/hooker.bash
+++ b/paludis/hooker.bash
@@ -29,8 +29,15 @@ if ! source $1 ; then
exit 123
fi
-if [[ $(type $2 2>/dev/null ) != "function" ]] ; then
- echo "Error running undefined function '$2' from file '$1' for hook '$HOOK'" 1>&2
+if [[ $(type -t $2 2>/dev/null ) != "function" ]] ; then
+ if [[ ${2#hook_depend} != ${2} ]] ; then
+ exit 0
+ elif [[ ${2#hook_after} != ${2} ]] ; then
+ exit 0
+ else
+ echo "Error running undefined function '$2' from file '$1' for hook '$HOOK'" | tee outfile 1>&2
+ exit 124
+ fi
fi
$2
diff --git a/paludis/hooker.cc b/paludis/hooker.cc
index dfb3ca2..b9115a5 100644
--- a/paludis/hooker.cc
+++ b/paludis/hooker.cc
@@ -89,6 +89,8 @@ namespace
const bool _run_prefixed;
const Environment * const _env;
+ virtual void _add_dependency_class(const Hook &, DirectedGraph<std::string, int> &, bool);
+
public:
FancyHookFile(const FSEntry & f, const bool r, const Environment * const e) :
_file_name(f),
@@ -190,11 +192,19 @@ FancyHookFile::add_dependencies(const Hook & hook, DirectedGraph<std::string, in
{
Context c("When finding dependencies of hook script '" + stringify(file_name()) + "' for hook '" + hook.name() + "':");
+ _add_dependency_class(hook, g, false);
+ _add_dependency_class(hook, g, true);
+}
+
+void
+FancyHookFile::_add_dependency_class(const Hook & hook, DirectedGraph<std::string, int> & g, bool depend)
+{
Log::get_instance()->message(ll_debug, lc_no_context, "Starting hook script '" +
stringify(file_name()) + "' for dependencies of '" + hook.name() + "'");
Command cmd(getenv_with_default("PALUDIS_HOOKER_DIR", LIBEXECDIR "/paludis") +
- "/hooker.bash '" + stringify(file_name()) + "' 'hook_depend_" + stringify(hook.name()) + "'");
+ "/hooker.bash '" + stringify(file_name()) + "' 'hook_" + (depend ? "depend" : "after") + "_" +
+ stringify(hook.name()) + "'");
cmd
.with_setenv("ROOT", stringify(_env->root()))
@@ -206,7 +216,7 @@ FancyHookFile::add_dependencies(const Hook & hook, DirectedGraph<std::string, in
.with_setenv("PALUDIS_REDUCED_UID", stringify(_env->reduced_uid()))
.with_setenv("PALUDIS_COMMAND", _env->paludis_command());
- cmd.with_stderr_prefix(strip_trailing_string(file_name().basename(), ".bash") + " (depend)> ");
+ cmd.with_stderr_prefix(strip_trailing_string(file_name().basename(), ".bash") + "> ");
for (Hook::Iterator x(hook.begin()), x_end(hook.end()) ; x != x_end ; ++x)
cmd.with_setenv(x->first, x->second);
@@ -228,9 +238,12 @@ FancyHookFile::add_dependencies(const Hook & hook, DirectedGraph<std::string, in
{
if (g.has_node(*d))
g.add_edge(strip_trailing_string(file_name().basename(), ".hook"), *d, 0);
- else
+ else if (depend)
Log::get_instance()->message(ll_warning, lc_context, "Hook dependency '" + stringify(*d) +
"' for '" + stringify(file_name()) + "' not found");
+ else
+ Log::get_instance()->message(ll_debug, lc_context, "Hook after '" + stringify(*d) +
+ "' for '" + stringify(file_name()) + "' not found");
}
}
else
diff --git a/paludis/hooker_TEST_setup.sh b/paludis/hooker_TEST_setup.sh
index 8348283..06c4ca5 100755
--- a/paludis/hooker_TEST_setup.sh
+++ b/paludis/hooker_TEST_setup.sh
@@ -19,6 +19,10 @@ hook_run_fancy_hook() {
hook_depend_fancy_hook() {
echo
}
+
+hook_after_fancy_hook() {
+ echo
+}
END
chmod +x fancy_hook/one.hook
@@ -77,6 +81,15 @@ hook_depend_ordering() {
echo e f
;;
h)
+ esac
+}
+
+hook_after_ordering() {
+ case $(basename ${HOOK_FILE} | sed -e 's,\.hook$,,' ) in
+ a)
+ echo x
+ ;;
+ h)
echo i
;;
j)