Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't display undefined variable warnings when evaluating the ? operator #5983

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ users)
## Var/Option

## Update / Upgrade
* [BUG] Stop triggering "Undefined filter variable variable" warning for `?variable` [#5983 @dra27]

## Tree
* [BUG] Fix `opam tree --with-*` assigning the `with-*` variables to unrequested packages [#5919 @kit-ty-kate @rjbou - fix #5755]
Expand Down
30 changes: 20 additions & 10 deletions src/state/opamSwitchState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,17 @@ let avoid_version st nv =
has_avoid_flag)
+! false)

let undefined_filter_variable nv v =
(if OpamFormatConfig.(!r.strict) then
OpamConsole.error_and_exit `File_error
"Undefined filter variable %s in dependencies of %s"
else
log
"ERR: Undefined filter variable %s in dependencies of %s")
(OpamVariable.Full.to_string v) (OpamPackage.to_string nv)

let package_env_t st ~force_dev_deps ~test ~doc ~dev_setup
~requested_allpkgs nv v =
~requested_allpkgs ?(err_undefined=true) nv v =
if List.mem v OpamPackageVar.predefined_depends_variables then
match OpamVariable.Full.to_string v with
| "dev" ->
Expand All @@ -899,19 +908,17 @@ let package_env_t st ~force_dev_deps ~test ~doc ~dev_setup
| _ -> None (* Computation delayed to the solver *)
else
let r = OpamPackageVar.resolve_switch ~package:nv st v in
if r = None then
(if OpamFormatConfig.(!r.strict) then
OpamConsole.error_and_exit `File_error
"Undefined filter variable %s in dependencies of %s"
else
log
"ERR: Undefined filter variable %s in dependencies of %s")
(OpamVariable.Full.to_string v) (OpamPackage.to_string nv);
if err_undefined && r = None then
undefined_filter_variable nv v;
r

let get_dependencies_t st ~force_dev_deps ~test ~doc ~dev_setup
~requested_allpkgs deps opams =
let filter_undefined nv =
let warn_undefined v =
if not (List.mem v OpamPackageVar.predefined_depends_variables) then
undefined_filter_variable nv v
in
OpamFormula.map (fun (name, fc) ->
let fc =
OpamFormula.map (function
Expand All @@ -923,6 +930,9 @@ let get_dependencies_t st ~force_dev_deps ~test ~doc ~dev_setup
"Undefined filter variable %s in dependencies of %s"
(OpamVariable.to_string v) (OpamPackage.to_string nv);
Atom (Filter (FBool false))
| (Filter filter) as f ->
List.iter warn_undefined (OpamFilter.variables filter);
Atom f
| f -> Atom f)
fc
in
Expand All @@ -931,7 +941,7 @@ let get_dependencies_t st ~force_dev_deps ~test ~doc ~dev_setup
OpamPackage.Map.mapi (fun nv opam ->
OpamFilter.partial_filter_formula
(package_env_t st ~force_dev_deps ~test ~doc
~dev_setup ~requested_allpkgs nv)
~dev_setup ~requested_allpkgs ~err_undefined:false nv)
(deps opam)
|> filter_undefined nv) opams

Expand Down
18 changes: 18 additions & 0 deletions tests/reftests/resolve-variables.test
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,21 @@ The following actions will be performed:
-> installed d.4
-> installed foo.1
Done.
### OPAMYES=1 OPAMSTRICT=1
### <REPO2/packages/undef/undef.1/opam>
opam-version: "2.0"
depends: "d" {?undefined-global & undefined-global != ""}
### <REPO2/repo>
opam-version: "2.0"
### opam switch create undefined-globals --empty
### opam repository add second ./REPO2 --this-switch
[second] Initialised
### opam repo remove default --this-switch
### opam install undef
The following actions will be performed:
=== install 1 package
- install undef 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed undef.1
Done.
Loading