-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a $tooldir variable for nicer toolchain detection on Windows
This patch affects several files that affect how we detect mingw and perl on Windows. The initial motivation is: snowleopard/hadrian#564 where, with Hadrian building relocatable (non-inplace) GHCs, the current detection mechanism falls short by e.g only trying $topdir/../mingw. But in Hadrian, for reasons given in that issue, we would need to store e.g mingw under $topdir/../../mingw except for binary distributions, where we want to follow the existing structure, in which case $topdir/../mingw is correct. So we need to support both, which is what this patch hopefully implements.
- Loading branch information
Showing
3 changed files
with
76 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ | |
----------------------------------------------------------------------------- | ||
-} | ||
|
||
module SysTools.BaseDir (expandTopDir, findTopDir) where | ||
module SysTools.BaseDir | ||
( expandTopDir, expandToolDir | ||
, findTopDir, findToolDir | ||
) where | ||
|
||
#include "HsVersions.h" | ||
|
||
|
@@ -70,16 +73,41 @@ On Windows: | |
from topdir we can find package.conf, ghc-asm, etc. | ||
Note [tooldir: How GHC finds mingw and perl on Windows] | ||
GHC has some custom logic on Windows for finding the mingw | ||
toolchain and perl. Depending on whether GHC is built | ||
with the make build system or Hadrian, and on whether we're | ||
running a bindist, we might find the mingw toolchain and perl | ||
either under $topdir/../{mingw, perl}/ or | ||
$topdir/../../{mingw, perl}/. | ||
-} | ||
|
||
-- | Expand occurrences of the @$topdir@ interpolation in a string. | ||
expandTopDir :: FilePath -> String -> String | ||
expandTopDir top_dir str | ||
| Just str' <- stripPrefix "$topdir" str | ||
expandTopDir = expandPathVar "topdir" | ||
|
||
-- | Expand occurrences of the @$tooldir@ interpolation in a string | ||
-- on Windows, leave the string untouched otherwise. | ||
expandToolDir :: FilePath -> String -> String | ||
#if defined(mingw32_HOST_OS) | ||
expandToolDir = expandPathVar "tooldir" | ||
#else | ||
expandToolDir _ s = s | ||
#endif | ||
|
||
-- | @expandPathVar var value str@ | ||
-- | ||
-- replaces occurences of variable @$var@ with @value@ in str. | ||
expandPathVar :: String -> FilePath -> String -> String | ||
expandPathVar var value str | ||
| Just str' <- stripPrefix ('$':var) str | ||
, null str' || isPathSeparator (head str') | ||
= top_dir ++ expandTopDir top_dir str' | ||
expandTopDir top_dir (x:xs) = x : expandTopDir top_dir xs | ||
expandTopDir _ [] = [] | ||
= value ++ expandPathVar var value str' | ||
expandPathVar var value (x:xs) = x : expandPathVar var value xs | ||
expandPathVar _ _ [] = [] | ||
|
||
-- | Returns a Unix-format path pointing to TopDir. | ||
findTopDir :: Maybe String -- Maybe TopDir path (without the '-B' prefix). | ||
|
@@ -193,3 +221,23 @@ getBaseDir = Just . (\p -> p </> "lib") . takeDirectory . takeDirectory <$> getE | |
#else | ||
getBaseDir = return Nothing | ||
#endif | ||
|
||
-- See Note [tooldir: How GHC finds mingw and perl on Windows] | ||
findToolDir | ||
:: FilePath -- ^ topdir | ||
-> IO FilePath | ||
#if defined(mingw32_HOST_OS) | ||
findToolDir top_dir = do | ||
oneLevel <- doesDirectoryExist (oneLevelUp </> "mingw") | ||
if oneLevel | ||
then return oneLevelUp | ||
else do twoLevels <- doesDirectoryExist (twoLevelsUp </> "mingw") | ||
if twoLevels | ||
then return twoLevelsUp | ||
else throwGhcExceptionIO (InstallationError "could not detect mingw toolchain") | ||
|
||
where oneLevelUp = top_dir </> ".." | ||
twoLevelsUp = top_dir </> ".." </> ".." | ||
This comment has been minimized.
Sorry, something went wrong.
Mistuke
|
||
#else | ||
findToolDir = panic "getToolDir should only be called on Windows" | ||
#endif |
You're missing an end quotation here