From f67060c6dcc2ba14949ab5e8a4ffe46bceadc14f Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 13 Nov 2021 03:59:48 +0000 Subject: Make ambient MinGW support a proper settings Get rid of `USE_INPLACE_MINGW_TOOLCHAIN` and use a settings file entry instead. The CPP setting was originally introduced in f065b6b012. --- compiler/GHC/Driver/Session.hs | 3 ++- compiler/GHC/Settings.hs | 4 ++++ compiler/GHC/Settings/IO.hs | 34 ++++++++++++++++++---------------- compiler/GHC/SysTools/BaseDir.hs | 24 +++++++++++++++--------- 4 files changed, 39 insertions(+), 26 deletions(-) (limited to 'compiler/GHC') diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 2a4d5aae3c..ccf4d18f2f 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -4544,8 +4544,9 @@ compilerInfo dflags showBool False = "NO" platform = targetPlatform dflags isWindows = platformOS platform == OSMinGW32 + useInplaceMinGW = toolSettings_useInplaceMinGW $ toolSettings dflags expandDirectories :: FilePath -> Maybe FilePath -> String -> String - expandDirectories topd mtoold = expandToolDir mtoold . expandTopDir topd + expandDirectories topd mtoold = expandToolDir useInplaceMinGW mtoold . expandTopDir topd wordAlignment :: Platform -> Alignment diff --git a/compiler/GHC/Settings.hs b/compiler/GHC/Settings.hs index 73f3b97b54..679d0266fe 100644 --- a/compiler/GHC/Settings.hs +++ b/compiler/GHC/Settings.hs @@ -22,6 +22,7 @@ module GHC.Settings , sLdSupportsFilelist , sLdIsGnuLd , sGccSupportsNoPie + , sUseInplaceMinGW , sPgm_L , sPgm_P , sPgm_F @@ -89,6 +90,7 @@ data ToolSettings = ToolSettings , toolSettings_ldSupportsFilelist :: Bool , toolSettings_ldIsGnuLd :: Bool , toolSettings_ccSupportsNoPie :: Bool + , toolSettings_useInplaceMinGW :: Bool -- commands for particular phases , toolSettings_pgm_L :: String @@ -190,6 +192,8 @@ sLdIsGnuLd :: Settings -> Bool sLdIsGnuLd = toolSettings_ldIsGnuLd . sToolSettings sGccSupportsNoPie :: Settings -> Bool sGccSupportsNoPie = toolSettings_ccSupportsNoPie . sToolSettings +sUseInplaceMinGW :: Settings -> Bool +sUseInplaceMinGW = toolSettings_useInplaceMinGW . sToolSettings sPgm_L :: Settings -> String sPgm_L = toolSettings_pgm_L . sToolSettings diff --git a/compiler/GHC/Settings/IO.hs b/compiler/GHC/Settings/IO.hs index 1e56d1c087..7d9be2f403 100644 --- a/compiler/GHC/Settings/IO.hs +++ b/compiler/GHC/Settings/IO.hs @@ -35,12 +35,6 @@ initSettings => String -- ^ TopDir path -> ExceptT SettingsError m Settings initSettings top_dir = do - -- see Note [topdir: How GHC finds its files] - -- NB: top_dir is assumed to be in standard Unix - -- format, '/' separated - mtool_dir <- liftIO $ findToolDir top_dir - -- see Note [tooldir: How GHC finds mingw on Windows] - let installed :: FilePath -> FilePath installed file = top_dir file libexec :: FilePath -> FilePath @@ -58,24 +52,31 @@ initSettings top_dir = do Nothing -> throwE $ SettingsError_BadData $ "Can't parse " ++ show settingsFile let mySettings = Map.fromList settingsList + getBooleanSetting :: String -> ExceptT SettingsError m Bool + getBooleanSetting key = either pgmError pure $ + getRawBooleanSetting settingsFile mySettings key + + -- On Windows, by mingw is often distributed with GHC, + -- so we look in TopDir/../mingw/bin, + -- as well as TopDir/../../mingw/bin for hadrian. + -- But we might be disabled, in which we we don't do that. + useInplaceMinGW <- getBooleanSetting "Use inplace MinGW toolchain" + + -- see Note [topdir: How GHC finds its files] + -- NB: top_dir is assumed to be in standard Unix + -- format, '/' separated + mtool_dir <- liftIO $ findToolDir useInplaceMinGW top_dir + -- see Note [tooldir: How GHC finds mingw on Windows] + -- See Note [Settings file] for a little more about this file. We're -- just partially applying those functions and throwing 'Left's; they're -- written in a very portable style to keep ghc-boot light. let getSetting key = either pgmError pure $ getRawFilePathSetting top_dir settingsFile mySettings key getToolSetting :: String -> ExceptT SettingsError m String - getToolSetting key = expandToolDir mtool_dir <$> getSetting key - getBooleanSetting :: String -> ExceptT SettingsError m Bool - getBooleanSetting key = either pgmError pure $ - getRawBooleanSetting settingsFile mySettings key + getToolSetting key = expandToolDir useInplaceMinGW mtool_dir <$> getSetting key targetPlatformString <- getSetting "target platform string" myExtraGccViaCFlags <- getSetting "GCC extra via C opts" - -- On Windows, mingw is distributed with GHC, - -- so we look in TopDir/../mingw/bin, - -- as well as TopDir/../../mingw/bin for hadrian. - -- It would perhaps be nice to be able to override this - -- with the settings file, but it would be a little fiddly - -- to make that possible, so for now you can't. cc_prog <- getToolSetting "C compiler command" cc_args_str <- getSetting "C compiler flags" cxx_args_str <- getSetting "C++ compiler flags" @@ -162,6 +163,7 @@ initSettings top_dir = do , toolSettings_ldSupportsFilelist = ldSupportsFilelist , toolSettings_ldIsGnuLd = ldIsGnuLd , toolSettings_ccSupportsNoPie = gccSupportsNoPie + , toolSettings_useInplaceMinGW = useInplaceMinGW , toolSettings_pgm_L = unlit_path , toolSettings_pgm_P = (cpp_prog, cpp_args) diff --git a/compiler/GHC/SysTools/BaseDir.hs b/compiler/GHC/SysTools/BaseDir.hs index 03169523c6..c0a1fa2cee 100644 --- a/compiler/GHC/SysTools/BaseDir.hs +++ b/compiler/GHC/SysTools/BaseDir.hs @@ -139,12 +139,16 @@ play nice with the system compiler instead. -- | Expand occurrences of the @$tooldir@ interpolation in a string -- on Windows, leave the string untouched otherwise. -expandToolDir :: Maybe FilePath -> String -> String -#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN) -expandToolDir (Just tool_dir) s = expandPathVar "tooldir" tool_dir s -expandToolDir Nothing _ = panic "Could not determine $tooldir" +expandToolDir + :: Bool -- ^ whether we are use the ambiant mingw toolchain + -> Maybe FilePath -- ^ tooldir + -> String -> String +#if defined(mingw32_HOST_OS) +expandToolDir False (Just tool_dir) s = expandPathVar "tooldir" tool_dir s +expandToolDir False Nothing _ = panic "Could not determine $tooldir" +expandToolDir True _ s = s #else -expandToolDir _ s = s +expandToolDir _ _ s = s #endif -- | Returns a Unix-format path pointing to TopDir. @@ -180,10 +184,11 @@ tryFindTopDir Nothing -- tooldir can't be located, or returns @Just tooldirpath@. -- If the distro toolchain is being used we treat Windows the same as Linux findToolDir - :: FilePath -- ^ topdir + :: Bool -- ^ whether we are use the ambiant mingw toolchain + -> FilePath -- ^ topdir -> IO (Maybe FilePath) -#if defined(mingw32_HOST_OS) && !defined(USE_INPLACE_MINGW_TOOLCHAIN) -findToolDir top_dir = go 0 (top_dir "..") [] +#if defined(mingw32_HOST_OS) +findToolDir False top_dir = go 0 (top_dir "..") [] where maxDepth = 3 go :: Int -> FilePath -> [FilePath] -> IO (Maybe FilePath) go k path tried @@ -196,6 +201,7 @@ findToolDir top_dir = go 0 (top_dir "..") [] if oneLevel then return (Just path) else go (k+1) (path "..") tried +findToolDir True _ = return Nothing #else -findToolDir _ = return Nothing +findToolDir _ _ = return Nothing #endif -- cgit v1.2.1