Skip to content

Commit 879f964

Browse files
committed
Parse 'installed' constraints
Cabal constraints, like those returned from stackage's cabal.config endpoint, can specify packages in a number of ways, including e.g. 'mtl installed'. Previously we were ignoring such constraints. We now parse these too.
1 parent 7779e97 commit 879f964

File tree

22 files changed

+304
-172
lines changed

22 files changed

+304
-172
lines changed

cabal.project

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ program-options
1717
-Wprepositive-qualified-module
1818
-Wredundant-constraints
1919
-Wunused-binds
20-
-Wunused-packages
2120
-Wunused-type-patterns
2221
-Wno-unticked-promoted-constructors
2322

clc-stackage.cabal

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ common common-lang
2424
if os(windows)
2525
cpp-options: -DWINDOWS
2626

27-
build-depends: base >=4.16.0.0 && <4.22
2827
default-language: GHC2021
2928

3029
library utils
@@ -35,15 +34,19 @@ library utils
3534
CLC.Stackage.Utils.JSON
3635
CLC.Stackage.Utils.Logging
3736
CLC.Stackage.Utils.OS
37+
CLC.Stackage.Utils.Package
3838
CLC.Stackage.Utils.Paths
3939

4040
build-depends:
4141
, aeson >=2.0 && <2.3
4242
, aeson-pretty ^>=0.8.9
43+
, base >=4.16.0.0 && <4.22
4344
, bytestring >=0.10.12.0 && <0.13
45+
, deepseq >=1.4.6.0 && <1.6
4446
, directory ^>=1.3.5.0
4547
, file-io ^>=0.1.0.0
4648
, filepath >=1.4.100.0 && <1.6
49+
, megaparsec >=9.5.0 && <9.8
4750
, pretty-terminal ^>=0.1.0.0
4851
, text >=1.2.3.2 && <2.2
4952
, time >=1.9.3 && <1.15
@@ -61,30 +64,32 @@ library parser
6164

6265
build-depends:
6366
, aeson
67+
, base
6468
, bytestring
6569
, containers >=0.6.3.1 && <0.9
66-
, deepseq >=1.4.6.0 && <1.6
70+
, deepseq
6771
, filepath
6872
, http-client >=0.5.9 && <0.8
6973
, http-client-tls ^>=0.3
7074
, http-types ^>=0.12.3
75+
, megaparsec
7176
, text
7277
, utils
7378

7479
hs-source-dirs: src/parser
80+
ghc-options: -Wunused-packages
7581

7682
library builder
7783
import: common-lang
7884
exposed-modules:
7985
CLC.Stackage.Builder
8086
CLC.Stackage.Builder.Batch
8187
CLC.Stackage.Builder.Env
82-
CLC.Stackage.Builder.Package
8388
CLC.Stackage.Builder.Process
8489
CLC.Stackage.Builder.Writer
8590

8691
build-depends:
87-
, aeson
92+
, base
8893
, containers
8994
, directory
9095
, filepath
@@ -93,6 +98,7 @@ library builder
9398
, utils
9499

95100
hs-source-dirs: src/builder
101+
ghc-options: -Wunused-packages
96102

97103
library runner
98104
import: common-lang
@@ -104,6 +110,7 @@ library runner
104110

105111
build-depends:
106112
, aeson
113+
, base
107114
, builder
108115
, containers
109116
, directory
@@ -116,17 +123,19 @@ library runner
116123
, utils
117124

118125
hs-source-dirs: src/runner
126+
ghc-options: -Wunused-packages
119127

120128
executable clc-stackage
121129
import: common-lang
122130
main-is: Main.hs
123131
build-depends:
132+
, base
124133
, runner
125134
, terminal-size ^>=0.3.4
126135
, utils
127136

128137
hs-source-dirs: ./app
129-
ghc-options: -threaded -with-rtsopts=-N
138+
ghc-options: -threaded -with-rtsopts=-N Wunused-packages
130139

131140
library test-utils
132141
import: common-lang
@@ -137,6 +146,7 @@ library test-utils
137146
, tasty-golden ^>=2.3.1.1
138147

139148
hs-source-dirs: test/utils
149+
ghc-options: -Wunused-packages
140150

141151
test-suite unit
142152
import: common-lang
@@ -146,6 +156,7 @@ test-suite unit
146156
Unit.CLC.Stackage.Parser.API
147157
Unit.CLC.Stackage.Runner.Env
148158
Unit.CLC.Stackage.Runner.Report
159+
Unit.CLC.Stackage.Utils.Package
149160
Unit.Prelude
150161

151162
build-depends:
@@ -165,7 +176,7 @@ test-suite unit
165176
, utils
166177

167178
hs-source-dirs: test/unit
168-
ghc-options: -threaded -with-rtsopts=-N
179+
ghc-options: -threaded -with-rtsopts=-N Wunused-packages
169180

170181
test-suite functional
171182
import: common-lang
@@ -187,3 +198,7 @@ test-suite functional
187198
, utils
188199

189200
hs-source-dirs: test/functional
201+
202+
-- For some reason -Wunused-packages is complaining about clc-stackage
203+
-- being an unnecessary dep for the functional test suite...hence it is
204+
-- removed from cabal.project and added manually to other targets.

src/builder/CLC/Stackage/Builder/Batch.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import CLC.Stackage.Builder.Env
1010
packagesToBuild
1111
),
1212
)
13-
import CLC.Stackage.Builder.Package (Package)
13+
import CLC.Stackage.Utils.Package (Package)
1414
import Data.Bifunctor (Bifunctor (first))
1515
import Data.List qualified as L
1616
import Data.List.NonEmpty (NonEmpty ((:|)), (<|))

src/builder/CLC/Stackage/Builder/Env.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module CLC.Stackage.Builder.Env
66
)
77
where
88

9-
import CLC.Stackage.Builder.Package (Package)
109
import CLC.Stackage.Utils.Logging qualified as Logging
10+
import CLC.Stackage.Utils.Package (Package)
1111
import Data.IORef (IORef)
1212
import Data.List.NonEmpty (NonEmpty)
1313
import Data.Set (Set)

src/builder/CLC/Stackage/Builder/Package.hs

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/builder/CLC/Stackage/Builder/Process.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import CLC.Stackage.Builder.Env
1818
WriteLogs (WriteLogsCurrent, WriteLogsNone, WriteLogsSaveFailures),
1919
)
2020
import CLC.Stackage.Builder.Env qualified as Env
21-
import CLC.Stackage.Builder.Package qualified as Package
2221
import CLC.Stackage.Builder.Writer qualified as Writer
2322
import CLC.Stackage.Utils.IO qualified as IO
2423
import CLC.Stackage.Utils.Logging qualified as Logging
24+
import CLC.Stackage.Utils.Package qualified as Package
2525
import CLC.Stackage.Utils.Paths qualified as Paths
2626
import Control.Exception (throwIO)
2727
import Control.Monad (when)
@@ -115,7 +115,7 @@ buildProject env idx pkgs = do
115115
mconcat
116116
[ T.pack $ show idx,
117117
": ",
118-
T.intercalate ", " (Package.toText <$> pkgsList)
118+
T.intercalate ", " (Package.toTextInstalled <$> pkgsList)
119119
]
120120
pkgsList = NE.toList pkgs.unPackageGroup
121121
pkgsSet = Set.fromList pkgsList

src/builder/CLC/Stackage/Builder/Writer.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module CLC.Stackage.Builder.Writer
55
where
66

77
import CLC.Stackage.Builder.Batch (PackageGroup (unPackageGroup))
8-
import CLC.Stackage.Builder.Package (Package)
9-
import CLC.Stackage.Builder.Package qualified as Package
108
import CLC.Stackage.Utils.IO qualified as IO
9+
import CLC.Stackage.Utils.Package (Package)
10+
import CLC.Stackage.Utils.Package qualified as Package
1111
import CLC.Stackage.Utils.Paths qualified as Paths
1212
import Data.List.NonEmpty qualified as NE
1313
import Data.Text (Text)
@@ -33,7 +33,7 @@ writeCabalProjectLocal pkgs = IO.writeBinaryFile path constraintsSrc
3333
path = Paths.generatedCabalProjectLocalPath
3434
constraintsSrc = TEnc.encodeUtf8 constraintsTxt
3535
constraintsTxt = T.unlines $ "constraints:" : constraints
36-
constraints = (\p -> " " <> Package.toText p <> ",") <$> pkgs
36+
constraints = (\p -> " " <> Package.toCabalConstraintsText p) <$> pkgs
3737

