-
Notifications
You must be signed in to change notification settings - Fork 723
Description
Hey, Cabal team.
Some time ago, I had to integrate Apache Thrift in one of my projects. But, I faced issues with HookedPreprocessors.
Let's say, that we have a preprocessor that can translate files with the .foo extension. If you declare some module in your exposed-modules (f.e. Test.Module), then Cabal will look for the file named Test.Module.foo and run the preprocessor for it. It is one-to-one correspondence.
Now, we have Apache Thrift. The preprocessor can parse Thrift DSL and generate protocols and RPC servers/clients. But, it will translate single Module.thrift file in many others: Module_Types.hs, Module_Consts.hs, RPCPoint_Iface.hs, RPCPoint_Client.hs. The first two files correspond to the source file, while the rest correspond to a single RPCPoint service inside the Module.thrift. There can be other interface/client files, if you declare more services in the Module.thrift.
So, here is a problem: Cabal finds Test.Module in exposed-modules sections, finds Test/Module.thrift among source files and thinks that's it, but after the preprocessing stage, there is no Module.hs among the build files. On the other hand, if you declare Module_Types/Module_Consts and others in your exposed-modules section, that Cabal will ignore Module.thrift source file.
What I did in my project:
- I've placed the single pattern
thrift/*.thriftin theextra-source-filesfield. - I've written custom
Setup.hsfile with overloadedbuildHook/testHook. Before running the default hook, they will call the thrift preprocessor for every file matching the pattern inextraSrcFileswith the destinationbuildDir.
This approach works, but I don't like it:
- Files specific for the build are listed in a global parameter.
- Part of preprocessing stage is placed in the
buildHook. Also, I have duplicated code in thetestHook(and I would have it in thebenchHook, if I needed to). - There are other preprocessors with similar problems.
I suggest to remove pattern matching on preprocessor stage at all. I think, time savings in case of dropping unnecessary files doesn't make a difference.
P.S. Here is a link on my Setup.hs