Sunday, November 21, 2010

Manual dependency resolution

Sometimes the tools one has at one's disposal just aren't smart enough. I wanted to profile a Haskell program and found out that I needed to reinstall all my libraries with profiling support, and cabal-install just wasn't smart enough to do it very well. I would try compiling my program with profiling support and it would complain about library X. I would try reinstalling library X and it would complain about library Y, and so on, ad nauseum. I seem to recall having a similar problem bootstrapping cabal-install in the first place. Here are a few shell functions I wrote that should make this process not quite so painful:
push () { 
STACK=("$1" "${STACK[@]}")
pop
}
pop () {
local TOP="${STACK[0]}";
run "$TOP" &&
unset STACK[0] &&
STACK=("${STACK[@]}") &&
if [ -n "${STACK[*]}" ]; then
pop
fi
}
run () {
cabal install --reinstall -p "$1"
}
Obviously one would redefine "run" as appropriate. For instance, the initial cabal bootstrap might look like
run () {
cd $1
for cmd in configure build install; do
runghc Setup.*hs $cmd
done
}
and I would "push $PWD" after downloading and unzipping each package.

No comments: