Skip to content
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

[WIP] Implement External Custom Setup #4055

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions Cabal/Distribution/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module Distribution.Package (

-- * Package source dependencies
Dependency(..),
ExeDependency(..),
thisPackageVersion,
notThisPackageVersion,
simplifyDependency,
Expand Down Expand Up @@ -291,7 +292,16 @@ mkLegacyUnitId = newSimpleUnitId . mkComponentId . display
data Dependency = Dependency PackageName VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)

-- | Describes a dependency on an executable from a package
--
data ExeDependency = ExeDependency
PackageName
String -- ^ name of executable component of package
VersionRange
deriving (Generic, Read, Show, Eq, Typeable, Data)

instance Binary Dependency
instance Binary ExeDependency

instance Text Dependency where
disp (Dependency name ver) =
Expand All @@ -303,7 +313,20 @@ instance Text Dependency where
Parse.skipSpaces
return (Dependency name ver)

instance Text ExeDependency where
disp (ExeDependency name exe ver) =
(disp name <<>> Disp.text ":" <<>> Disp.text exe) <+> disp ver

parse = do name <- parse
_ <- Parse.char ':'
exe <- Parse.munch1 isAlphaNum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the executable name format is more flexible than AlphaNum. Safest is to parse as if it were a PackageName.

Parse.skipSpaces
ver <- parse <++ return anyVersion
Parse.skipSpaces
return (ExeDependency name exe ver)

instance NFData Dependency where rnf = genericRnf
instance NFData ExeDependency where rnf = genericRnf

thisPackageVersion :: PackageIdentifier -> Dependency
thisPackageVersion (PackageIdentifier n v) =
Expand Down
11 changes: 11 additions & 0 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ checkSanity pkg =
++ concatMap (checkExecutable pkg) (executables pkg)
++ concatMap (checkTestSuite pkg) (testSuites pkg)
++ concatMap (checkBenchmark pkg) (benchmarks pkg)
++ concatMap (checkSetup pkg) (maybeToList $ setupBuildInfo pkg)

++ catMaybes [

Expand Down Expand Up @@ -404,6 +405,16 @@ checkBenchmark _pkg bm =
BenchmarkExeV10 _ f -> takeExtension f `notElem` [".hs", ".lhs"]
_ -> False

checkSetup :: PackageDescription -> SetupBuildInfo -> [PackageCheck]
checkSetup _pkg sbinfo =
catMaybes [

check (not $ null (setupDepends sbinfo) && null (setupTool sbinfo)) $
PackageBuildImpossible $
"Cannot specify both setup-depends and setup-tool"

]

-- ------------------------------------------------------------
-- * Additional pure checks
-- ------------------------------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions Cabal/Distribution/PackageDescription/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,11 @@ sourceRepoFieldDescrs =
setupBInfoFieldDescrs :: [FieldDescr SetupBuildInfo]
setupBInfoFieldDescrs =
[ commaListFieldWithSep vcat "setup-depends"
disp parse
setupDepends (\xs binfo -> binfo{setupDepends=xs})
disp parse
setupDepends (\xs sbinfo -> sbinfo { setupDepends = xs })
, simpleField "setup-tool"
(maybe mempty disp) (fmap Just parse)
setupTool (\val sbinfo -> sbinfo { setupTool = val })
]

-- ---------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions Cabal/Distribution/PackageDescription/Parsec/FieldDescr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,13 @@ sourceRepoFieldDescrs =
setupBInfoFieldDescrs :: [FieldDescr SetupBuildInfo]
setupBInfoFieldDescrs =
[ commaListFieldWithSep vcat "setup-depends"
disp parsec
setupDepends (\xs binfo -> binfo{setupDepends=xs})
disp parsec
setupDepends (\xs sbinfo -> sbinfo { setupDepends = xs })
, simpleField "setup-tool"
(maybe mempty disp) (Just <$> parsec)
setupTool (\val sbinfo -> sbinfo { setupTool = val })
]


-------------------------------------------------------------------------------
-- Utilities
-------------------------------------------------------------------------------
Expand Down
10 changes: 9 additions & 1 deletion Cabal/Distribution/Parsec/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import Distribution.License (License (..))
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.Package
(Dependency (..), PackageName, mkPackageName)
(Dependency (..), ExeDependency (..), PackageName, mkPackageName)
import Distribution.System
(Arch (..), ClassificationStrictness (..), OS (..),
classifyArch, classifyOS)
Expand Down Expand Up @@ -115,6 +115,14 @@ instance Parsec Dependency where
ver <- parsec <|> pure anyVersion
return (Dependency name ver)

instance Parsec ExeDependency where
parsec = do
name <- lexemeParsec
_ <- P.char ':'
exe <- P.munch1 isAlphaNum
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update here too when you're done.

ver <- parsec <|> pure anyVersion
return (ExeDependency name exe ver)

instance Parsec Version where
parsec = mkVersion <$>
P.sepBy1 P.integral (P.char '.')
Expand Down
14 changes: 11 additions & 3 deletions Cabal/Distribution/Types/SetupBuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Distribution.Package

data SetupBuildInfo = SetupBuildInfo {
setupDepends :: [Dependency],
setupTool :: Maybe ExeDependency,
defaultSetupDepends :: Bool
-- ^ Is this a default 'custom-setup' section added by the cabal-install
-- code (as opposed to user-provided)? This field is only used
Expand All @@ -30,9 +31,16 @@ data SetupBuildInfo = SetupBuildInfo {
instance Binary SetupBuildInfo

instance Monoid SetupBuildInfo where
mempty = SetupBuildInfo [] False
mempty = SetupBuildInfo [] Nothing False
mappend = (<>)

instance Semigroup SetupBuildInfo where
a <> b = SetupBuildInfo (setupDepends a <> setupDepends b)
(defaultSetupDepends a || defaultSetupDepends b)
a <> b = SetupBuildInfo {
setupDepends = combine setupDepends,
setupTool = combineMby setupTool,
defaultSetupDepends = defaultSetupDepends a || defaultSetupDepends b
}
where
combine field = field a `mappend` field b
combineNub field = nub (combine field)
combineMby field = field b `mplus` field a