Skip to content

Commit 908b042

Browse files
committed
Ignore disabled executables #763
1 parent 385332d commit 908b042

File tree

4 files changed

+53
-54
lines changed

4 files changed

+53
-54
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.1.3.1
2+
3+
Bug fixes:
4+
5+
* Ignore disabled executables [#763](https://github.com/commercialhaskell/stack/issues/763)
6+
17
## 0.1.3.0
28

39
Major changes:

src/Stack/Build/Source.hs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Data.List
3737
import qualified Data.Map as Map
3838
import Data.Map.Strict (Map)
3939
import Data.Maybe
40-
import Data.Monoid ((<>), Any (..), mconcat)
40+
import Data.Monoid ((<>), Any (..), mconcat, mempty)
4141
import Data.Set (Set)
4242
import qualified Data.Set as Set
4343
import Data.Text (Text)
@@ -88,8 +88,6 @@ loadSourceMap bopts = do
8888
(cliExtraDeps, targets) <-
8989
parseTargets
9090
(bcImplicitGlobal bconfig)
91-
(boptsTests bopts)
92-
(boptsBenchmarks bopts)
9391
(mpiVersion <$> mbpPackages mbp0)
9492
(bcExtraDeps bconfig)
9593
(fst <$> rawLocals)
@@ -119,7 +117,8 @@ loadSourceMap bopts = do
119117
nonLocalTargets =
120118
Map.keysSet $ Map.filter (not . isLocal) targets
121119
where
122-
isLocal (STLocal _) = True
120+
isLocal (STLocalComps _) = True
121+
isLocal STLocalAll = True
123122
isLocal STUnknown = False
124123
isLocal STNonLocal = False
125124

@@ -203,26 +202,36 @@ loadLocalPackage bopts targets (name, (lpv, gpkg)) = do
203202
bconfig <- asks getBuildConfig
204203
econfig <- asks getEnvConfig
205204

206-
let mtarget = Map.lookup name targets
207-
components =
208-
case mtarget of
209-
Just (STLocal comps) -> comps
210-
Just STNonLocal -> assert False Set.empty
211-
Just STUnknown -> assert False Set.empty
212-
Nothing -> Set.empty
213-
(exes, tests, benches) = splitComponents $ Set.toList components
214-
config = PackageConfig
205+
let config = PackageConfig
215206
{ packageConfigEnableTests = False
216207
, packageConfigEnableBenchmarks = False
217208
, packageConfigFlags = localFlags (boptsFlags bopts) bconfig name
218209
, packageConfigGhcVersion = envConfigGhcVersion econfig
219210
, packageConfigPlatform = configPlatform $ getConfig bconfig
220211
}
212+
pkg = resolvePackage config gpkg
213+
214+
mtarget = Map.lookup name targets
215+
(exes, tests, benches) =
216+
case mtarget of
217+
Just (STLocalComps comps) -> splitComponents $ Set.toList comps
218+
Just STLocalAll ->
219+
( packageExes pkg
220+
, if boptsTests bopts
221+
then packageTests pkg
222+
else Set.empty
223+
, if boptsBenchmarks bopts
224+
then packageBenchmarks pkg
225+
else Set.empty
226+
)
227+
Just STNonLocal -> assert False mempty
228+
Just STUnknown -> assert False mempty
229+
Nothing -> mempty
230+
221231
btconfig = config
222232
{ packageConfigEnableTests = not $ Set.null tests
223233
, packageConfigEnableBenchmarks = not $ Set.null benches
224234
}
225-
pkg = resolvePackage config gpkg
226235
btpkg
227236
| Set.null tests && Set.null benches = Nothing
228237
| otherwise = Just $ LocalPackageTB
@@ -248,7 +257,11 @@ loadLocalPackage bopts targets (name, (lpv, gpkg)) = do
248257
, lpNewBuildCache = newBuildCache
249258
, lpCabalFile = lpvCabalFP lpv
250259
, lpDir = lpvRoot lpv
251-
, lpComponents = components
260+
, lpComponents = Set.unions
261+
[ Set.map CExe exes
262+
, Set.map CTest tests
263+
, Set.map CBench benches
264+
]
252265
}
253266

