Skip to content

Add option to list recursive dependencies of a package along with their licenses #879

Closed

Description

@bos

(Imported from Trac #889, reported by joeyadams on 2011-09-27)

It should be possible to list all of the dependencies of a package, including their licenses. This would be useful for:

  • Developers writing proprietary applications.
  • Developers who don't want their liberally-licensed libraries to be "upgraded" to the GPL or similar by subtle dependencies.
Attached is a simple patch that makes cabal-install list this information when the verbosity level is 2 or higher. Sample usage:
$ cabal install --verbose=2 --dry-run gnutls
Reading available packages...
Resolving dependencies...
base         BSD3
bytestring   BSD3
ffi          BSD3
ghc-prim     BSD3
gnutls       GPL (Just (Version {versionBranch = [3], versionTags = []}))
integer-gmp  BSD3
monads-tf    BSD3
rts          BSD3
transformers BSD3
In order, the following would be installed:
monads-tf-0.1.0.0 (new package)
gnutls-0.1 (new package)
This is a quick hack, as I am not familiar with the Cabal codebase. This should probably be wrapped as a --list-licenses command line switch. Pretty-printing licenses would be a plus.

I am already finding this feature useful, and hope others will too.

Activity

  1. bos commented on May 24, 2012

    @bos
    ContributorAuthor

    (Imported comment by @kosmikus on 2011-09-27)

    Vaguely related to #539. (Both are about getting more info about the overall dependency graph, but admittedly in quite different ways.)

  2. ivanperez-keera commented on Sep 29, 2013

    @ivanperez-keera
    Contributor

    I would find this useful to list all the dependencies of a project when I need to reinstall them (for instance, with --enable-library-profiling).

    I suggest that this behaviour be included with 'list-dependencies' (either as a command or a flag of some other command), and that licenses be printed only when --verbose is used.

  3. tibbe commented on Sep 29, 2013

    @tibbe
    Contributor

    @ivanperez-keera We're solving the freezing of dependencies another way, namely using #1519

  4. mtullsen commented on Nov 20, 2014

    @mtullsen

    This (the "along with their licenses" part) is something that Galois is very interested in. On one of our projects we are delivering a binary to a customer and we want some confidence regarding the license(s) for that binary.
    What we currently have is highly ad hoc:

    • a "cabal test" target with a 'postTest' user hook that prints the licenses.

    We basically want a way to list the package dependencies and their licenses. Here's some ideas as to a more principled way to add this capability:

    How to invoke the feature:

    • Alternative 1: add options to the cabal list command:

      cabal list --dependencies-only
      cabal list --dependencies-only --simple-output --show-licenses
      

      (In the latter case we need --show-licenses because --simple-output doesn't print the license information.)

    • Alternative 2: a new cabal command that works similar to 'cabal list':

      cabal list-dependencies ... [--show-licenses]
      

    Also, we might generalize --showlicenses to an ability to display the value of any cabal field:

    cabal list-dependencies --show-field=license
    cabal list-dependencies --show-field=author
    ...
    

    What seem to be less desirable approaches:

    • As an option to install: we'd like to extract this information after installation without having to re-install.

    • Using the by-products of cabal freeze: I see that I can get the list of dependencies from

      cabal freeze --dry-run
      

      but I'd much prefer to not be parsing the by-product of another command.

    Yet another need we have:

    • Getting the information needed so that we can snag all the license files to bundle them into our binary distribution. Maybe this capability could be built into the --show-field option, but I'm not sure how we'd get the information where the license files are stored.

    Galois is interested in doing the development needed. But before we start, we'd like to get some consensus on what the community is interested in (and what patches would be likely to be accepted :-).

    Input? Wishes? Other thoughts?

    Thanks, Mark

  5. 23Skidoo commented on Nov 20, 2014

    @23Skidoo
    Member

    @mtullsen

    Galois is interested in doing the development needed.

    Great! You may be interested in https://github.com/jaspervdj/cabal-dependency-licenses which also implements this functionality.

    Alternative 1: add options to the cabal list command.

    I'm +1 on this alternative.

    Getting the information needed so that we can snag all the license files to bundle them into our binary distribution. Maybe this capability could be built into the --show-field option, but I'm not sure how we'd get the information where the license files are stored.

    The licenses are stored under ~/.cabal/share/doc/$arch-$os-$compiler/$pkgid (aka InstallDirs.docdir), so if you know the target platform and have a package description of the dependency in question (which tells you the value of license-file), retrieving them is easy. Note that there can be multiple license files per package. Also note that with GHC 7.10, $pkgid also includes the package key in addition to package name and version. Maybe we could add a flag to cabal copy to do what you want.

  6. 23Skidoo commented on Nov 20, 2014

    @23Skidoo
    Member
  7. mtullsen commented on Nov 20, 2014

    @mtullsen

    Great! You may be interested in https://github.com/jaspervdj/cabal-dependency-licenses which also implements this functionality.

    Thanks for the pointer, I was completely unaware of this.

    We'd still be interested in bringing this functionality into cabal-install. I'm assuming that others would also find this useful ...?

  8. mietek commented on Nov 27, 2014

    @mietek
    Contributor

    In a similar vein, I would like to be able to list the build-tools and extra-libs used by a project's transitive dependencies. I have done some work towards this, but it is not quite satisfactory (mietek/haskell-on-heroku#34).

  9. dcoutts commented on Nov 27, 2014

    @dcoutts
    Contributor

    People have looked before at the feature to collect the bundle of licenses for a package (in a particular configuration). Would that be enough and cover the other use cases or do we need it in multiple places?

  10. libeako commented on Oct 12, 2017

    @libeako

    I was about to request this feature.

    Many common licenses require a reproduction of the license when the software is distributed in binary form. For example : BSD3 :
    "Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution."

    It is too tedious and error-prone to manually traverse the dependency graph and the individual licenses.

    I imagine a command line tool that collects the license info into a folder dedicated for this purpose, which would be distributed together with the executable.

  11. hvr commented on Oct 13, 2017

    @hvr
    Member
  12. Profpatsch commented on Nov 24, 2017

    @Profpatsch

    A command line feature like this would be awesome, to see which package introduced which dependencies. For reference, here’s how nix-store 1.11 implements it (though I’m not a fan of the naming at all).

    OPERATION --QUERY
       Synopsis
           nix-store {--query | -q} {--outputs | --requisites | -R | --references |
                     --referrers | --referrers-closure | --deriver | --deriver | --graph
                     | --tree | --binding name | --hash | --size | --roots}
                     [--use-output] [-u] [--force-realise] [-f] paths...
    
       Description
           The operation --query displays various bits of information about the store
           paths . The queries are described below. At most one query can be specified.
           The default query is --outputs.
    
           The paths paths may also be symlinks from outside of the Nix store, to the Nix
           store. In that case, the query is applied to the target of the symlink.
    
       Common query options
           --use-output, -u
               For each argument to the query that is a store derivation, apply the query
               to the output path of the derivation instead.
    
           --force-realise, -f
               Realise each argument to the query first (see nix-store --realise).
    
       Queries
           --outputs
               Prints out the output paths of the store derivations paths. These are the
               paths that will be produced when the derivation is built.
    
           --requisites, -R
               Prints out the closure of the store path paths.
    
               This query has one option:
    
               --include-outputs
                   Also include the output path of store derivations, and their closures.
               This query can be used to implement various kinds of deployment. A source
               deployment is obtained by distributing the closure of a store derivation.
               A binary deployment is obtained by distributing the closure of an output
               path. A cache deployment (combined source/binary deployment, including
               binaries of build-time-only dependencies) is obtained by distributing the
               closure of a store derivation and specifying the option --include-outputs.
    
           --references
               Prints the set of references of the store paths paths, that is, their
               immediate dependencies. (For all dependencies, use --requisites.)
    
           --referrers
               Prints the set of referrers of the store paths paths, that is, the store
               paths currently existing in the Nix store that refer to one of paths. Note
               that contrary to the references, the set of referrers is not constant; it
               can change as store paths are added or removed.
    
           --referrers-closure
               Prints the closure of the set of store paths paths under the referrers
               relation; that is, all store paths that directly or indirectly refer to
               one of paths. These are all the path currently in the Nix store that are
               dependent on paths.
    
           --graph
               Prints the references graph of the store paths paths in the format of the
               dot tool of AT&T's Graphviz package[1]. This can be used to visualise
               dependency graphs. To obtain a build-time dependency graph, apply this to
               a store derivation. To obtain a runtime dependency graph, apply it to an
               output path.
    
           --tree
               Prints the references graph of the store paths paths as a nested ASCII
               tree. References are ordered by descending closure size; this tends to
               flatten the tree, making it more readable. The query only recurses into a
               store path when it is first encountered; this prevents a blowup of the
               tree representation of the graph.
           
            … a few more
    

    Interesting is the distinction between run-time and build-time dependencies, though I’m not sure if that’s relevant for cabal.

  13. neosimsim commented on Oct 25, 2019

    @neosimsim

    Interesting is the distinction between run-time and build-time dependencies, though I’m not sure if that’s relevant for cabal.

    Might be relevant/interesting for custom setups.

  14. Mikolaj commented on Aug 27, 2021

    @Mikolaj
    Member

    Given that the original ticket is from 2011 and @andreasabel's solution seems plausible, I'm closing this. Please reopen if the solution does not work for you, with details what's missing, or open a new ticket about the missing parts. #4887 remains open for now.

  15. ethercrow commented on Nov 24, 2021

    @ethercrow

    Posting just in case someone would have the same problem.

    cabal install -f license-report cabal-plan was failing for me, claiming that it's not buildable.

    However, cabal install -f exe -f license-report cabal-plan seems to work.

  16. andreasabel commented on Nov 25, 2021

    @andreasabel
    Member

    @ethercrow :

    cabal install -f license-report cabal-plan was failing for me, claiming that it's not buildable.

    However, cabal install -f exe -f license-report cabal-plan seems to work.

    I stumbled over this myself: Here is some justification for the current flag setup by the author: #7814 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions