Skip to content

Commit 0e8f2cd

Browse files
Subsequent Cabal Exceptions (#9143)
* Subsequent Cabal Exceptions * Accepting new ouput with error codes * Changed to "VersionMismatch" * Accepting new test outputs with error codes * "UnrecognisedBuildTarget" processing moved to error handler * Changes in type definition for constructors "ReportBuildTargetProblems", "UnknownBuildTarget", "AmbiguousBuildTarget" --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 9fe1ac8 commit 0e8f2cd

File tree

21 files changed

+232
-153
lines changed

21 files changed

+232
-153
lines changed

Cabal/src/Distribution/Simple/BuildTarget.hs

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ import Distribution.Types.LocalBuildInfo
4747
import Distribution.Types.TargetInfo
4848
import Distribution.Types.UnqualComponentName
4949

50+
import qualified Distribution.Compat.CharParsing as P
5051
import Distribution.ModuleName
5152
import Distribution.Package
5253
import Distribution.PackageDescription
5354
import Distribution.Parsec
5455
import Distribution.Pretty
56+
import Distribution.Simple.Errors
5557
import Distribution.Simple.LocalBuildInfo
5658
import Distribution.Simple.Utils
5759
import Distribution.Utils.Path
5860
import Distribution.Verbosity
5961

60-
import qualified Distribution.Compat.CharParsing as P
61-
6262
import Control.Arrow ((&&&))
6363
import Control.Monad (msum)
6464
import Data.List (groupBy, stripPrefix)
@@ -246,19 +246,8 @@ reportUserBuildTargetProblems verbosity problems = do
246246
case [target | UserBuildTargetUnrecognised target <- problems] of
247247
[] -> return ()
248248
target ->
249-
die' verbosity $
250-
unlines
251-
[ "Unrecognised build target '" ++ name ++ "'."
252-
| name <- target
253-
]
254-
++ "Examples:\n"
255-
++ " - build foo -- component name "
256-
++ "(library, executable, test-suite or benchmark)\n"
257-
++ " - build Data.Foo -- module name\n"
258-
++ " - build Data/Foo.hsc -- file name\n"
259-
++ " - build lib:foo exe:foo -- component qualified by kind\n"
260-
++ " - build foo:Data.Foo -- module qualified by component\n"
261-
++ " - build foo:Data/Foo.hsc -- file qualified by component"
249+
dieWithException verbosity $
250+
UnrecognisedBuildTarget target
262251

263252
showUserBuildTarget :: UserBuildTarget -> String
264253
showUserBuildTarget = intercalate ":" . getComponents
@@ -407,57 +396,29 @@ reportBuildTargetProblems verbosity problems = do
407396
case [(t, e, g) | BuildTargetExpected t e g <- problems] of
408397
[] -> return ()
409398
targets ->
410-
die' verbosity $
411-
unlines
412-
[ "Unrecognised build target '"
413-
++ showUserBuildTarget target
414-
++ "'.\n"
415-
++ "Expected a "
416-
++ intercalate " or " expected
417-
++ ", rather than '"
418-
++ got
419-
++ "'."
420-
| (target, expected, got) <- targets
421-
]
399+
dieWithException verbosity $
400+
ReportBuildTargetProblems $
401+
map (\(target, expected, got) -> (showUserBuildTarget target, expected, got)) targets
422402

423403
case [(t, e) | BuildTargetNoSuch t e <- problems] of
424404
[] -> return ()
425405
targets ->
426-
die' verbosity $
427-
unlines
428-
[ "Unknown build target '"
429-
++ showUserBuildTarget target
430-
++ "'.\nThere is no "
431-
++ intercalate
432-
" or "
433-
[ mungeThing thing ++ " '" ++ got ++ "'"
434-
| (thing, got) <- nosuch
435-
]
436-
++ "."
437-
| (target, nosuch) <- targets
438-
]
439-
where
440-
mungeThing "file" = "file target"
441-
mungeThing thing = thing
406+
dieWithException verbosity $
407+
UnknownBuildTarget $
408+
map (\(target, nosuch) -> (showUserBuildTarget target, nosuch)) targets
442409

443410
case [(t, ts) | BuildTargetAmbiguous t ts <- problems] of
444411
[] -> return ()
445412
targets ->
446-
die' verbosity $
447-
unlines
448-
[ "Ambiguous build target '"
449-
++ showUserBuildTarget target
450-
++ "'. It could be:\n "
451-
++ unlines
452-
[ " "
453-
++ showUserBuildTarget ut
454-
++ " ("
455-
++ showBuildTargetKind bt
456-
++ ")"
457-
| (ut, bt) <- amb
458-
]
459-
| (target, amb) <- targets
460-
]
413+
dieWithException verbosity $
414+
AmbiguousBuildTarget $
415+
map
416+
( \(target, amb) ->
417+
( showUserBuildTarget target
418+
, (map (\(ut, bt) -> (showUserBuildTarget ut, showBuildTargetKind bt)) amb)
419+
)
420+
)
421+
targets
461422
where
462423
showBuildTargetKind (BuildTargetComponent _) = "component"
463424
showBuildTargetKind (BuildTargetModule _ _) = "module"
@@ -1093,7 +1054,7 @@ checkBuildTargets verbosity pkg_descr lbi targets = do
10931054

10941055
case disabled of
10951056
[] -> return ()
1096-
((cname, reason) : _) -> die' verbosity $ formatReason (showComponentName cname) reason
1057+
((cname, reason) : _) -> dieWithException verbosity $ CheckBuildTargets $ formatReason (showComponentName cname) reason
10971058

10981059
for_ [(c, t) | (c, Just t) <- enabled] $ \(c, t) ->
10991060
warn verbosity $

Cabal/src/Distribution/Simple/ConfigureScript.hs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import Prelude ()
2222

2323
-- local
2424
import Distribution.PackageDescription
25+
import Distribution.Pretty
26+
import Distribution.Simple.Errors
27+
import Distribution.Simple.LocalBuildInfo
2528
import Distribution.Simple.Program
2629
import Distribution.Simple.Program.Db
2730
import Distribution.Simple.Setup.Common
2831
import Distribution.Simple.Setup.Config
29-
30-
import Distribution.Pretty
31-
import Distribution.Simple.LocalBuildInfo
3232
import Distribution.Simple.Utils
3333
import Distribution.System (buildPlatform)
3434
import Distribution.Utils.NubList
@@ -182,18 +182,11 @@ runConfigureScript verbosity flags lbi = do
182182
(programInvocation (sh{programOverrideEnv = overEnv}) args')
183183
{ progInvokeCwd = Just (buildDir lbi)
184184
}
185-
Nothing -> die' verbosity notFoundMsg
185+
Nothing -> dieWithException verbosity NotFoundMsg
186186
where
187187
args = configureArgs backwardsCompatHack flags
188188
backwardsCompatHack = False
189189

190-
notFoundMsg =
191-
"The package has a './configure' script. "
192-
++ "If you are on Windows, This requires a "
193-
++ "Unix compatibility toolchain such as MinGW+MSYS or Cygwin. "
194-
++ "If you are not on Windows, ensure that an 'sh' command "
195-
++ "is discoverable in your path."
196-
197190
-- | Convert Windows path to Unix ones
198191
toUnix :: String -> String
199192
#ifdef mingw32_HOST_OS

Cabal/src/Distribution/Simple/Errors.hs

Lines changed: 146 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,31 @@ data CabalException
7070
| PkgDumpFailed
7171
| FailedToParseOutput
7272
| CantFindSourceModule ModuleName
73-
| VersionMisMatch FilePath Version FilePath Version
74-
| VersionMisMatchGHC FilePath Version FilePath Version
73+
| VersionMismatchJS FilePath Version FilePath Version
74+
| VersionMismatchGHCJS FilePath Version FilePath Version
7575
| GlobalPackageDBLimitation
7676
| GlobalPackageDBSpecifiedFirst
7777
| MatchDirFileGlob String
7878
| MatchDirFileGlobErrors [String]
79+
| ErrorParsingFileDoesntExist FilePath
80+
| FailedParsing String
81+
| NotFoundMsg
82+
| UnrecognisedBuildTarget [String]
83+
| ReportBuildTargetProblems [(String, [String], String)]
84+
| UnknownBuildTarget [(String, [(String, String)])]
85+
| AmbiguousBuildTarget [(String, [(String, String)])]
86+
| CheckBuildTargets String
87+
| VersionMismatchGHC FilePath Version FilePath Version
88+
| CheckPackageDbStackPost76
89+
| CheckPackageDbStackPre76
90+
| GlobalPackageDbSpecifiedFirst
91+
| CantInstallForeignLib
92+
| NoSupportForPreProcessingTest TestType
93+
| NoSupportForPreProcessingBenchmark BenchmarkType
94+
| CantFindSourceForPreProcessFile String
95+
| NoSupportPreProcessingTestExtras TestType
96+
| NoSupportPreProcessingBenchmarkExtras BenchmarkType
97+
| UnlitException String
7998
deriving (Show, Typeable)
8099

81100
exceptionCode :: CabalException -> Int
@@ -120,12 +139,31 @@ exceptionCode e = case e of
120139
PkgDumpFailed{} -> 2290
121140
FailedToParseOutput{} -> 5500
122141
CantFindSourceModule{} -> 8870
123-
VersionMisMatch{} -> 9001
124-
VersionMisMatchGHC{} -> 4001
142+
VersionMismatchJS{} -> 9001
143+
VersionMismatchGHCJS{} -> 4001
125144
GlobalPackageDBLimitation{} -> 5002
126145
GlobalPackageDBSpecifiedFirst{} -> 3901
127146
MatchDirFileGlob{} -> 9760
128147
MatchDirFileGlobErrors{} -> 6661
148+
ErrorParsingFileDoesntExist{} -> 1234
149+
FailedParsing{} -> 6565
150+
NotFoundMsg{} -> 8011
151+
UnrecognisedBuildTarget{} -> 3410
152+
ReportBuildTargetProblems{} -> 5504
153+
UnknownBuildTarget{} -> 4444
154+
AmbiguousBuildTarget{} -> 7865
155+
CheckBuildTargets{} -> 4733
156+
VersionMismatchGHC{} -> 4000
157+
CheckPackageDbStackPost76{} -> 3000
158+
CheckPackageDbStackPre76{} -> 5640
159+
GlobalPackageDbSpecifiedFirst{} -> 2345
160+
CantInstallForeignLib{} -> 8221
161+
NoSupportForPreProcessingTest{} -> 3008
162+
NoSupportForPreProcessingBenchmark{} -> 6990
163+
CantFindSourceForPreProcessFile{} -> 7554
164+
NoSupportPreProcessingTestExtras{} -> 7886
165+
NoSupportPreProcessingBenchmarkExtras{} -> 9999
166+
UnlitException{} -> 5454
129167

130168
exceptionMessage :: CabalException -> String
131169
exceptionMessage e = case e of
@@ -186,7 +224,7 @@ exceptionMessage e = case e of
186224
PkgDumpFailed -> "pkg dump failed"
187225
FailedToParseOutput -> "failed to parse output of 'pkg dump'"
188226
CantFindSourceModule moduleName -> "can't find source for module " ++ prettyShow moduleName
189-
VersionMisMatch ghcjsProgPath ghcjsVersion ghcjsPkgProgPath ghcjsPkgGhcjsVersion ->
227+
VersionMismatchJS ghcjsProgPath ghcjsVersion ghcjsPkgProgPath ghcjsPkgGhcjsVersion ->
190228
"Version mismatch between ghcjs and ghcjs-pkg: "
191229
++ show ghcjsProgPath
192230
++ " is version "
@@ -195,7 +233,7 @@ exceptionMessage e = case e of
195233
++ show ghcjsPkgProgPath
196234
++ " is version "
197235
++ prettyShow ghcjsPkgGhcjsVersion
198-
VersionMisMatchGHC ghcjsProgPath ghcjsGhcVersion ghcjsPkgProgPath ghcjsPkgVersion ->
236+
VersionMismatchGHCJS ghcjsProgPath ghcjsGhcVersion ghcjsPkgProgPath ghcjsPkgVersion ->
199237
"Version mismatch between ghcjs and ghcjs-pkg: "
200238
++ show ghcjsProgPath
201239
++ " was built with GHC version "
@@ -213,3 +251,105 @@ exceptionMessage e = case e of
213251
++ "specified first and cannot be specified multiple times"
214252
MatchDirFileGlob pathError -> pathError
215253
MatchDirFileGlobErrors errors -> unlines errors
254+
ErrorParsingFileDoesntExist filePath -> "Error Parsing: file \"" ++ filePath ++ "\" doesn't exist. Cannot continue."
255+
FailedParsing name -> "Failed parsing \"" ++ name ++ "\"."
256+
NotFoundMsg ->
257+
"The package has a './configure' script. "
258+
++ "If you are on Windows, This requires a "
259+
++ "Unix compatibility toolchain such as MinGW+MSYS or Cygwin. "
260+
++ "If you are not on Windows, ensure that an 'sh' command "
261+
++ "is discoverable in your path."
262+
UnrecognisedBuildTarget target ->
263+
unlines
264+
[ "Unrecognised build target '" ++ name ++ "'."
265+
| name <- target
266+
]
267+
++ "Examples:\n"
268+
++ " - build foo -- component name "
269+
++ "(library, executable, test-suite or benchmark)\n"
270+
++ " - build Data.Foo -- module name\n"
271+
++ " - build Data/Foo.hsc -- file name\n"
272+
++ " - build lib:foo exe:foo -- component qualified by kind\n"
273+
++ " - build foo:Data.Foo -- module qualified by component\n"
274+
++ " - build foo:Data/Foo.hsc -- file qualified by component"
275+
ReportBuildTargetProblems targets ->
276+
unlines
277+
[ "Unrecognised build target '"
278+
++ target
279+
++ "'.\n"
280+
++ "Expected a "
281+
++ intercalate " or " expected
282+
++ ", rather than '"
283+
++ got
284+
++ "'."
285+
| (target, expected, got) <- targets
286+
]
287+
UnknownBuildTarget targets ->
288+
unlines
289+
[ "Unknown build target '"
290+
++ target
291+
++ "'.\nThere is no "
292+
++ intercalate
293+
" or "
294+
[ mungeThing thing ++ " '" ++ got ++ "'"
295+
| (thing, got) <- nosuch
296+
]
297+
++ "."
298+
| (target, nosuch) <- targets
299+
]
300+
where
301+
mungeThing "file" = "file target"
302+
mungeThing thing = thing
303+
AmbiguousBuildTarget targets ->
304+
unlines
305+
[ "Ambiguous build target '"
306+
++ target
307+
++ "'. It could be:\n "
308+
++ unlines
309+
[ " "
310+
++ ut
311+
++ " ("
312+
++ bt
313+
++ ")"
314+
| (ut, bt) <- amb
315+
]
316+
| (target, amb) <- targets
317+
]
318+
CheckBuildTargets errorStr -> errorStr
319+
VersionMismatchGHC ghcProgPath ghcVersion ghcPkgProgPath ghcPkgVersion ->
320+
"Version mismatch between ghc and ghc-pkg: "
321+
++ ghcProgPath
322+
++ " is version "
323+
++ prettyShow ghcVersion
324+
++ " "
325+
++ ghcPkgProgPath
326+
++ " is version "
327+
++ prettyShow ghcPkgVersion
328+
CheckPackageDbStackPost76 ->
329+
"If the global package db is specified, it must be "
330+
++ "specified first and cannot be specified multiple times"
331+
CheckPackageDbStackPre76 ->
332+
"With current ghc versions the global package db is always used "
333+
++ "and must be listed first. This ghc limitation is lifted in GHC 7.6,"
334+
++ "see https://gitlab.haskell.org/ghc/ghc/-/issues/5977"
335+
GlobalPackageDbSpecifiedFirst ->
336+
"If the global package db is specified, it must be "
337+
++ "specified first and cannot be specified multiple times"
338+
CantInstallForeignLib -> "Can't install foreign-library symlink on non-Linux OS"
339+
NoSupportForPreProcessingTest tt ->
340+
"No support for preprocessing test "
341+
++ "suite type "
342+
++ prettyShow tt
343+
NoSupportForPreProcessingBenchmark tt ->
344+
"No support for preprocessing benchmark "
345+
++ "type "
346+
++ prettyShow tt
347+
CantFindSourceForPreProcessFile errorStr -> errorStr
348+
NoSupportPreProcessingTestExtras tt ->
349+
"No support for preprocessing test suite type "
350+
++ prettyShow tt
351+
NoSupportPreProcessingBenchmarkExtras tt ->
352+
"No support for preprocessing benchmark "
353+
++ "type "
354+
++ prettyShow tt
355+
UnlitException str -> str

0 commit comments

Comments
 (0)