Skip to content

Commit efbee72

Browse files
committed
Remove UnknownBuildType from BuildType
This is a follow-up to haskell#4958 which opened up the opportunity to do this make-illegal-states-unrepresentable refactoring as well.
1 parent 0122cf2 commit efbee72

File tree

5 files changed

+17
-40
lines changed

5 files changed

+17
-40
lines changed

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,6 @@ checkFields pkg =
453453
"No 'build-type' specified. If you do not need a custom Setup.hs or "
454454
++ "./configure script then use 'build-type: Simple'."
455455

456-
, case buildType pkg of
457-
UnknownBuildType unknown -> Just $
458-
PackageBuildWarning $
459-
quote unknown ++ " is not a known 'build-type'. "
460-
++ "The known build types are: "
461-
++ commaSep (map display knownBuildTypes)
462-
_ -> Nothing
463-
464456
, check (isJust (setupBuildInfo pkg) && buildType pkg /= Custom) $
465457
PackageBuildWarning $
466458
"Ignoring the 'custom-setup' section because the 'build-type' is "

Cabal/Distribution/Types/BuildType.hs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ data BuildType
2525
-- information used by later phases.
2626
| Make -- ^ calls @Distribution.Make.defaultMain@
2727
| Custom -- ^ uses user-supplied @Setup.hs@ or @Setup.lhs@ (default)
28-
| UnknownBuildType String
29-
-- ^ a package that uses an unknown build type cannot actually
30-
-- be built. Doing it this way rather than just giving a
31-
-- parse error means we get better error messages and allows
32-
-- you to inspect the rest of the package description.
3328
deriving (Generic, Show, Read, Eq, Typeable, Data)
3429

3530
instance Binary BuildType
@@ -38,25 +33,24 @@ knownBuildTypes :: [BuildType]
3833
knownBuildTypes = [Simple, Configure, Make, Custom]
3934

4035
instance Pretty BuildType where
41-
pretty (UnknownBuildType other) = Disp.text other
42-
pretty other = Disp.text (show other)
36+
pretty = Disp.text . show
4337

4438
instance Parsec BuildType where
4539
parsec = do
4640
name <- P.munch1 isAlphaNum
47-
return $ case name of
48-
"Simple" -> Simple
49-
"Configure" -> Configure
50-
"Custom" -> Custom
51-
"Make" -> Make
52-
_ -> UnknownBuildType name
41+
case name of
42+
"Simple" -> return Simple
43+
"Configure" -> return Configure
44+
"Custom" -> return Custom
45+
"Make" -> return Make
46+
_ -> fail ("unknown build-type: '" ++ name ++ "'")
5347

5448
instance Text BuildType where
5549
parse = do
5650
name <- Parse.munch1 isAlphaNum
57-
return $ case name of
58-
"Simple" -> Simple
59-
"Configure" -> Configure
60-
"Custom" -> Custom
61-
"Make" -> Make
62-
_ -> UnknownBuildType name
51+
case name of
52+
"Simple" -> return Simple
53+
"Configure" -> return Configure
54+
"Custom" -> return Custom
55+
"Make" -> return Make
56+
_ -> fail ("unknown build-type: '" ++ name ++ "'")

Cabal/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Use better defaulting for `build-type`; rename `PackageDescription`'s
1717
`buildType` field to `buildTypeRaw` and introduce new `buildType`
1818
function (#4958)
19+
* Removed `UnknownBuildType` constructor from `BuildType` (#5003).
1920
* Added `HexFloatLiterals` to `KnownExtension`.
2021
* Cabal will no longer try to build an empty set of `inputModules`
2122
(#4890).

cabal-install/Distribution/Client/SetupWrapper.hs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Distribution.Types.Dependency
3939
import Distribution.PackageDescription
4040
( GenericPackageDescription(packageDescription)
4141
, PackageDescription(..), specVersion, buildType
42-
, BuildType(..), knownBuildTypes, defaultRenaming )
42+
, BuildType(..), defaultRenaming )
4343
import Distribution.PackageDescription.Parsec
4444
( readGenericPackageDescription )
4545
import Distribution.Simple.Configure
@@ -294,7 +294,6 @@ getSetup verbosity options mpkg = do
294294
(orLaterVersion (specVersion pkg))
295295
}
296296
buildType' = buildType pkg
297-
checkBuildType buildType'
298297
(version, method, options'') <-
299298
getSetupMethod verbosity options' pkg buildType'
300299
return Setup { setupMethod = method
@@ -308,12 +307,6 @@ getSetup verbosity options mpkg = do
308307
>>= readGenericPackageDescription verbosity
309308
>>= return . packageDescription
310309

311-
checkBuildType (UnknownBuildType name) =
312-
die' verbosity $ "The build-type '" ++ name ++ "' is not known. Use one of: "
313-
++ intercalate ", " (map display knownBuildTypes) ++ "."
314-
checkBuildType _ = return ()
315-
316-
317310
-- | Decide if we're going to be able to do a direct internal call to the
318311
-- entry point in the Cabal library or if we're going to have to compile
319312
-- and execute an external Setup.hs script.
@@ -429,7 +422,6 @@ buildTypeAction Configure = Simple.defaultMainWithHooksArgs
429422
Simple.autoconfUserHooks
430423
buildTypeAction Make = Make.defaultMainArgs
431424
buildTypeAction Custom = error "buildTypeAction Custom"
432-
buildTypeAction (UnknownBuildType _) = error "buildTypeAction UnknownBuildType"
433425

434426

435427
-- | @runProcess'@ is a version of @runProcess@ where we have
@@ -699,8 +691,7 @@ getExternalSetupMethod verbosity options pkg bt = do
699691
then "autoconfUserHooks\n"
700692
else "defaultUserHooks\n"
701693
Make -> "import Distribution.Make; main = defaultMain\n"
702-
Custom -> error "buildTypeScript Custom"
703-
UnknownBuildType _ -> error "buildTypeScript UnknownBuildType"
694+
Custom -> error "buildTypeScript Custom"
704695

705696
installedCabalVersion :: SetupScriptOptions -> Compiler -> ProgramDb
706697
-> IO (Version, Maybe InstalledPackageId

cabal-install/main/Main.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,7 @@ actAsSetupAction actAsSetupFlags args _globalFlags =
12141214
Configure -> Simple.defaultMainWithHooksArgs
12151215
Simple.autoconfUserHooks args
12161216
Make -> Make.defaultMainArgs args
1217-
Custom -> error "actAsSetupAction Custom"
1218-
(UnknownBuildType _) -> error "actAsSetupAction UnknownBuildType"
1217+
Custom -> error "actAsSetupAction Custom"
12191218

12201219
manpageAction :: [CommandSpec action] -> Flag Verbosity -> [String] -> Action
12211220
manpageAction commands flagVerbosity extraArgs _ = do

0 commit comments

Comments
 (0)