Skip to content

Commit

Permalink
Look up variables even if they refer to other packages
Browse files Browse the repository at this point in the history
1. Fixes the problem of not resolving variables that refer to other
   packages
2. Silences the warning about unresolved variables if the variable
   refers to a package that is not installed.
3. Keeps the warning if the variable is not referring to a package and
   undefined OR the package is installed and is missing the definition.

Closes ocaml-opam#45.
  • Loading branch information
Leonidas-from-XIV committed Dec 20, 2022
1 parent b759d7c commit 1f0dcfb
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions lib/switch_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,35 @@ let user_restrictions t name =
OpamPackage.Name.Map.find_opt name t.constraints

let env t pkg v =
if List.mem v OpamPackageVar.predefined_depends_variables then None
else (
let r = OpamPackageVar.resolve_switch ~package:pkg t.st v in
if r = None then OpamConsole.warning "Unknown variable %S" (OpamVariable.Full.to_string v);
r
match List.mem v OpamPackageVar.predefined_depends_variables with
| true -> None
| false -> (
match OpamPackageVar.resolve_switch ~package:pkg t.st v with
| Some _ as resolved -> resolved
| None -> (
match OpamVariable.Full.package v with
| None -> (
(* a local variable that is unknown *)
OpamConsole.warning "Unknown variable %S" (OpamVariable.Full.to_string v);
None)
| Some pkg_name ->
let installed_package = OpamPackage.Set.find_opt (fun package ->
OpamPackage.Name.equal (OpamPackage.name package) pkg_name)
t.st.installed
in
match installed_package with
| None ->
(* [v] refers to a package that is not installed in the switch *)
None
| Some package -> (
let unscoped = OpamVariable.Full.(self (variable v)) in
match OpamPackageVar.resolve_switch ~package t.st unscoped with
| None ->
OpamConsole.warning "Unknown variable %S" (OpamVariable.Full.to_string v);
None
| Some _ as resolved -> resolved
)
)
)

let filter_deps t pkg f =
Expand Down

0 comments on commit 1f0dcfb

Please sign in to comment.