diff --git a/master_changes.md b/master_changes.md index 6a2b0505cb8..20ee3bdb852 100644 --- a/master_changes.md +++ b/master_changes.md @@ -54,6 +54,7 @@ users) * [BUG] Prevent `.changes` files from being updated during dry-run [#5144 @na4zagin3 - fix #5132] * Log a summary of recorded `.changes` as a `ACTION` trace log to help debug #4419 [#5144 @na4zagin3] * ◈ Add `--with-tools` option to install recommended development tools from opam file (as `with-test`/`with-doc`), and its environment variable `OPAMWITHTOOLS` [#5016 @rjbou] + * Resolve `with-tools` for post messages too [#5160 @rjbou] ## Remove * @@ -310,6 +311,7 @@ users) * Add test for opam file write with format preserved bug in #4936, fixed in #4941 [#4159 @rjbou] * Add test for switch upgrade from 2.0 root, with pinned compiler [#5176 @rjbou @kit-ty-kate] * Add switch import (for pinned packages) test [#5181 @rjbou] + * Add `--with-tools` test [#5160 @rjbou] ### Engine * Add `opam-cat` to normalise opam file printing [#4763 @rjbou @dra27] [2.1.0~rc2 #4715] * Fix meld reftest: open only with failing ones [#4913 @rjbou] diff --git a/src/client/opamSolution.ml b/src/client/opamSolution.ml index c9613e59829..0d88677086d 100644 --- a/src/client/opamSolution.ml +++ b/src/client/opamSolution.ml @@ -38,6 +38,10 @@ let post_message ?(failed=false) st action = OpamVariable.Map.add (OpamVariable.of_string "failure") (Some (B failed)) local_variables in + let local_variables = + OpamVariable.Map.add (OpamVariable.of_string "with-tools") + (Some (B OpamStateConfig.(!r.with_tools))) local_variables + in let messages = let filter_env = OpamPackageVar.resolve ~opam ~local:local_variables st in (if OpamFile.OPAM.has_flag Pkgflag_Deprecated opam then diff --git a/tests/reftests/dune.inc b/tests/reftests/dune.inc index 7c2b726d817..f49044cad9a 100644 --- a/tests/reftests/dune.inc +++ b/tests/reftests/dune.inc @@ -909,6 +909,23 @@ %{targets} (run ./run.exe %{bin:opam} %{dep:var-option.test} %{read-lines:testing-env})))) +(rule + (alias reftest-with-tools) + (action + (diff with-tools.test with-tools.out))) + +(alias + (name reftest) + (deps (alias reftest-with-tools))) + +(rule + (targets with-tools.out) + (deps root-N0REP0) + (action + (with-stdout-to + %{targets} + (run ./run.exe %{bin:opam} %{dep:with-tools.test} %{read-lines:testing-env})))) + (rule (alias reftest-working-dir) (action diff --git a/tests/reftests/with-tools.test b/tests/reftests/with-tools.test new file mode 100644 index 00000000000..4b9d3056e5c --- /dev/null +++ b/tests/reftests/with-tools.test @@ -0,0 +1,58 @@ +N0REP0 +### +opam-version: "2.0" +depends: [ "b" "tool" {with-tools} ] +build: [ [ "touch" "one" ] [ "touch" "two" ] {with-tools} ] +install: [ [ "cp" "one" "%{lib}%" ] [ "cp" "two" "%{lib}%" ] {with-tools} ] +post-messages: +[ "Thanks for installing the packages" + "and its tool dependencies too" {with-tools} ] +### +opam-version: "2.0" +### +opam-version: "2.0" +### OPAMYES=1 +### opam switch create tooling --empty +### opam install a +The following actions will be performed: +=== install 2 packages + - install a 1 + - install b 1 [required by a] + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> installed b.1 +-> installed a.1 +Done. + +<><> a.1 installed successfully <><><><><><><><><><><><><><><><><><><><><><><><> +=> Thanks for installing the packages +### opam list a --column=installed-files +# Packages matching: name-match(a) & (installed | available) +# Installed files +${BASEDIR}/OPAM/tooling/lib/one +### opam remove a +The following actions will be performed: +=== remove 1 package + - remove a 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> removed a.1 +Done. +### opam install a --with-tools +The following actions will be performed: +=== install 2 packages + - install a 1 + - install tool 1 [required by a] + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> installed tool.1 +-> installed a.1 +Done. + +<><> a.1 installed successfully <><><><><><><><><><><><><><><><><><><><><><><><> +=> Thanks for installing the packages +=> and its tool dependencies too +### opam list a --column=installed-files +# Packages matching: name-match(a) & (installed | available) +# Installed files +${BASEDIR}/OPAM/tooling/lib/one ${BASEDIR}/OPAM/tooling/lib/two