From 7f5a63d43115f18742e6bdfd5e7476bc9bff5932 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sun, 6 Aug 2017 17:07:56 -0700 Subject: [PATCH] Only plan to build a target if some of its components will built #2862 --- ChangeLog.md | 2 ++ src/Stack/Build/Source.hs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 6b0d6ad795..bf3c94a18e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -51,6 +51,8 @@ Bug fixes: * Fixed an issue where Stack wouldn't detect missing Docker images properly with newer Docker versions. [#3171](https://github.com/commercialhaskell/stack/pull/3171) +* Previously, cabal files with just test-suite could cause build to fail + ([#2862](https://github.com/commercialhaskell/stack/issues/2862)) ## 1.5.1 diff --git a/src/Stack/Build/Source.hs b/src/Stack/Build/Source.hs index 98c3bf4822..fca5ee7094 100644 --- a/src/Stack/Build/Source.hs +++ b/src/Stack/Build/Source.hs @@ -183,12 +183,23 @@ loadLocalPackage boptsCli targets (name, lpv) = do ) Nothing -> mempty + -- See https://github.com/commercialhaskell/stack/issues/2862 + isWanted = case mtarget of + Nothing -> False + -- FIXME: When issue #1406 ("stack 0.1.8 lost ability to + -- build individual executables or library") is resolved, + -- 'packageHasLibrary' is only relevant if the library is + -- part of the target spec. + Just _ -> packageHasLibrary pkg || not (Set.null allComponents) + filterSkippedComponents = Set.filter (not . (`elem` boptsSkipComponents bopts)) (exes, tests, benches) = (filterSkippedComponents exeCandidates, filterSkippedComponents testCandidates, filterSkippedComponents benchCandidates) + allComponents = toComponents exes tests benches + toComponents e t b = Set.unions [ Set.map CExe e , Set.map CTest t @@ -254,8 +265,8 @@ loadLocalPackage boptsCli targets (name, lpv) = do , lpNewBuildCache = newBuildCache , lpCabalFile = lpvCabalFP lpv , lpDir = lpvRoot lpv - , lpWanted = isJust mtarget - , lpComponents = toComponents exes tests benches + , lpWanted = isWanted + , lpComponents = allComponents -- TODO: refactor this so that it's easier to be sure that these -- components are indeed unbuildable. --