From 7d75787ae39a929db1a2a78a25f92096e81355d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Tue, 15 Apr 2014 05:18:42 +0200 Subject: [PATCH] Only add available package to ghc options Fixes #185 --- Language/Haskell/GhcMod/CabalApi.hs | 16 ++++++++++++---- test/CabalApiSpec.hs | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Language/Haskell/GhcMod/CabalApi.hs b/Language/Haskell/GhcMod/CabalApi.hs index ff478ea..7b34123 100644 --- a/Language/Haskell/GhcMod/CabalApi.hs +++ b/Language/Haskell/GhcMod/CabalApi.hs @@ -39,10 +39,14 @@ import System.FilePath (dropExtension, takeFileName, ()) ---------------------------------------------------------------- -- | Getting necessary 'CompilerOptions' from three information sources. -getCompilerOptions :: [GHCOption] -> Cradle -> PackageDescription -> IO CompilerOptions +getCompilerOptions :: [GHCOption] + -> Cradle + -> PackageDescription + -> IO CompilerOptions getCompilerOptions ghcopts cradle pkgDesc = do gopts <- getGHCOptions ghcopts cradle rdir $ head buildInfos - return $ CompilerOptions gopts idirs depPkgs + dbPkgs <- getPackageDbPackages rdir + return $ CompilerOptions gopts idirs (depPkgs dbPkgs) where wdir = cradleCurrentDir cradle rdir = cradleRootDir cradle @@ -50,7 +54,12 @@ getCompilerOptions ghcopts cradle pkgDesc = do pkgs = cradlePackages cradle buildInfos = cabalAllBuildInfo pkgDesc idirs = includeDirectories rdir wdir $ cabalSourceDirs buildInfos - depPkgs = attachPackageIds pkgs $ removeThem problematicPackages $ removeMe cfile $ cabalDependPackages buildInfos + depPkgs ps = attachPackageIds pkgs + $ removeThem problematicPackages + $ removeMe cfile + $ filter (`elem` ps) -- remove packages not available in any + -- package dbs + $ cabalDependPackages buildInfos ---------------------------------------------------------------- -- Dependent packages @@ -212,4 +221,3 @@ cabalAllTargets pd = do getExecutableTarget exe = do let maybeExes = [p e | p <- P.hsSourceDirs $ P.buildInfo exe, e <- [P.modulePath exe]] liftIO $ filterM doesFileExist maybeExes - diff --git a/test/CabalApiSpec.hs b/test/CabalApiSpec.hs index 27e57cf..4020db8 100644 --- a/test/CabalApiSpec.hs +++ b/test/CabalApiSpec.hs @@ -33,6 +33,7 @@ spec = do } res' `shouldBe` CompilerOptions {ghcOptions = ["-global-package-db", "-no-user-package-db","-package-db",cwd "test/data/.cabal-sandbox/i386-osx-ghc-7.6.3-packages.conf.d","-XHaskell98"], includeDirs = ["test/data","test/data/dist/build","test/data/dist/build/autogen","test/data/subdir1/subdir2","test/data/test"], depPackages = [("Cabal", Nothing), ("base", Nothing) , ("template-haskell", Nothing)]} + describe "cabalDependPackages" $ do it "extracts dependent packages" $ do pkgs <- cabalDependPackages . cabalAllBuildInfo <$> parseCabalFile "test/data/cabalapi.cabal"