3838
-- | Writes the package set to a cabal file for building. This will be called
3939
-- for each group we want to build.
@@ -60,7 +60,7 @@ mkCabalFile pkgs =
6060
" default-language: Haskell2010"
6161
]
6262
where
63-
pkgsTxt = (\p -> pkgsIndent <> Package.toDepText p) <$> NE.toList pkgs.unPackageGroup
63+
pkgsTxt = (\p -> pkgsIndent <> Package.toCabalDepText p) <$> NE.toList pkgs.unPackageGroup
6464

6565
-- build-depends is indented 4, then 2 for the package itself.
6666
pkgsIndent :: Text

src/parser/CLC/Stackage/Parser.hs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ module CLC.Stackage.Parser
1111
where
1212

1313
import CLC.Stackage.Parser.API
14-
( PackageResponse (name, version),
15-
StackageResponse (packages),
14+
( StackageResponse (packages),
1615
)
1716
import CLC.Stackage.Parser.API qualified as API
1817
import CLC.Stackage.Parser.API.CabalConfig qualified as CabalConfig
@@ -21,6 +20,8 @@ import CLC.Stackage.Utils.JSON qualified as JSON
2120
import CLC.Stackage.Utils.Logging qualified as Logging
2221
import CLC.Stackage.Utils.OS (Os (Linux, Osx, Windows))
2322
import CLC.Stackage.Utils.OS qualified as OS
23+
import CLC.Stackage.Utils.Package (Package)
24+
import CLC.Stackage.Utils.Package qualified as Package
2425
import Control.Monad (when)
2526
import Data.Aeson (FromJSON, ToJSON)
2627
import Data.Foldable (for_)
@@ -33,13 +34,13 @@ import System.OsPath (OsPath, osp)
3334

3435
-- | Retrieves the list of packages, based on
3536
-- 'CLC.Stackage.Parser.API.stackageUrl'.
36-
getPackageList :: Logging.Handle -> Maybe OsPath -> IO [PackageResponse]
37+
getPackageList :: Logging.Handle -> Maybe OsPath -> IO [Package]
3738
getPackageList hLogger msnapshotPath =
3839
getPackageListByOs hLogger msnapshotPath OS.currentOs
3940

4041
-- | Prints the package list to a file.
41-
printPackageList :: Bool -> Maybe Os -> IO ()
42-
printPackageList incVers mOs = do
42+
printPackageList :: Maybe Os -> IO ()
43+
printPackageList mOs = do
4344
case mOs of
4445
Just os -> printOsList os
4546
Nothing -> for_ [minBound .. maxBound] printOsList
@@ -49,23 +50,18 @@ printPackageList incVers mOs = do
4950
file Windows = [osp|pkgs_windows.txt|]
5051

5152
printOsList os = do
52-
pkgs <- getPackageListByOsFmt incVers os
53+
pkgs <- getPackageListByOsFmt os
5354
let txt = T.unlines pkgs
5455
IO.writeFileUtf8 (file os) txt
5556

5657
-- | Retrieves the package list formatted to text.
57-
getPackageListByOsFmt :: Bool -> Os -> IO [Text]
58-
getPackageListByOsFmt incVers =
59-
(fmap . fmap) toText
58+
getPackageListByOsFmt :: Os -> IO [Text]
59+
getPackageListByOsFmt =
60+
(fmap . fmap) Package.toTextInstalled
6061
. getPackageListByOs Logging.mkDefaultLogger Nothing
61-
where
62-
toText r =
63-
if incVers
64-
then r.name <> "-" <> r.version
65-
else r.name
6662

6763
-- | Helper in case we want to see what the package set for a given OS is.
68-
getPackageListByOs :: Logging.Handle -> Maybe OsPath -> Os -> IO [PackageResponse]
64+
getPackageListByOs :: Logging.Handle -> Maybe OsPath -> Os -> IO [Package]
6965
getPackageListByOs hLogger msnapshotPath os = do
7066
excludedPkgs <- getExcludedPkgs os
7167
let filterExcluded = flip Set.notMember excludedPkgs . (.name)

src/parser/CLC/Stackage/Parser/API.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
module CLC.Stackage.Parser.API
33
( -- * Querying stackage
44
StackageResponse (..),
5-
PackageResponse (..),
65
getStackage,
76

87
-- ** Exceptions
@@ -22,7 +21,6 @@ import CLC.Stackage.Parser.API.Common
2221
ReasonReadBody,
2322
ReasonStatus
2423
),
25-
PackageResponse (name, version),
2624
StackageException (MkStackageException),
2725
StackageResponse (MkStackageResponse, packages),
2826
)

0 commit comments

Comments
 (0)