Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
b42f4fdd
Commit
b42f4fdd
authored
Oct 30, 2016
by
Andrey Mokhov
Browse files
Merge LookupInPath and Path oracles
parent
e1e2621d
Changes
4
Hide whitespace changes
Inline
Side-by-side
hadrian.cabal
View file @
b42f4fdd
...
...
@@ -32,7 +32,6 @@ executable hadrian
, Oracles.Config.Setting
, Oracles.Dependencies
, Oracles.DirectoryContent
, Oracles.LookupInPath
, Oracles.ModuleFiles
, Oracles.PackageData
, Oracles.Path
...
...
src/Oracles/LookupInPath.hs
deleted
100644 → 0
View file @
e1e2621d
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module
Oracles.LookupInPath
(
lookupInPath
,
lookupInPathOracle
)
where
import
System.Directory
import
Base
newtype
LookupInPath
=
LookupInPath
String
deriving
(
Binary
,
Eq
,
Hashable
,
NFData
,
Show
,
Typeable
)
-- | Lookup an executable in @PATH@.
lookupInPath
::
FilePath
->
Action
FilePath
lookupInPath
name
|
name
==
takeFileName
name
=
askOracle
$
LookupInPath
name
|
otherwise
=
return
name
lookupInPathOracle
::
Rules
()
lookupInPathOracle
=
void
$
addOracle
$
\
(
LookupInPath
name
)
->
do
let
unpack
=
fromMaybe
.
error
$
"Cannot find executable "
++
quote
name
path
<-
unifyPath
<$>
unpack
<$>
liftIO
(
findExecutable
name
)
putLoud
$
"Executable found: "
++
name
++
" => "
++
path
return
path
src/Oracles/Path.hs
View file @
b42f4fdd
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module
Oracles.Path
(
fixAbsolutePathOnWindows
,
topDirectory
,
getTopDirectory
,
windowsPathOracle
,
systemBuilderPath
topDirectory
,
getTopDirectory
,
systemBuilderPath
,
pathOracle
)
where
import
Control.Monad.Trans.Reader
import
Data.Char
import
System.Directory
import
Base
import
Builder
import
Oracles.Config
import
Oracles.Config.Setting
import
Oracles.LookupInPath
import
Stage
newtype
WindowsPath
=
WindowsPath
FilePath
deriving
(
Binary
,
Eq
,
Hashable
,
NFData
,
Show
,
Typeable
)
-- | Path to the GHC source tree.
topDirectory
::
Action
FilePath
topDirectory
=
fixAbsolutePathOnWindows
=<<
setting
GhcSourcePath
...
...
@@ -59,6 +55,12 @@ systemBuilderPath builder = case builder of
return
""
-- TODO: Use a safe interface.
else
fixAbsolutePathOnWindows
=<<
lookupInPath
path
-- | Lookup an executable in @PATH@.
lookupInPath
::
FilePath
->
Action
FilePath
lookupInPath
name
|
name
==
takeFileName
name
=
askOracle
$
LookupInPath
name
|
otherwise
=
return
name
-- | Fix an absolute path on Windows:
-- * "/c/" => "C:/"
-- * "/usr/bin/tar.exe" => "C:/msys/usr/bin/tar.exe"
...
...
@@ -73,11 +75,24 @@ fixAbsolutePathOnWindows path = do
else
return
path
-- | Compute path mapping on Windows. This is slow and requires caching.
windowsPathOracle
::
Rules
()
windowsPathOracle
=
void
$
addOracle
$
\
(
WindowsPath
path
)
->
do
newtype
LookupInPath
=
LookupInPath
String
deriving
(
Binary
,
Eq
,
Hashable
,
NFData
,
Show
,
Typeable
)
newtype
WindowsPath
=
WindowsPath
FilePath
deriving
(
Binary
,
Eq
,
Hashable
,
NFData
,
Show
,
Typeable
)
-- | Oracles for looking up paths. These are slow and require caching.
pathOracle
::
Rules
()
pathOracle
=
do
void
$
addOracle
$
\
(
WindowsPath
path
)
->
do
Stdout
out
<-
quietly
$
cmd
[
"cygpath"
,
"-m"
,
path
]
let
windowsPath
=
unifyPath
$
dropWhileEnd
isSpace
out
putLoud
$
"Windows path mapping: "
++
path
++
" => "
++
windowsPath
return
windowsPath
void
$
addOracle
$
\
(
LookupInPath
name
)
->
do
let
unpack
=
fromMaybe
.
error
$
"Cannot find executable "
++
quote
name
path
<-
unifyPath
<$>
unpack
<$>
liftIO
(
findExecutable
name
)
putLoud
$
"Executable found: "
++
name
++
" => "
++
path
return
path
src/Rules/Oracles.hs
View file @
b42f4fdd
...
...
@@ -5,7 +5,6 @@ import qualified Oracles.ArgsHash
import
qualified
Oracles.Config
import
qualified
Oracles.Dependencies
import
qualified
Oracles.DirectoryContent
import
qualified
Oracles.LookupInPath
import
qualified
Oracles.ModuleFiles
import
qualified
Oracles.PackageData
import
qualified
Oracles.Path
...
...
@@ -16,7 +15,6 @@ oracleRules = do
Oracles
.
Config
.
configOracle
Oracles
.
Dependencies
.
dependenciesOracles
Oracles
.
DirectoryContent
.
directoryContentOracle
Oracles
.
LookupInPath
.
lookupInPathOracle
Oracles
.
ModuleFiles
.
moduleFilesOracle
Oracles
.
PackageData
.
packageDataOracle
Oracles
.
Path
.
windowsP
athOracle
Oracles
.
Path
.
p
athOracle
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment