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

One opam file for multiple packages #3793

Open
AltGr opened this issue Mar 22, 2019 · 6 comments
Open

One opam file for multiple packages #3793

AltGr opened this issue Mar 22, 2019 · 6 comments

Comments

@AltGr
Copy link
Member

AltGr commented Mar 22, 2019

This could make it much nicer to handle for packages with multiple definitions from the same source.
Quoting @avsm:

name: foo
maintainer: anil
dev-repo: blah.git
build: [ dune blah blah ]
package mirage {
  depends: [...]
}
package unix {
  depends: [...]
}

Instead of having mirage.opam, unix.opam.
The idea could be as simple as "interpret the file as multiple foo.opam files, for foo as each package * section, and the contents the common part + that section"

@samoht
Copy link
Member

samoht commented Mar 22, 2019

One of the UI question then becomes: how do you install the sub-package unix? For instance:

$ opam install foo-bar-unix

This could lead to the following resolution scheme:

  • check if foo-bar-unix is a concrete package
  • if not check if unix is a sub-package of foo-bar
  • if not, check if unix is a sub-package of bar, a sub-package in foo
  • if not, fail with a nice error message.

@AltGr
Copy link
Member Author

AltGr commented Mar 22, 2019

Ah, my understanding of it so far was more limited, here is what I had in mind:

  • this is specifically for in-source opam files, not for the repository (indeed that would end up with name clashes)
  • there is no automatic prefixing nor package hierarchy: you just specify a list of packages in a shorter way, and in a single file

Basically, it would be like assuming you have a command expand_opams that does

type multi_opam = defs * (pkgname * defs) list
let expand_opams (base_defs, sub_pkgs) =
  let pkgs =
    (if has_field "name" base_defs then [get_field "name" base_defs, base_defs] else []) @
    List.map (fun (pkgname, defs) -> pkgname, base_defs ++ sub_pkgs) sub_pkgs
  in
  List.iter (fun (pkgname, opam) -> write (pkgname ^".opam") opam) pkgs

and that is (virtually) run before opam does the search for package definitions (where ++ is by-field overriding merge).

Would that be sufficient, or at least a good start ?

It may probably be also worth discussing adding hierarchical packages to the repository, but IMHO in that case it would be better to start from the repository shape point of view rather than package definitions. What do you think ?

@samoht
Copy link
Member

samoht commented Mar 22, 2019

But what is the concrete syntax to install sub-packages? You mean opam-publish will have to expand these files during the submission?

@AltGr
Copy link
Member Author

AltGr commented Mar 22, 2019

yes, I guess referring to the directory or opam file would include them all (for opam or opam-publish), and they would be internally considered as expansed (i.e. publish would submit n packages) ; and you would otherwise refer to them individually by name.

Also, opam pin foo . would extract the definition for foo from the file.

@dbuenzli
Copy link
Contributor

It seems to me that this is significantly complexifying the current opam model (I also already see problem with the install of opam files in lib/PKG/opam which odig uses).

If this is only for pins (as far as I understand). Why don't we rather define a protocol (step) that given the package name allows to generate the opam file from the pinned source to use when you pin a repo.

@dbuenzli
Copy link
Contributor

I have opened #3797 which from a workflow perspective would, if feasible, provide a better answer to the problem than this proposal (and to a few others along the way).

@rjbou rjbou added this to the 2.2.0~alpha milestone May 15, 2020
@dra27 dra27 removed this from the 2.2.0~alpha milestone Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants