Skip to content

Commit 94eca69

Browse files
committed
Clearer error messages when build of Setup.hs fails commercialhaskell#3560
1 parent 8a13027 commit 94eca69

2 files changed

Lines changed: 54 additions & 24 deletions

File tree

src/Stack/Build/Execute.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ getSetupExe setupHs setupShimHs tmpdir = do
306306
, toFilePath tmpOutputPath
307307
] ++
308308
["-build-runner" | wc == Ghcjs]
309-
runCmd' (\cp -> cp { std_out = UseHandle stderr }) (Cmd (Just tmpdir) (compilerExeName wc) menv args) Nothing
309+
callProcess' (\cp -> cp { std_out = UseHandle stderr }) (Cmd (Just tmpdir) (compilerExeName wc) menv args)
310+
`catch` \(ProcessExitedUnsuccessfully _ ec) -> do
311+
compilerPath <- getCompilerPath wc
312+
throwM $ SetupHsBuildFailure ec Nothing compilerPath args Nothing []
310313
when (wc == Ghcjs) $ renameDir tmpJsExePath jsExePath
311314
renameFile tmpExePath exePath
312315
return $ Just exePath
@@ -1073,9 +1076,9 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
10731076
=$= CT.decodeUtf8Lenient
10741077
$$ mungeBuildOutput stripTHLoading makeAbsolute pkgDir compilerVer
10751078
=$ CL.consume
1076-
throwM $ CabalExitedUnsuccessfully
1079+
throwM $ SetupHsBuildFailure
10771080
ec
1078-
taskProvides
1081+
(Just taskProvides)
10791082
exeName
10801083
fullArgs
10811084
(fmap fst mlogFile)
@@ -1104,10 +1107,9 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
11041107
ExcludeTHLoading -> ConvertPathsToAbsolute
11051108
KeepTHLoading -> KeepPathsAsIs
11061109

1107-
wc <- view $ actualCompilerVersionL.whichCompilerL
1108-
exeName <- case (esetupexehs, wc) of
1109-
(Left setupExe, _) -> return setupExe
1110-
(Right setuphs, compiler) -> do
1110+
exeName <- case esetupexehs of
1111+
Left setupExe -> return setupExe
1112+
Right setuphs -> do
11111113
distDir <- distDirFromDir pkgDir
11121114
let setupDir = distDir </> $(mkRelDir "setup")
11131115
outputFile = setupDir </> $(mkRelFile "setup")
@@ -1116,6 +1118,7 @@ withSingleContext runInBase ActionContext {..} ExecuteEnv {..} task@Task {..} md
11161118
then return outputFile
11171119
else do
11181120
ensureDir setupDir
1121+
compiler <- view $ actualCompilerVersionL.whichCompilerL
11191122
compilerPath <-
11201123
case compiler of
11211124
Ghc -> eeGetGhcPath

src/Stack/Types/Build.hs

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ data StackBuildException
111111
[String] -- cabal arguments
112112
(Maybe (Path Abs File)) -- logfiles location
113113
[Text] -- log contents
114+
| SetupHsBuildFailure
115+
ExitCode
116+
(Maybe PackageIdentifier) -- which package's custom setup, is simple setup if Nothing
117+
(Path Abs File) -- ghc Executable
118+
[String] -- ghc arguments
119+
(Maybe (Path Abs File)) -- logfiles location
120+
[Text] -- log contents
114121
| ExecutionFailure [SomeException]
115122
| LocalPackageDoesn'tMatchTarget
116123
PackageName
@@ -220,23 +227,9 @@ instance Show StackBuildException where
220227
"Unsupported test suite type: " <> show interface
221228
-- Supressing duplicate output
222229
show (CabalExitedUnsuccessfully exitCode taskProvides' execName fullArgs logFiles bss) =
223-
let fullCmd = unwords
224-
$ dropQuotes (toFilePath execName)
225-
: map (T.unpack . showProcessArgDebug) fullArgs
226-
logLocations = maybe "" (\fp -> "\n Logs have been written to: " ++ toFilePath fp) logFiles
227-
in "\n-- While building package " ++ dropQuotes (show taskProvides') ++ " using:\n" ++
228-
" " ++ fullCmd ++ "\n" ++
229-
" Process exited with code: " ++ show exitCode ++
230-
(if exitCode == ExitFailure (-9)
231-
then " (THIS MAY INDICATE OUT OF MEMORY)"
232-
else "") ++
233-
logLocations ++
234-
(if null bss
235-
then ""
236-
else "\n\n" ++ doubleIndent (map T.unpack bss))
237-
where
238-
doubleIndent = dropWhileEnd isSpace . unlines . fmap (\line -> " " ++ line)
239-
dropQuotes = filter ('\"' /=)
230+
showBuildError False exitCode (Just taskProvides') execName fullArgs logFiles bss
231+
show (SetupHsBuildFailure exitCode mtaskProvides execName fullArgs logFiles bss) =
232+
showBuildError True exitCode mtaskProvides execName fullArgs logFiles bss
240233
show (ExecutionFailure es) = intercalate "\n\n" $ map show es
241234
show (LocalPackageDoesn'tMatchTarget name localV requestedV) = concat
242235
[ "Version for local package "
@@ -338,6 +331,40 @@ missingExeError isSimpleBuildType msg =
338331
then []
339332
else ["The Setup.hs file is changing the installation target dir."]
340333

334+
showBuildError
335+
:: Bool
336+
-> ExitCode
337+
-> Maybe PackageIdentifier
338+
-> Path Abs File
339+
-> [String]
340+
-> Maybe (Path Abs File)
341+
-> [Text]
342+
-> String
343+
showBuildError isBuildingSetup exitCode mtaskProvides execName fullArgs logFiles bss =
344+
let fullCmd = unwords
345+
$ dropQuotes (toFilePath execName)
346+
: map (T.unpack . showProcessArgDebug) fullArgs
347+
logLocations = maybe "" (\fp -> "\n Logs have been written to: " ++ toFilePath fp) logFiles
348+
in "\n-- While building " ++
349+
(case (isBuildingSetup, mtaskProvides) of
350+
(False, Nothing) -> error "Invariant violated: unexpected case in showBuildError"
351+
(False, Just taskProvides') -> "package " ++ dropQuotes (show taskProvides')
352+
(True, Nothing) -> "simple Setup.hs"
353+
(True, Just taskProvides') -> "custom Setup.hs for package " ++ dropQuotes (show taskProvides')
354+
) ++
355+
" using:\n " ++ fullCmd ++ "\n" ++
356+
" Process exited with code: " ++ show exitCode ++
357+
(if exitCode == ExitFailure (-9)
358+
then " (THIS MAY INDICATE OUT OF MEMORY)"
359+
else "") ++
360+
logLocations ++
361+
(if null bss
362+
then ""
363+
else "\n\n" ++ doubleIndent (map T.unpack bss))
364+
where
365+
doubleIndent = dropWhileEnd isSpace . unlines . fmap (\line -> " " ++ line)
366+
dropQuotes = filter ('\"' /=)
367+
341368
instance Exception StackBuildException
342369

343370
----------------------------------------------

0 commit comments

Comments
 (0)