Skip to content

Commit e374b6d

Browse files
authored
Merge pull request #3805 from grayjay/issue-3436-1.24
Cherry-pick #3688 and #3723 onto 1.24
2 parents 1598967 + ee4a403 commit e374b6d

File tree

17 files changed

+171
-21
lines changed

17 files changed

+171
-21
lines changed

appveyor.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
install:
2-
- choco install ghc -version 7.10.3
3-
- SET PATH=%PATH%;C:\tools\ghc\ghc-7.10.3\bin
2+
# Using '-y' and 'refreshenv' as a workaround to:
3+
# https://github.com/haskell/cabal/issues/3687
4+
- choco install -y ghc --version 8.0.1
5+
- refreshenv
46
- curl -o cabal.zip https://www.haskell.org/cabal/release/cabal-install-1.24.0.0/cabal-install-1.24.0.0-x86_64-unknown-mingw32.zip
57
- 7z x cabal.zip
68
- cabal --version

cabal-install/Distribution/Client/SetupWrapper.hs

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import Control.Applicative ( (<$>), (<*>) )
105105
import Data.Monoid ( mempty )
106106
#endif
107107
import Control.Monad ( when, unless )
108-
import Data.List ( foldl1' )
108+
import Data.List ( find, foldl1' )
109109
import Data.Maybe ( fromMaybe, isJust )
110110
import Data.Char ( isSpace )
111111
import Distribution.Client.Compat.ExecutablePath ( getExecutablePath )
@@ -381,26 +381,45 @@ externalSetupMethod verbosity options pkg bt mkargs = do
381381
Nothing -> getInstalledPackages verbosity
382382
comp (usePackageDB options') conf
383383

384-
cabalLibVersionToUse :: IO (Version, (Maybe UnitId)
384+
-- Choose the version of Cabal to use if the setup script has a dependency on
385+
-- Cabal, and possibly update the setup script options. The version also
386+
-- determines how to filter the flags to Setup.
387+
--
388+
-- We first check whether the dependency solver has specified a Cabal version.
389+
-- If it has, we use the solver's version without looking at the installed
390+
-- package index (See issue #3436). Otherwise, we pick the Cabal version by
391+
-- checking 'useCabalSpecVersion', then the saved version, and finally the
392+
-- versions available in the index.
393+
--
394+
-- The version chosen here must match the one used in 'compileSetupExecutable'
395+
-- (See issue #3433).
396+
cabalLibVersionToUse :: IO (Version, Maybe UnitId
385397
,SetupScriptOptions)
386398
cabalLibVersionToUse =
387-
case useCabalSpecVersion options of
388-
Just version -> do
399+
case find (hasCabal . snd) (useDependencies options) of
400+
Just (unitId, pkgId) -> do
401+
let version = pkgVersion pkgId
389402
updateSetupScript version bt
390-
writeFile setupVersionFile (show version ++ "\n")
391-
return (version, Nothing, options)
392-
Nothing -> do
393-
savedVer <- savedVersion
394-
case savedVer of
395-
Just version | version `withinRange` useCabalVersion options
396-
-> do updateSetupScript version bt
397-
-- Does the previously compiled setup executable still exist
398-
-- and is it up-to date?
399-
useExisting <- canUseExistingSetup version
400-
if useExisting
401-
then return (version, Nothing, options)
402-
else installedVersion
403-
_ -> installedVersion
403+
writeSetupVersionFile version
404+
return (version, Just unitId, options)
405+
Nothing ->
406+
case useCabalSpecVersion options of
407+
Just version -> do
408+
updateSetupScript version bt
409+
writeSetupVersionFile version
410+
return (version, Nothing, options)
411+
Nothing -> do
412+
savedVer <- savedVersion
413+
case savedVer of
414+
Just version | version `withinRange` useCabalVersion options
415+
-> do updateSetupScript version bt
416+
-- Does the previously compiled setup executable still exist
417+
-- and is it up-to date?
418+
useExisting <- canUseExistingSetup version
419+
if useExisting
420+
then return (version, Nothing, options)
421+
else installedVersion
422+
_ -> installedVersion
404423
where
405424
-- This check duplicates the checks in 'getCachedSetupExecutable' /
406425
-- 'compileSetupExecutable'. Unfortunately, we have to perform it twice
@@ -416,13 +435,20 @@ externalSetupMethod verbosity options pkg bt mkargs = do
416435
(&&) <$> setupProgFile `existsAndIsMoreRecentThan` setupHs
417436
<*> setupProgFile `existsAndIsMoreRecentThan` setupVersionFile
418437

438+
writeSetupVersionFile :: Version -> IO ()
439+
writeSetupVersionFile version =
440+
writeFile setupVersionFile (show version ++ "\n")
441+
442+
hasCabal (PackageIdentifier (PackageName "Cabal") _) = True
443+
hasCabal _ = False
444+
419445
installedVersion :: IO (Version, Maybe UnitId
420446
,SetupScriptOptions)
421447
installedVersion = do
422448
(comp, conf, options') <- configureCompiler options
423449
(version, mipkgid, options'') <- installedCabalVersion options' comp conf
424450
updateSetupScript version bt
425-
writeFile setupVersionFile (show version ++ "\n")
451+
writeSetupVersionFile version
426452
return (version, mipkgid, options'')
427453

428454
savedVersion :: IO (Maybe Version)

cabal-install/cabal-install.cabal

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ Extra-Source-Files:
3030
-- Generated with '../Cabal/misc/gen-extra-source-files.sh'
3131
-- Do NOT edit this section manually; instead, run the script.
3232
-- BEGIN gen-extra-source-files
33+
tests/IntegrationTests/custom-setup/common.sh
34+
tests/IntegrationTests/custom-setup/should_run/Cabal-99998/Cabal.cabal
35+
tests/IntegrationTests/custom-setup/should_run/Cabal-99998/CabalMessage.hs
36+
tests/IntegrationTests/custom-setup/should_run/Cabal-99999/Cabal.cabal
37+
tests/IntegrationTests/custom-setup/should_run/Cabal-99999/CabalMessage.hs
38+
tests/IntegrationTests/custom-setup/should_run/custom-setup-without-cabal-defaultMain/Setup.hs
39+
tests/IntegrationTests/custom-setup/should_run/custom-setup-without-cabal-defaultMain/custom-setup-without-cabal-defaultMain.cabal
40+
tests/IntegrationTests/custom-setup/should_run/custom-setup-without-cabal/Setup.hs
41+
tests/IntegrationTests/custom-setup/should_run/custom-setup-without-cabal/custom-setup-without-cabal.cabal
42+
tests/IntegrationTests/custom-setup/should_run/custom-setup/Setup.hs
43+
tests/IntegrationTests/custom-setup/should_run/custom-setup/custom-setup.cabal
44+
tests/IntegrationTests/custom-setup/should_run/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh
45+
tests/IntegrationTests/custom-setup/should_run/custom_setup_without_Cabal_doesnt_require_Cabal.sh
46+
tests/IntegrationTests/custom-setup/should_run/installs_Cabal_as_setup_dep.sh
3347
tests/IntegrationTests/custom/common.sh
3448
tests/IntegrationTests/custom/should_run/plain.err
3549
tests/IntegrationTests/custom/should_run/plain.sh
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Helper to run Cabal
2+
cabal() {
3+
"$CABAL" $CABAL_ARGS "$@"
4+
}
5+
6+
die() {
7+
echo "die: $@"
8+
exit 1
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Cabal
2+
version: 99998
3+
build-type: Simple
4+
cabal-version: >= 1.2
5+
6+
library
7+
build-depends: base
8+
exposed-modules: CabalMessage
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CabalMessage where
2+
3+
message = "This is Cabal-99998"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Cabal
2+
version: 99999
3+
build-type: Simple
4+
cabal-version: >= 1.2
5+
6+
library
7+
build-depends: base
8+
exposed-modules: CabalMessage
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CabalMessage where
2+
3+
message = "This is Cabal-99999"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Distribution.Simple
2+
3+
main = defaultMain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: custom-setup-without-cabal-defaultMain
2+
version: 1.0
3+
build-type: Custom
4+
cabal-version: >= 1.2
5+
6+
custom-setup
7+
setup-depends: base
8+
9+
library
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import System.Exit
2+
import System.IO
3+
4+
main = hPutStrLn stderr "My custom Setup" >> exitFailure
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: custom-setup-without-cabal
2+
version: 1.0
3+
build-type: Custom
4+
cabal-version: >= 99999
5+
6+
custom-setup
7+
setup-depends: base
8+
9+
library
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import CabalMessage (message)
2+
import System.Exit
3+
import System.IO
4+
5+
main = hPutStrLn stderr message >> exitFailure
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: custom-setup
2+
version: 1.0
3+
build-type: Custom
4+
cabal-version: >= 99999
5+
6+
custom-setup
7+
setup-depends: base, Cabal >= 99999
8+
9+
library
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. ../common.sh
2+
cd custom-setup-without-cabal-defaultMain
3+
4+
# This package has explicit setup dependencies that do not include Cabal.
5+
# Compilation should fail because Setup.hs imports Distribution.Simple.
6+
! cabal new-build custom-setup-without-cabal-defaultMain > output 2>&1
7+
cat output
8+
grep -q "\(Could not find module\|Failed to load interface for\).*Distribution\\.Simple" output \
9+
|| die "Should not have been able to import Cabal"
10+
11+
grep -q "It is a member of the hidden package .*Cabal-" output \
12+
|| die "Cabal should be available"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
. ../common.sh
2+
cd custom-setup-without-cabal
3+
4+
# This package has explicit setup dependencies that do not include Cabal.
5+
# new-build should try to build it, even though the cabal-version cannot be
6+
# satisfied by an installed version of Cabal (cabal-version: >= 99999). However,
7+
# configure should fail because Setup.hs just prints an error message and exits.
8+
! cabal new-build custom-setup-without-cabal > output 2>&1
9+
cat output
10+
grep -q "My custom Setup" output \
11+
|| die "Expected output from custom Setup"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Regression test for issue #3436
2+
3+
. ../common.sh
4+
cabal sandbox init
5+
cabal install ./Cabal-99998
6+
cabal sandbox add-source Cabal-99999
7+
8+
# Install custom-setup, which has a setup dependency on Cabal-99999.
9+
# cabal should build the setup script with Cabal-99999, but then
10+
# configure should fail because Setup just prints an error message
11+
# imported from Cabal and exits.
12+
! cabal install custom-setup/ > output 2>&1
13+
14+
cat output
15+
grep -q "This is Cabal-99999" output || die "Expected output from Cabal-99999"

0 commit comments

Comments
 (0)