Skip to content

Commit 27a114b

Browse files
ezyangabooij
authored andcommitted
Test case for haskell#4049.
Signed-off-by: Edward Z. Yang <[email protected]> Signed-off-by: Auke Booij <[email protected]>
1 parent 3bd00f6 commit 27a114b

File tree

11 files changed

+192
-64
lines changed

11 files changed

+192
-64
lines changed

.travis.yml

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,17 @@ sudo: false
88
# we whitelist branches, as we don't really need to build dev-branches.
99
branches:
1010
only:
11-
- master
12-
- "1.24"
13-
- "1.22"
14-
- "1.20"
15-
- "1.18"
11+
- "pr4064-fixing"
1612

1713
# The following enables several GHC versions to be tested; often it's enough to
1814
# test only against the last release in a major GHC version. Feel free to omit
1915
# lines listings versions you don't need/want testing for.
2016
matrix:
2117
include:
22-
- env: GHCVER=8.0.1 SCRIPT=meta BUILDER=none
23-
os: linux
24-
sudo: required
25-
# These don't have -dyn/-prof whitelisted yet, so we have to
26-
# do the old-style installation
27-
- env: GHCVER=7.4.2 SCRIPT=script CABAL_LIB_ONLY=YES
28-
os: linux
29-
sudo: required
30-
- env: GHCVER=7.6.3 SCRIPT=script
31-
os: linux
32-
sudo: required
33-
- env: GHCVER=7.8.4 SCRIPT=script
34-
os: linux
35-
sudo: required
36-
# Ugh, we'd like to drop 'sudo: required' and use the
37-
# apt plugin for the next two
38-
# but the GCE instance we get has more memory, which makes
39-
# a big difference
40-
- env: GHCVER=7.10.3 SCRIPT=script
41-
os: linux
42-
sudo: required
43-
- env: GHCVER=8.0.1 SCRIPT=script DEPLOY_DOCS=YES TEST_OTHER_VERSIONS=YES
44-
sudo: required
45-
os: linux
46-
- env: GHCVER=8.0.1 SCRIPT=solver-debug-flags
47-
sudo: required
48-
os: linux
49-
- env: GHCVER=8.0.1 SCRIPT=script PARSEC=YES TEST_OTHER_VERSIONS=YES
50-
os: linux
51-
sudo: required
52-
- env: GHCVER=8.0.1 SCRIPT=bootstrap
53-
sudo: required
54-
os: linux
55-
56-
# We axed GHC 7.6 and earlier because it's not worth the trouble to
57-
# make older GHC work with clang's cpp. See
58-
# https://ghc.haskell.org/trac/ghc/ticket/8493
59-
- env: GHCVER=7.8.4 SCRIPT=script
60-
os: osx
61-
osx_image: xcode6.4 # We need 10.10
62-
63-
# TODO: We might want to specify OSX version
64-
# https://docs.travis-ci.com/user/osx-ci-environment/#OS-X-Version
65-
- env: GHCVER=7.10.3 SCRIPT=script
18+
- env: GHCVER=7.10.3 SCRIPT=pr4064
6619
os: osx
67-
- env: GHCVER=8.0.1 SCRIPT=script
20+
- env: GHCVER=8.0.1 SCRIPT=pr4064
6821
os: osx
69-
- env: GHCVER=8.0.1 SCRIPT=bootstrap
70-
os: osx
71-
72-
- env: GHCVER=via-stack SCRIPT=stack STACKAGE_RESOLVER=lts
73-
os: linux
74-
addons:
75-
apt:
76-
packages:
77-
- libgmp-dev
7822

7923
allow_failures:
8024
- env: GHCVER=via-stack SCRIPT=stack STACKAGE_RESOLVER=lts

cabal-install/Distribution/Client/Install.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import System.Exit
4747
( ExitCode(..) )
4848
import Distribution.Compat.Exception
4949
( catchIO, catchExit )
50-
import Control.Exception ( assert )
5150
import Control.Monad
5251
( forM_, mapM )
5352
import System.Directory
@@ -1426,9 +1425,7 @@ installUnpackedPackage verbosity installLock numJobs
14261425
ipkgs <- genPkgConfs mLogPath
14271426
let ipkgs' = case ipkgs of
14281427
[ipkg] -> [ipkg { Installed.installedUnitId = uid }]
1429-
_ -> assert (any ((== uid)
1430-
. Installed.installedUnitId)
1431-
ipkgs) ipkgs
1428+
_ -> ipkgs
14321429
let packageDBs = interpretPackageDbFlags
14331430
(fromFlag (configUserInstall configFlags))
14341431
(configPackageDBs configFlags)

cabal-install/cabal-install.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ Extra-Source-Files:
8080
tests/IntegrationTests/custom/segfault/plain.cabal
8181
tests/IntegrationTests/exec/Foo.hs
8282
tests/IntegrationTests/exec/My.hs
83+
tests/IntegrationTests/exec/T4049.sh
84+
tests/IntegrationTests/exec/T4049/UseLib.c
85+
tests/IntegrationTests/exec/T4049/csrc/MyForeignLibWrapper.c
86+
tests/IntegrationTests/exec/T4049/my-foreign-lib.cabal
87+
tests/IntegrationTests/exec/T4049/src/MyForeignLib/Hello.hs
88+
tests/IntegrationTests/exec/T4049/src/MyForeignLib/SomeBindings.hsc
8389
tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out
8490
tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.sh
8591
tests/IntegrationTests/exec/auto_configures_on_exec.out

cabal-install/tests/IntegrationTests.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Distribution.Compat.CreatePipe (createPipe)
1212
import Distribution.Compat.Environment (setEnv, getEnvironment)
1313
import Distribution.Compat.Internal.TempFile (createTempDirectory)
1414
import Distribution.Simple.Configure (findDistPrefOrDefault)
15-
import Distribution.Simple.Program.Builtin (ghcPkgProgram)
15+
import Distribution.Simple.Program.Builtin (ghcPkgProgram, ghcProgram)
1616
import Distribution.Simple.Program.Db
1717
(defaultProgramDb, requireProgram, setProgramSearchPath)
1818
import Distribution.Simple.Program.Find
@@ -285,10 +285,12 @@ main = do
285285
let programSearchPath = ProgramSearchPathDir buildDir : defaultProgramSearchPath
286286
(cabal, _) <- requireProgram normal cabalProgram (setProgramSearchPath programSearchPath defaultProgramDb)
287287
(ghcPkg, _) <- requireProgram normal ghcPkgProgram defaultProgramDb
288+
(ghc, _) <- requireProgram normal ghcProgram defaultProgramDb
288289
baseDirectory <- canonicalizePath $ "tests" </> "IntegrationTests"
289290
-- Set up environment variables for test scripts
290291
setEnv "GHC_PKG" $ programPath ghcPkg
291292
setEnv "CABAL" $ programPath cabal
293+
setEnv "GHC" $ programPath ghc
292294
-- Define default arguments
293295
setEnv "CABAL_ARGS" $ "--config-file=config-file"
294296
setEnv "CABAL_ARGS_NO_CONFIG_FILE" " "
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
. ./common.sh
2+
3+
require_ghc_ge 708
4+
5+
cd T4049
6+
cabal sandbox init > /dev/null
7+
cabal install --enable-shared > /dev/null
8+
$GHC -no-hs-main UseLib.c -o UseLib -lmyforeignlib -L"$PWD/.cabal-sandbox/lib"
9+
find "$PWD/.cabal-sandbox/"
10+
DYLD_LIBRARY_PATH="$PWD/.cabal-sandbox/lib" $PWD/UseLib
11+
cabal exec "$PWD/UseLib"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
#include "HsFFI.h"
3+
4+
HsBool myForeignLibInit(void);
5+
void myForeignLibExit(void);
6+
void sayHi(void);
7+
8+
int main()
9+
{
10+
myForeignLibInit();
11+
sayHi();
12+
myForeignLibExit();
13+
return 0;
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <stdlib.h>
2+
#include "HsFFI.h"
3+
4+
HsBool myForeignLibInit(void){
5+
int argc = 2;
6+
char *argv[] = { "+RTS", "-A32m", NULL };
7+
char **pargv = argv;
8+
9+
// Initialize Haskell runtime
10+
hs_init(&argc, &pargv);
11+
12+
// do any other initialization here and
13+
// return false if there was a problem
14+
return HS_BOOL_TRUE;
15+
}
16+
17+
void myForeignLibExit(void){
18+
hs_exit();
19+
}
20+
21+
int cFoo2() {
22+
return 1234;
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: my-foreign-lib
2+
version: 0.1.0.0
3+
author: Edsko de Vries
4+
maintainer: [email protected]
5+
build-type: Simple
6+
cabal-version: >=1.10
7+
8+
foreign-library myforeignlib
9+
type: native-shared
10+
11+
if os(windows)
12+
options: standalone
13+
14+
other-modules: MyForeignLib.Hello
15+
MyForeignLib.SomeBindings
16+
build-depends: base
17+
hs-source-dirs: src
18+
c-sources: csrc/MyForeignLibWrapper.c
19+
default-language: Haskell2010
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- | Module with single foreign export
2+
module MyForeignLib.Hello (sayHi) where
3+
4+
import MyForeignLib.SomeBindings
5+
6+
foreign export ccall sayHi :: IO ()
7+
8+
-- | Say hi!
9+
sayHi :: IO ()
10+
sayHi = putStrLn $ "Hi from a foreign library! Foo has value " ++ show valueOfFoo
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- | Module that needs the hsc2hs preprocessor
2+
module MyForeignLib.SomeBindings where
3+
4+
#define FOO 1
5+
6+
#ifdef FOO
7+
-- | Value guarded by a CPP flag
8+
valueOfFoo :: Int
9+
valueOfFoo = 5678
10+
#endif

travis-pr4064.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
3+
# ATTENTION! Before editing this file, maybe you can make a
4+
# separate script to do your test? We don't want individual
5+
# Travis builds to take too long (they time out at 50min and
6+
# it's generally unpleasant if the build takes that long.)
7+
# If you make a separate matrix entry in .travis.yml it can
8+
# be run in parallel.
9+
10+
. ./travis-common.sh
11+
12+
CABAL_STORE_DB="${HOME}/.cabal/store/ghc-${GHCVER}/package.db"
13+
CABAL_LOCAL_DB="${PWD}/dist-newstyle/packagedb/ghc-${GHCVER}"
14+
CABAL_BDIR="${PWD}/dist-newstyle/build/Cabal-${CABAL_VERSION}"
15+
CABAL_TESTSUITE_BDIR="${PWD}/dist-newstyle/build/cabal-testsuite-${CABAL_VERSION}"
16+
CABAL_INSTALL_BDIR="${PWD}/dist-newstyle/build/cabal-install-${CABAL_VERSION}"
17+
CABAL_INSTALL_SETUP="${CABAL_INSTALL_BDIR}/setup/setup"
18+
# --hide-successes uses terminal control characters which mess up
19+
# Travis's log viewer. So just print them all!
20+
TEST_OPTIONS=""
21+
22+
# ---------------------------------------------------------------------
23+
# Update the Cabal index
24+
# ---------------------------------------------------------------------
25+
26+
timed cabal update
27+
28+
# ---------------------------------------------------------------------
29+
# Install happy if necessary
30+
# ---------------------------------------------------------------------
31+
32+
if ! command -v happy; then
33+
timed cabal install happy
34+
fi
35+
36+
# ---------------------------------------------------------------------
37+
# Setup our local project
38+
# ---------------------------------------------------------------------
39+
40+
cp cabal.project.travis cabal.project.local
41+
42+
# ---------------------------------------------------------------------
43+
# Cabal
44+
# ---------------------------------------------------------------------
45+
46+
# Needed to work around some bugs in nix-local-build code.
47+
export CABAL_BUILDDIR="${CABAL_BDIR}"
48+
49+
# NB: Best to do everything for a single package together as it's
50+
# more efficient (since new-build will uselessly try to rebuild
51+
# Cabal otherwise).
52+
if [ "x$PARSEC" = "xYES" ]; then
53+
timed cabal new-build -fparsec Cabal Cabal:unit-tests Cabal:parser-tests Cabal:parser-hackage-tests
54+
else
55+
timed cabal new-build Cabal
56+
fi
57+
58+
unset CABAL_BUILDDIR
59+
60+
# ---------------------------------------------------------------------
61+
# cabal-install
62+
# ---------------------------------------------------------------------
63+
64+
# Needed to work around some bugs in nix-local-build code.
65+
export CABAL_BUILDDIR="${CABAL_INSTALL_BDIR}"
66+
67+
timed cabal new-build cabal-install:cabal \
68+
cabal-install:integration-tests \
69+
cabal-install:integration-tests2 \
70+
cabal-install:unit-tests \
71+
cabal-install:solver-quickcheck
72+
73+
# The integration-tests2 need the hackage index, and need it in the secure
74+
# format, which is not necessarily the default format of the bootstrap cabal.
75+
# If the format does match then this will be very quick.
76+
timed ${CABAL_INSTALL_BDIR}/build/cabal/cabal update
77+
78+
# Run tests
79+
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests/integration-tests $TEST_OPTIONS) || exit $?
80+
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/unit-tests/unit-tests $TEST_OPTIONS) || exit $?
81+
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/solver-quickcheck/solver-quickcheck $TEST_OPTIONS --quickcheck-tests=1000) || exit $?
82+
(cd cabal-install && timed ${CABAL_INSTALL_BDIR}/build/integration-tests2/integration-tests2 $TEST_OPTIONS) || exit $?
83+
84+
# Haddock
85+
(cd cabal-install && timed ${CABAL_INSTALL_SETUP} haddock --builddir=${CABAL_INSTALL_BDIR} ) || exit $?
86+
87+
(cd cabal-install && timed cabal check) || exit $?
88+
89+
unset CABAL_BUILDDIR
90+
91+
# Check what we got
92+
${CABAL_INSTALL_BDIR}/build/cabal/cabal --version

0 commit comments

Comments
 (0)