Skip to content

Commit 402bd57

Browse files
authored
Merge pull request #3304 from commercialhaskell/unsupported-cabal-2-dot-0
Support for Stackage Nightly based on GHC 8.2.1
2 parents e0814c0 + 77d5520 commit 402bd57

File tree

7 files changed

+69
-23
lines changed

7 files changed

+69
-23
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ before_install:
7373

7474
install:
7575
- echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
76+
# Note: we build store by itself below due to high memory usage
7677
- case "$BUILD" in
7778
style)
7879
stack --system-ghc --no-terminal install hlint;;
7980
stack)
81+
stack --no-terminal build store;
8082
stack --no-terminal test --only-dependencies;;
8183
cabal)
8284
cabal --version;

ChangeLog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# Changelog
22

33

4+
## 1.5.1
5+
6+
Bug fixes:
7+
8+
* Stack eagerly tries to parse all cabal files related to a
9+
snapshot. Starting with Stackage Nightly 2017-07-31, snapshots are
10+
using GHC 8.2.1, and the `ghc.cabal` file implicitly referenced uses
11+
the (not yet supported) Cabal 2.0 file format. Future releases of
12+
Stack will both be less eager about cabal file parsing and support
13+
Cabal 2.0. This patch simply bypasses the error for invalid parsing.
14+
15+
416
## 1.5.0
517

618
Behavior changes:

src/Stack/Build.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ withLoadPackage inner = do
323323
-- Intentionally ignore warnings, as it's not really
324324
-- appropriate to print a bunch of warnings out while
325325
-- resolving the package index.
326-
(_warnings,pkg) <- readPackageBS (depPackageConfig econfig flags ghcOptions) bs
326+
(_warnings,pkg) <- readPackageBS
327+
(depPackageConfig econfig flags ghcOptions)
328+
(PackageIdentifier name version)
329+
bs
327330
return pkg
328331
where
329332
-- | Package config to be used for dependencies

