user2879704
user2879704

Reputation:

Haskell packages - dependency tree

In java - maven build tool, you can print a tree of dependencies for any package/project using the command,

mvn dependency:tree -Dverbose -Dincludes=commons-collections

and output will be a tree structure of artifacts/dependencies like,

[INFO] [dependency:tree]
[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT
[INFO] +- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:compile
[INFO] |  \- commons-validator:commons-validator:jar:1.2.0:compile
[INFO] |     \- commons-digester:commons-digester:jar:1.6:compile
[INFO] |        \- (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.0)
[INFO] \- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile
[INFO]    \- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile
[INFO]       \- commons-collections:commons-collections:jar:2.0:compile

So, how can i do this same for a haskell package using cabal?

Upvotes: 12

Views: 1354

Answers (3)

Peter Becich
Peter Becich

Reputation: 1053

To visualize the dependencies of a Stack project: https://docs.haskellstack.org/en/stable/dependency_visualization/ By default Stack visualizes the internal dependencies.

To visualize the external and internal dependencies of a Cabal project, cabal-plan works: https://hackage.haskell.org/package/cabal-plan

i.e.

cabal-plan dot | twopi -Groot=ROOT-PACKAGE -Goverlap=false -Tpng -o graph.png

(source https://docs.haskellstack.org/en/stable/dependency_visualization/)

To visualize only the internal dependencies of a Cabal project:

cabal-plan --hide-global --hide-builtin dot | twopi -Groot=ROOT-PACKAGE -Goverlap=false -Tpng -o graph.png

(source https://github.com/haskell-hvr/cabal-plan/issues/84#issuecomment-1073232622)

Upvotes: 0

Joachim Breitner
Joachim Breitner

Reputation: 25782

A graph containing all installed packages can be produced using ghc-pkg, e.g.

ghc-pkg dot | tred | dot -Tpdf >pkgs.pdf

Note that the graphviz package provides tred and the dot program.

Upvotes: 17

Sibi
Sibi

Reputation: 48766

For the installed package you can find the dependencies using ghc-pkg. For a package named text, you have to do:

$ ghc-pkg field text depends
depends: array-0.5.0.0-470385a50d2b78598af85cfe9d988e1b
         base-4.7.0.2-bfd89587617e381ae01b8dd7b6c7f1c1
         bytestring-0.10.4.0-d6f1d17d717e8652498cab8269a0acd5
         deepseq-1.3.0.2-63a1ab91b7017a28bb5d04cb1b5d2d02
         ghc-prim-0.3.1.0-a24f9c14c632d75b683d0f93283aea37
         integer-gmp-0.5.1.0-26579559b3647acf4f01d5edd9491a46

For any working project all you have to do is see the depends field on cabal file to determine it's dependency.

Upvotes: 1

Related Questions