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.
According to the manpage of
opam lock, the command saves all the installeddependencies 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
AandBand adependency
C. The packageCis a mandatory dependency ofAand a optionaldependency of
B.Now, you generate a lock file for both
AandB, as followsAs
Cis a mandatory dependency ofB, opam installs it and bothA.opam.lockedandB.opam.lockedmention it. It is annoying if you want to install onlyAandCis a hugedependency that you don't want most of the time.
A possible workaround is to generate lock files incrementally:
But
opam install ./A.opam ./B.opam --deps-only --lockedcould fail as the constraints inA.opam.lockedcould be incompatible with the constraints inB.opam.locked.Another workaround is to generate three lock files:
Now, you can install
Aonly,Bonly andA+Bbut it requires a lot of work.It would be nice to add an extra flag
--ignoretoopam lock. Runningopam lock ./A.opam --ignore Cproduces a lock file without
Cand its transitive dependencies if there is no needto install them.