1

I'm working on a custom ghc plugin. In order to test it out, I want to run it on every package on hackage. I'm running into two difficulties with this.


First, I need to pass the -fplugin=MyPlugin option to ghc when installing packages. The only way I've found to do this is to create the file myghc.sh that contains:

#!/bin/sh
ghc -fplugin=MyPlugin $@

And then run cabal install --with-compiler=./myghc.sh. But then when I run that command, I get the error

Could not find module 'MyPlugin'
it is a member of the hidden package...

So is there a special flag I can pass to cabal install to use my plugin without having to modify every packages' cabal file?


Second, I want my plugin to record information about the package it is compiling, so I need a way for my package to know this information.

It seems like there might be a number of ways to do this, but here's what I've come up with so far. I want a list of hackage packages ordered so that all the dependencies of a package are guaranteed to come before it in the list? Then, when I run cabal install, I can pass the name of the package it is installing to the plugin. Since the dependencies are already installed, I wouldn't have to worry about them getting installed under the wrong name.

Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53

1 Answers1

1

I'm not sure about the second part, but the first part should be possible with a command-line flag to cabal:

cabal install --ghc-option=-fplugin=MyPlugin
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380
  • This still gives the `Could not find module ‘MyPlugin’` error message. – Mike Izbicki Sep 14 '15 at 20:11
  • @MikeIzbicki You can ask `cabal` which exact `ghc` command it's running by setting the verbosity high enough. I recommend you try that, then manually play with the ghc invocation yourself until you figure out what needs to change to make it work; then we can work out how to get `cabal` to invoke ghc in the way that works. – Daniel Wagner Sep 14 '15 at 20:17
  • I guess `--ghc-option="-package MyPluginPackage"` *might* work. At least I can't think of a specific reason why it wouldn't work (given that the plugin package is already installed). – Reid Barton Sep 14 '15 at 23:24
  • After playing around with cabal sandboxes a bit, I managed to get this to work by passing the `package-id` and `package-db` flags to GHC via `-ghc-option` cabal flag. – Mike Izbicki Sep 14 '15 at 23:55
  • I also managed to get a hacked together solution to the second part by creating a script that recusively calling `cabal install --dry-run`. It's not very efficient, and doesn't take advantage of cabal's parallelism, but it works. – Mike Izbicki Sep 14 '15 at 23:57