Skip to content

Commit

Permalink
Remove ghc-paths
Browse files Browse the repository at this point in the history
Since the functions are now "getRuntimeGhc*", it doesn't make sense to
try and use anything compiletime related
  • Loading branch information
lukel97 committed Jun 26, 2020
1 parent fdea533 commit 126bfd8
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
1 change: 0 additions & 1 deletion hie-bios.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ Library
extra >= 1.6.14 && < 1.8,
process >= 1.6.1 && < 1.7,
ghc >= 8.4.1 && < 8.11,
ghc-paths >= 0.1 && < 0.2,
transformers >= 0.5.2 && < 0.6,
temporary >= 1.2 && < 1.4,
text >= 1.2.3 && < 1.3,
Expand Down
16 changes: 2 additions & 14 deletions src/HIE/Bios/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import qualified GHC as G
import qualified DriverPhases as G
import qualified Util as G
import DynFlags
import qualified GHC.Paths as Paths

import Control.Applicative
import Control.Monad (void)
Expand Down Expand Up @@ -55,32 +54,21 @@ initSession ComponentOptions {..} = do

----------------------------------------------------------------

-- | @getRuntimeGhcLibDir cradle avoidHardcoding@ will give you the ghc libDir:
-- | @getRuntimeGhcLibDir cradle@ will give you the ghc libDir:
-- __do not__ use 'runGhcLibDir' directly.
-- This will also perform additional lookups and fallbacks to try and get a
-- reliable library directory.
--
-- It tries this specific order of paths:
--
-- 1. the @NIX_GHC_LIBDIR@ if it is set
-- 2. calling 'runCradleGhc' on the provided cradle
-- 3. using @ghc-paths@
--
-- If @avoidHardcoding@ is 'True', then 'getRuntimeGhcLibDir' will __not__ fall
-- back on @ghc-paths@. Set this to 'False' whenever you are planning on
-- distributing the resulting binary you are compiling, otherwise paths from
-- the system you were compiling on will be baked in!
getRuntimeGhcLibDir :: Cradle a
-> Bool -- ^ If 'True', avoid hardcoding the paths.
-> IO (Maybe FilePath)
getRuntimeGhcLibDir cradle avoidHardcoding =
runMaybeT $ fromNix <|> fromCradle <|> fromGhcPaths
getRuntimeGhcLibDir cradle = runMaybeT $ fromNix <|> fromCradle
where
fromNix = MaybeT $ lookupEnv "NIX_GHC_LIBDIR"
fromCradle = MaybeT $ fmap (fmap trim) $
runGhc (cradleOptsProg cradle) ["--print-libdir"]
fromGhcPaths = MaybeT $ pure $
if avoidHardcoding then Just Paths.libdir else Nothing

-- | Gets the version of ghc used when compiling the cradle. It is based off of
-- 'getRuntimeGhcLibDir'. If it can't work out the verison reliably, it will
Expand Down
2 changes: 1 addition & 1 deletion src/HIE/Bios/Ghc/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ checkSyntax :: Show a
-> IO String
checkSyntax _ [] = return ""
checkSyntax cradle files = do
libDir <- getRuntimeGhcLibDir cradle False
libDir <- getRuntimeGhcLibDir cradle
G.runGhcT libDir $ do
Log.debugm $ "Cradle: " ++ show cradle
res <- initializeFlagsWithCradle (head files) cradle
Expand Down
2 changes: 1 addition & 1 deletion src/HIE/Bios/Internal/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ debugInfo fp cradle = unlines <$> do
canonFp <- canonicalizePath fp
conf <- findConfig canonFp
crdl <- findCradle' canonFp
ghcLibDir <- getRuntimeGhcLibDir cradle False
ghcLibDir <- getRuntimeGhcLibDir cradle
ghcVer <- getRuntimeGhcVersion cradle
case res of
CradleSuccess (ComponentOptions gopts croot deps) -> do
Expand Down
3 changes: 3 additions & 0 deletions src/HIE/Bios/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ data CradleAction a = CradleAction {
-- -- this cradle uses to compile stuff normally. You don't
-- -- want to call this directly, use 'getGhcLibDir' instead.
, runGhc :: [String] -> IO (Maybe String)
-- ^ Executes the @ghc@ binary that is usually used to
-- build the cradle. E.g. for a cabal cradle this should be
-- equivalent to @cabal exec ghc -- args@
}
deriving (Functor)

Expand Down
6 changes: 3 additions & 3 deletions tests/BiosTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ testDirectory cradlePred fp step = do
-- always works.
testGetGhcLibDir :: Cradle a -> IO ()
testGetGhcLibDir crd =
getRuntimeGhcLibDir crd True `shouldNotReturn` Nothing
getRuntimeGhcLibDir crd `shouldNotReturn` Nothing

-- Here we are testing that the cradle's method of getting the runtime ghc
-- version is correct - which while testing, should be the version that we have
Expand Down Expand Up @@ -140,7 +140,7 @@ initialiseCradle cradlePred a_fp step = do
testLoadFile :: Cradle a -> FilePath -> (String -> IO ()) -> IO ()
testLoadFile crd fp step = do
a_fp <- canonicalizePath fp
libDir <- getRuntimeGhcLibDir crd False
libDir <- getRuntimeGhcLibDir crd
withCurrentDirectory (cradleRootDir crd) $
G.runGhc libDir $ do
let relFp = makeRelative (cradleRootDir crd) a_fp
Expand All @@ -159,7 +159,7 @@ testLoadFile crd fp step = do
testLoadFileCradleFail :: Cradle a -> FilePath -> (CradleError -> Expectation) -> (String -> IO ()) -> IO ()
testLoadFileCradleFail crd fp cradleErrorExpectation step = do
a_fp <- canonicalizePath fp
libDir <- getRuntimeGhcLibDir crd False
libDir <- getRuntimeGhcLibDir crd
withCurrentDirectory (cradleRootDir crd) $
G.runGhc libDir $ do
let relFp = makeRelative (cradleRootDir crd) a_fp
Expand Down

0 comments on commit 126bfd8

Please sign in to comment.