ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.6k stars 397 forks source link

`$ dune install` shouldn't install to opam prefix #8844

Open rgrinberg opened 11 months ago

rgrinberg commented 11 months ago

$ dune install is currently defaulting to install in the opam prefix. This is problematic because it's modifying the switch state without updating the switch state.

There's a few ways to address this problem:

  1. Warn the user when this is happening. This is the least we can do for now.
  2. In dune 4.0, stop install to the opam prefix completely. There's really no need for it in the first place. If the user has opam installed, they also have opam-installer which can do the same thing.
  3. dune install can use opam-installer under the hood when installing to the opam switch

cc @rjbou

emillon commented 11 months ago

In addition that's a UI issue: dune install is used by many people because it's at a very prominent place in the CLI, but should actually only be used in situations where opam is not being used.

nojb commented 11 months ago

I think 3. is the best way forward; it will do what people expect and does not break anything.

AllanBlanchard commented 11 months ago

One thing is the fact that when a package is composed of many sub-projects, say using dune-sites and plug-ins, the use of dune install is basically the only way to guarantee that everything will be installed with a simple command.

When a package has many dune-projects, each project has its own .install, but Opam only considers the root one. Thus, one would have to list every single subpackage which is not practical and error prone.

In Frama-C, we disable the promotion of install files and force Opam to use dune install precisely because of this.

nojb commented 11 months ago

Sorry for the naïve question, but in what way is opam-installer updating the switch state? I took a quick look at the source and it seems to be a light wrapper around cp, rm, etc, without any other side effects. What am I missing?

Alizter commented 11 months ago

@nojb I think its also updating OCAMLPATH.

nojb commented 11 months ago

@nojb I think its also updating OCAMLPATH.

From a quick glance at the source, I don't see how it could have this effect. @rjbou: any insights?

Alizter commented 11 months ago

@nojb There is this file:

.opam/default/.opam-switch/switch-state

which contains:

opam-version: "2.0"
installed: [
  "base-bigarray.base"
  "base-threads.base"
  "base-unix.base"
  "ocaml-options-vanilla.1"
]

I gather then from this the OCAMLPATH is created when you do opam env. (All speculation however).

rgrinberg commented 11 months ago

@nojb is right, I don't see how opam-installer updates anything in the switch state. @rjbou could you clarify?

Alizter commented 11 months ago

Maybe I'm confused about opam-installer? I thought we were talking about opam install.