Skip to content

Commit

Permalink
Test case for haskell#4049.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Signed-off-by: Auke Booij <auke@tulcod.com>
  • Loading branch information
ezyang authored and abooij committed Nov 1, 2016
1 parent 3bd00f6 commit c4dd4bc
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 64 deletions.
62 changes: 3 additions & 59 deletions .travis.yml
Expand Up @@ -8,73 +8,17 @@ sudo: false
# we whitelist branches, as we don't really need to build dev-branches.
branches:
only:
- master
- "1.24"
- "1.22"
- "1.20"
- "1.18"
- "pr4064-fixing"

# The following enables several GHC versions to be tested; often it's enough to
# test only against the last release in a major GHC version. Feel free to omit
# lines listings versions you don't need/want testing for.
matrix:
include:
- env: GHCVER=8.0.1 SCRIPT=meta BUILDER=none
os: linux
sudo: required
# These don't have -dyn/-prof whitelisted yet, so we have to
# do the old-style installation
- env: GHCVER=7.4.2 SCRIPT=script CABAL_LIB_ONLY=YES
os: linux
sudo: required
- env: GHCVER=7.6.3 SCRIPT=script
os: linux
sudo: required
- env: GHCVER=7.8.4 SCRIPT=script
os: linux
sudo: required
# Ugh, we'd like to drop 'sudo: required' and use the
# apt plugin for the next two
# but the GCE instance we get has more memory, which makes
# a big difference
- env: GHCVER=7.10.3 SCRIPT=script
os: linux
sudo: required
- env: GHCVER=8.0.1 SCRIPT=script DEPLOY_DOCS=YES TEST_OTHER_VERSIONS=YES
sudo: required
os: linux
- env: GHCVER=8.0.1 SCRIPT=solver-debug-flags
sudo: required
os: linux
- env: GHCVER=8.0.1 SCRIPT=script PARSEC=YES TEST_OTHER_VERSIONS=YES
os: linux
sudo: required
- env: GHCVER=8.0.1 SCRIPT=bootstrap
sudo: required
os: linux

# We axed GHC 7.6 and earlier because it's not worth the trouble to
# make older GHC work with clang's cpp. See
# https://ghc.haskell.org/trac/ghc/ticket/8493
- env: GHCVER=7.8.4 SCRIPT=script
os: osx
osx_image: xcode6.4 # We need 10.10

# TODO: We might want to specify OSX version
# https://docs.travis-ci.com/user/osx-ci-environment/#OS-X-Version
- env: GHCVER=7.10.3 SCRIPT=script
- env: GHCVER=7.10.3 SCRIPT=pr4064
os: osx
- env: GHCVER=8.0.1 SCRIPT=script
- env: GHCVER=8.0.1 SCRIPT=pr4064
os: osx
- env: GHCVER=8.0.1 SCRIPT=bootstrap
os: osx

- env: GHCVER=via-stack SCRIPT=stack STACKAGE_RESOLVER=lts
os: linux
addons:
apt:
packages:
- libgmp-dev

allow_failures:
- env: GHCVER=via-stack SCRIPT=stack STACKAGE_RESOLVER=lts
Expand Down
5 changes: 1 addition & 4 deletions cabal-install/Distribution/Client/Install.hs
Expand Up @@ -47,7 +47,6 @@ import System.Exit
( ExitCode(..) )
import Distribution.Compat.Exception
( catchIO, catchExit )
import Control.Exception ( assert )
import Control.Monad
( forM_, mapM )
import System.Directory
Expand Down Expand Up @@ -1426,9 +1425,7 @@ installUnpackedPackage verbosity installLock numJobs
ipkgs <- genPkgConfs mLogPath
let ipkgs' = case ipkgs of
[ipkg] -> [ipkg { Installed.installedUnitId = uid }]
_ -> assert (any ((== uid)
. Installed.installedUnitId)
ipkgs) ipkgs
_ -> ipkgs
let packageDBs = interpretPackageDbFlags
(fromFlag (configUserInstall configFlags))
(configPackageDBs configFlags)
Expand Down
6 changes: 6 additions & 0 deletions cabal-install/cabal-install.cabal
Expand Up @@ -80,6 +80,12 @@ Extra-Source-Files:
tests/IntegrationTests/custom/segfault/plain.cabal
tests/IntegrationTests/exec/Foo.hs
tests/IntegrationTests/exec/My.hs
tests/IntegrationTests/exec/T4049.sh
tests/IntegrationTests/exec/T4049/UseLib.c
tests/IntegrationTests/exec/T4049/csrc/MyForeignLibWrapper.c
tests/IntegrationTests/exec/T4049/my-foreign-lib.cabal
tests/IntegrationTests/exec/T4049/src/MyForeignLib/Hello.hs
tests/IntegrationTests/exec/T4049/src/MyForeignLib/SomeBindings.hsc
tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out
tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh
tests/IntegrationTests/exec/auto_configures_on_exec.out
Expand Down
4 changes: 3 additions & 1 deletion cabal-install/tests/IntegrationTests.hs
Expand Up @@ -12,7 +12,7 @@ import Distribution.Compat.CreatePipe (createPipe)
import Distribution.Compat.Environment (setEnv, getEnvironment)
import Distribution.Compat.Internal.TempFile (createTempDirectory)
import Distribution.Simple.Configure (findDistPrefOrDefault)
import Distribution.Simple.Program.Builtin (ghcPkgProgram)
import Distribution.Simple.Program.Builtin (ghcPkgProgram, ghcProgram)
import Distribution.Simple.Program.Db
(defaultProgramDb, requireProgram, setProgramSearchPath)
import Distribution.Simple.Program.Find
Expand Down Expand Up @@ -285,10 +285,12 @@ main = do
let programSearchPath = ProgramSearchPathDir buildDir : defaultProgramSearchPath
(cabal, _) <- requireProgram normal cabalProgram (setProgramSearchPath programSearchPath defaultProgramDb)
(ghcPkg, _) <- requireProgram normal ghcPkgProgram defaultProgramDb
(ghc, _) <- requireProgram normal ghcProgram defaultProgramDb
baseDirectory <- canonicalizePath $ "tests" </> "IntegrationTests"
-- Set up environment variables for test scripts
setEnv "GHC_PKG" $ programPath ghcPkg
setEnv "CABAL" $ programPath cabal
setEnv "GHC" $ programPath ghc
-- Define default arguments
setEnv "CABAL_ARGS" $ "--config-file=config-file"
setEnv "CABAL_ARGS_NO_CONFIG_FILE" " "
Expand Down
10 changes: 10 additions & 0 deletions cabal-install/tests/IntegrationTests/exec/T4049.sh
@@ -0,0 +1,10 @@
. ./common.sh

require_ghc_ge 708

cd T4049
cabal sandbox init > /dev/null
cabal install --enable-shared > /dev/null
$GHC -no-hs-main UseLib.c -o UseLib -lmyforeignlib -L"$PWD/.cabal-sandbox/lib"
DYLD_LIBRARY_PATH="$PWD/.cabal-sandbox/lib" $PWD/UseLib
cabal exec "$PWD/UseLib"
9 changes: 9 additions & 0 deletions cabal-install/tests/IntegrationTests/exec/T4049/UseLib.c
@@ -0,0 +1,9 @@
#include <stdio.h>

int main()
{
myForeignLibInit();
sayHi();
myForeignLibExit();
return 0;
}
@@ -0,0 +1,23 @@
#include <stdlib.h>
#include "HsFFI.h"

HsBool myForeignLibInit(void){
int argc = 2;
char *argv[] = { "+RTS", "-A32m", NULL };
char **pargv = argv;

// Initialize Haskell runtime
hs_init(&argc, &pargv);

// do any other initialization here and
// return false if there was a problem
return HS_BOOL_TRUE;
}

void myForeignLibExit(void){
hs_exit();
}

int cFoo2() {
return 1234;
}
@@ -0,0 +1,19 @@
name: my-foreign-lib
version: 0.1.0.0
author: Edsko de Vries
maintainer: edsko@well-typed.com
build-type: Simple
cabal-version: >=1.10

foreign-library myforeignlib
type: native-shared

if os(windows)
options: standalone

other-modules: MyForeignLib.Hello
MyForeignLib.SomeBindings
build-depends: base
hs-source-dirs: src
c-sources: csrc/MyForeignLibWrapper.c
default-language: Haskell2010
@@ -0,0 +1,10 @@
-- | Module with single foreign export
module MyForeignLib.Hello (sayHi) where

import MyForeignLib.SomeBindings

foreign export ccall sayHi :: IO ()

-- | Say hi!
sayHi :: IO ()
sayHi = putStrLn $ "Hi from a foreign library! Foo has value " ++ show valueOfFoo
@@ -0,0 +1,10 @@
-- | Module that needs the hsc2hs preprocessor
module MyForeignLib.SomeBindings where

#define FOO 1

#ifdef FOO
-- | Value guarded by a CPP flag
valueOfFoo :: Int
valueOfFoo = 5678
#endif
92 changes: 92 additions & 0 deletions travis-pr4064.sh
@@ -0,0 +1,92 @@
#!/bin/sh

# ATTENTION! Before editing this file, maybe you can make a
# separate script to do your test? We don't want individual
# Travis builds to take too long (they time out at 50min and
# it's generally unpleasant if the build takes that long.)
# If you make a separate matrix entry in .travis.yml it can
# be run in parallel.

. ./travis-common.sh

CABAL_STORE_DB="${HOME}/.cabal/store/ghc-${GHCVER}/package.db"
CABAL_LOCAL_DB="${PWD}/dist-newstyle/packagedb/ghc-${GHCVER}"
CABAL_BDIR="${PWD}/dist-newstyle/build/Cabal-${CABAL_VERSION}"
CABAL_TESTSUITE_BDIR="${PWD}/dist-newstyle/build/cabal-testsuite-${CABAL_VERSION}"
CABAL_INSTALL_BDIR="${PWD}/dist-newstyle/build/cabal-install-${CABAL_VERSION}"
CABAL_INSTALL_SETUP="${CABAL_INSTALL_BDIR}/setup/setup"
# --hide-successes uses terminal control characters which mess up
# Travis's log viewer. So just print them all!
TEST_OPTIONS=""

# ---------------------------------------------------------------------
# Update the Cabal index
# ---------------------------------------------------------------------

timed cabal update

# ---------------------------------------------------------------------
# Install happy if necessary
# ---------------------------------------------------------------------

if ! command -v happy; then
timed cabal install happy
fi

# ---------------------------------------------------------------------
# Setup our local project
# ---------------------------------------------------------------------

cp cabal.project.travis cabal.project.local

# ---------------------------------------------------------------------
# Cabal
# ---------------------------------------------------------------------

# Needed to work around some bugs in nix-local-build code.
export CABAL_BUILDDIR="${CABAL_BDIR}"

# NB: Best to do everything for a single package together as it's
# more efficient (since new-build will uselessly try to rebuild
# Cabal otherwise).
if [ "x$PARSEC" = "xYES" ]; then
timed cabal new-build -fparsec Cabal Cabal:unit-tests Cabal:parser-tests Cabal:parser-hackage-tests
else
timed cabal new-build Cabal
fi

unset CABAL_BUILDDIR

# ---------------------------------------------------------------------
# cabal-install
# ---------------------------------------------------------------------

# Needed to work around some bugs in nix-local-build code.
export CABAL_BUILDDIR="${CABAL_INSTALL_BDIR}"

timed cabal new-build cabal-install:cabal \
cabal-install:integration-tests \
cabal-install:integration-tests2 \
cabal-install:unit-tests \
cabal-install:solver-quickcheck

# The integration-tests2 need the hackage index, and need it in the secure
# format, which is not necessarily the default format of the bootstrap cabal.
# If the format does match then this will be very quick.
timed ${CABAL_INSTALL_BDIR}/build/cabal/cabal update

# Run tests
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests/integration-tests $TEST_OPTIONS) || exit $?
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/unit-tests/unit-tests $TEST_OPTIONS) || exit $?
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/solver-quickcheck/solver-quickcheck $TEST_OPTIONS --quickcheck-tests=1000) || exit $?
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests2/integration-tests2 $TEST_OPTIONS) || exit $?

# Haddock
(cd cabal-install && timed ${CABAL_INSTALL_SETUP} haddock --builddir=${CABAL_INSTALL_BDIR} ) || exit $?

(cd cabal-install && timed cabal check) || exit $?

unset CABAL_BUILDDIR

# Check what we got
${CABAL_INSTALL_BDIR}/build/cabal/cabal --version

0 comments on commit c4dd4bc

Please sign in to comment.