Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support package pinning via http+tar #11446

Merged
merged 8 commits into from
Feb 13, 2025

Conversation

maiste
Copy link
Collaborator

@maiste maiste commented Feb 5, 2025

This PR reduces the gap between opam and dune package management functionnalities. It allows users to ping a tar file (gz or bz) using http (and https) protocol.

Closes #10121

Copy link
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

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

Thanks. The ZIP file changes can be added in a separate PR if you want, but I think that it would be useful to support it given it is a rather common format, especially on Windows.

bin/pkg/pkg_common.ml Outdated Show resolved Hide resolved
src/dune_pkg/mount.ml Outdated Show resolved Hide resolved
src/dune_pkg/opamUrl0.ml Show resolved Hide resolved
src/dune_pkg/opamUrl0.ml Outdated Show resolved Hide resolved
src/dune_pkg/opamUrl0.ml Outdated Show resolved Hide resolved
src/dune_pkg/source.ml Outdated Show resolved Hide resolved
test/blackbox-tests/test-cases/pkg/pin-depends.t Outdated Show resolved Hide resolved
src/dune_pkg/opamUrl0.mli Show resolved Hide resolved
test/blackbox-tests/test-cases/pkg/pin-depends.t Outdated Show resolved Hide resolved
@maiste maiste force-pushed the fix/pinning-10121-bis branch from 2182db3 to 5992d48 Compare February 6, 2025 16:07
@Leonidas-from-XIV
Copy link
Collaborator

@maiste I've looked into the describe.t failure and when I run it locally the issue does not happen, so it seems like that might be another CI failure.

src/dune_pkg/mount.ml Outdated Show resolved Hide resolved
src/dune_pkg/mount.ml Outdated Show resolved Hide resolved
src/dune_pkg/tar.ml Outdated Show resolved Hide resolved
Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Do we plan to support tarballs on the file system?

@maiste
Copy link
Collaborator Author

maiste commented Feb 10, 2025

Do we plan to support tarballs on the file system?

No, we expect people to untar directory themselves on the file system and point to the path. I don't think it is worth adding the machinery for this as there is already one for file://.

What if the tar file is updated remotely?

If the file is updated remotely:

  • you will have to re-run dune pkg lock if you clean the _build or,
  • it will keep using the version in the _build without updating it.

I don't think we have a proper when to address it. If we checked on every run, people would have to download the tar file every time they run dune build. In the current configuration, people will have a checksum error if they do dune clean && dune build which is the equivalent of the behavior (good or bad, idk) with opam: you have to run opam reinstall to get the changes.

I would expect people to want to be aware when the checksum change, but having to explicitly state when they want to synchronize the checksum. It would prevent them from downloading tar they don't expect to change.

@rgrinberg
Copy link
Member

I think we should re-download the tarball and construct the checksum every time we run dune pkg lock. This is consistent with how we treat all other sources that lack a checksum. Anything else will be bound to create confusion that will have to be solved by reminding everyone to do the equivalent of opam update.

You could still avoid re-downloading if you use curl with the correct e-tag incantations.

@maiste
Copy link
Collaborator Author

maiste commented Feb 11, 2025

I agree with you, and this is what happens in the current situation. If you run dune pkg lock, it will download the tar and update the checksum. What I meant is that it is not going to change if you run dune build and the file changed remotely.

Regarding the etag, @Leonidas-from-XIV suggested this. However, many of the packages on opam-repository live in GitHub Release and from the requests I tried with curl, it does not seem to provide an ETag header. It is still an optimization we can do later.

@rgrinberg
Copy link
Member

Okay, thanks. Is there a test that demonstrates that subsequent dune pkg lock re-download it? We should have one.

@maiste
Copy link
Collaborator Author

maiste commented Feb 11, 2025

I'm rewriting my test to show the behavior. It should be ready for a next review round by the end of the day 👍

@maiste maiste force-pushed the fix/pinning-10121-bis branch 2 times, most recently from 6a41320 to 2fb6b32 Compare February 11, 2025 14:21
6 | (checksum md5=aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: "md5=aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is an invalid Cryptographic hash
of a package.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is the wrong error message to show: this shows that the checksum is invalid as a checksum, but we want an error message that the checksum doesn't match.

You can probably just use any valid MD5, like 92449184682b45b5f07e811fdd61d35f.

test/blackbox-tests/test-cases/pkg/pin-depends.t Outdated Show resolved Hide resolved
@maiste
Copy link
Collaborator Author

maiste commented Feb 12, 2025

It seems that having caching efficient is not really easy for the pinning with http and tar. More specifically, it is hard to cache the fetch for when you need the opam file and later when you will need the code. They live in the same directory but of_opam_rule needs the tar to present, and it will generate new rules using the opam file.

To reduce the amount of tar executed, I can "cache" the file somewhere. This way, if the file is still the same, it won't try to unpack it again. I would like to avoid storing it inside the ~/.cache/dune dir because there is a risk it grows exponentially in function of the user usage. I was thinking about storing it under _build/_archive but I'm really not confident with this.

Maybe I'm missing something, but it seems there is no way to avoid the double download without changing the logic.

My proposition is to stick to the behavior where it stores the tar into the _build and let the engine do the fetch when parsing the *.pkg file. It is not optimal but at least the change is not big, and it brings the feature to Dune.

WDTY?

@rgrinberg
Copy link
Member

My proposition is to stick to the behavior where it stores the tar into the _build and let the engine do the fetch when parsing the *.pkg file. It is not optimal but at least the change is not big, and it brings the feature to Dune.

IMO you should just write to a temp dir and leave a comment about future improvements. I think placing it in _build just creates a false expectation. You could just fix the re-downloading issue in subsequent PR's. In any case, I don't think this need to block the PR.

maiste and others added 4 commits February 13, 2025 11:29
Signed-off-by: Etienne Marais <dev@maiste.fr>
Co-authored-by: ArthurW <arthur@tarides.com>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Co-authored-by: Marek Kubica <marek@xivilization.net>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
Signed-off-by: Etienne Marais <dev@maiste.fr>
@maiste maiste merged commit 6b10f5e into ocaml:main Feb 13, 2025
23 of 25 checks passed
@maiste maiste deleted the fix/pinning-10121-bis branch February 13, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support pinning packages with an archive url
3 participants