Skip to content

Commit b96e518

Browse files
authored
Merge pull request #4841 from grayjay/issue-4832
Apply 'any' qualifier to new-freeze constraints (fixes #4832).
2 parents f669217 + be5da15 commit b96e518

File tree

9 files changed

+125
-1
lines changed

9 files changed

+125
-1
lines changed

cabal-install/Distribution/Client/CmdFreeze.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ projectFreezeConstraints plan =
173173
versionConstraints :: Map PackageName [(UserConstraint, ConstraintSource)]
174174
versionConstraints =
175175
Map.mapWithKey
176-
(\p v -> [(UserConstraint (UserQualified UserQualToplevel p) (PackagePropertyVersion v),
176+
(\p v -> [(UserConstraint (UserAnyQualifier p) (PackagePropertyVersion v),
177177
ConstraintSourceFreeze)])
178178
versionRanges
179179

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-local-package
2+
version: 1.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
library
7+
build-depends: base, my-library-dep
8+
build-tool-depends: my-build-tool-dep:my-build-tool >= 2
9+
default-language: Haskell2010
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# cabal update
2+
Downloading the latest package list from test-local-repo
3+
# cabal new-build
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following would be built:
7+
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
8+
- my-build-tool-dep-3.0 (exe:my-build-tool) (requires download & build)
9+
- my-library-dep-1.0 (lib) (requires download & build)
10+
- my-local-package-1.0 (lib) (first run)
11+
# cabal new-freeze
12+
Resolving dependencies...
13+
Wrote freeze file: <ROOT>/new_freeze.dist/source/cabal.project.freeze
14+
# cabal new-build
15+
Resolving dependencies...
16+
Build profile: -w ghc-<GHCVER> -O1
17+
In order, the following would be built:
18+
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
19+
- my-build-tool-dep-2.0 (exe:my-build-tool) (requires download & build)
20+
- my-library-dep-1.0 (lib) (requires download & build)
21+
- my-local-package-1.0 (lib) (first run)
22+
# cabal new-build
23+
Resolving dependencies...
24+
Build profile: -w ghc-<GHCVER> -O1
25+
In order, the following would be built:
26+
- my-build-tool-dep-1.0 (exe:my-build-tool) (requires download & build)
27+
- my-build-tool-dep-3.0 (exe:my-build-tool) (requires download & build)
28+
- my-library-dep-1.0 (lib) (requires download & build)
29+
- my-local-package-1.0 (lib) (first run)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Test.Cabal.Prelude
2+
import Control.Monad.IO.Class
3+
import System.Directory
4+
5+
-- Test that 'cabal new-freeze' works with multiple versions of a build tool
6+
-- dependency.
7+
--
8+
-- The repository contains versions 1.0, 2.0, and 3.0 of the build tool. There
9+
-- is one local package, which requires >= 2, and a library dependency of the
10+
-- local package, which requires < 2, so cabal should pick versions 1.0 and 3.0
11+
-- of the build tool when there are no constraints.
12+
main = cabalTest $ withSourceCopy $ do
13+
withRepo "repo" $ do
14+
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestBuildTool
15+
16+
-- Force the project to use versions 1.0 and 2.0 of the build tool.
17+
cabal "new-freeze" ["--constraint=any.my-build-tool-dep < 3"]
18+
19+
cwd <- fmap testCurrentDir getTestEnv
20+
let freezeFile = cwd </> "cabal.project.freeze"
21+
22+
-- The freeze file should specify a version range that includes both
23+
-- versions of the build tool from the install plan. (This constraint will
24+
-- be replaced with two exe qualified constraints once #3502 is fully
25+
-- implemented).
26+
assertFileDoesContain freezeFile "any.my-build-tool-dep ==1.0 || ==2.0"
27+
28+
-- The library dependency should have a constraint on an exact version.
29+
assertFileDoesContain freezeFile "any.my-library-dep ==1.0"
30+
31+
-- The local package should be unconstrained.
32+
assertFileDoesNotContain freezeFile "my-local-package"
33+
34+
-- cabal should be able to find an install plan that fits the constraints
35+
-- from the freeze file.
36+
cabal' "new-build" ["--dry-run"] >>= assertDoesNotUseLatestBuildTool
37+
38+
-- cabal should choose the latest version again after the freeze file is
39+
-- removed.
40+
liftIO $ removeFile freezeFile
41+
cabal' "new-build" ["--dry-run"] >>= assertUsesLatestBuildTool
42+
where
43+
assertUsesLatestBuildTool out = do
44+
assertOutputContains "my-build-tool-dep-3.0 (exe:my-build-tool)" out
45+
assertOutputDoesNotContain "my-build-tool-dep-2.0" out
46+
47+
assertDoesNotUseLatestBuildTool out = do
48+
assertOutputContains "my-build-tool-dep-2.0 (exe:my-build-tool)" out
49+
assertOutputDoesNotContain "my-build-tool-dep-3.0" out
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-build-tool-dep
2+
version: 1.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
executable my-build-tool
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-build-tool-dep
2+
version: 2.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
executable my-build-tool
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-build-tool-dep
2+
version: 3.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
executable my-build-tool
7+
main-is: Main.hs
8+
build-depends: base
9+
default-language: Haskell2010
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: my-library-dep
2+
version: 1.0
3+
cabal-version: >= 1.20
4+
build-type: Simple
5+
6+
library
7+
build-depends: base
8+
build-tool-depends: my-build-tool-dep:my-build-tool < 2
9+
default-language: Haskell2010

0 commit comments

Comments
 (0)