Skip to content

Commit

Permalink
Merge pull request #2934 from BardurArantsson/rework-setup-dev-sh
Browse files Browse the repository at this point in the history
Rework setup-dev.sh to reduce redundancy
  • Loading branch information
23Skidoo committed Nov 26, 2015
2 parents 84cecac + 7e0c753 commit c3070e6
Showing 1 changed file with 26 additions and 39 deletions.
65 changes: 26 additions & 39 deletions setup-dev.sh
Expand Up @@ -6,45 +6,32 @@ die() {
exit 1
}

build_and_test() {
# Find sandbox location
local PACKAGEDB=`cabal exec -- sh -c 'echo $GHC_PACKAGE_PATH' | sed 's/:.*//'`
echo "Cabal package DB location: $PACKAGEDB"
# Do the building
./Setup configure --enable-tests --package-db="$PACKAGEDB" || die "$1 'configure' failed"
./Setup build || die "$1 'build' failed"
# Disabled for now: Tests fail on my system for some reason
# ./Setup test || die "$1 'test' failed"
}

install_deps() {
cabal install --only-dependencies --enable-tests || die "$1: Could not install needed dependencies"
}

create_setup() {
ghc --make -threaded Setup.hs || die "$1: Could not create 'Setup' executable"
}

init_sandbox() {
cabal sandbox delete # Ignore error status; probably just means sandbox doesn't exist
cabal sandbox init || die "$1: Could not initialize sandbox"
}

setup_cabal() {
init_sandbox Cabal
install_deps Cabal
create_setup Cabal
build_and_test Cabal
}

setup_cabalinstall() {
init_sandbox cabal-install
cabal sandbox add-source ../Cabal/ || die "cabal-install: Failed to add ../Cabal source"
install_deps cabal-install
create_setup cabal-install
build_and_test cabal-install
setup() {
# Extract parameters
local NAME="$1"
shift
local DEPS="$@"
# (Re-)create sandbox
cabal sandbox delete # Ignore error status; probably just means sandbox doesn't exist
cabal sandbox init || die "$NAME: Could not initialize sandbox"
# Add dependencies
for DEP in $DEPS; do
cabal sandbox add-source "$DEP"
done
# Install dependencies
cabal install --only-dependencies --enable-tests || die "$NAME: Could not install needed dependencies"
# Build the 'Setup' executable
ghc --make -threaded Setup.hs || die "$NAME: Could not create 'Setup' executable"
# Build the package
local PACKAGEDB=`cabal exec -- sh -c 'echo $GHC_PACKAGE_PATH' | sed 's/:.*//'`
echo "Cabal package DB location: $PACKAGEDB"
./Setup configure --enable-tests --package-db="$PACKAGEDB" || die "$NAME: 'configure' failed"
./Setup build || die "$NAME: 'build' failed"
# Run tests
# Disabled for now: There are some test failures
#./Setup test || die "$1 'test' failed"
}

# Build
(cd ${SCRIPT_DIR}/Cabal && setup_cabal ) || die "Failed to build Cabal"
(cd ${SCRIPT_DIR}/cabal-install && setup_cabalinstall) || die "Failed to build cabal-install"
(cd ${SCRIPT_DIR}/Cabal && setup "Cabal" ) || die "Failed to build Cabal"
(cd ${SCRIPT_DIR}/cabal-install && setup "cabal-install" ../Cabal) || die "Failed to build cabal-install"

0 comments on commit c3070e6

Please sign in to comment.