diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CabalHelper/Compiletime/Cabal.hs | 17 | ||||
| -rw-r--r-- | src/CabalHelper/Compiletime/Compat/Directory.hs | 26 | ||||
| -rw-r--r-- | src/CabalHelper/Compiletime/Program/CabalInstall.hs | 2 | 
3 files changed, 14 insertions, 31 deletions
| diff --git a/src/CabalHelper/Compiletime/Cabal.hs b/src/CabalHelper/Compiletime/Cabal.hs index 17f4d7f..85ab83c 100644 --- a/src/CabalHelper/Compiletime/Cabal.hs +++ b/src/CabalHelper/Compiletime/Cabal.hs @@ -43,7 +43,7 @@ import qualified Data.ByteString.Char8 as BS8  import CabalHelper.Compiletime.Types  import CabalHelper.Compiletime.Process -import CabalHelper.Shared.Common (replace, parseVer, parseVerMay, parsePkgIdBS) +import CabalHelper.Shared.Common (replace, parseVer, parseVerMay, parsePkgIdBS, panicIO)  type UnpackedCabalVersion = CabalVersion' (CommitId, CabalSourceDir)  type ResolvedCabalVersion = CabalVersion' CommitId @@ -246,10 +246,14 @@ resolveCabalVersion (CabalHEAD ()) = do    let commit = takeWhile isHexDigit out    return $ CabalHEAD $ CommitId commit -findCabalFile :: FilePath -> IO FilePath +findCabalFile :: FilePath -> IO (Maybe FilePath)  findCabalFile pkgdir = do -    [cfile] <- filter isCabalFile <$> getDirectoryContents pkgdir -    return $ pkgdir </> cfile +    cfiles <- filter isCabalFile <$> getDirectoryContents pkgdir +    case cfiles of +      [] -> return Nothing +      [cfile] -> return $ Just $ pkgdir </> cfile +      _ -> panicIO $ "Multiple cabal-files found in directory '" +             ++pkgdir++"': " ++ show cfiles    where      isCabalFile :: FilePath -> Bool      isCabalFile f = takeExtension' f == ".cabal" @@ -260,6 +264,11 @@ findCabalFile pkgdir = do            then "" -- just ".cabal" is not a valid cabal file            else takeExtension p +complainIfNoCabalFile :: FilePath -> Maybe FilePath -> IO FilePath +complainIfNoCabalFile _ (Just cabal_file) = return cabal_file +complainIfNoCabalFile pkgdir Nothing = +  panicIO $ "No cabal file found in package-dir: '"++pkgdir++"'" +  bultinCabalVersion :: Version  bultinCabalVersion = parseVer VERSION_Cabal diff --git a/src/CabalHelper/Compiletime/Compat/Directory.hs b/src/CabalHelper/Compiletime/Compat/Directory.hs deleted file mode 100644 index 0a65164..0000000 --- a/src/CabalHelper/Compiletime/Compat/Directory.hs +++ /dev/null @@ -1,26 +0,0 @@ --- cabal-helper: Simple interface to Cabal's configuration state --- Copyright (C) 2019  Daniel Gröber <cabal-helper@dxld.at> --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU General Public License as published by --- the Free Software Foundation, either version 3 of the License, or --- (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program.  If not, see <http://www.gnu.org/licenses/>. - -{-# LANGUAGE CPP #-} -module CabalHelper.Compiletime.Compat.Directory where - -import System.Directory (getDirectoryContents) - -#if !MIN_VERSION_directory(1,2,5) -listDirectory :: FilePath -> IO [FilePath] -listDirectory path = -  filter (\f -> f /= "." && f /= "..") <$> getDirectoryContents path -#endif diff --git a/src/CabalHelper/Compiletime/Program/CabalInstall.hs b/src/CabalHelper/Compiletime/Program/CabalInstall.hs index b1c661c..4411bc3 100644 --- a/src/CabalHelper/Compiletime/Program/CabalInstall.hs +++ b/src/CabalHelper/Compiletime/Program/CabalInstall.hs @@ -261,7 +261,7 @@ planUnits plan = do        , uComps=comps        , uPId=CP.PkgId pkg_name _        } = do -        cabal_file <- Cabal.findCabalFile pkgdir +        cabal_file <- Cabal.complainIfNoCabalFile pkgdir =<< Cabal.findCabalFile pkgdir          let comp_names = Map.keys comps          let uiV2Components =                map (Text.unpack . CP.dispCompNameTarget pkg_name) $ Map.keys comps | 
