Commit 68cf6048 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Fix executable lookup.

parent f5299c86
......@@ -112,11 +112,11 @@ builderPath builder = case builderProvenance builder of
path <- askConfigWithDefault builderKey . putError $
"\nCannot find path to '" ++ builderKey
++ "' in configuration files. Have you forgot to run configure?"
windows <- windowsHost
case (path, windows) of
("", _ ) -> return path
(p , True ) -> fixAbsolutePathOnWindows (p -<.> exe)
(p , False) -> lookupInPath p
if path == "" -- TODO: get rid of "" paths
then return ""
else do
path' <- lookupInPath path
fixAbsolutePathOnWindows $ path' -<.> exe
getBuilderPath :: Builder -> ReaderT a Action FilePath
getBuilderPath = lift . builderPath
......
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
module Oracles.LookupInPath (lookupInPath, lookupInPathOracle) where
import System.Directory
import Base
newtype LookupInPath = LookupInPath String
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
-- | Fetches the absolute FilePath to a given FilePath using the oracle.
commandPath :: FilePath -> Action FilePath
commandPath = askOracle . LookupInPath
-- | Lookup a @command@ in @PATH@ environment.
-- | Lookup an executable in @PATH@.
lookupInPath :: FilePath -> Action FilePath
lookupInPath c
| c /= takeFileName c = return c
| otherwise = commandPath c
lookupInPath name
| name == takeFileName name = askOracle $ LookupInPath name
| otherwise = return name
lookupInPathOracle :: Rules ()
lookupInPathOracle = do
answer <- newCache $ \query -> do
envPaths <- wordsBy (== ':') <$> getEnvWithDefault "" "PATH"
let candidates = map (-/- query) envPaths
-- this will crash if we do not find any valid candidate.
fullCommand <- head <$> filterM doesFileExist candidates
putOracle $ "Found '" ++ query ++ "' at " ++ "'" ++ fullCommand ++ "'"
return fullCommand
maybePath <- liftIO $ findExecutable query
let path = fromMaybe query maybePath
putOracle $ "Lookup executable '" ++ query ++ "': " ++ path
return path
_ <- addOracle $ \(LookupInPath query) -> answer query
return ()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment