David Eichmann pushed to branch wip/davide/hadrian-aclocal_path at Glasgow Haskell Compiler / GHC
Commits:
-
1db26f87
by David Eichmann at 2026-05-28T15:06:40+01:00
3 changed files:
Changes:
| ... | ... | @@ -52,9 +52,8 @@ def autoreconf(): |
| 52 | 52 | # Run autoreconf on everything that needs it.
|
| 53 | 53 | processes = {}
|
| 54 | 54 | if os.name == 'nt':
|
| 55 | - # Get the normalized ACLOCAL_PATH for Windows
|
|
| 56 | - # This is necessary since on Windows this will be a Windows
|
|
| 57 | - # path, which autoreconf doesn't know doesn't know how to handle.
|
|
| 55 | + # Convert ACLOCAL_PATH env variable to unix style paths on Windows
|
|
| 56 | + # See Note [Autoreconf unix paths from ACLOCAL_PATH]
|
|
| 58 | 57 | ac_local = os.getenv('ACLOCAL_PATH', '')
|
| 59 | 58 | ac_local_arg = re.sub(r';', r':', ac_local)
|
| 60 | 59 | ac_local_arg = re.sub(r'\\', r'/', ac_local_arg)
|
| 1 | 1 | {-# LANGUAGE TypeFamilies #-}
|
| 2 | 2 | module Hadrian.Oracles.Path (
|
| 3 | - lookupInPath, fixAbsolutePathOnWindows, pathOracle
|
|
| 3 | + lookupInPath, fixAbsolutePathOnWindows, fixUnixPathsOnWindows,
|
|
| 4 | + pathOracle
|
|
| 4 | 5 | ) where
|
| 5 | 6 | |
| 6 | 7 | import Control.Monad
|
| ... | ... | @@ -33,6 +34,14 @@ fixAbsolutePathOnWindows path = |
| 33 | 34 | else
|
| 34 | 35 | return path
|
| 35 | 36 | |
| 37 | +-- | Fix a unix path list on Windows:
|
|
| 38 | +-- * "C:\\foo\\bar;C:\\msys2\\bin" => "/c/foo/bar:/c/msys2/bin"
|
|
| 39 | +fixUnixPathsOnWindows :: FilePath -> Action FilePath
|
|
| 40 | +fixUnixPathsOnWindows paths =
|
|
| 41 | + if isWindows
|
|
| 42 | + then askOracle $ UnixPathList paths
|
|
| 43 | + else return paths
|
|
| 44 | + |
|
| 36 | 45 | newtype LookupInPath = LookupInPath String
|
| 37 | 46 | deriving (Binary, Eq, Hashable, NFData, Show)
|
| 38 | 47 | type instance RuleResult LookupInPath = String
|
| ... | ... | @@ -41,6 +50,10 @@ newtype WindowsPath = WindowsPath FilePath |
| 41 | 50 | deriving (Binary, Eq, Hashable, NFData, Show)
|
| 42 | 51 | type instance RuleResult WindowsPath = String
|
| 43 | 52 | |
| 53 | +newtype UnixPathList = UnixPathList FilePath
|
|
| 54 | + deriving (Binary, Eq, Hashable, NFData, Show)
|
|
| 55 | +type instance RuleResult UnixPathList = String
|
|
| 56 | + |
|
| 44 | 57 | -- | Oracles for looking up paths. These are slow and require caching.
|
| 45 | 58 | pathOracle :: Rules ()
|
| 46 | 59 | pathOracle = do
|
| ... | ... | @@ -50,6 +63,12 @@ pathOracle = do |
| 50 | 63 | putVerbose $ "| Windows path mapping: " ++ path ++ " => " ++ windowsPath
|
| 51 | 64 | return windowsPath
|
| 52 | 65 | |
| 66 | + void $ addOracleCache $ \(UnixPathList paths) -> do
|
|
| 67 | + Stdout out <- quietly $ cmd ["cygpath", "-p", "-u", paths]
|
|
| 68 | + let unixPaths = unifyPath $ dropWhileEnd isSpace out
|
|
| 69 | + putVerbose $ "| Unix path mapping: " ++ paths ++ " => " ++ unixPaths
|
|
| 70 | + return unixPaths
|
|
| 71 | + |
|
| 53 | 72 | void $ addOracleCache $ \(LookupInPath name) -> do
|
| 54 | 73 | path <- liftIO getSearchPath
|
| 55 | 74 | exes <- liftIO (findExecutablesInDirectories path name)
|
| ... | ... | @@ -14,6 +14,7 @@ import qualified System.Directory.Extra as IO |
| 14 | 14 | import Data.Either
|
| 15 | 15 | import qualified Data.Set as Set
|
| 16 | 16 | import Oracles.Flavour
|
| 17 | +import Hadrian.Oracles.Path (fixUnixPathsOnWindows)
|
|
| 17 | 18 | |
| 18 | 19 | {-
|
| 19 | 20 | Note [Binary distributions]
|
| ... | ... | @@ -331,7 +332,25 @@ bindistRules = do |
| 331 | 332 | ghcRoot <- topDirectory
|
| 332 | 333 | copyFile (ghcRoot -/- "aclocal.m4") (ghcRoot -/- "distrib" -/- "aclocal.m4")
|
| 333 | 334 | copyDirectory (ghcRoot -/- "m4") (ghcRoot -/- "distrib")
|
| 334 | - buildWithCmdOptions [] $
|
|
| 335 | + |
|
| 336 | + -- Note [Autoreconf unix paths from ACLOCAL_PATH]
|
|
| 337 | + -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 338 | + -- On windows, autoreconf fails when the ACLOCAL_PATH env variable contains windows
|
|
| 339 | + -- style paths. This happens because msys2 automatically converts env variables to
|
|
| 340 | + -- windows style paths. To fix this, we convert ACLOCAL_PATH back to unix style.
|
|
| 341 | + -- This is done both in the boot phython script and here when building a bindist.
|
|
| 342 | + win_host <- isWinHost
|
|
| 343 | + env <- if not win_host
|
|
| 344 | + then pure []
|
|
| 345 | + else do
|
|
| 346 | + aclocalPathMay <- getEnv "ACLOCAL_PATH"
|
|
| 347 | + case aclocalPathMay of
|
|
| 348 | + Nothing -> pure []
|
|
| 349 | + Just aclocalPath -> do
|
|
| 350 | + unixAclocalPath <- fixUnixPathsOnWindows aclocalPath
|
|
| 351 | + pure [AddEnv "ACLOCAL_PATH" unixAclocalPath]
|
|
| 352 | + |
|
| 353 | + buildWithCmdOptions env $
|
|
| 335 | 354 | target (vanillaContext Stage1 ghc) (Autoreconf $ ghcRoot -/- "distrib") [] []
|
| 336 | 355 | -- We clean after ourselves, moving the configure script we generated in
|
| 337 | 356 | -- our bindist dir
|