src/Stack/BuildPlan.hs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,14 @@ addDeps allowMissing compilerVersion toCalc = do
299299
Nothing -> (Map.empty, [], Nothing)
300300
Just (_, x, y, z) -> (x, y, z)
301301
in (indexName $ rpIndex rp, [(rp, (cache, ghcOptions, sha))])
302-
res <- forM (Map.toList byIndex) $ \(indexName', pkgs) -> withCabalFiles indexName' pkgs
303-
$ \ident (flags, ghcOptions, mgitSha) cabalBS -> do
304-
(_warnings,gpd) <- readPackageUnresolvedBS Nothing cabalBS
302+
res <- forM (Map.toList byIndex) $ \(indexName', pkgs) ->
303+
fmap Map.unions $ withCabalFiles indexName' pkgs
304+
$ \ident (flags, ghcOptions, mgitSha) cabalBS ->
305+
case readPackageUnresolvedBS (Right ident) cabalBS of
306+
Left e
307+
| allowedToSkip ident -> return Map.empty
308+
| otherwise -> throwM e
309+
Right (_warnings, gpd) -> do
305310
let packageConfig = PackageConfig
306311
{ packageConfigEnableTests = False
307312
, packageConfigEnableBenchmarks = False
@@ -314,7 +319,7 @@ addDeps allowMissing compilerVersion toCalc = do
314319
pd = resolvePackageDescription packageConfig gpd
315320
exes = Set.fromList $ map (ExeName . T.pack . exeName) $ executables pd
316321
notMe = Set.filter (/= name) . Map.keysSet
317-
return (name, MiniPackageInfo
322+
return $ Map.singleton name MiniPackageInfo
318323
{ mpiVersion = packageIdentifierVersion ident
319324
, mpiFlags = flags
320325
, mpiGhcOptions = ghcOptions
@@ -326,13 +331,31 @@ addDeps allowMissing compilerVersion toCalc = do
326331
(buildable . libBuildInfo)
327332
(library pd)
328333
, mpiGitSHA1 = mgitSha
329-
})
330-
return (Map.fromList $ concat res, missingIdents)
334+
}
335+
return (Map.unions res, missingIdents)
331336
where
332337
shaMap = Map.fromList
333338
$ map (\(n, (v, _f, _ghcOptions, gitsha)) -> (PackageIdentifier n v, gitsha))
334339
$ Map.toList toCalc
335340

341+
-- Michael Snoyman, 2017-07-31:
342+
--
343+
-- This is a stop-gap measure to address a specific concern around
344+
-- the GHC 8.2.1 release. The current Stack version (1.5.0) will
345+
-- eagerly parse all cabal files mentioned in a snapshot,
346+
-- including global packages. Additionally, for the first time
347+
-- (AFAICT), GHC 8.2.1 is providing a package on Hackage with a
348+
-- ghc.cabal file, which requires the (not yet supported) Cabal
349+
-- 2.0 file format. To work around this, we're adding a special
350+
-- dispensation to ignore parse failures for this package.
351+
--
352+
-- Master already does better by simply ignoring global
353+
-- information and looking things up in the database. We may want
354+
-- to consider going a step further and simply ignoring _all_
355+
-- parse failures, or turning them into warnings, though I haven't
356+
-- considered the repercussions of that.
357+
allowedToSkip (PackageIdentifier name _) = name == $(mkPackageName "ghc")
358+
336359
-- | Resolve all packages necessary to install for the needed packages.
337360
getDeps :: MiniBuildPlan
338361
-> (PackageName -> Bool) -- ^ is it shadowed by a local package?

src/Stack/Package.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ readPackageUnresolved :: (MonadIO m, MonadThrow m)
110110
-> m ([PWarning],GenericPackageDescription)
111111
readPackageUnresolved cabalfp =
112112
liftIO (BS.readFile (FL.toFilePath cabalfp))
113-
>>= readPackageUnresolvedBS (Just cabalfp)
113+
>>= readPackageUnresolvedBS (Left cabalfp)
114114

115115
-- | Read the raw, unresolved package information from a ByteString.
116116
readPackageUnresolvedBS :: (MonadThrow m)
117-
=> Maybe (Path Abs File)
117+
=> Either (Path Abs File) PackageIdentifier
118118
-> BS.ByteString
119119
-> m ([PWarning],GenericPackageDescription)
120-
readPackageUnresolvedBS mcabalfp bs =
120+
readPackageUnresolvedBS source bs =
121121
case parsePackageDescription chars of
122122
ParseFailed per ->
123-
throwM (PackageInvalidCabalFile mcabalfp per)
123+
throwM (PackageInvalidCabalFile source per)
124124
ParseOk warnings gpkg -> return (warnings,gpkg)
125125
where
126126
chars = T.unpack (dropBOM (decodeUtf8With lenientDecode bs))
@@ -140,10 +140,11 @@ readPackage packageConfig cabalfp =
140140
-- | Reads and exposes the package information, from a ByteString
141141
readPackageBS :: (MonadThrow m)
142142
=> PackageConfig
143+
-> PackageIdentifier
143144
-> BS.ByteString
144145
-> m ([PWarning],Package)
145-
readPackageBS packageConfig bs =
146-
do (warnings,gpkg) <- readPackageUnresolvedBS Nothing bs
146+
readPackageBS packageConfig ident bs =
147+
do (warnings,gpkg) <- readPackageUnresolvedBS (Right ident) bs
147148
return (warnings,resolvePackage packageConfig gpkg)
148149

149150
-- | Get 'GenericPackageDescription' and 'PackageDescription' reading info

src/Stack/SDist.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ getCabalLbs :: (StackM env m, HasEnvConfig env)
177177
-> FilePath
178178
-> m (PackageIdentifier, L.ByteString)
179179
getCabalLbs pvpBounds mrev fp = do
180-
bs <- liftIO $ S.readFile fp
181-
(_warnings, gpd) <- readPackageUnresolvedBS Nothing bs
180+
path <- liftIO $ resolveFile' fp
181+
(_warnings, gpd) <- readPackageUnresolved path
182182
(_, sourceMap) <- loadSourceMap AllowNoTargets defaultBuildOptsCLI
183183
menv <- getMinimalEnvOverride
184184
(installedMap, _, _, _) <- getInstalled menv GetInstalledOpts

src/Stack/Types/Package.hs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,25 @@ import Stack.Types.Version
4848

4949
-- | All exceptions thrown by the library.
5050
data PackageException
51-
= PackageInvalidCabalFile (Maybe (Path Abs File)) PError
51+
= PackageInvalidCabalFile (Either (Path Abs File) PackageIdentifier) PError
5252
| PackageNoCabalFileFound (Path Abs Dir)
5353
| PackageMultipleCabalFilesFound (Path Abs Dir) [Path Abs File]
5454
| MismatchedCabalName (Path Abs File) PackageName
5555
deriving Typeable
5656
instance Exception PackageException
5757
instance Show PackageException where
58-
show (PackageInvalidCabalFile mfile err) =
59-
"Unable to parse cabal file" ++
60-
(case mfile of
61-
Nothing -> ""
62-
Just file -> ' ' : toFilePath file) ++
63-
": " ++
64-
show err
58+
show (PackageInvalidCabalFile (Left file) err) = concat
59+
[ "Unable to parse cabal file "
60+
, toFilePath file
61+
, ": "
62+
, show err
63+
]
64+
show (PackageInvalidCabalFile (Right ident) err) = concat
65+
[ "Unable to parse cabal file for "
66+
, packageIdentifierString ident
67+
, ": "
68+
, show err
69+
]
6570
show (PackageNoCabalFileFound dir) = concat
6671
[ "Stack looks for packages in the directories configured in"
6772
, " the 'packages' variable defined in your stack.yaml\n"

0 commit comments

Comments
 (0)