Skip to content

Commit

Permalink
Fix InvalidRelFile in stack solver #1954
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed Apr 29, 2016
1 parent f250fa8 commit 42a61fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Stack.Solver
( checkResolverSpec
, cabalPackagesCheck
Expand Down Expand Up @@ -553,7 +555,7 @@ cabalPackagesCheck cabalfps noPkgMsg dupErrMsg = do
when (null cabalfps) $
error noPkgMsg

relpaths <- mapM makeRelativeToCurrentDir cabalfps
relpaths <- mapM prettyPath cabalfps
$logInfo $ "Using cabal packages:"
$logInfo $ T.pack (formatGroup relpaths)

Expand All @@ -573,7 +575,7 @@ cabalPackagesCheck cabalfps noPkgMsg dupErrMsg = do
nameMismatchPkgs = mapMaybe getNameMismatchPkg packages

when (nameMismatchPkgs /= []) $ do
rels <- mapM makeRelativeToCurrentDir nameMismatchPkgs
rels <- mapM prettyPath nameMismatchPkgs
error $ "Package name as defined in the .cabal file must match the \
\.cabal file name.\n\
\Please fix the following packages and try again:\n"
Expand All @@ -591,7 +593,7 @@ cabalPackagesCheck cabalfps noPkgMsg dupErrMsg = do
unique = packages \\ dupIgnored

when (dupIgnored /= []) $ do
dups <- mapM (mapM (makeRelativeToCurrentDir . fst)) (dupGroups packages)
dups <- mapM (mapM (prettyPath. fst)) (dupGroups packages)
$logWarn $ T.pack $
"Following packages have duplicate package names:\n"
<> intercalate "\n" (map formatGroup dups)
Expand All @@ -605,9 +607,8 @@ cabalPackagesCheck cabalfps noPkgMsg dupErrMsg = do
$ map (\(file, gpd) -> (gpdPackageName gpd,(file, gpd))) unique
, map fst dupIgnored)

formatGroup :: [Path Rel File] -> String
formatGroup = concatMap formatPath
where formatPath path = "- " <> toFilePath path <> "\n"
formatGroup :: [String] -> String
formatGroup = concatMap (\path -> "- " <> path <> "\n")

reportMissingCabalFiles :: (MonadIO m, MonadThrow m, MonadLogger m)
=> [Path Abs File] -- ^ Directories to scan
Expand All @@ -616,7 +617,7 @@ reportMissingCabalFiles :: (MonadIO m, MonadThrow m, MonadLogger m)
reportMissingCabalFiles cabalfps includeSubdirs = do
allCabalfps <- findCabalFiles includeSubdirs =<< getCurrentDir

relpaths <- mapM makeRelativeToCurrentDir (allCabalfps \\ cabalfps)
relpaths <- mapM prettyPath (allCabalfps \\ cabalfps)
unless (null relpaths) $ do
$logWarn $ "The following packages are missing from the config:"
$logWarn $ T.pack (formatGroup relpaths)
Expand Down Expand Up @@ -763,3 +764,12 @@ solveExtraDeps modStackYaml = do
, " - Add any missing remote packages.\n"
, " - Add extra dependencies to guide solver.\n"
]

prettyPath
:: forall r t m. (MonadIO m, RelPath (Path r t) ~ Path Rel t, AnyPath (Path r t))
=> Path r t -> m String
prettyPath path = do
eres <- liftIO $ try $ makeRelativeToCurrentDir path
return $ case eres of
Left (_ :: PathParseException) -> toFilePath path
Right res -> toFilePath (res :: Path Rel t)
4 changes: 4 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ nix:
extra-deps:
- hpack-0.13.0
- path-io-1.1.0
- th-lift-instances-0.1.6
packages:
- .
- ../store

0 comments on commit 42a61fb

Please sign in to comment.