From 0b5fe8282794e522d75f8ea3f1136d0518faa386 Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Fri, 3 May 2024 18:09:11 +0200 Subject: [PATCH 1/4] reftest: add tree test for packages that have dependencies whit variables in their dependencies (second level) --- master_changes.md | 1 + tests/reftests/tree.test | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/master_changes.md b/master_changes.md index 1e8d2513f0e..4afad5a8a50 100644 --- a/master_changes.md +++ b/master_changes.md @@ -102,6 +102,7 @@ users) ## Reftests ### Tests + * tree: add a test for packages that have variables in their transitive dependencies [#5919 @rjbou] ### Engine diff --git a/tests/reftests/tree.test b/tests/reftests/tree.test index 0eaa2878d6e..615322a6e4b 100644 --- a/tests/reftests/tree.test +++ b/tests/reftests/tree.test @@ -320,6 +320,31 @@ The following actions are simulated: l.1 |-- a.1 '-- l-dev.1 (dev) +### : dependency have variables in their dependencies +### +opam-version: "2.0" +depends: [ "j" "d" {with-doc} ] +# j depends on k with-test +### opam install m k --with-doc +The following actions will be performed: +=== install 2 packages + - install k 1 + - install m 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +-> installed k.1 +-> installed m.1 +Done. +### opam tree m +m.1 +'-- j.1 + '-- a.1 +### opam tree m --with-test --with-doc +m.1 +|-- d.1 (with-doc) +'-- j.1 + |-- a.1 + '-- k.1 (with-test) ### :::::::::::::::: ### : Empty switch : ### :::::::::::::::: From 9fe17d14c552be9182e251e1c5381f947ac00a10 Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Fri, 3 May 2024 17:19:28 +0200 Subject: [PATCH 2/4] reftest: update tree test with '--with-test --no-switch' case --- master_changes.md | 1 + tests/reftests/tree.test | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/master_changes.md b/master_changes.md index 4afad5a8a50..b1b66a7f2c1 100644 --- a/master_changes.md +++ b/master_changes.md @@ -103,6 +103,7 @@ users) ## Reftests ### Tests * tree: add a test for packages that have variables in their transitive dependencies [#5919 @rjbou] + * tree: add test for `opam tree pkg --with-test --no-switch` [#5919 @rjbou] ### Engine diff --git a/tests/reftests/tree.test b/tests/reftests/tree.test index 615322a6e4b..ce63192af4a 100644 --- a/tests/reftests/tree.test +++ b/tests/reftests/tree.test @@ -388,7 +388,7 @@ e.1 [ERROR] No package to display # Return code 5 # ### :::::::::::::::: -### : --not-switch : +### : --no-switch : ### :::::::::::::::: ### opam tree --no-switch | '…' -> '...' | '`' -> "'" opam: --no-switch can't be used without specifying a package or a path @@ -477,6 +477,26 @@ The following actions are simulated: - install j 1 j.1 +### # e depend on d with-test +### opam tree e --no-switch +The following actions are simulated: +=== install 3 packages + - install a 1 [required by e] + - install b 1 + - install e 1 + +e.1 +'-- a.1 +### opam tree e --with-test --no-switch +The following actions are simulated: +=== install 3 packages + - install a 1 [required by e] + - install b 1 + - install e 1 + +e.1 +'-- a.1 +### : invariant ### opam-version: "2.0" flags: compiler From 3c5f234280cf71bc0a7b5e014bc6080c81c3f01a Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 10 Apr 2024 18:30:09 +0100 Subject: [PATCH 3/4] Fix 'opam tree --with-*' assigning the 'with-*' variables to unrequested packages Co-authored-by: Raja Boujbel --- master_changes.md | 1 + src/client/opamTreeCommand.ml | 22 +++++++++++----------- tests/reftests/tree.test | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/master_changes.md b/master_changes.md index b1b66a7f2c1..6f375eaf0f4 100644 --- a/master_changes.md +++ b/master_changes.md @@ -42,6 +42,7 @@ users) ## Update / Upgrade ## Tree + * [BUG] Fix `opam tree --with-*` assigning the `with-*` variables to unrequested packages [#5919 @kit-ty-kate @rjbou - fix #5755] ## Exec diff --git a/src/client/opamTreeCommand.ml b/src/client/opamTreeCommand.ml index e1331327b85..0d7664f5a55 100644 --- a/src/client/opamTreeCommand.ml +++ b/src/client/opamTreeCommand.ml @@ -378,19 +378,22 @@ let print_solution st new_st missing solution = (** Setting states for building *) -let get_universe tog st = +let get_universe tog requested st = let OpamListCommand.{doc; test; dev_setup; dev; _} = tog in OpamSwitchState.universe st ~doc ~test ~dev_setup ~force_dev_deps:dev - ~requested:st.installed + ~requested Query -let simulate_new_state tog st universe install names = +let dry_install tog st universe install = match OpamSolver.resolve universe (OpamSolver.request ~install ()) with | Success solution -> let new_st = OpamSolution.dry_run st solution in - print_solution st new_st names solution; - new_st, get_universe tog new_st + print_solution st new_st + (OpamPackage.Name.Set.of_list (List.map fst install)) + solution; + let requested = OpamFormula.packages_of_atoms new_st.installed install in + new_st, get_universe tog requested new_st | Conflicts cs -> OpamConsole.error "Could not simulate installing the specified package(s) to this switch:"; @@ -399,10 +402,6 @@ let simulate_new_state tog st universe install names = (OpamSwitchState.unavailable_reason st) cs); OpamStd.Sys.exit_because `No_solution -let dry_install tog st universe install = - simulate_new_state tog st universe install - (OpamPackage.Name.Set.of_list (List.map fst install)) - let run st tog ?no_constraint mode filter atoms = let open OpamPackage.Set.Op in let select, missing = @@ -412,11 +411,12 @@ let run st tog ?no_constraint mode filter atoms = in if OpamPackage.Set.is_empty installed then (select, atom :: missing) - else (installed ++ select, missing)) + else + (installed ++ select, missing)) (OpamPackage.Set.empty, []) atoms in let st, universe = - let universe = get_universe tog st in + let universe = get_universe tog select st in match mode, filter, missing with | Deps, _, [] -> st, universe | Deps, Roots_from, _::_ -> diff --git a/tests/reftests/tree.test b/tests/reftests/tree.test index ce63192af4a..9820f76784e 100644 --- a/tests/reftests/tree.test +++ b/tests/reftests/tree.test @@ -343,8 +343,7 @@ m.1 m.1 |-- d.1 (with-doc) '-- j.1 - |-- a.1 - '-- k.1 (with-test) + '-- a.1 ### :::::::::::::::: ### : Empty switch : ### :::::::::::::::: From 09739899fb0846ee2ad06eb513fbf3d6642ed89a Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 3 May 2024 17:31:42 +0100 Subject: [PATCH 4/4] Fix combinations of 'opam tree --with-*' and '--no-switch' And more generally for simulated states, when packages need to be installed Co-authored-by: Raja Boujbel --- master_changes.md | 1 + src/client/opamTreeCommand.ml | 8 +++++++- tests/reftests/tree.test | 12 ++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/master_changes.md b/master_changes.md index 6f375eaf0f4..15f3bfe88f7 100644 --- a/master_changes.md +++ b/master_changes.md @@ -43,6 +43,7 @@ users) ## Tree * [BUG] Fix `opam tree --with-*` assigning the `with-*` variables to unrequested packages [#5919 @kit-ty-kate @rjbou - fix #5755] + * [BUG] Fix combinations of `opam tree --with-*` and `--no-switch` [#5919 @kit-ty-kate @rjbou - fix #5920] ## Exec diff --git a/src/client/opamTreeCommand.ml b/src/client/opamTreeCommand.ml index 0d7664f5a55..f6972106072 100644 --- a/src/client/opamTreeCommand.ml +++ b/src/client/opamTreeCommand.ml @@ -416,7 +416,13 @@ let run st tog ?no_constraint mode filter atoms = (OpamPackage.Set.empty, []) atoms in let st, universe = - let universe = get_universe tog select st in + let universe = + let requested = + OpamFormula.packages_of_atoms + (if missing = [] then st.installed else st.packages) atoms + in + get_universe tog requested st + in match mode, filter, missing with | Deps, _, [] -> st, universe | Deps, Roots_from, _::_ -> diff --git a/tests/reftests/tree.test b/tests/reftests/tree.test index 9820f76784e..ec5fd080b33 100644 --- a/tests/reftests/tree.test +++ b/tests/reftests/tree.test @@ -367,12 +367,14 @@ h.1 '-- b.1 (>= 1 & < 3) [*] ### opam tree j --with-test The following actions are simulated: -=== install 2 packages +=== install 3 packages - install a 1 [required by j] - install j 1 + - install k 1 [required by j] j.1 -'-- a.1 +|-- a.1 +'-- k.1 (with-test) ### opam tree e The following actions are simulated: === install 3 packages @@ -488,13 +490,15 @@ e.1 '-- a.1 ### opam tree e --with-test --no-switch The following actions are simulated: -=== install 3 packages +=== install 4 packages - install a 1 [required by e] - install b 1 + - install d 1 [required by e] - install e 1 e.1 -'-- a.1 +|-- a.1 +'-- d.1 (< 2 & with-test) ### : invariant ### opam-version: "2.0"