Skip to content

Fix preferred-versions format#66

Merged
andreabedini merged 1 commit intoinput-output-hk:mainfrom
amesgen:fix-deprecations
Jun 6, 2023
Merged

Fix preferred-versions format#66
andreabedini merged 1 commit intoinput-output-hk:mainfrom
amesgen:fix-deprecations

Conversation

@amesgen
Copy link
Copy Markdown
Contributor

@amesgen amesgen commented Jun 3, 2023

Cabal can not parse the preferred-versions format as written by foliage before this PR as the preceding package name is missing, so all deprecations were ignored before this PR. E.g. the mtl/preferred-versions file from the Hackage index looks like this:

mtl <2.1 || >2.1 && <2.3 || >2.3

Relevant links to the Cabal source code:


I used this code to create this repo (src) for haskell/cabal#8997; this can be used to verify that deprecations now work with this PR.

@andreabedini
Copy link
Copy Markdown
Contributor

Thank you!

@michaelpj @yvan-sraka can you review (and merge)? It's public holiday on Monday.

@amesgen do we have already wrongly formatted preferred-versions on chap? If yes, this means we need to reset the index (😥) as the fix will change old entries.

@amesgen
Copy link
Copy Markdown
Contributor Author

amesgen commented Jun 4, 2023

do we have already wrongly formatted preferred-versions on chap? If yes, this means we need to reset the index (disappointed_relieved) as the fix will change old entries.

No, CHaP does not yet have any deprecations, e.g. this returns no entries:

curl -sL https://input-output-hk.github.io/cardano-haskell-packages/01-index.tar.gz \
  | tar tzf - | rg preferred-versions

Copy link
Copy Markdown
Contributor

@andreabedini andreabedini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we pretty-print it as a Dependency. Would you be able to check if this works correctly? (since you already have the setup to reproduce the problem :P)

Comment on lines +325 to +330
createTarEntry (ts, effectiveRange) = mkTarEntry prettyEffectiveRange (IndexPkgPrefs pn) ts
where
-- We have to prepend the package name despite this file residing
-- in a package-specific directory.
prettyEffectiveRange =
BL.pack $ unPackageName pn <> " " <> prettyShow effectiveRange
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you tracked down that cabal parses this as a Dependency I suggest we pretty-print it as a Dependency too, so to avoid any incompatibility.

Suggested change
createTarEntry (ts, effectiveRange) = mkTarEntry prettyEffectiveRange (IndexPkgPrefs pn) ts
where
-- We have to prepend the package name despite this file residing
-- in a package-specific directory.
prettyEffectiveRange =
BL.pack $ unPackageName pn <> " " <> prettyShow effectiveRange
createTarEntry (ts, effectiveRange) = mkTarEntry (BL.pack $ prettyShow dep) (IndexPkgPrefs pn) ts
where
dep = mkDependency pn effectiveRange mainLibSet

Where mkDependency and mainLibSet are defined in Distribution.Types.Dependency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense; I still find Dependency a bit misleading in this specific context as sublibraries are not applicable here (Cabal will simply ignore them, see here), but I will just add a comment 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also confirming that this works just as well as the previous approach

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense; I still find Dependency a bit misleading in this specific context as sublibraries are not applicable here

100% agree with you. This also made me just realise per-component solving won't work with deprecated-packages OOTB (since they only deprecate the main lib and the solver could still pick some other lib). This should be reworked in cabal-install ... (one day 🙄)

@andreabedini andreabedini self-assigned this Jun 5, 2023
Co-authored-by: Andrea Bedini <andrea@andreabedini.com>
@amesgen amesgen force-pushed the fix-deprecations branch from 96473b0 to 9833056 Compare June 5, 2023 12:51
@andreabedini
Copy link
Copy Markdown
Contributor

Note for future ourselves (and new visitors 👋). A deprecated package is avoided if possible but it will still be choosen if it's the only solution.

Consider the following setup:

❯ cat cabal.project 
extra-packages: tagged

repository cabal-repo-override-example
  url: file:/home/andrea/cabal-repo-override-example-repo/_repo
  secure: True

active-repositories: hackage.haskell.org, cabal-repo-override-example:override
❯ tar tzf /home/andrea/cabal-repo-override-example-repo/_repo/01-index.tar.gz --full-time --utc | grep tagged
-rw-r--r-- foliage/foliage 2770 2023-06-02 18:05:25 tagged/0.8.6.1/tagged.cabal
-rw-r--r-- foliage/foliage  805 2023-06-02 18:05:25 tagged/0.8.6.1/package.json
-rw-r--r-- foliage/foliage   27 2023-06-02 18:37:52 tagged/preferred-versions

With this PR, foliage produces the correct preferred-version

❯ tar xzf /home/andrea/cabal-repo-override-example-repo/_repo/01-index.tar.gz -O tagged/preferred-versions
tagged <0.8.6.1 || >0.8.6.1

