Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kit-ty-kate
Copy link
Member

@kit-ty-kate kit-ty-kate commented Aug 28, 2025

Extracted from #6625
Fixes #5346

@kit-ty-kate kit-ty-kate added this to the 2.5.0~alpha1 milestone Aug 28, 2025
@kit-ty-kate kit-ty-kate changed the title Fix var opamfile Make the computation of pkg:opamfile match its specification Aug 28, 2025
@kit-ty-kate kit-ty-kate requested a review from rjbou August 29, 2025 11:44
@kit-ty-kate
Copy link
Member Author

Discussed yesterday during the dev meeting:

The original PR that added this variable is #4402 (opam 2.1) and while we expect very few people to actually use it, opam-bin clearly shows the need for it. The thing is that it needs it during the pre-build-commands and post-install-commands wrappers, which isn't supported by this PR and would break opam-bin.

One solution we can do is to change the definition of the variable to the following:

returns the installed opam file, or the one that is "pre-recorded" (that is going to be installed) if the package is known by opam (via repository or pin), and otherwise undefined

However this definition is close to the the current/previous behaviour and with #6625 in mind, we want to avoid reading in repositories (it takes a small but non-negligible amount of time to extract a file from the tar.gz file).

Another solution could be to put the file (when missing) in TMPDIR from its definition already available in RAM. This could require some rework of the code by resolving the function to None then handle that case after PackageVar.

Yet another solution could be to move the opam file to the internal directory before any action (at the moment it is only put there after the install) and we could remove it if something wrong happened. To do that we would have to check whether we have any invariant somewhere in the code that relies on the "if a package is in the 'packages' directory, it is installed" invariant.

@kit-ty-kate
Copy link
Member Author

In the end i've chose the second solution. I looked at the third solution but found it too complicated to implement and potentially dangerous as the invariant seems to be used

@kit-ty-kate kit-ty-kate added the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Sep 17, 2025
@rjbou rjbou force-pushed the fix-var-opamfile branch 2 times, most recently from 32298da to 7cee6ab Compare September 18, 2025 09:46
Copy link
Collaborator

@rjbou rjbou left a comment

Choose a reason for hiding this comment

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

I think the is the good way to do it, especially if we don't have the invariant about packages/ directory.

I've added a test for internal variables in an opam file, that completes the one in var-option that is specific for opamfile.

Maybe the PR / changes need to be updated as we change the specification, so in it no longer making it match the old specification.

ret (OpamPath.Switch.Overlay.opam st.switch_global.root st.switch (OpamPackage.name nv))
else if OpamPackage.Set.mem nv st.packages then
let opam = OpamPackage.Map.find nv st.opams in
let temp_dir = OpamFilename.mk_tmp_dir () in
Copy link
Collaborator

Choose a reason for hiding this comment

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

This temporary file won't be cleaned, but it is the wanted behaviour.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, there is no need to keep it, as it is only available during opam run.

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed dep.1
Done.
### opam install i-am-a-repo-pkg -vv | "${OPAMVERSION}" -> "++current++" | '[0-9a-z]{64}' -> '+hash+' | $MD5 -> +archive-hash+ | sed-cmd bash tar rsync | etc -> etc
Copy link
Collaborator

Choose a reason for hiding this comment

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

| etc -> etc is a workaround to force installed-files lines to go into path rewriter. I don't know if it worth have the installed-files moved in the windows/unix test to avoid that or have the (more) exact output ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine for now. Maybe we can think of something to handle path rewriting better in the future but it'll do for now

@kit-ty-kate kit-ty-kate removed the PR: QUEUED Pending pull request, waiting for other work to be merged or closed label Sep 19, 2025
@kit-ty-kate kit-ty-kate force-pushed the fix-var-opamfile branch 4 times, most recently from d59d121 to 729a4f5 Compare September 20, 2025 01:07
@kit-ty-kate kit-ty-kate merged commit ddf8ba6 into ocaml:master Sep 20, 2025
46 checks passed
@kit-ty-kate kit-ty-kate deleted the fix-var-opamfile branch September 20, 2025 11:33
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.

opamfile variable refers to missing file

2 participants