Skip to content

Cherry-pick #4094 onto 1.24. #4125

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 4 commits into from
Nov 20, 2016
Merged
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
2 changes: 2 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
@@ -80,6 +80,8 @@ extra-source-files:
tests/PackageTests/BuildDeps/TargetSpecificDeps3/MyLibrary.hs
tests/PackageTests/BuildDeps/TargetSpecificDeps3/lemon.hs
tests/PackageTests/BuildDeps/TargetSpecificDeps3/my.cabal
tests/PackageTests/BuildTargetErrors/BuildTargetErrors.cabal
tests/PackageTests/BuildTargetErrors/Main.hs
tests/PackageTests/BuildTestSuiteDetailedV09/Dummy2.hs
tests/PackageTests/BuildableField/BuildableField.cabal
tests/PackageTests/BuildableField/Main.hs
38 changes: 30 additions & 8 deletions Cabal/Distribution/PackageDescription/Configuration.hs
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ resolveWithFlags dom os arch impl constrs trees checkDeps =
-- dependencies to dependency maps.
simplifiedTrees :: [CondTree FlagName DependencyMap PDTagged]
simplifiedTrees = map ( mapTreeConstrs toDepMap -- convert to maps
. addBuildableCondition pdTaggedBuildInfo
. addBuildableConditionPDTagged
. mapTreeConds (fst . simplifyWithSysParams os arch impl))
trees

@@ -278,13 +278,6 @@ resolveWithFlags dom os arch impl constrs trees checkDeps =
env :: FlagAssignment -> FlagName -> Either FlagName Bool
env flags flag = (maybe (Left flag) Right . lookup flag) flags

pdTaggedBuildInfo :: PDTagged -> BuildInfo
pdTaggedBuildInfo (Lib l) = libBuildInfo l
pdTaggedBuildInfo (Exe _ e) = buildInfo e
pdTaggedBuildInfo (Test _ t) = testBuildInfo t
pdTaggedBuildInfo (Bench _ b) = benchmarkBuildInfo b
pdTaggedBuildInfo PDNull = mempty

-- | Transforms a 'CondTree' by putting the input under the "then" branch of a
-- conditional that is True when Buildable is True. If 'addBuildableCondition'
-- can determine that Buildable is always True, it returns the input unchanged.
@@ -298,6 +291,35 @@ addBuildableCondition getInfo t =
Lit False -> CondNode mempty mempty []
c -> CondNode mempty mempty [(c, t, Nothing)]

-- | This is a special version of 'addBuildableCondition' for the 'PDTagged'
-- type.
--
-- It is not simply a specialisation. It is more complicated than it
-- ought to be because of the way the 'PDTagged' monoid instance works. The
-- @mempty = 'PDNull'@ forgets the component type, which has the effect of
-- completely deleting components that are not buildable.
--
-- See <https://github.com/haskell/cabal/pull/4094> for more details.
--
addBuildableConditionPDTagged :: (Eq v, Monoid c) =>
CondTree v c PDTagged
-> CondTree v c PDTagged
addBuildableConditionPDTagged t =
case extractCondition (buildable . getInfo) t of
Lit True -> t
Lit False -> deleteConstraints t
c -> CondNode mempty mempty [(c, t, Just (deleteConstraints t))]
where
deleteConstraints = mapTreeConstrs (const mempty)

getInfo :: PDTagged -> BuildInfo
getInfo (Lib l) = libBuildInfo l
getInfo (Exe _ e) = buildInfo e
getInfo (Test _ test) = testBuildInfo test
getInfo (Bench _ b) = benchmarkBuildInfo b
getInfo PDNull = mempty


-- Note: extracting buildable conditions.
-- --------------------------------------
--
3 changes: 3 additions & 0 deletions Cabal/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
-*-change-log-*-
1.24.1.1 Ryan Thomas <ryan@ryant.org> ??? 2016
* Fixed a bug in the handling of non-buildable components (#4094).

1.24.1.0 Ryan Thomas <ryan@ryant.org> October 2016
* API addition: 'differenceVersionRanges' (#3519).
* Fixed reexported-modules display mangling (#3928).
10 changes: 10 additions & 0 deletions Cabal/tests/PackageTests/BuildTargetErrors/BuildTargetErrors.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: BuildTargetErrors
version: 1.0
build-type: Simple
cabal-version: >= 1.9

library

executable not-buildable-exe
main-is: Main.hs
buildable: False
1 change: 1 addition & 0 deletions Cabal/tests/PackageTests/BuildTargetErrors/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main = return ()
7 changes: 7 additions & 0 deletions Cabal/tests/PackageTests/Tests.hs
Original file line number Diff line number Diff line change
@@ -279,6 +279,13 @@ tests config = do
"tests/PackageTests/GhcPkgGuess/SymlinkGhcVersion/ghc" $
ghc_pkg_guess "ghc"

-- Test error message we report when a non-buildable target is
-- requested to be built
tc "BuildTargetErrors" $ do
cabal "configure" []
assertOutputContains "the component is marked as disabled"
=<< shouldFail (cabal' "build" ["not-buildable-exe"])

where
ghc_pkg_guess bin_name = do
cwd <- packageDir