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

Use solver to validate depends stanza #95

Conversation

mbacarella
Copy link

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.

@rjbou
Copy link
Contributor

rjbou commented Feb 21, 2020

Thanks for your proposal!

Such check can definitively be very useful for some maintainers.
I'm wondering if checking that the packages exists in current switch is relevant. opam-publish is not meant to be used in a given switch. Maybe adding an option to select the development switch ? or even read it interactively ? Also instead of having it by default, maybe ask user if a switch check should be done in switch, wuth a yes default ?

More comments in the review itself.

Comment on lines +604 to +605
OpamConsole.note "Checking 'depends' stanza in your opam files \
(bypass with --skip-deps-check)";
Copy link
Contributor

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

Comment on lines +611 to +617
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 ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

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

Comment on lines +669 to +672
let pinned_pkgs_s =
List.map OpamPackage.name pinned_deps
|> List.map OpamPackage.Name.to_string
|> String.concat ", "
Copy link
Contributor

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
Copy link
Contributor

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 <> [])
Copy link
Contributor

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

Comment on lines +626 to +651
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
Copy link
Contributor

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.

@mbacarella
Copy link
Author

way out of date, closing

@mbacarella mbacarella closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants