Skip to content

Commit 03d9829

Browse files
authored
Merge pull request #9988 from sheaf/no-implicit-prelude-setup
Add NoImplicitPrelude to buildTypeScript
2 parents 47e7295 + 42b8dc1 commit 03d9829

File tree

7 files changed

+54
-6
lines changed

7 files changed

+54
-6
lines changed

cabal-install/src/Distribution/Client/ProjectPlanning/SetupPolicy.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ mkDefaultSetupDeps compiler platform pkg =
133133

134134
-- For other build types (like Simple) if we still need to compile an
135135
-- external Setup.hs, it'll be one of the simple ones that only depends
136-
-- on Cabal and base.
136+
-- on Cabal.
137137
SetupNonCustomExternalLib ->
138138
Just
139139
[ Dependency cabalPkgname cabalConstraint mainLibSet
140-
, Dependency basePkgname anyVersion mainLibSet
141140
]
142141
where
143142
cabalConstraint = orLaterVersion (csvToVersion (specVersion pkg))
@@ -217,9 +216,8 @@ packageSetupScriptSpecVersion _ pkg libDepGraph deps =
217216
fromMaybe [] $
218217
Graph.closure libDepGraph (CD.setupDeps deps)
219218

220-
cabalPkgname, basePkgname :: PackageName
219+
cabalPkgname :: PackageName
221220
cabalPkgname = mkPackageName "Cabal"
222-
basePkgname = mkPackageName "base"
223221

224222
legacyCustomSetupPkgs :: Compiler -> Platform -> [PackageName]
225223
legacyCustomSetupPkgs compiler (Platform _ os) =

cabal-install/src/Distribution/Client/SetupWrapper.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ import Distribution.Utils.NubList
181181
import Distribution.Verbosity
182182

183183
import Data.List (foldl1')
184+
import qualified Data.Map.Lazy as Map
184185
import Distribution.Simple.Setup (globalCommand)
185186
import Distribution.Client.Compat.ExecutablePath (getExecutablePath)
186187
import Distribution.Compat.Process (proc)
@@ -858,7 +859,7 @@ getExternalSetupMethod verbosity options pkg bt = do
858859
rewriteFileLBS verbosity (i setupHs) (buildTypeScript cabalLibVersion)
859860

860861
buildTypeScript :: Version -> BS.ByteString
861-
buildTypeScript cabalLibVersion = case bt of
862+
buildTypeScript cabalLibVersion = "{-# LANGUAGE NoImplicitPrelude #-}\n" <> case bt of
862863
Simple -> "import Distribution.Simple; main = defaultMain\n"
863864
Configure
864865
| cabalLibVersion >= mkVersion [1, 3, 10] -> "import Distribution.Simple; main = defaultMainWithHooks autoconfUserHooks\n"
@@ -1111,6 +1112,13 @@ getExternalSetupMethod verbosity options pkg bt = do
11111112
| useVersionMacros options'
11121113
]
11131114
, ghcOptExtra = extraOpts
1115+
, ghcOptExtensions = toNubListR $
1116+
if bt == Custom || any (isBasePkgId . snd) selectedDeps
1117+
then []
1118+
else [ Simple.DisableExtension Simple.ImplicitPrelude ]
1119+
-- Pass -WNoImplicitPrelude to avoid depending on base
1120+
-- when compiling a Simple Setup.hs file.
1121+
, ghcOptExtensionMap = Map.fromList . Simple.compilerExtensions $ compiler
11141122
}
11151123
let ghcCmdLine = renderGhcOptions compiler platform ghcOptions
11161124
when (useVersionMacros options') $
@@ -1131,5 +1139,6 @@ getExternalSetupMethod verbosity options pkg bt = do
11311139
hPutStr logHandle output
11321140
return $ i setupProgFile
11331141

1134-
isCabalPkgId :: PackageIdentifier -> Bool
1142+
isCabalPkgId, isBasePkgId :: PackageIdentifier -> Bool
11351143
isCabalPkgId (PackageIdentifier pname _) = pname == mkPackageName "Cabal"
1144+
isBasePkgId (PackageIdentifier pname _) = pname == mkPackageName "base"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
module A where {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
3+
module SetupHooks ( setupHooks ) where
4+
5+
import Distribution.Simple.SetupHooks ( SetupHooks, noSetupHooks )
6+
7+
setupHooks :: SetupHooks
8+
setupHooks = noSetupHooks
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Test that we can compile the Setup.hs script for a package with
4+
-- build-type:Hooks without requiring a dependency on 'base'.
5+
--
6+
-- NB: we specifically don't include a 'Setup.hs' file in this package,
7+
-- as we rely on 'cabal-install' generating one that does not incur an extra
8+
-- dependency on base.
9+
main = cabalTest $ do
10+
mpkgdb <- testPackageDbPath <$> getTestEnv
11+
case mpkgdb of
12+
Nothing -> skip "Cabal-hooks library unavailable."
13+
Just _pkgdb -> recordMode DoNotRecord $ do
14+
cabal "v2-build" [ "all" ]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cabal-version: 3.14
2+
name: setup-hooks-no-base-test
3+
version: 0.1.0.0
4+
synopsis: Test that we can build Setup.hs without base
5+
license: BSD-3-Clause
6+
author: NA
7+
maintainer: NA
8+
category: Testing
9+
build-type: Hooks
10+
11+
custom-setup
12+
setup-depends: Cabal-hooks
13+
14+
library
15+
exposed-modules: A
16+
default-language: Haskell2010

0 commit comments

Comments
 (0)