1
votes

What's the best way to iterate over all the modules (files) in a given package? Concretely, suppose I have

  1. an executable called "runThis"
  2. a cabal package P with files F1.hs, F2.hs, ..., Fn.hs

Whats the easiest way to execute:

runThis F1.hs
runThis F2.hs
...
runThis Fn.hs 

?

I thought I might try --with-compiler but that fails with

cabal: The program ghc version >=6.4 is required but the version of runThis

(The other option looks like tweaking the Setup.lhs -- but ideally I'd like to hijack the build process and use "runThis" instead of, say, ghc)

Thanks!

1
This mailing list message looks relevant: opensubscriber.com/message/[email protected]/… - Daniel Wagner
What sort of program is runThis? Would something like $ for file in *.hs; do runThis $file; done; do what you want? - Daniel Fischer
Thanks @DanielWagner, that does the trick. Turns out though that it misses hidden modules not mentioned in the .cabal (which I also want) so, its actually easier to do something like what Daniel Fischer suggests (plus using, say, filemanip, to recursively find all *.hs files...) - Ranjit Jhala
@DanielWagner: since your comment was an answer, perhaps you should submit it? - sclv

1 Answers

1
votes

From Duncan Coutts' email:

  1. Question: How to add the preprocessor? I have tried

    main = 
       defaultMainWithHooks 
              simpleUserHooks{hookedPreProcessors=[("foo",transformation)]} 
    
    transformation :: BuildInfo -> LocalBuildInfo -> PreProcessor 
    

That looks right. Here's how to complete it (example taken from the Cabal haddock docs for the PreProcess module):

transformation _ _ = 
  PreProcessor { 
    platformIndependent = True, 
    runPreProcessor = 
      mkSimplePreProcessor $ \inFile outFile verbosity -> do 
        fail $ "transformation: " ++ inFile ++ " " ++ outFile 
  } 

and it works fine:

runghc Setup.hs build 
Preprocessing library foo-1.0... 
Setup.hs: transformation: Abc.foo dist/build/Abc.hs 

But under which circumstances will this function be called? Up to now
I have not succeeded in making cabal call this function.

It calls it when it goes and looks for the module Abc (ie Abc.hs or .lhs), and since if does not find it, it'll check through the list of preprocessors and go looking for the corresponding files, ie Abc.foo.