Skip to content

Commit 67d5b99

Browse files
committed
Use PackageName instead of comparing strings
[#4845]
1 parent 3135462 commit 67d5b99

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/Stack/Dot.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ data DotOpts = DotOpts
5353
-- ^ Include dependencies on base
5454
, dotDependencyDepth :: !(Maybe Int)
5555
-- ^ Limit the depth of dependency resolution to (Just n) or continue until fixpoint
56-
, dotPrune :: !(Set String)
56+
, dotPrune :: !(Set PackageName)
5757
-- ^ Package names to prune from the graph
5858
, dotTargets :: [Text]
5959
-- ^ stack TARGETs to trace dependencies for
@@ -215,14 +215,14 @@ payloadText opts payload =
215215
-- unless they are in @dontPrune@
216216
pruneGraph :: (F.Foldable f, F.Foldable g, Eq a)
217217
=> f PackageName
218-
-> g String
218+
-> g PackageName
219219
-> Map PackageName (Set PackageName, a)
220220
-> Map PackageName (Set PackageName, a)
221221
pruneGraph dontPrune names =
222222
pruneUnreachable dontPrune . Map.mapMaybeWithKey (\pkg (pkgDeps,x) ->
223-
if packageNameString pkg `F.elem` names
223+
if pkg `F.elem` names
224224
then Nothing
225-
else let filtered = Set.filter (\n -> packageNameString n `F.notElem` names) pkgDeps
225+
else let filtered = Set.filter (\n -> n `F.notElem` names) pkgDeps
226226
in if Set.null filtered && not (Set.null pkgDeps)
227227
then Nothing
228228
else Just (filtered,x))
@@ -342,7 +342,7 @@ printGraph dotOpts locals graph = do
342342
void (Map.traverseWithKey printEdges (fst <$> graph))
343343
liftIO $ Text.putStrLn "}"
344344
where filteredLocals = Set.filter (\local' ->
345-
packageNameString local' `Set.notMember` dotPrune dotOpts) locals
345+
local' `Set.notMember` dotPrune dotOpts) locals
346346

347347
-- | Print the local nodes with a different style depending on options
348348
printLocalNodes :: (F.Foldable t, MonadIO m)

src/Stack/Options/DotParser.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Data.Char (isSpace)
77
import Data.List.Split (splitOn)
88
import qualified Data.Set as Set
99
import qualified Data.Text as T
10+
import Distribution.Types.PackageName(PackageName, mkPackageName)
1011
import Options.Applicative
1112
import Options.Applicative.Builder.Extra
1213
import Stack.Dot
@@ -50,8 +51,8 @@ dotOptsParser externalDefault =
5051
benchTargets = switch (long "bench" <>
5152
help "Consider dependencies of benchmark components")
5253

53-
splitNames :: String -> [String]
54-
splitNames = map (takeWhile (not . isSpace) . dropWhile isSpace) . splitOn ","
54+
splitNames :: String -> [PackageName]
55+
splitNames = map (mkPackageName . takeWhile (not . isSpace) . dropWhile isSpace) . splitOn ","
5556

5657
globalHints = switch (long "global-hints" <>
5758
help "Do not require an install GHC; instead, use a hints file for global packages")

src/test/Stack/DotSpec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ spec = do
5353

5454
prop "requested packages are pruned" $ do
5555
let resolvedGraph = runIdentity (resolveDependencies Nothing graph stubLoader)
56-
allPackages g = Set.map packageNameString (Map.keysSet g `Set.union` fold (fmap fst g))
56+
allPackages g = Map.keysSet g `Set.union` fold (fmap fst g)
5757
forAll (sublistOf (Set.toList (allPackages resolvedGraph))) $ \toPrune ->
5858
let pruned = pruneGraph [pkgName "one", pkgName "two"] toPrune resolvedGraph
5959
in Set.null (allPackages pruned `Set.intersection` Set.fromList toPrune)
6060

6161
prop "pruning removes orhpans" $ do
6262
let resolvedGraph = runIdentity (resolveDependencies Nothing graph stubLoader)
63-
allPackages g = Set.map packageNameString (Map.keysSet g `Set.union` fold (fmap fst g))
63+
allPackages g = Map.keysSet g `Set.union` fold (fmap fst g)
6464
orphans g = Map.filterWithKey (\k _ -> not (graphElem k g)) g
6565
forAll (sublistOf (Set.toList (allPackages resolvedGraph))) $ \toPrune ->
6666
let pruned = pruneGraph [pkgName "one", pkgName "two"] toPrune resolvedGraph

0 commit comments

Comments
 (0)