Skip to content

Commit

Permalink
Log GHC configure output on stack -v setup
Browse files Browse the repository at this point in the history
If -v global flag is passed to stack-setup subcommand we log the GHC
configure output.
Ref: commercialhaskell#3716
  • Loading branch information
Krishnan Parthasarathi committed Jan 2, 2018
1 parent 2e86213 commit 682b8dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
46 changes: 27 additions & 19 deletions src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ setupEnv mResolveMissingGHC = do
, soptsGHCJSBootOpts = ["--clean"]
}

(mghcBin, compilerBuild, _) <- ensureCompiler sopts
(mghcBin, compilerBuild, _) <- ensureCompiler sopts LevelInfo

-- Modify the initial environment to include the GHC path, if a local GHC
-- is being used
Expand Down Expand Up @@ -374,8 +374,9 @@ addIncludeLib (ExtraDirs _bins includes libs) config = config
-- | Ensure compiler (ghc or ghcjs) is installed and provide the PATHs to add if necessary
ensureCompiler :: (HasConfig env, HasGHCVariant env)
=> SetupOpts
-> LogLevel
-> RIO env (Maybe ExtraDirs, CompilerBuild, Bool)
ensureCompiler sopts = do
ensureCompiler sopts logLevel = do
let wc = whichCompiler (soptsWantedCompiler sopts)
when (getGhcVersion (soptsWantedCompiler sopts) < $(mkVersion "7.8")) $ do
logWarn "Stack will almost certainly fail with GHC below version 7.8"
Expand Down Expand Up @@ -467,6 +468,7 @@ ensureCompiler sopts = do
(soptsWantedCompiler sopts)
(soptsCompilerCheck sopts)
(soptsGHCBindistURL sopts)
logLevel
| otherwise -> do
recommendSystemGhc <-
if soptsUseSystem sopts
Expand Down Expand Up @@ -848,8 +850,9 @@ downloadAndInstallCompiler :: (HasConfig env, HasGHCVariant env)
-> CompilerVersion 'CVWanted
-> VersionCheck
-> Maybe String
-> LogLevel
-> RIO env Tool
downloadAndInstallCompiler ghcBuild si wanted@GhcVersion{} versionCheck mbindistURL = do
downloadAndInstallCompiler ghcBuild si wanted@GhcVersion{} versionCheck mbindistURL logLevel = do
ghcVariant <- view ghcVariantL
(selectedVersion, downloadInfo) <- case mbindistURL of
Just bindistURL -> do
Expand All @@ -875,7 +878,7 @@ downloadAndInstallCompiler ghcBuild si wanted@GhcVersion{} versionCheck mbindist
let installer =
case configPlatform config of
Platform _ Cabal.Windows -> installGHCWindows selectedVersion
_ -> installGHCPosix selectedVersion downloadInfo
_ -> installGHCPosix selectedVersion downloadInfo logLevel
logInfo $
"Preparing to install GHC" <>
(case ghcVariant of
Expand All @@ -889,7 +892,7 @@ downloadAndInstallCompiler ghcBuild si wanted@GhcVersion{} versionCheck mbindist
ghcPkgName <- parsePackageNameFromString ("ghc" ++ ghcVariantSuffix ghcVariant ++ compilerBuildSuffix ghcBuild)
let tool = Tool $ PackageIdentifier ghcPkgName selectedVersion
downloadAndInstallTool (configLocalPrograms config) si (gdiDownloadInfo downloadInfo) tool installer
downloadAndInstallCompiler compilerBuild si wanted versionCheck _mbindistUrl = do
downloadAndInstallCompiler compilerBuild si wanted versionCheck _mbindistUrl _ = do
config <- view configL
ghcVariant <- view ghcVariantL
case (ghcVariant, compilerBuild) of
Expand Down Expand Up @@ -928,9 +931,10 @@ downloadAndInstallPossibleCompilers
-> CompilerVersion 'CVWanted
-> VersionCheck
-> Maybe String
-> LogLevel
-> RIO env (Tool, CompilerBuild)
downloadAndInstallPossibleCompilers possibleCompilers si wanted versionCheck mbindistURL =
go possibleCompilers Nothing
downloadAndInstallPossibleCompilers possibleCompilers si wanted versionCheck mbindistURL logLevel =
go logLevel possibleCompilers Nothing
where
-- This will stop as soon as one of the builds doesn't throw an @UnknownOSKey@ or
-- @UnknownCompilerVersion@ exception (so it will only try subsequent builds if one is non-existent,
Expand All @@ -939,26 +943,26 @@ downloadAndInstallPossibleCompilers possibleCompilers si wanted versionCheck mbi
-- (if only @UnknownOSKey@ is thrown, then the first of those is rethrown, but if any
-- @UnknownCompilerVersion@s are thrown then the attempted OS keys and available versions
-- are unioned).
go [] Nothing = throwM UnsupportedSetupConfiguration
go [] (Just e) = throwM e
go (b:bs) e = do
go _ [] Nothing = throwM UnsupportedSetupConfiguration
go _ [] (Just e) = throwM e
go logLevel (b:bs) e = do
logDebug $ "Trying to setup GHC build: " <> T.pack (compilerBuildName b)
er <- try $ downloadAndInstallCompiler b si wanted versionCheck mbindistURL
er <- try $ downloadAndInstallCompiler b si wanted versionCheck mbindistURL logLevel
case er of
Left e'@(UnknownCompilerVersion ks' w' vs') ->
case e of
Nothing -> go bs (Just e')
Nothing -> go logLevel bs (Just e')
Just (UnknownOSKey k) ->
go bs $ Just $ UnknownCompilerVersion (Set.insert k ks') w' vs'
go logLevel bs $ Just $ UnknownCompilerVersion (Set.insert k ks') w' vs'
Just (UnknownCompilerVersion ks _ vs) ->
go bs $ Just $ UnknownCompilerVersion (Set.union ks' ks) w' (Set.union vs' vs)
go logLevel bs $ Just $ UnknownCompilerVersion (Set.union ks' ks) w' (Set.union vs' vs)
Just x -> throwM x
Left e'@(UnknownOSKey k') ->
case e of
Nothing -> go bs (Just e')
Just (UnknownOSKey _) -> go bs e
Nothing -> go logLevel bs (Just e')
Just (UnknownOSKey _) -> go logLevel bs e
Just (UnknownCompilerVersion ks w vs) ->
go bs $ Just $ UnknownCompilerVersion (Set.insert k' ks) w vs
go logLevel bs $ Just $ UnknownCompilerVersion (Set.insert k' ks) w vs
Just x -> throwM x
Left e' -> throwM e'
Right r -> return (r, b)
Expand Down Expand Up @@ -1042,13 +1046,14 @@ data ArchiveType
installGHCPosix :: HasConfig env
=> Version
-> GHCDownloadInfo
-> LogLevel
-> SetupInfo
-> Path Abs File
-> ArchiveType
-> Path Abs Dir
-> Path Abs Dir
-> RIO env ()
installGHCPosix version downloadInfo _ archiveFile archiveType tempDir destDir = do
installGHCPosix version downloadInfo logLevel _ archiveFile archiveType tempDir destDir = do
platform <- view platformL
menv0 <- getMinimalEnvOverride
menv <- mkEnvOverride platform (removeHaskellEnvVars (unEnvOverride menv0))
Expand Down Expand Up @@ -1081,7 +1086,10 @@ installGHCPosix version downloadInfo _ archiveFile archiveType tempDir destDir =

let runStep step wd env cmd args = do
menv' <- modifyEnvOverride menv (Map.union env)
result <- try (readProcessNull (Just wd) menv' cmd args)
result <- case logLevel of
LevelDebug -> try (logProcessStderrStdout (Just wd) cmd menv' args)
_ -> try (readProcessNull (Just wd) menv' cmd args)

case result of
Right _ -> return ()
Left ex -> do
Expand Down
7 changes: 4 additions & 3 deletions src/Stack/SetupCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ setupParser = SetupCmdOpts

setup
:: (HasConfig env, HasGHCVariant env)
=> SetupCmdOpts
=> GlobalOpts
-> SetupCmdOpts
-> CompilerVersion 'CVWanted
-> VersionCheck
-> Maybe (Path Abs File)
-> RIO env ()
setup SetupCmdOpts{..} wantedCompiler compilerCheck mstack = do
setup gopts SetupCmdOpts{..} wantedCompiler compilerCheck mstack = do
Config{..} <- view configL
(_, _, sandboxedGhc) <- ensureCompiler SetupOpts
{ soptsInstallIfMissing = True
Expand All @@ -123,7 +124,7 @@ setup SetupCmdOpts{..} wantedCompiler compilerCheck mstack = do
, soptsSetupInfoYaml = scoSetupInfoYaml
, soptsGHCBindistURL = scoGHCBindistURL
, soptsGHCJSBootOpts = scoGHCJSBootOpts ++ ["--clean" | scoGHCJSBootClean]
}
} (globalLogLevel gopts)
let compiler = case wantedCompiler of
GhcVersion _ -> "GHC"
GhcjsVersion {} -> "GHCJS"
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ setupCompiler compiler = do
, soptsSetupInfoYaml = defaultSetupInfoYaml
, soptsGHCBindistURL = Nothing
, soptsGHCJSBootOpts = ["--clean"]
}
} LevelInfo
return dirs

-- | Runs the given inner command with an updated configuration that
Expand Down
2 changes: 1 addition & 1 deletion src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ setupCmd sco@SetupCmdOpts{..} go@GlobalOpts{..} = loadConfigWithOpts go $ \lc ->
, configCompilerCheck (lcConfig lc)
, Just $ view stackYamlL bc
)
runRIO (loadMiniConfig (lcConfig lc)) $ setup sco wantedCompiler compilerCheck mstack
runRIO (loadMiniConfig (lcConfig lc)) $ setup go sco wantedCompiler compilerCheck mstack
)
Nothing
(Just $ munlockFile lk)
Expand Down

0 comments on commit 682b8dc

Please sign in to comment.