Skip to content

Remove 'ExecutableScopeUnknown'. #5085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import Distribution.System
import Distribution.Text
import Distribution.Types.ComponentRequestedSpec
import Distribution.Types.CondTree
import Distribution.Types.ExecutableScope
import Distribution.Types.ExeDependency
import Distribution.Types.UnqualComponentName
import Distribution.Utils.Generic (isAscii)
Expand Down Expand Up @@ -315,12 +314,6 @@ checkExecutable pkg exe =
PackageBuildImpossible $
"On executable '" ++ display (exeName exe) ++ "' an 'autogen-module' is not "
++ "on 'other-modules'"

, checkSpecVersion pkg [2,0] (exeScope exe /= ExecutableScopeUnknown) $
PackageDistSuspiciousWarn $
"To use the 'scope' field the package needs to specify "
++ "at least 'cabal-version: >= 2.0'."

]
where
moduleDuplicates = dups (exeModules exe)
Expand Down
4 changes: 3 additions & 1 deletion Cabal/Distribution/PackageDescription/FieldGrammar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Distribution.Parsec.Common
import Distribution.Parsec.Newtypes
import Distribution.Parsec.ParseResult
import Distribution.Text (display)
import Distribution.Types.ExecutableScope
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibType
import Distribution.Types.UnqualComponentName
Expand Down Expand Up @@ -159,7 +160,8 @@ executableFieldGrammar
executableFieldGrammar n = Executable n
-- main-is is optional as conditional blocks don't have it
<$> optionalFieldDefAla "main-is" FilePathNT L.modulePath ""
<*> monoidalField "scope" L.exeScope
<*> optionalFieldDef "scope" L.exeScope ExecutablePublic
^^^ availableSince [2,0] ExecutablePublic
<*> blurFieldGrammar L.buildInfo buildInfoFieldGrammar
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> ParsecFieldGrammar' Executable #-}
{-# SPECIALIZE executableFieldGrammar :: UnqualComponentName -> PrettyFieldGrammar' Executable #-}
Expand Down
27 changes: 11 additions & 16 deletions Cabal/Distribution/Types/ExecutableScope.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@ import qualified Distribution.Compat.CharParsing as P
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp

data ExecutableScope = ExecutableScopeUnknown
| ExecutablePublic
data ExecutableScope = ExecutablePublic
| ExecutablePrivate
deriving (Generic, Show, Read, Eq, Typeable, Data)

instance Pretty ExecutableScope where
pretty ExecutablePublic = Disp.text "public"
pretty ExecutablePrivate = Disp.text "private"
pretty ExecutableScopeUnknown = Disp.text "unknown"

instance Parsec ExecutableScope where
parsec = do
name <- P.munch1 (\c -> isAlphaNum c || c == '-')
return $ case name of
"public" -> ExecutablePublic
"private" -> ExecutablePrivate
_ -> ExecutableScopeUnknown
parsec = P.try pub <|> pri where
pub = ExecutablePublic <$ P.string "public"
pri = ExecutablePrivate <$ P.string "private"

instance Text ExecutableScope where
parse = Parse.choice
Expand All @@ -44,12 +39,12 @@ instance Binary ExecutableScope

instance NFData ExecutableScope where rnf = genericRnf

-- | 'Any' like semigroup, where 'ExecutablePrivate' is 'Any True'
instance Semigroup ExecutableScope where
ExecutablePublic <> x = x
x@ExecutablePrivate <> _ = x

-- | 'mempty' = 'ExecutablePublic'
instance Monoid ExecutableScope where
mempty = ExecutableScopeUnknown
mempty = ExecutablePublic
mappend = (<>)

instance Semigroup ExecutableScope where
ExecutableScopeUnknown <> x = x
x <> ExecutableScopeUnknown = x
x <> y | x == y = x
| otherwise = error "Ambiguous executable scope"
2 changes: 1 addition & 1 deletion Cabal/tests/ParserTests/regressions/issue-5055.expr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ GenericPackageDescription
`mkVersion [5]`))],
virtualModules = []},
exeName = `UnqualComponentName "flag-test-exe"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = "FirstMain.hs"}}],
condForeignLibs = [],
condLibrary = Nothing,
Expand Down
1 change: 0 additions & 1 deletion Cabal/tests/ParserTests/regressions/issue-5055.format
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ build-type: Simple

executable flag-test-exe
main-is: FirstMain.hs
scope: unknown
default-language: Haskell2010
build-depends:
base >=4.8 && <5
Expand Down
14 changes: 7 additions & 7 deletions Cabal/tests/ParserTests/regressions/shake.expr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ GenericPackageDescription
targetBuildDepends = [],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = ""}}},
CondBranch
{condBranchCondition = `Var (Flag (FlagName "portable"))`,
Expand Down Expand Up @@ -118,7 +118,7 @@ GenericPackageDescription
`mkVersion [2,5,1]`)],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = ""}}}],
condTreeConstraints = [],
condTreeData = Executable
Expand Down Expand Up @@ -165,7 +165,7 @@ GenericPackageDescription
targetBuildDepends = [],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = ""}},
condBranchIfTrue = CondNode
{condTreeComponents = [CondBranch
Expand Down Expand Up @@ -222,7 +222,7 @@ GenericPackageDescription
AnyVersion],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = ""}}}],
condTreeConstraints = [],
condTreeData = Executable
Expand Down Expand Up @@ -269,7 +269,7 @@ GenericPackageDescription
targetBuildDepends = [],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = ""}}},
CondBranch
{condBranchCondition = `CNot (Var (OS Windows))`,
Expand Down Expand Up @@ -325,7 +325,7 @@ GenericPackageDescription
AnyVersion],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = ""}}}],
condTreeConstraints = [Dependency
`PackageName "base"`
Expand Down Expand Up @@ -520,7 +520,7 @@ GenericPackageDescription
AnyVersion],
virtualModules = []},
exeName = `UnqualComponentName "shake"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = "Run.hs"}}],
condForeignLibs = [],
condLibrary = Just
Expand Down
7 changes: 0 additions & 7 deletions Cabal/tests/ParserTests/regressions/shake.format
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ library

executable shake
main-is: Run.hs
scope: unknown
hs-source-dirs: src
other-modules:
Development.Make.All
Expand Down Expand Up @@ -249,27 +248,21 @@ executable shake
primitive -any

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

if flag(portable)
scope: unknown
cpp-options: -DPORTABLE

if impl(ghc <7.6)
scope: unknown
build-depends:
old-time -any
else
scope: unknown

if !os(windows)
scope: unknown
build-depends:
unix >=2.5.1

if !os(windows)
scope: unknown
build-depends:
unix -any

Expand Down
2 changes: 1 addition & 1 deletion Cabal/tests/ParserTests/regressions/wl-pprint-indef.expr
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GenericPackageDescription
AnyVersion],
virtualModules = []},
exeName = `UnqualComponentName "wl-pprint-string-example"`,
exeScope = ExecutableScopeUnknown,
exeScope = ExecutablePublic,
modulePath = "Main.hs"}}],
condForeignLibs = [],
condLibrary = Just
Expand Down
1 change: 0 additions & 1 deletion Cabal/tests/ParserTests/regressions/wl-pprint-indef.format
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ library

executable wl-pprint-string-example
main-is: Main.hs
scope: unknown
hs-source-dirs: example-string
other-modules:
StringImpl
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ doctest :
gen-extra-source-files:
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- Cabal/Cabal.cabal
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- cabal-install/cabal-install.cabal

cabal-install-test:
cabal new-build cabal cabal-tests
cd cabal-testsuite && `cabal-plan list-bin cabal-tests` --with-cabal=`cabal-plan list-bin cabal` --hide-successes -j3