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
...@@ -1276,7 +1276,7 @@ test_findIndentTabs = findIndentTabs $ unlines $ ...@@ -1276,7 +1276,7 @@ test_findIndentTabs = findIndentTabs $ unlines $
sanityCheckPackage :: PackageDescription -> IO ([String] -- Warnings sanityCheckPackage :: PackageDescription -> IO ([String] -- Warnings
,[String])-- Errors ,[String])-- Errors
sanityCheckPackage pkg_descr = sanityCheckPackage pkg_descr = do
let libSane = sanityCheckLib (library pkg_descr) let libSane = sanityCheckLib (library pkg_descr)
nothingToDo = checkSanity nothingToDo = checkSanity
(null (executables pkg_descr) (null (executables pkg_descr)
...@@ -1290,9 +1290,14 @@ sanityCheckPackage pkg_descr = ...@@ -1290,9 +1290,14 @@ sanityCheckPackage pkg_descr =
++ (showVersionRange v) ++ ".") ++ (showVersionRange v) ++ ".")
noBuildType = checkSanity (isNothing $ buildType pkg_descr) noBuildType = checkSanity (isNothing $ buildType pkg_descr)
"No build-type specified. If possible use build-type: Simple" "No build-type specified. If possible use build-type: Simple"
in return $ ( catMaybes [nothingToDo, noModules, noBuildType], lf = licenseFile pkg_descr
catMaybes (libSane:goodCabal: checkMissingFields pkg_descr
++ map sanityCheckExe (executables 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 :: Bool -> a -> Maybe a
toMaybe b x = if b then Just x else Nothing toMaybe b x = if b then Just x else Nothing
...@@ -1328,11 +1333,20 @@ sanityCheckExe exe ...@@ -1328,11 +1333,20 @@ sanityCheckExe exe
checkSanity :: Bool -> String -> Maybe String checkSanity :: Bool -> String -> Maybe String
checkSanity = toMaybe checkSanity = toMaybe
checkSanityIO :: IO Bool -> String -> IO (Maybe String)
checkSanityIO test str = do b <- test
return $ toMaybe b str
hasMods :: PackageDescription -> Bool hasMods :: PackageDescription -> Bool
hasMods pkg_descr = hasMods pkg_descr =
null (executables pkg_descr) && null (executables pkg_descr) &&
maybe True (null . exposedModules) (library 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 :: String -> a
bug msg = error $ msg ++ ". Consider this a bug." bug msg = error $ msg ++ ". Consider this a bug."
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment