ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.21k stars 348 forks source link

Using the `+=` opetator in `build-env` to prepend an empty (but set) variable adds a trailing seperator #5925

Closed gridbugs closed 2 months ago

gridbugs commented 2 months ago

This is contrary to the documentation here:

+= or := prepend. They differ when the variable is unset of empty, where := adds a trailing separator.

To reproduce, put the following in a file named foo.opam:

opam-version: "2.0"

build-env: [
 [ FOO = "" ]
 [ FOO += "foo" ]
]

install: [
 [ "bash" "-c" "echo FOO=$FOO >> %{lib}%/x" ]
]

Then run:

opam switch create .
opam install ./foo.opam
cat _opam/lib/x

The output will be be:

FOO=foo:

But according to the documentation the output should be:

FOO=foo

I'm on linux. Reproduced on both 2.1.5 and opam-2.2.0-beta2.

dra27 commented 2 months ago

OK, I've been looking at this in more detail with the preparatory work in #5935. Cross-referencing a slew of other previous issues in this area to be sure we don't accidentally regress them (because the fixes predate the reftests infrastructure):

With that history paged in, I still think this issue is unequivocally a bug (i.e. the docs are correct and opam isn't adhering to them). It might be relevant to see whether OPAM 1.2.2 was doing this, in terms of assessing whether fixing this may cause a regression.