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 Sep 9, 2025

Extracted from #6625
Queued on

To allow to change the type of repository from a directory to something else, we need some of the internal functions that expects to be dealing with a directory to be rearranged a little.
In this PR, we do so for OpamFile.OPAM.get_extra_files which currently takes a function returning a directory (repository root), to return instead the list of files and content that users of the function actually expect.

=== install 1 package
- install lot-of-files ~dev
SYSTEM mkdir ${BASEDIR}/OPAM/inst/.opam-switch/build/lot-of-files.~dev
SYSTEM copy ${BASEDIR}/OPAM/repo/default/packages/lot-of-files/lot-of-files.~dev/files/lot-of-files.install.in -> ${BASEDIR}/OPAM/inst/.opam-switch/build/lot-of-files.~dev/lot-of-files.install.in
Copy link
Collaborator

Choose a reason for hiding this comment

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

To investigate...

Copy link
Member Author

Choose a reason for hiding this comment

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

It's simply that OpamSystem.write has no log

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe todo: have a look why action-disk test is not affected

Copy link
Collaborator

Choose a reason for hiding this comment

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

Added logging for read & write. To extract in its own PR

<default>/no-checksum.1: Errors.
error 3: File format error in 'extra-files' at line 11, column 2: expected [file checksum]
# Return code 1 #
<default>/no-checksum.1: Passed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is due to the fact that now we take the opam file from repo state instead of the plain file from opam internal repo copy. Stored opam file in repo state removes the mismatching extra files, so there is no longer the error (extra-files field removed).

Copy link
Collaborator

Choose a reason for hiding this comment

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

We may change --package behaviour to be used only with pinned package...

Copy link
Collaborator

Choose a reason for hiding this comment

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

From dev meeting: we decided to put back the mechanism to retrieve the file from repo root. At first, we wanted to avoid it because extracting a file from a tarred repository is a consuming operation.
For the usages that are done in this PR (opam lint --package and opam pin with version and / or edit), it is conceivable to have this consuming operation as they are not operation that are done often, and it permit to keep the same behaviour (respectively linting without preprocessing and preserve format of opam files).

let get_repo_root rt repo =
get_root_raw rt.repos_global.root rt.repos_tmp repo.repo_name

let get_repo_files rt name dir =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let get_repo_files rt name dir =
(* We need to keep the argument as string to be able to have the
non resolved path to concatenate. *)
let get_repo_files rt name dir =

Copy link
Collaborator

Choose a reason for hiding this comment

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

or use a basename


(** Finds back the location of the opam file this package definition was loaded
from *)
val orig_opam_file:
Copy link
Collaborator

Choose a reason for hiding this comment

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

renamed and moved to switch state to fit its new specification

Copy link
Collaborator

Choose a reason for hiding this comment

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

kept, cf #6679 (comment)

@rjbou rjbou added PR: NEEDS UPDATE PR: WAITING FOR REVIEW and removed PR: QUEUED Pending pull request, waiting for other work to be merged or closed labels Sep 23, 2025
let opam = OpamSwitchState.opam st nv in
match OpamPinned.orig_opam_file st (OpamPackage.name nv) opam with
| None -> raise Not_found
match OpamSwitchState.overlay_opam_file st name with
Copy link
Member Author

Choose a reason for hiding this comment

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

Something feels a bit off with the use of overlay_opam_file vs. the previous orig_opam_file, in here and with its use via ?format_from. I think we should probably avoid breaking compatibility on this and instead do something like copying the file to a temporary directory, and simply remove the ability for orig_opam_file to fetch things from the repository and only fallback to overlay if the original file isn't accessible. It was in OpamPinned after all

Copy link
Collaborator

Choose a reason for hiding this comment

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

This will keep backward compat only for already pinned packages. Pinned package from repo won't have the format kept as now.

=== install 1 package
- install lot-of-files ~dev
SYSTEM mkdir ${BASEDIR}/OPAM/inst/.opam-switch/build/lot-of-files.~dev
SYSTEM copy ${BASEDIR}/OPAM/repo/default/packages/lot-of-files/lot-of-files.~dev/files/lot-of-files.install.in -> ${BASEDIR}/OPAM/inst/.opam-switch/build/lot-of-files.~dev/lot-of-files.install.in
Copy link
Member Author

Choose a reason for hiding this comment

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

It's simply that OpamSystem.write has no log

@kit-ty-kate kit-ty-kate requested a review from rjbou October 1, 2025 15:28
# Return code 31 #
### opam source escape-good-md5
Successfully extracted to ${BASEDIR}/escape-good-md5.1
[WARNING] Some errors extracting to ${BASEDIR}/escape-good-md5.1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

todo

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, in fact it resolves an error that we had 👍

@kit-ty-kate kit-ty-kate changed the title Change the OpamFile.OPAM API to suite different formats of repositories OpamFile.OPAM API: No longer assume that internal opam repositories are directories Oct 9, 2025
@kit-ty-kate kit-ty-kate requested a review from rjbou October 10, 2025 16:45
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.

Nice 4 hands job :D

@kit-ty-kate kit-ty-kate merged commit 6c51e0e into ocaml:master Oct 10, 2025
46 checks passed
@kit-ty-kate kit-ty-kate deleted the get_repo_files branch October 10, 2025 19:38
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.

2 participants