ndmitchell / weeder

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

Support cabal projects #28

Open Fresheyeball opened 7 years ago

Fresheyeball commented 7 years ago

This is a very nice tool, and I wish I could use it without stack.

ndmitchell commented 7 years ago

What's the reason for wanting to avoid stack? A simple stack init && weeder should be enough, so you don't have to use stack for day to day development - I don't.

If you do want to use Cabal, that's possible, but requires passing some extra flags to Cabal, then modifying Weeder to find the suitable output files. If there was a volunteer to do that I can give a few pointers.

Fresheyeball commented 6 years ago

I just don't use stack, since I manage haskell dependencies with nix. Can you tell me more about the output files?

ndmitchell commented 6 years ago

Ah, that makes a lot more sense. To a first approximation weeder needs to find the list of cabal files (easy if you aren't using stack), and from there find all the -dump-hi output files, which Stack generates as standard (hence why Stack makes it a lot easier). The options are to compile for Cabal/Nix using -dump-hi, or convert the .hi files after-the-fact. I don't know which one is easier, but happy with either approach.

robcohen commented 6 years ago

I also would like to use nix/cabal with weeder. The CI setup I have does not rely on stack, so that's not an option. If I can figure out how to do this, I'll do my best to submit a patch. If you know of any resources that document how I might do this, please let me know.

robcohen commented 6 years ago

Is it possible you meant "-ddump-hi" as documented here?

ndmitchell commented 6 years ago

Yep, I definitely meant -ddump-hi!

If you want to integrate it the file to replace/augment is https://github.com/ndmitchell/weeder/blob/master/src/Weeder.hs#L37-L42 which calls things in https://github.com/ndmitchell/weeder/blob/master/src/Stack.hs. Basically find the project, make sure it has .hi files and then get its necessary info.

robcohen commented 6 years ago

Thanks a lot, I appreciate the guidance!

cleverca22 commented 6 years ago
mkDerivation = args: super.mkDerivation (args // {
  configureFlags = (args.configureFlags or []) ++ [ "--ghc-options=-ddump-hi" ];
});

if you put this inside your haskell package overrides, it will modify the configureFlags that get passed to cabal, and then you will probably have dump-hi files in every output path

ndmitchell commented 6 years ago

If you demand that anyone who has built with Cabal must have already passed ddump-hi then it probably isn't too hard a problem to solve - just rewriting things to look for cabal files and find hi files in a different place. Ideally in that case it would automatically figure out stack vs Cabal (perhaps with a setting to force one mode or the other).

cleverca22 commented 6 years ago

https://github.com/input-output-hk/cardano-sl/pull/3400 this restructures the file to have multiple haskell overlays, and then an optional overlay that does cabal configure --ghc-options=-ddump-hi for the entire set of haskell packages

Shimuuar commented 5 years ago

So what I found about generating *.dump-hi files using cabal new-build.

  1. One needs to pass both -ddump-hi and -ddump-to-file to GHC. This could be done either using cabal new-build --ghc-option=-ddump-hi --ghc-option=-ddump-to-file ... invocation or using nix overrides.

  2. All *.dump-hi files are located inside dist-newstyle even if project contains multiple packages

  3. cabal doesn't clean up dist-newstyle so it may contain files from older builds. For example if one bumps version in cabal file and rebuilds. dist-newstyle will contain files from both old and new version

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.