Skip to content

Feature request: ignoring optional dependencies in lockfiles #7076

Description

@Halbaroth

According to the manpage of opam lock, the command saves all the installed
dependencies of a package in the current switch. I understand that the purpose of
this feature is to save the current state of switch and it makes sense to lock
optional dependencies but sometimes, it is desirable to ignore them.

Consider the following use case. Image that you have two packages A and B and a
dependency C. The package C is a mandatory dependency of A and a optional
dependency of B.

Now, you generate a lock file for both A and B, as follows

opam switch create foo --empty
opam install ./A.opam ./B.opam --deps-only
opam lock ./A.opam ./B.opam

As C is a mandatory dependency of B, opam installs it and both A.opam.locked and
B.opam.locked mention it. It is annoying if you want to install only A and C is a huge
dependency that you don't want most of the time.

A possible workaround is to generate lock files incrementally:

opam switch create foo --empty
opam install ./A.opam
opam lock ./A.opam
opam install ./B.opam
opam lock ./B.opam

But opam install ./A.opam ./B.opam --deps-only --locked could fail as the constraints in
A.opam.locked could be incompatible with the constraints in B.opam.locked.

Another workaround is to generate three lock files:

opam opam switch create fooA --no--switch --empty
opam install --switch fooA ./A.opam --deps-only
opam lock --switch fooA ./A.opam
opam opam switch create fooB --no--switch --empty
opam install --switch fooB ./B.opam --deps-only
opam lock --switch fooB ./B.opam
opam opam switch create fooAB --no--switch --empty
opam install --switch fooAB ./A.opam ./B.opam --deps-only
opam lock --switch fooAB ./A.opam ./B.opam --suffix common

Now, you can install A only, B only and A+B but it requires a lot of work.

It would be nice to add an extra flag --ignore to opam lock. Running

opam lock ./A.opam --ignore C

produces a lock file without C and its transitive dependencies if there is no need
to install them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions