use Cabal to determine location of ar'
This commit is contained in:
parent
0b9edf6282
commit
0ee840da44
@ -11,7 +11,11 @@ import qualified Distribution.Verbosity as D
|
|||||||
import qualified Distribution.PackageDescription.Parse as D
|
import qualified Distribution.PackageDescription.Parse as D
|
||||||
import qualified Distribution.PackageDescription as D
|
import qualified Distribution.PackageDescription as D
|
||||||
import qualified Distribution.ModuleName as D
|
import qualified Distribution.ModuleName as D
|
||||||
|
import qualified Distribution.Simple.Configure as D
|
||||||
|
import qualified Distribution.Simple.Program as D
|
||||||
|
import qualified Distribution.Compiler as D
|
||||||
|
|
||||||
|
import Control.Applicative ((<$>), (<*>))
|
||||||
import Control.Concurrent (forkIO, threadDelay)
|
import Control.Concurrent (forkIO, threadDelay)
|
||||||
import qualified Control.Exception as Ex
|
import qualified Control.Exception as Ex
|
||||||
import Control.Monad (forever, when, unless)
|
import Control.Monad (forever, when, unless)
|
||||||
@ -57,11 +61,12 @@ devel isCabalDev passThroughArgs = do
|
|||||||
cabal <- D.findPackageDesc "."
|
cabal <- D.findPackageDesc "."
|
||||||
gpd <- D.readPackageDescription D.normal cabal
|
gpd <- D.readPackageDescription D.normal cabal
|
||||||
|
|
||||||
|
ldar <- lookupLdAr
|
||||||
hsSourceDirs <- checkCabalFile gpd
|
hsSourceDirs <- checkCabalFile gpd
|
||||||
|
|
||||||
_<- rawSystem cmd args
|
_<- rawSystem cmd args
|
||||||
|
|
||||||
mainLoop hsSourceDirs cabal
|
mainLoop hsSourceDirs cabal ldar
|
||||||
|
|
||||||
_ <- getLine
|
_ <- getLine
|
||||||
writeLock
|
writeLock
|
||||||
@ -88,12 +93,12 @@ devel isCabalDev passThroughArgs = do
|
|||||||
]
|
]
|
||||||
args = "configure":diffArgs ++ ["--disable-library-profiling" ]
|
args = "configure":diffArgs ++ ["--disable-library-profiling" ]
|
||||||
|
|
||||||
mainLoop :: [FilePath] -> FilePath -> IO ()
|
mainLoop :: [FilePath] -> FilePath -> (FilePath, FilePath) -> IO ()
|
||||||
mainLoop hsSourceDirs cabal = do
|
mainLoop hsSourceDirs cabal ldar = do
|
||||||
ghcVer <- ghcVersion
|
ghcVer <- ghcVersion
|
||||||
_ <- rebuildCabal cmd
|
_ <- rebuildCabal cmd
|
||||||
pkgArgs <- ghcPackageArgs isCabalDev ghcVer
|
pkgArgs <- ghcPackageArgs isCabalDev ghcVer
|
||||||
rebuild <- mkRebuild ghcVer cabal cmd
|
rebuild <- mkRebuild ghcVer cabal cmd ldar
|
||||||
let devArgs = pkgArgs ++ ["devel.hs"] ++ passThroughArgs
|
let devArgs = pkgArgs ++ ["devel.hs"] ++ passThroughArgs
|
||||||
forever $ do
|
forever $ do
|
||||||
recompDeps hsSourceDirs
|
recompDeps hsSourceDirs
|
||||||
@ -118,8 +123,8 @@ devel isCabalDev passThroughArgs = do
|
|||||||
Ex.throwTo watchTid (userError "process finished")
|
Ex.throwTo watchTid (userError "process finished")
|
||||||
watchForChanges hsSourceDirs list
|
watchForChanges hsSourceDirs list
|
||||||
|
|
||||||
mkRebuild :: String -> FilePath -> String -> IO (IO Bool)
|
mkRebuild :: String -> FilePath -> String -> (FilePath, FilePath) -> IO (IO Bool)
|
||||||
mkRebuild ghcVer cabalFile cabalCmd
|
mkRebuild ghcVer cabalFile cabalCmd (ldPath, arPath)
|
||||||
| GHC.cProjectVersion == ghcVer = do
|
| GHC.cProjectVersion == ghcVer = do
|
||||||
bf <- getBuildFlags
|
bf <- getBuildFlags
|
||||||
return $ do
|
return $ do
|
||||||
@ -128,15 +133,15 @@ mkRebuild ghcVer cabalFile cabalCmd
|
|||||||
n3 <- cabalFile `isNewerThan` "dist/ldargs.txt"
|
n3 <- cabalFile `isNewerThan` "dist/ldargs.txt"
|
||||||
if n1 || n2 || n3
|
if n1 || n2 || n3
|
||||||
then rebuildCabal cabalCmd
|
then rebuildCabal cabalCmd
|
||||||
else rebuildGhc bf
|
else rebuildGhc bf ldPath arPath
|
||||||
| otherwise = return $ do
|
| otherwise = return $ do
|
||||||
putStrLn "WARNING: yesod is compiled with a different ghc version, falling back to cabal"
|
putStrLn "WARNING: yesod is compiled with a different ghc version, falling back to cabal"
|
||||||
rebuildCabal cabalCmd
|
rebuildCabal cabalCmd
|
||||||
|
|
||||||
rebuildGhc :: [Located String] -> IO Bool
|
rebuildGhc :: [Located String] -> FilePath -> FilePath -> IO Bool
|
||||||
rebuildGhc bf = do
|
rebuildGhc bf ld ar = do
|
||||||
putStrLn "Rebuilding application... (GHC API)"
|
putStrLn "Rebuilding application... (GHC API)"
|
||||||
buildPackage bf
|
buildPackage bf ld ar
|
||||||
|
|
||||||
rebuildCabal :: String -> IO Bool
|
rebuildCabal :: String -> IO Bool
|
||||||
rebuildCabal cmd = do
|
rebuildCabal cmd = do
|
||||||
@ -243,6 +248,22 @@ lookupDevelLib ct | found = Just (D.condTreeData ct)
|
|||||||
isDevelLib (D.Var (D.Flag (D.FlagName f)), _, _) = f `elem` ["library-only", "devel"]
|
isDevelLib (D.Var (D.Flag (D.FlagName f)), _, _) = f `elem` ["library-only", "devel"]
|
||||||
isDevelLib _ = False
|
isDevelLib _ = False
|
||||||
|
|
||||||
|
-- location of `ld' and `ar' programs
|
||||||
|
lookupLdAr :: IO (FilePath, FilePath)
|
||||||
|
lookupLdAr = do
|
||||||
|
mla <- lookupLdAr'
|
||||||
|
case mla of
|
||||||
|
Nothing -> failWith "Cannot determine location of `ar' or `ld' program"
|
||||||
|
Just la -> return la
|
||||||
|
|
||||||
|
lookupLdAr' :: IO (Maybe (FilePath, FilePath))
|
||||||
|
lookupLdAr' = do
|
||||||
|
(comp, pgmc) <- D.configCompiler (Just D.GHC) Nothing Nothing D.defaultProgramConfiguration D.silent
|
||||||
|
pgmc' <- D.configureAllKnownPrograms D.silent pgmc
|
||||||
|
return $ (,) <$> look D.ldProgram pgmc' <*> look D.arProgram pgmc'
|
||||||
|
where
|
||||||
|
look pgm pdb = fmap D.programPath (D.lookupProgram pgm pdb)
|
||||||
|
|
||||||
-- | Acts like @rawSystem@, but filters out lines from the output that we're not interested in seeing.
|
-- | Acts like @rawSystem@, but filters out lines from the output that we're not interested in seeing.
|
||||||
rawSystemFilter :: String -> [String] -> IO ExitCode
|
rawSystemFilter :: String -> [String] -> IO ExitCode
|
||||||
rawSystemFilter command args = do
|
rawSystemFilter command args = do
|
||||||
|
|||||||
@ -48,13 +48,13 @@ getBuildFlags = do
|
|||||||
(argv2, staticFlagWarnings) <- GHC.parseStaticFlags argv1'
|
(argv2, staticFlagWarnings) <- GHC.parseStaticFlags argv1'
|
||||||
return argv2
|
return argv2
|
||||||
|
|
||||||
buildPackage :: [Located String] -> IO Bool
|
buildPackage :: [Located String] -> FilePath -> FilePath -> IO Bool
|
||||||
buildPackage a = buildPackage' a `Ex.catch` \(e::Ex.SomeException) -> do
|
buildPackage a ld ar = buildPackage' a ld ar `Ex.catch` \(e::Ex.SomeException) -> do
|
||||||
putStrLn ("exception building package: " ++ show e)
|
putStrLn ("exception building package: " ++ show e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
buildPackage' :: [Located String] -> IO Bool
|
buildPackage' :: [Located String] -> FilePath -> FilePath -> IO Bool
|
||||||
buildPackage' argv2 = do
|
buildPackage' argv2 ld ar = do
|
||||||
(mode, argv3, modeFlagWarnings) <- parseModeFlags argv2
|
(mode, argv3, modeFlagWarnings) <- parseModeFlags argv2
|
||||||
GHC.runGhc (Just libdir) $ do
|
GHC.runGhc (Just libdir) $ do
|
||||||
dflags0 <- GHC.getSessionDynFlags
|
dflags0 <- GHC.getSessionDynFlags
|
||||||
@ -93,15 +93,14 @@ buildPackage' argv2 = do
|
|||||||
ok_flag <- GHC.load GHC.LoadAllTargets
|
ok_flag <- GHC.load GHC.LoadAllTargets
|
||||||
if GHC.failed ok_flag
|
if GHC.failed ok_flag
|
||||||
then return False
|
then return False
|
||||||
else liftIO linkPkg >> return True
|
else liftIO (linkPkg ld ar) >> return True
|
||||||
|
|
||||||
-- fixme, find default ar and ld versions
|
linkPkg :: FilePath -> FilePath -> IO ()
|
||||||
linkPkg :: IO ()
|
linkPkg ld ar = do
|
||||||
linkPkg = do
|
|
||||||
arargs <- fmap read $ readFile "dist/arargs.txt"
|
arargs <- fmap read $ readFile "dist/arargs.txt"
|
||||||
rawSystem "ar" arargs
|
rawSystem ar arargs
|
||||||
ldargs <- fmap read $ readFile "dist/ldargs.txt"
|
ldargs <- fmap read $ readFile "dist/ldargs.txt"
|
||||||
rawSystem "ld" ldargs
|
rawSystem ld ldargs
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user