aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexwl <alexey.a.kiryushin@gmail.com>2019-09-02 22:08:37 +0300
committeralexwl <alexey.a.kiryushin@gmail.com>2019-09-02 22:08:37 +0300
commit6c6d96288f41b7c44657e265dc98e519505e357c (patch)
treeb628adc81b4663b750bd380685ef09248dd7c397
parentbc2859c64e73f21629c7387119b00c6e0278beb3 (diff)
Add check for .cabal file
-rw-r--r--src/HaskellCodeExplorer/PackageInfo.hs38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/HaskellCodeExplorer/PackageInfo.hs b/src/HaskellCodeExplorer/PackageInfo.hs
index 5bc30b7..466b518 100644
--- a/src/HaskellCodeExplorer/PackageInfo.hs
+++ b/src/HaskellCodeExplorer/PackageInfo.hs
@@ -22,7 +22,7 @@ import Control.Exception
, throw
, try
)
-import Control.Monad (foldM, unless)
+import Control.Monad (foldM, unless, when)
import Control.Monad.Extra (anyM, findM)
import Control.Monad.Logger
( LoggingT(..)
@@ -103,6 +103,7 @@ import System.Directory
, setCurrentDirectory
, getCurrentDirectory
, makeAbsolute
+ , getDirectoryContents
)
import qualified System.Directory.Tree as DT
import System.Exit (exitFailure)
@@ -114,6 +115,7 @@ import System.FilePath
, replaceExtension
, splitPath
, takeExtension
+ , takeFileName
, takeBaseName
, takeDirectory
, splitDirectories
@@ -141,6 +143,25 @@ createPackageInfo packageDirectoryPath mbDistDirRelativePath sourceCodePreproces
Right distDir -> return distDir
Left errorMessage ->
logErrorN (T.pack errorMessage) >> liftIO exitFailure
+ cabalFiles <-
+ liftIO $
+ length .
+ filter
+ (\path -> takeFileName path /= ".cabal" && takeExtension path == ".cabal") <$>
+ getDirectoryContents packageDirectoryAbsPath
+ _ <-
+ if cabalFiles == 0
+ then do
+ logErrorN $
+ T.concat ["No .cabal file found in ", T.pack packageDirectoryAbsPath]
+ liftIO exitFailure
+ else when (cabalFiles >= 2) $ do
+ logErrorN $
+ T.concat
+ [ "Found more than one .cabal file in "
+ , T.pack packageDirectoryAbsPath
+ ]
+ liftIO exitFailure
let cabalHelperQueryEnv = mkQueryEnv packageDirectoryAbsPath distDir
((packageName, packageVersion), (_packageCompilerName, packageCompilerVersion), compInfo) <-
liftIO $
@@ -154,13 +175,14 @@ createPackageInfo packageDirectoryPath mbDistDirRelativePath sourceCodePreproces
unless
(take 3 (versionBranch packageCompilerVersion) ==
take 3 (versionBranch ghcVersion)) $ do
- logErrorN $ T.concat
- [ "GHC version mismatch. haskell-code-indexer: "
- , T.pack $ showVersion ghcVersion
- , ", package: "
- , T.pack $ showVersion packageCompilerVersion
- ]
- liftIO exitFailure
+ logErrorN $
+ T.concat
+ [ "GHC version mismatch. haskell-code-indexer: "
+ , T.pack $ showVersion ghcVersion
+ , ", package: "
+ , T.pack $ showVersion packageCompilerVersion
+ ]
+ liftIO exitFailure
logInfoN $ T.append "Indexing " $ HCE.packageIdToText currentPackageId
let buildComponents =
L.map