but then cabal-install picks tagged-0.8.6.1 anyway!

❯ cabal clean && cabal build tagged --dry-run -v3 | grep tagged
Warning: There are no packages or optional-packages in the project
targets: tagged
  tagged >=0 (user target)
  tagged <0.8.6.1 || >0.8.6.1
[__0] trying: tagged-0.8.6.1 (user goal)
[__1] trying: base-4.17.1.0/installed-4.17.1.0 (dependency of tagged)
[__5] trying: tagged:+deepseq
[__6] trying: deepseq-1.4.8.0/installed-1.4.8.0 (dependency of tagged +deepseq)
[__8] trying: tagged:+transformers
[__9] trying: transformers-0.5.6.2/installed-0.5.6.2 (dependency of tagged +transformers)
[_10] trying: template-haskell-2.19.0.0/installed-2.19.0.0 (dependency of tagged)
Component graph for tagged-0.8.6.1: component lib
...

This because cabal-repo-override-example:override has masked any other possible choice of tagged so tagged-0.8.6.1 has to be.

If we add tagged-0.8.6 to the repository, we can see the prefereces taking effect:

❯ tar tzf /home/andrea/cabal-repo-override-example-repo/_repo/01-index.tar.gz --full-time --utc | grep tagged
-rw-r--r-- foliage/foliage 2509 2023-06-02 17:05:25 tagged/0.8.6/tagged.cabal
-rw-r--r-- foliage/foliage  804 2023-06-02 17:05:25 tagged/0.8.6/package.json
-rw-r--r-- foliage/foliage 2770 2023-06-02 18:05:25 tagged/0.8.6.1/tagged.cabal
-rw-r--r-- foliage/foliage  805 2023-06-02 18:05:25 tagged/0.8.6.1/package.json
-rw-r--r-- foliage/foliage   27 2023-06-02 18:37:52 tagged/preferred-versions
❯ tar xzf /home/andrea/cabal-repo-override-example-repo/_repo/01-index.tar.gz -O tagged/preferred-versions
tagged <0.8.6.1 || >0.8.6.1

cabal-install is not picking the latest version of tagged anymore, because it's now deprecated.

❯ cabal clean && cabal build tagged --dry-run -v3 | grep tagged
Warning: There are no packages or optional-packages in the project
targets: tagged
  tagged >=0 (user target)
  tagged <0.8.6.1 || >0.8.6.1
[__0] trying: tagged-0.8.6 (user goal)
[__1] trying: base-4.17.1.0/installed-4.17.1.0 (dependency of tagged)
[__5] trying: tagged:+deepseq
[__6] trying: deepseq-1.4.8.0/installed-1.4.8.0 (dependency of tagged +deepseq)
[__8] trying: tagged:+transformers
[__9] trying: transformers-0.5.6.2/installed-0.5.6.2 (dependency of tagged +transformers)
[_10] trying: template-haskell-2.19.0.0/installed-2.19.0.0 (dependency of tagged)
Component graph for tagged-0.8.6: component lib
...

Setting index-state to just before the deprecation makes tagged-0.8.6.1 available again.

❯ cabal clean && cabal build tagged --dry-run -v3 --index-state='cabal-repo-override-example 2023-06-02T18:37:51Z' | grep tagged
...
targets: tagged
  tagged >=0 (user target)
[__0] trying: tagged-0.8.6.1 (user goal)
[__1] trying: base-4.17.1.0/installed-4.17.1.0 (dependency of tagged)
[__5] trying: tagged:+deepseq
[__6] trying: deepseq-1.4.8.0/installed-1.4.8.0 (dependency of tagged +deepseq)
[__8] trying: tagged:+transformers
[__9] trying: transformers-0.5.6.2/installed-0.5.6.2 (dependency of tagged +transformers)
[_10] trying: template-haskell-2.19.0.0/installed-2.19.0.0 (dependency of tagged)
Component graph for tagged-0.8.6.1: component lib
...

@andreabedini andreabedini merged commit 7474ed7 into input-output-hk:main Jun 6, 2023
@andreabedini
Copy link
Copy Markdown
Contributor

Thank you @amesgen <3

andreabedini added a commit to IntersectMBO/cardano-haskell-packages that referenced this pull request Jun 6, 2023
Bump foliage to include fix for wrong formatting of preferred-versions.
See input-output-hk/foliage#66
@amesgen amesgen deleted the fix-deprecations branch June 6, 2023 08:13
andreabedini added a commit to IntersectMBO/cardano-haskell-packages that referenced this pull request Jun 6, 2023
Bump foliage to include fix for wrong formatting of preferred-versions.
See input-output-hk/foliage#66
andreabedini added a commit to IntersectMBO/cardano-haskell-packages that referenced this pull request Jun 7, 2023
Bump foliage to include fix for wrong formatting of preferred-versions.
See input-output-hk/foliage#66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants