-
Notifications
You must be signed in to change notification settings - Fork 22
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
Use solver to validate depends stanza #95
Use solver to validate depends stanza #95
Conversation
Thanks for your proposal! Such check can definitively be very useful for some maintainers. More comments in the review itself. |
OpamConsole.note "Checking 'depends' stanza in your opam files \ | ||
(bypass with --skip-deps-check)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can help to have the name of the switch in the message
let switch = | ||
match OpamFile.Config.switch config with | ||
| Some switch -> switch | ||
| None -> failwith "OpamFile.Config.switch" | ||
in | ||
OpamGlobalState.with_ `Lock_none @@ fun gt -> | ||
OpamSwitchState.with_ `Lock_none gt ~switch @@ fun st -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let switch = | |
match OpamFile.Config.switch config with | |
| Some switch -> switch | |
| None -> failwith "OpamFile.Config.switch" | |
in | |
OpamGlobalState.with_ `Lock_none @@ fun gt -> | |
OpamSwitchState.with_ `Lock_none gt ~switch @@ fun st -> | |
let switch = OpamStateConfig.get_switch_opt () in | |
OpamGlobalState.with_ `Lock_none @@ fun gt -> | |
OpamSwitchState.with_ `Lock_none gt ?switch @@ fun st -> |
better use this function to resolve local switches also
%s\n\n\ | ||
Please double-check the filters and constraints (package names, version strings) \ | ||
listed in the 'depends' section of your opam-files." | ||
(String.concat ", " missing_direct_deps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use OpamStd.Format.pretty_list
let pinned_pkgs_s = | ||
List.map OpamPackage.name pinned_deps | ||
|> List.map OpamPackage.Name.to_string | ||
|> String.concat ", " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, You can use OpamStd.Format.pretty_list
else | ||
true | ||
in | ||
if not (OpamConsole.confirm ~default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
let missing_direct_deps, pinned_pkgs = | ||
check_depends_stanza meta_opams opam_root | ||
in | ||
not (missing_direct_deps <> [] || pinned_pkgs <> []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not returning directly the boolean? In that case, you can have only skip_deps_check || check_depends_stanza
let resolved_deps = | ||
let direct_pkgs = | ||
OpamFormula.packages_of_atoms | ||
(OpamPackage.Set.union st.installed st.packages) | ||
(OpamFormula.atoms direct_deps) | ||
in | ||
let transitive_pkgs = | ||
let universe = | ||
OpamSwitchState.universe st | ||
~requested:(OpamPackage.names_of_packages st.packages) | ||
Query | ||
in | ||
OpamSolver.dependencies ~depopts:false ~build:false ~post:false | ||
~installed:false ~unavailable:false | ||
universe direct_pkgs | ||
|> OpamPackage.Set.of_list | ||
in | ||
OpamPackage.Set.union direct_pkgs transitive_pkgs | ||
in | ||
let missing_direct_deps = | ||
OpamFormula.fold_left (fun acc (name, _) -> | ||
if not (OpamPackage.Set.exists (fun pkg -> | ||
OpamPackage.name pkg = name) resolved_deps) | ||
then OpamPackage.Name.to_string name :: acc | ||
else acc) | ||
[] direct_deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to see more in details this part, I thing that we can do it simpler and without solver.
way out of date, closing |
Humbly submitted as a solution for #94
It basically works for a few repos that I've spot-tested, but it bombs out if "build" is listed in the depends stanza.
I've less time to dig into this than when I started, and this was just languishing on my box, so I thought it'd be better to expose it to light now in case it's an obvious fix to people with more knowledge of opam.