254267
-- | Ensure that the flags specified in the stack.yaml file and on the command

src/Stack/Build/Target.hs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,11 @@ parseRawTargetDirs root locals t =
129129
then Just name
130130
else Nothing
131131

132-
data TargetType
133-
= TTUnknown
134-
| TTNonLocal
135-
| TTLocalComp !NamedComponent
136-
| TTLocalAllComps !(Set NamedComponent)
137-
138132
data SimpleTarget
139133
= STUnknown
140134
| STNonLocal
141-
| STLocal !(Set NamedComponent)
135+
| STLocalComps !(Set NamedComponent)
136+
| STLocalAll
142137
deriving (Show, Eq, Ord)
143138

144139
resolveIdents :: Map PackageName Version -- ^ snapshot
@@ -180,7 +175,7 @@ resolveRawTarget :: Map PackageName Version -- ^ snapshot
180175
-> Map PackageName Version -- ^ extra deps
181176
-> Map PackageName LocalPackageView
182177
-> (RawInput, RawTarget NoIdents)
183-
-> Either Text (PackageName, (RawInput, TargetType))
178+
-> Either Text (PackageName, (RawInput, SimpleTarget))
184179
resolveRawTarget snap extras locals (ri, rt) =
185180
go rt
186181
where
@@ -191,7 +186,7 @@ resolveRawTarget snap extras locals (ri, rt) =
191186
case ucomp of
192187
ResolvedComponent comp
193188
| comp `Set.member` lpvComponents lpv ->
194-
Right (name, (ri, TTLocalComp comp))
189+
Right (name, (ri, STLocalComps $ Set.singleton comp))
195190
| otherwise -> Left $ T.pack $ concat
196191
[ "Component "
197192
, show comp
@@ -206,7 +201,7 @@ resolveRawTarget snap extras locals (ri, rt) =
206201
, " does not exist in package "
207202
, T.pack $ packageNameString name
208203
]
209-
[x] -> Right (name, (ri, TTLocalComp x))
204+
[x] -> Right (name, (ri, STLocalComps $ Set.singleton x))
210205
matches -> Left $ T.concat
211206
[ "Ambiguous component name "
212207
, comp
@@ -222,7 +217,7 @@ resolveRawTarget snap extras locals (ri, rt) =
222217
in case filter (isCompNamed cname . snd) allPairs of
223218
[] -> Left $ "Could not find a component named " `T.append` cname
224219
[(name, comp)] ->
225-
Right (name, (ri, TTLocalComp comp))
220+
Right (name, (ri, STLocalComps $ Set.singleton comp))
226221
matches -> Left $ T.concat
227222
[ "Ambiugous component name "
228223
, cname
@@ -232,41 +227,33 @@ resolveRawTarget snap extras locals (ri, rt) =
232227

233228
go (RTPackage name) =
234229
case Map.lookup name locals of
235-
Just lpv -> Right (name, (ri, TTLocalAllComps $ lpvComponents lpv))
230+
Just _lpv -> Right (name, (ri, STLocalAll))
236231
Nothing ->
237232
case Map.lookup name extras of
238-
Just _ -> Right (name, (ri, TTNonLocal))
233+
Just _ -> Right (name, (ri, STNonLocal))
239234
Nothing ->
240235
case Map.lookup name snap of
241-
Just _ -> Right (name, (ri, TTNonLocal))
242-
Nothing -> Right (name, (ri, TTUnknown))
236+
Just _ -> Right (name, (ri, STNonLocal))
237+
Nothing -> Right (name, (ri, STUnknown))
243238

244239
isCompNamed :: Text -> NamedComponent -> Bool
245240
isCompNamed _ CLib = False
246241
isCompNamed t1 (CExe t2) = t1 == t2
247242
isCompNamed t1 (CTest t2) = t1 == t2
248243
isCompNamed t1 (CBench t2) = t1 == t2
249244

250-
simplifyTargets :: Bool -- ^ include tests
251-
-> Bool -- ^ include benchmarks
252-
-> [(PackageName, (RawInput, TargetType))]
245+
simplifyTargets :: [(PackageName, (RawInput, SimpleTarget))]
253246
-> ([Text], Map PackageName SimpleTarget)
254-
simplifyTargets includeTests includeBenches =
247+
simplifyTargets =
255248
mconcat . map go . Map.toList . Map.fromListWith (++) . fmap (second return)
256249
where
257-
go :: (PackageName, [(RawInput, TargetType)])
250+
go :: (PackageName, [(RawInput, SimpleTarget)])
258251
-> ([Text], Map PackageName SimpleTarget)
259252
go (_, []) = error "Stack.Build.Target.simplifyTargets: the impossible happened"
260-
go (name, [(_, tt)]) = ([], Map.singleton name $
261-
case tt of
262-
TTUnknown -> STUnknown
263-
TTNonLocal -> STNonLocal
264-
TTLocalComp comp -> STLocal $ Set.singleton comp
265-
TTLocalAllComps comps -> STLocal $ Set.filter keepComp comps
266-
)
253+
go (name, [(_, st)]) = ([], Map.singleton name st)
267254
go (name, pairs) =
268255
case partitionEithers $ map (getLocalComp . snd) pairs of
269-
([], comps) -> ([], Map.singleton name $ STLocal $ Set.fromList comps)
256+
([], comps) -> ([], Map.singleton name $ STLocalComps $ Set.unions comps)
270257
_ ->
271258
let err = T.pack $ concat
272259
[ "Overlapping targets provided for package "
@@ -276,25 +263,18 @@ simplifyTargets includeTests includeBenches =
276263
]
277264
in ([err], Map.empty)
278265

279-
keepComp CLib = True
280-
keepComp (CExe _) = True
281-
keepComp (CTest _) = includeTests
282-
keepComp (CBench _) = includeBenches
283-
284-
getLocalComp (TTLocalComp comp) = Right comp
266+
getLocalComp (STLocalComps comps) = Right comps
285267
getLocalComp _ = Left ()
286268

287269
parseTargets :: (MonadThrow m, MonadIO m)
288270
=> Bool -- ^ using implicit global?
289-
-> Bool -- ^ include tests
290-
-> Bool -- ^ include benchmarks
291271
-> Map PackageName Version -- ^ snapshot
292272
-> Map PackageName Version -- ^ extra deps
293273
-> Map PackageName LocalPackageView
294274
-> Path Abs Dir -- ^ current directory
295275
-> [Text] -- ^ command line targets
296276
-> m (Map PackageName Version, Map PackageName SimpleTarget)
297-
parseTargets implicitGlobal includeTests includeBenches snap extras locals currDir textTargets' = do
277+
parseTargets implicitGlobal snap extras locals currDir textTargets' = do
298278
let textTargets =
299279
if null textTargets'
300280
then map (T.pack . packageNameString) $ Map.keys $ Map.filter (not . lpvExtraDep) locals
@@ -306,7 +286,7 @@ parseTargets implicitGlobal includeTests includeBenches snap extras locals currD
306286
map (resolveIdents snap extras locals) $ concat rawTargets
307287
(errs3, targetTypes) = partitionEithers $
308288
map (resolveRawTarget snap extras locals) rawTargets'
309-
(errs4, targets) = simplifyTargets includeTests includeBenches targetTypes
289+
(errs4, targets) = simplifyTargets targetTypes
310290
errs = concat [errs1, errs2, errs3, errs4]
311291

312292
if null errs

stack.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: stack
2-
version: 0.1.3.0
2+
version: 0.1.3.1
33
synopsis: The Haskell Tool Stack
44
description: Please see the README.md for usage information, and
55
the wiki on Github for more details. Also, note that

0 commit comments

Comments
 (0)