Skip to content
Snippets Groups Projects
Commit 738c7935 authored by Ben Gamari's avatar Ben Gamari
Browse files

hadrian: Always canonicalize topDirectory

Hadrian's `topDirectory` is intended to provide an absolute path to the
root of the GHC tree. However, if the tree is reached via a symlink this

One question here is whether the `canonicalizePath` call is expensive
enough to warrant caching. In a quick microbenchmark I observed that
`canonicalizePath "."` takes around 10us per call; this seems
sufficiently low not to worry.

Alternatively, another approach here would have been to rather move the
canonicalization into `m4/fp_find_root.m4`. This would have avoided
repeated canonicalization but sadly path canonicalization is a hard
problem in POSIX shell.

Addresses #22451.

(cherry picked from commit 5efa9ca5)
parent 20d3ed02
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ module Oracles.Setting (
ghcWithInterpreter
) where
import System.Directory
import System.Info.Extra
import Hadrian.Expression
import Hadrian.Oracles.TextFile
import Hadrian.Oracles.Path
......@@ -330,9 +332,14 @@ ghcCanonVersion = do
let leadingZero = [ '0' | length ghcMinorVersion == 1 ]
return $ ghcMajorVersion ++ leadingZero ++ ghcMinorVersion
-- | Path to the GHC source tree.
-- | Absolute path to the GHC source tree.
topDirectory :: Action FilePath
topDirectory = fixAbsolutePathOnWindows =<< setting GhcSourcePath
topDirectory = do
x <- fixAbsolutePathOnWindows =<< setting GhcSourcePath
canonicalize x
where
-- We must canonicalize as the source directory may be accessed via a symlink. See #22451.
canonicalize = if isWindows then return else liftIO . canonicalizePath
ghcVersionStage :: Stage -> Action String
ghcVersionStage (Stage0 {}) = setting GhcVersion
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment