Skip to content
Snippets Groups Projects
Commit 4eb65a26 authored by byorgey's avatar byorgey
Browse files

PackageDescription.hs: add check for existence of license file

Added a check for the existence of the license file (if one is
specified in a license-file: field) during description file
sanity checking.  If a license is specified but does not exist,
a warning is generated.  This patch resolves issue #180.
parent 9ccb003b
No related branches found
No related tags found
No related merge requests found
......@@ -1276,7 +1276,7 @@ test_findIndentTabs = findIndentTabs $ unlines $
sanityCheckPackage :: PackageDescription -> IO ([String] -- Warnings
,[String])-- Errors
sanityCheckPackage pkg_descr =
sanityCheckPackage pkg_descr = do
let libSane = sanityCheckLib (library pkg_descr)
nothingToDo = checkSanity
(null (executables pkg_descr)
......@@ -1290,9 +1290,14 @@ sanityCheckPackage pkg_descr =
++ (showVersionRange v) ++ ".")
noBuildType = checkSanity (isNothing $ buildType pkg_descr)
"No build-type specified. If possible use build-type: Simple"
in return $ ( catMaybes [nothingToDo, noModules, noBuildType],
catMaybes (libSane:goodCabal: checkMissingFields pkg_descr
++ map sanityCheckExe (executables pkg_descr)) )
lf = licenseFile pkg_descr
noLicense <- checkSanityIO (licenseDoesNotExist lf)
("License file " ++ lf ++ " does not exist.")
return $ ( catMaybes [nothingToDo, noModules, noBuildType, noLicense],
catMaybes (libSane:goodCabal: checkMissingFields pkg_descr
++ map sanityCheckExe (executables pkg_descr)) )
toMaybe :: Bool -> a -> Maybe a
toMaybe b x = if b then Just x else Nothing
......@@ -1328,11 +1333,20 @@ sanityCheckExe exe
checkSanity :: Bool -> String -> Maybe String
checkSanity = toMaybe
checkSanityIO :: IO Bool -> String -> IO (Maybe String)
checkSanityIO test str = do b <- test
return $ toMaybe b str
hasMods :: PackageDescription -> Bool
hasMods pkg_descr =
null (executables pkg_descr) &&
maybe True (null . exposedModules) (library pkg_descr)
licenseDoesNotExist :: FilePath -> IO Bool
licenseDoesNotExist lf = do
b <- doesFileExist lf
return $ not (null lf || b)
bug :: String -> a
bug msg = error $ msg ++ ". Consider this a bug."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment