Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

expose the transitive opam dependencies of a project #151

Merged
merged 2 commits into from
Nov 16, 2018

Conversation

hannesm
Copy link
Member

@hannesm hannesm commented Mar 23, 2018

the current state is that the explicitly named opam dependencies are gathered in Functoria_info. While this is useful for building a unikernel, at runtime it is much more convenient to have a complete list of all runtime dependencies (maybe even including build time dependencies) available. One use case is to be able to poke at a unikernel image and discover whether it needs to be updated (given a new stream of released libraries). Another use case is to be able to reproduce a unikernel just from a binary (this requires to include cc, ld, and as version information - but not more AFAICT, maybe CFLAGS set in the environment).

The approach taken here uses ocamlfind query -r -format %p during build, and using opam subst afterwards to replace the version numbers with the installed opam packages.

Drawbacks:

  • the list of opam repositories is not included (best done including the latest commit/modification -- if anyone has some opam command line to get this information, that'd be great -- opam repo list is rather incomplete and not too useful)
  • the list generated by ocamlfind is incomplete (since it uses ocamlfind dependencies, as specified in META, which is incomplete -- e.g. there's no mention of ocaml-freestanding in mirage-solo5, bigarray requires unix, gmp-xen/gmp-freestanding don't appear in any dependency chain, and I can't find any ocaml-src dependencies anywhere)
  • for reproducibility, build dependencies may also be crucial: a ppx at version X may generate different output than at version Y. I'd prefer to separate the build and runtime dependencies though (whereas opam list --recursive --resolve=tcpip doesn't distinguish between the two).

Previous discussion at mirage/mirage#896 where (a) @avsm mentions the need for the opam repositories, (b) @samoht points to https://github.com/MagnusS/mirage-stats-demo/blob/master/manifest/manifest.ml for earlier work (using opam list -s --required-by %s --rec --depopts --installed which includes build dependencies AFAICT), (c) @Drup suggests to use opam2: opam list --nobuild --depopts --installed --rec --required-by <PKG> - but I don't think that relying on opam2 is an option atm.

@Drup
Copy link
Member

Drup commented Mar 23, 2018

You seem to be inferring the opam package from the ocamlfind dependencies. That's completely wrong, you shouldn't do that. Infer the opam dependencies using opam! ocamlfind and opam packages are only
very loosely connected in today's ecosystem. It's best to treat them as separate entity and use the appropriate tools to take the transitive closure for each.

@hannesm
Copy link
Member Author

hannesm commented Mar 23, 2018

@Drup thanks for your feedback. I find your choice of words insulting ("completely wrong", "you shouldn't do that") -- I'm open for constructive feedback, but not for insults.

As the build process of MirageOS goes: it calls ocamlbuild -use-ocamlfind (see line 1817 of mirage.ml atm, receiving a list of libs (which is Info.libraries -- i.e. the ocamlfind libraries), and cflags passed via pkg-config) -- opam packages and their dependencies are not used for the compilation and final linking! If we would use opam , that information would be slightly wrong, though likely an overapproximation (as long as you always mirage build in a fresh switch to avoid other packages being required by ocamlfind, but not opam).

On the other hand a user looks at opam packages (including their version numbers and dependencies), and is interested in these releases, rather than ocamlfind. This is why we end up having to map ocamlfind libraries and version numbers to opam packages, and this PR is an attempt at that.

"use the appropriate tools" well, please educate me what are the appropriate ones. As mentioned above, I don't think requiring opam2 is an option for now.

We should keep in mind what is the current state, what is the goal, and how to get there!? I don't think the current state (released functoria) is of much use for the cases outlined above (reproducibility, figuring out whether a recompilation is required), and this PR improves this information, but does not yet reach the goal.
As mentioned above, the reproducibility clearly needs more information (system tools), and the drawbacks of the ocamlfind vs opam inconsistencies are described as well - I'd try to get rid of the inconsistencies between ocamlfind and opam by improving the META information of packages (and/or get rid of ocamlfind at a later stage) - which may fail due to our "cross-compilation" approach atm.

Other inconsistencies I just noticed include tcpip now requires: tcpip.unix (why? this didn't use to be the case in earlier releases, see https://github.com/mirage/mirage-tcpip/blob/v3.1.4/lib/META).

@Drup
Copy link
Member

Drup commented Mar 23, 2018

I'm sorry if you feel insulted, that was not my intention, but I don't feel like I have been particularly mean or anything.

But trying to map ocamlfind to opam packages by name is doomed to fail. The current ecosystem is far too irregular for that. You might aim to make the ecosystem more regular, and I would agree, but that's a long term battle, not something you can rely on now.

The command line I gave you is for opam2 simply because that's what I have installed. :)
The command line used by mirage-stat-demo is pretty much the exact same one, but without --nobuild. Is it so bad to include build dependencies for now ?

@AltGr Do you have a proposition to fetch all the installed non-build recursive dependencies of some currently-installed packages that is compatible with 1.2 ? With their installed depopts ?

@AltGr
Copy link

AltGr commented Mar 23, 2018

fetch all the installed non-build recursive dependencies of some currently-installed packages

not per se, but opam-lock or opam-bundle do parts of this.
Also, opam list -s --owns-file $(opam var prefix)/lib/LIBNAME might help ?

And there is the obvious: opam list --installed --nobuild --rec --required-by PKG I guess ?

that is compatible with 1.2

No.

@Drup
Copy link
Member

Drup commented Mar 23, 2018

Yeah, I proposed the "obvious" above. --owns is also 2.0 only, right ?

No.

😞

Second attempt: we can fetch all the deps in 1.2 easily. Would it be possible after the fact to know which one are build (using some script, if necessary) ?

@AltGr
Copy link

AltGr commented Mar 23, 2018

opam 1.2 already has json output, although less complete, so it could probably extracted from that, yes.

@hannesm
Copy link
Member Author

hannesm commented Nov 16, 2018

now that we require opam2, I rebased this PR to use opam2! :) feedback is welcome (for pinned packages, the output is a bit uninformative atm (only displays version number), would be nice to get the source-hash, ref ocaml/opam#3675).

I convinced myself that the build vs runtime dependencies is not crucial. @Drup what do you think about this revised PR?

Copy link
Member

@Drup Drup left a comment

Choose a reason for hiding this comment

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

The new version looks good!

pp_libraries (Info.libraries i)
module_name name
pp_packages (List.sort String.compare (String.Set.elements pkg))
pp_libraries (List.sort String.compare (String.Set.elements libs))
Copy link
Member

Choose a reason for hiding this comment

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

According to the doc, Set.elements is guaranteed to be sorted. You could either remove the sorting, or remove the transformation to a set.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 520079e (removed List.sort String.compare)

@hannesm hannesm merged commit fba29ac into mirage:master Nov 16, 2018
@hannesm hannesm deleted the rdeps branch November 16, 2018 15:53
hannesm added a commit to hannesm/opam-repository that referenced this pull request Nov 16, 2018
CHANGES:

* compute all transitive opam dependencies for info (mirage/functoria#151, by @hannesm)
* support pin-depends in generated opam file (mirage/functoria#163, by @hannesm)
* use dune as build system (mirage/functoria#158, by @emillon)
* use Ptime for time printing (mirage/functoria#160, by @emillon)
* inject global arguments into generated header (mirage/functoria#159, by @emillon)
* add Functoria_key.add_to_context (mirage/functoria#161, by @emillon)
* output opam2 files (mirage/functoria#157, by @hannesm)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants