Skip to content

Commit

Permalink
init: check pkg name and .cabal file name match
Browse files Browse the repository at this point in the history
Since stack does not allow package name to mismatch with the .cabal file name
stack init should also not allow that. This commit disallows the mismatch.
  • Loading branch information
harendra-kumar committed Jan 19, 2016
1 parent 0149ba5 commit 63c7f48
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -494,15 +494,23 @@ cabalPackagesCheck cabalfps noPkgMsg dupErrMsg = do
(warnings, gpds) <- fmap unzip (mapM readPackageUnresolved cabalfps)
zipWithM_ (mapM_ . printCabalFileWarning) cabalfps warnings

-- package name cannot be empty or missing otherwise
-- it will result in cabal solver failure.
-- stack requires packages name to match the cabal file name
-- Just the latter check is enough to cover both the cases

let packages = zip cabalfps gpds
getEmptyNamePkg (fp, gpd)
| ((show . gpdPackageName) gpd) == "" = Just fp
getNameMismatchPkg (fp, gpd)
| (show . gpdPackageName) gpd /= (FP.takeBaseName . toFilePath) fp
= Just fp
| otherwise = Nothing
emptyNamePkgs = mapMaybe getEmptyNamePkg packages
nameMismatchPkgs = mapMaybe getNameMismatchPkg packages

when (emptyNamePkgs /= []) $ do
rels <- mapM makeRel emptyNamePkgs
error $ "Please assign a name to the following package(s):\n"
when (nameMismatchPkgs /= []) $ do
rels <- mapM makeRel 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"
<> (formatGroup rels)

let dupGroups = filter ((> 1) . length)
Expand Down

0 comments on commit 63c7f48

Please sign in to comment.