ndmitchell / weeder

Detect dead exports or package imports
BSD 3-Clause "New" or "Revised" License
124 stars 8 forks source link

Confusing handling of Cabal internal libraries #51

Closed recursion-ninja closed 4 years ago

recursion-ninja commented 5 years ago

Our project uses multiple packages as sub-libraries, one of which has multiple internal libraries that are re-exported.

When we run weeder on the package with multiple internal libraries, we get the following output:

= Package pcg-core =

== Section library ==
Module not compiled
* Analysis.Parsimony.Additive
* Analysis.Parsimony.Additive.Internal
* Analysis.Parsimony.Dynamic.DirectOptimization
* Analysis.Parsimony.Dynamic.DirectOptimization.Internal
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise.FFI
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise.Internal
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise.NeedlemanWunsch
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise.Ukkonen
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise.Ukkonen.Internal
* Analysis.Parsimony.Dynamic.DirectOptimization.Pairwise.Ukkonen.Ribbon
* Analysis.Parsimony.Fitch
* Analysis.Parsimony.Fitch.Internal
* Analysis.Parsimony.Sankoff
* Analysis.Parsimony.Sankoff.Internal
* Analysis.Scoring
* Analysis.TotalEdgeCost
* Bio.Character
* Bio.Character.Decoration.Additive
* Bio.Character.Decoration.Additive.Class
* Bio.Character.Decoration.Additive.Internal
* Bio.Character.Decoration.Continuous
* Bio.Character.Decoration.Continuous.Class
* Bio.Character.Decoration.Continuous.Internal
* Bio.Character.Decoration.Discrete
* Bio.Character.Decoration.Dynamic
* Bio.Character.Decoration.Dynamic.Class
* Bio.Character.Decoration.Dynamic.Internal
* Bio.Character.Decoration.Fitch
* Bio.Character.Decoration.Fitch.Class
* Bio.Character.Decoration.Fitch.Internal
* Bio.Character.Decoration.Metric
* Bio.Character.Decoration.Metric.Class
* Bio.Character.Decoration.Metric.Internal
* Bio.Character.Decoration.NonMetric
* Bio.Character.Decoration.NonMetric.Class
* Bio.Character.Decoration.NonMetric.Internal
* Bio.Character.Decoration.Shared
* Bio.Character.Encodable
* Bio.Character.Encodable.Continuous
* Bio.Character.Encodable.Continuous.Class
* Bio.Character.Encodable.Continuous.Internal
* Bio.Character.Encodable.Dynamic
* Bio.Character.Encodable.Dynamic.Class
* Bio.Character.Encodable.Dynamic.Internal
* Bio.Character.Encodable.Internal
* Bio.Character.Encodable.Static
* Bio.Character.Encodable.Static.Class
* Bio.Character.Encodable.Static.Internal
* Bio.Character.Encodable.Stream
* Bio.Character.Type
* Bio.Graph
* Bio.Graph.BinaryRenderingTree
* Bio.Graph.Component
* Bio.Graph.Constructions
* Bio.Graph.Forest
* Bio.Graph.LeafSet
* Bio.Graph.Node
* Bio.Graph.Node.Context
* Bio.Graph.Node.Internal
* Bio.Graph.PhylogeneticDAG
* Bio.Graph.PhylogeneticDAG.Class
* Bio.Graph.PhylogeneticDAG.DynamicCharacterRerooting
* Bio.Graph.PhylogeneticDAG.Internal
* Bio.Graph.PhylogeneticDAG.NetworkEdgeQuantification
* Bio.Graph.PhylogeneticDAG.Postorder
* Bio.Graph.PhylogeneticDAG.Preorder
* Bio.Graph.PhylogeneticDAG.Reification
* Bio.Graph.ReferenceDAG
* Bio.Graph.ReferenceDAG.Internal
* Bio.Graph.ReferenceDAG.Network
* Bio.Graph.ReferenceDAG.Traversal
* Bio.Graph.ReferenceDAG.Utility
* Bio.Graph.Solution
* Bio.Graph.ZipperDAG
* Bio.Graph.ZipperDAG.Internal
* Bio.Metadata
* Bio.Metadata.CharacterName
* Bio.Metadata.Continuous
* Bio.Metadata.Discrete
* Bio.Metadata.Discrete.Class
* Bio.Metadata.Discrete.Internal
* Bio.Metadata.DiscreteWithTCM
* Bio.Metadata.DiscreteWithTCM.Class
* Bio.Metadata.DiscreteWithTCM.Internal
* Bio.Metadata.Dynamic
* Bio.Metadata.Dynamic.Class
* Bio.Metadata.Dynamic.Internal
* Bio.Metadata.General
* Bio.Metadata.General.Class
* Bio.Metadata.General.Internal
* Bio.Sequence
* Bio.Sequence.Block
* Bio.Sequence.Block.Builder
* Bio.Sequence.Block.Character
* Bio.Sequence.Block.Internal
* Bio.Sequence.Block.Metadata
* Bio.Sequence.Character
* Bio.Sequence.Internal
* Bio.Sequence.Metadata
* Data.EdgeLength
* Data.EdgeSet
* Data.MetricRepresentation
* Data.NodeLabel
* Data.TCM
* Data.TCM.Dense
* Data.TCM.Dense.FFI
* Data.TCM.Internal
* Data.TopologyRepresentation
* Test.Custom.NucleotideSequence
Redundant build-depends entry
* 
* QuickCheck
* bimap
* binary
* bv-little
* cassava
* compact
* containers
* data-default
* deepseq
* dlist
* foldl
* graphviz
* hashable
* keys
* lens
* monad-loops
* mtl
* parallel
* pcg-alphabet
* pcg-analysis
* pcg-data-structures
* pcg-evaluation
* pcg-exportable
* pcg-serialize
* pcg-tcm
* pcg-tcm-memo
* pcg-utility
* pretty-tree
* semigroupoids
* smallcheck
* text
* text-short
* text-show
* text-show-instances
* unordered-containers
* vector
* vector-binary-instances
* vector-instances
* xml

== Section test:analysis-tests ==
Redundant build-depends entry
* 
* pcg-analysis
* pcg-data-structures
* pcg-tcm

== Section test:data-structures-tests ==
Redundant build-depends entry
* 
* pcg-data-structures

== Section test:tcm-tests ==
Redundant build-depends entry
* 
* pcg-tcm
* pcg-tcm-memo

= Package pcg-language =

== Section library ==
Redundant build-depends entry
* 

weeder reports as weeds that the re-exported modules were not compiled, however these modules need to be re-exported from the package's main library as the interface to be consumed by other packages in our code base.

Additionally, weeder reports the internal libraries which are dependencies of other build targets as redundant, however they are require to build the build target and cannot be removed.

I'm hoping to get your input on whether or not these weed reports are expected, they seem to be erroneous from my perspective in this use case.

ndmitchell commented 5 years ago

The problem "module not compiled" is the root of all the issues. The problem is always that https://github.com/ndmitchell/weeder/blob/master/src/Cabal.hs#L52 guesses a set of possible locations the .hi file and associated dump file can be at. In this case, it guessed wrong. My assumption is that https://github.com/ndmitchell/weeder/blob/master/src/Cabal.hs#L75 needs extending to have Library take a Maybe String for the name, and then cabalSectionTypeName if suitably tweaked might make it just work.

ndmitchell commented 4 years ago

Weeder 2.0 is being developed at https://github.com/ocharles/weeder so I suggest you go see if that fixes your issues.