Skip to content

Commit 442dcf8

Browse files
committed
Remove 'ExecutableScopeUnknown'.
Solves #5087 Related to #5003 Note: `buildable: ` field has `All` semantics. `scope: ` has `AnyPrivate` semantics. Both might be surprising, but are "logical". https://hackage.haskell.org/package/Cabal-2.0.1.1/docs/src/Distribution.PackageDescription.Parse.html#line-248
1 parent 6750de6 commit 442dcf8

File tree

10 files changed

+27
-42
lines changed

10 files changed

+27
-42
lines changed

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import Distribution.System
5353
import Distribution.Text
5454
import Distribution.Types.ComponentRequestedSpec
5555
import Distribution.Types.CondTree
56-
import Distribution.Types.ExecutableScope
5756
import Distribution.Types.ExeDependency
5857
import Distribution.Types.UnqualComponentName
5958
import Distribution.Utils.Generic (isAscii)
@@ -315,12 +314,6 @@ checkExecutable pkg exe =
315314
PackageBuildImpossible $
316315
"On executable '" ++ display (exeName exe) ++ "' an 'autogen-module' is not "
317316
++ "on 'other-modules'"
318-
319-
, checkSpecVersion pkg [2,0] (exeScope exe /= ExecutableScopeUnknown) $
320-
PackageDistSuspiciousWarn $
321-
"To use the 'scope' field the package needs to specify "
322-
++ "at least 'cabal-version: >= 2.0'."
323-
324317
]
325318
where
326319
moduleDuplicates = dups (exeModules exe)

Cabal/Distribution/PackageDescription/FieldGrammar.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import Distribution.Parsec.Common
5252
import Distribution.Parsec.Newtypes
5353
import Distribution.Parsec.ParseResult
5454
import Distribution.Text (display)
55+
import Distribution.Types.ExecutableScope
5556
import Distribution.Types.ForeignLib
5657
import Distribution.Types.ForeignLibType
5758
import Distribution.Types.UnqualComponentName
@@ -159,7 +160,8 @@ executableFieldGrammar
159160
executableFieldGrammar n = Executable n
160161
-- main-is is optional as conditional blocks don't have it
161162
<$> optionalFieldDefAla "main-is" FilePathNT L.modulePath ""
162-
<*> monoidalField "scope" L.exeScope
163+
<*> optionalFieldDef "scope" L.exeScope ExecutablePublic
164+
^^^ availableSince [2,0] ExecutablePublic
163165
<*> blurFieldGrammar L.buildInfo buildInfoFieldGrammar
164166
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> ParsecFieldGrammar' Executable #-}
165167
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> PrettyFieldGrammar' Executable #-}

Cabal/Distribution/Types/ExecutableScope.hs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,18 @@ import qualified Distribution.Compat.CharParsing as P
1616
import qualified Distribution.Compat.ReadP as Parse
1717
import qualified Text.PrettyPrint as Disp
1818

19-
data ExecutableScope = ExecutableScopeUnknown
20-
| ExecutablePublic
19+
data ExecutableScope = ExecutablePublic
2120
| ExecutablePrivate
2221
deriving (Generic, Show, Read, Eq, Typeable, Data)
2322

2423
instance Pretty ExecutableScope where
2524
pretty ExecutablePublic = Disp.text "public"
2625
pretty ExecutablePrivate = Disp.text "private"
27-
pretty ExecutableScopeUnknown = Disp.text "unknown"
2826

2927
instance Parsec ExecutableScope where
30-
parsec = do
31-
name <- P.munch1 (\c -> isAlphaNum c || c == '-')
32-
return $ case name of
33-
"public" -> ExecutablePublic
34-
"private" -> ExecutablePrivate
35-
_ -> ExecutableScopeUnknown
28+
parsec = P.try pub <|> pri where
29+
pub = ExecutablePublic <$ P.string "public"
30+
pri = ExecutablePrivate <$ P.string "private"
3631

3732
instance Text ExecutableScope where
3833
parse = Parse.choice
@@ -44,12 +39,12 @@ instance Binary ExecutableScope
4439

4540
instance NFData ExecutableScope where rnf = genericRnf
4641

42+
-- | 'Any' like semigroup, where 'ExecutablePrivate' is 'Any True'
43+
instance Semigroup ExecutableScope where
44+
ExecutablePublic <> x = x
45+
x@ExecutablePrivate <> _ = x
46+
47+
-- | 'mempty' = 'ExecutablePublic'
4748
instance Monoid ExecutableScope where
48-
mempty = ExecutableScopeUnknown
49+
mempty = ExecutablePublic
4950
mappend = (<>)
50-
51-
instance Semigroup ExecutableScope where
52-
ExecutableScopeUnknown <> x = x
53-
x <> ExecutableScopeUnknown = x
54-
x <> y | x == y = x
55-
| otherwise = error "Ambiguous executable scope"

Cabal/tests/ParserTests/regressions/issue-5055.expr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ GenericPackageDescription
5959
`mkVersion [5]`))],
6060
virtualModules = []},
6161
exeName = `UnqualComponentName "flag-test-exe"`,
62-
exeScope = ExecutableScopeUnknown,
62+
exeScope = ExecutablePublic,
6363
modulePath = "FirstMain.hs"}}],
6464
condForeignLibs = [],
6565
condLibrary = Nothing,

Cabal/tests/ParserTests/regressions/issue-5055.format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ build-type: Simple
1010

1111
executable flag-test-exe
1212
main-is: FirstMain.hs
13-
scope: unknown
1413
default-language: Haskell2010
1514
build-depends:
1615
base >=4.8 && <5

Cabal/tests/ParserTests/regressions/shake.expr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ GenericPackageDescription
5656
targetBuildDepends = [],
5757
virtualModules = []},
5858
exeName = `UnqualComponentName "shake"`,
59-
exeScope = ExecutableScopeUnknown,
59+
exeScope = ExecutablePublic,
6060
modulePath = ""}}},
6161
CondBranch
6262
{condBranchCondition = `Var (Flag (FlagName "portable"))`,
@@ -118,7 +118,7 @@ GenericPackageDescription
118118
`mkVersion [2,5,1]`)],
119119
virtualModules = []},
120120
exeName = `UnqualComponentName "shake"`,
121-
exeScope = ExecutableScopeUnknown,
121+
exeScope = ExecutablePublic,
122122
modulePath = ""}}}],
123123
condTreeConstraints = [],
124124
condTreeData = Executable
@@ -165,7 +165,7 @@ GenericPackageDescription
165165
targetBuildDepends = [],
166166
virtualModules = []},
167167
exeName = `UnqualComponentName "shake"`,
168-
exeScope = ExecutableScopeUnknown,
168+
exeScope = ExecutablePublic,
169169
modulePath = ""}},
170170
condBranchIfTrue = CondNode
171171
{condTreeComponents = [CondBranch
@@ -222,7 +222,7 @@ GenericPackageDescription
222222
AnyVersion],
223223
virtualModules = []},
224224
exeName = `UnqualComponentName "shake"`,
225-
exeScope = ExecutableScopeUnknown,
225+
exeScope = ExecutablePublic,
226226
modulePath = ""}}}],
227227
condTreeConstraints = [],
228228
condTreeData = Executable
@@ -269,7 +269,7 @@ GenericPackageDescription
269269
targetBuildDepends = [],
270270
virtualModules = []},
271271
exeName = `UnqualComponentName "shake"`,
272-
exeScope = ExecutableScopeUnknown,
272+
exeScope = ExecutablePublic,
273273
modulePath = ""}}},
274274
CondBranch
275275
{condBranchCondition = `CNot (Var (OS Windows))`,
@@ -325,7 +325,7 @@ GenericPackageDescription
325325
AnyVersion],
326326
virtualModules = []},
327327
exeName = `UnqualComponentName "shake"`,
328-
exeScope = ExecutableScopeUnknown,
328+
exeScope = ExecutablePublic,
329329
modulePath = ""}}}],
330330
condTreeConstraints = [Dependency
331331
`PackageName "base"`
@@ -520,7 +520,7 @@ GenericPackageDescription
520520
AnyVersion],
521521
virtualModules = []},
522522
exeName = `UnqualComponentName "shake"`,
523-
exeScope = ExecutableScopeUnknown,
523+
exeScope = ExecutablePublic,
524524
modulePath = "Run.hs"}}],
525525
condForeignLibs = [],
526526
condLibrary = Just

Cabal/tests/ParserTests/regressions/shake.format

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ library
169169

170170
executable shake
171171
main-is: Run.hs
172-
scope: unknown
173172
hs-source-dirs: src
174173
other-modules:
175174
Development.Make.All
@@ -249,27 +248,21 @@ executable shake
249248
primitive -any
250249

251250
if impl(ghc >=7.8)
252-
scope: unknown
253251
ghc-options: -threaded "-with-rtsopts=-I0 -qg -qb"
254252

255253
if flag(portable)
256-
scope: unknown
257254
cpp-options: -DPORTABLE
258255

259256
if impl(ghc <7.6)
260-
scope: unknown
261257
build-depends:
262258
old-time -any
263259
else
264-
scope: unknown
265260

266261
if !os(windows)
267-
scope: unknown
268262
build-depends:
269263
unix >=2.5.1
270264

271265
if !os(windows)
272-
scope: unknown
273266
build-depends:
274267
unix -any
275268

Cabal/tests/ParserTests/regressions/wl-pprint-indef.expr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ GenericPackageDescription
6666
AnyVersion],
6767
virtualModules = []},
6868
exeName = `UnqualComponentName "wl-pprint-string-example"`,
69-
exeScope = ExecutableScopeUnknown,
69+
exeScope = ExecutablePublic,
7070
modulePath = "Main.hs"}}],
7171
condForeignLibs = [],
7272
condLibrary = Just

Cabal/tests/ParserTests/regressions/wl-pprint-indef.format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ library
2929

3030
executable wl-pprint-string-example
3131
main-is: Main.hs
32-
scope: unknown
3332
hs-source-dirs: example-string
3433
other-modules:
3534
StringImpl

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ doctest :
3333
gen-extra-source-files:
3434
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- Cabal/Cabal.cabal
3535
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- cabal-install/cabal-install.cabal
36+
37+
cabal-install-test:
38+
cabal new-build cabal cabal-tests
39+
cd cabal-testsuite && `cabal-plan list-bin cabal-tests` --with-cabal=`cabal-plan list-bin cabal` --hide-successes -j3

0 commit comments

Comments
 (0)