Is there a way to tell dune to list all the dependencies of the current project, grouped by license ?
Thanks!
Is there a way to tell dune to list all the dependencies of the current project, grouped by license ?
Thanks!
opam is the responsable of the project dependencies.
opam list
But there’s no way that I know of listing the licenses with list.
I think the following might work (e.g. with eio
). The package will have to be pinned if it isn’t released I think.
opam list --required-by=eio --recursive --column=name,license:
Unless one is using per-project-switch, I believe opam list
is all installed pkgs, not merely what current dune build needs.
Furthermore, I believe opam list
also includes ocaml
, even if dune build
never pulls in the ocaml sources as a dep.
I don’t think there’s anything off-the-shelf that does specifically what you want, but there are some packages which can collect dependencies of a project at least.
dune-deps | grep ' ->' | sed 's/"lib:\([^"]*\)"/\1/g' | sed 's/.*->//' | sort | uniq
Very nice. For future reference, I’ll note that we can specify the version of the package so as to get only the dependencies for the selected version. For example, yojson 2 dropped the dependency on biniou and this can be seen by specifying yojson.2.0.2
instead of just yojson
:
$ opam list --required-by=yojson.2.0.2 --recursive --column=name,license:
# Packages matching: (installed | available) & rec-required-by(yojson.2.0.2)
# Name # License
base-bytes
base-num
base-ocamlbuild
base-threads
base-unix
conf-m4 "GPL-3.0-only"
cppo "BSD-3-Clause"
dkml-base-compiler "Apache-2.0"
dkml-runtime-common "Apache-2.0"
dune "MIT"
jbuilder "MIT"
num "LGPL-2.1-only WITH OCaml-LGPL-linking-exception"
ocaml "LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
ocaml-base-compiler "LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
ocaml-config
ocaml-option-nnp
ocaml-secondary-compiler "LGPL-2.1-only WITH OCaml-LGPL-linking-exception"
ocaml-variants "LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
ocamlbuild "LGPL-2.0-or-later WITH OCaml-LGPL-linking-exception"
ocamlfind "MIT"
ocamlfind-secondary "MIT"
seq
yojson "BSD-3-Clause"
To group by license, | sort -k2
does the job.
Regarding the original question:
What worked for me in the past is to use a clean opam switch that contains only the packages needed by the current project. opam list
without specifying a specific package will produce the desired list. Here is the command:
$ opam list --column=name,license: | grep -v '^#' | sort -k2
I don’t know how to turn a list of opam files specifying dependencies into an opam list ...
command with the correct filters. I would love to know as well.
If you have that you can also use various commands of odig to access the actual license files
odig show license -l # License tags of installed packages
odig show license-files -l # Path to license files
odig license --no-pager # All licenses separated by U+001C
Of course this can be combined with opam for example:
odig license --no-pager $(opam list --required-by=$PKG -s)
but one should be careful with --required-by/--depends-on
, see this issue.
opam list
permit to list dependencies (and related information) of a (or several) package, it don’t need to be installed. The default search is installed | available
. For a local project, you need to pin it (without installing) to make opam aware of the package.
opam pin . --no-action
If you specified project dependencies in dune-project
, dune should have generated an up-to-date opam file locally.
Once pinned, you can use opam list
with that package, as with any other package
opam list --required mypkg --recursive --column=name,license:
If you need to constraint to only installed ones, you can use option --installed
. All options are available in the man page.
If you use --short
, you don’t need to grep output.