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

Populate pin-depends only with the packages that needs to be pinned in the switch #400

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

samoht
Copy link
Collaborator

@samoht samoht commented Oct 27, 2023

This is a tentative fix for mirage/mirage#1476

I guess we could want to add the switch pins to that pin-depends field for reproducibility.

@samoht samoht changed the title Only add root pin-depends in the .opam.locked file Populate pin-depends only with the packages that needs to be pinned in the switch Oct 29, 2023
@samoht
Copy link
Collaborator Author

samoht commented Oct 29, 2023

This is ready to review.

This is a breaking change:

  • currently, pin-depends of the locked file contains the complete list of vendored packages. The rationale is to be able to opam install <pkg>.opam.locked to get something similar to opam monorepo pull. It was a great initial goal. Still, nowadays, with the distinction between switch local and vendored directories (and the ?vendor variable), I am not sure this is still very consistent.
  • so instead, this PR populates pin-depends with the list of packages to be pinned in the current switch. The rationale is to make sure opam install <pkg>.opam.locked will install the required dependencies for the existing switch. If there is a x-opam-monorepo-repositories field, we skip the locally pinned packages, otherwise, we record them in the locked file.

Note that I am still a bit confused with the expected workflow to use when using x-opam-monorepo-provided. Maybe we do not need all of this, but unless I'm mistaken, I don't see how support for pinned packages in the switch is working today.

Copy link
Member

@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.

Yeah, I think this makes sense.

I am not entirely sure what the original reason was for writing all the package in the pin-depends field - maybe indeed it was about being able to reproduce the monorepo with just opam. That decision precedes my involvement in opam-monorepo.

let get_local_pins source_config =
match (source_config : D.Source_opam_config.t) with
| { repositories = Some _; _ } ->
(* ignore local pins with using x-opam-monorepo-repositories *)
Copy link
Member

Choose a reason for hiding this comment

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

Small typo:

Suggested change
(* ignore local pins with using x-opam-monorepo-repositories *)
(* ignore local pins when using x-opam-monorepo-repositories *)

match OpamSwitchState.url switch_state pkg with
| None ->
(* ignore version-pinned packages *)
None
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would make more sense to make this into a named function is_pinned then it would be clearer that checking for an empty URL means a pinned package (or actually, maybe the OPAM libraries should expose this in some more obviously correct way instead of us trying to interpret what OPAM does).

x-opam-monorepo-opam-repositories: [
"file://$OPAM_MONOREPO_CWD/minimal-repo"
"file://$OPAM_MONOREPO_CWD/repo"
]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think printing it here makes sense. If you want to have the contents of the pin-depends.opam in the run.t I would suggest just creating it with cat > pin-depends.opam <<EOF, otherwise its just the same info duplicated.

The lockfile should contain the base packages, dune and our 2 dependencies
`b` and `c` which should be pulled in the duniverse

$ cat pin-depends.opam.locked | sed 's|file://.*/pin-depends.t/|file://$LOCAL_PATH/|'
Copy link
Member

Choose a reason for hiding this comment

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

Could you make this print just the relevant subsets of the lockfile? Otherwise the test is full of incidental content of the lockfile that will need to keep getting updated.

Something like opam show --just-file --raw -fpin-depends ./pin-depends.opam.locked.

List.filter
~f:(fun (p, _) ->
match OpamPackage.Map.find_opt p dependency_table with
| None -> assert false
Copy link
Member

Choose a reason for hiding this comment

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

In this case find can also be used, if that is not a case that we expect to happen.

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