Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto-expose generated modules #373

Open
tim2CF opened this issue Feb 27, 2020 · 2 comments
Open

auto-expose generated modules #373

tim2CF opened this issue Feb 27, 2020 · 2 comments

Comments

@tim2CF
Copy link

tim2CF commented Feb 27, 2020

Hi guys! Is there any way to export all modules from Haskell library? I just have really a lot (hundreds) modules generated by proto-lens tool from Google Protobuf files. It's very inconvenient to write them all manually in exposed-modules section.

Here is example of how it's working now. Just imagine that protobuf schema contains not 2 but ~200 modules which you want to export from your library.

exposed-modules:
- Proto.Person
- Proto.Person_Fields

@judah
Copy link
Collaborator

judah commented Feb 27, 2020

I believe there isn't a way to do this right now, but you bring up a good point. When we originally set this up we had the opposite problem, namely, the set of .protos was large and we only wanted to use a small subset. But for your situtation, a blanket "export all" seems sensible.

Maybe we should change defaultMainGeneratingSpecificProtos to do what you want?

http://hackage.haskell.org/package/proto-lens-setup-0.4.0.3/docs/Data-ProtoLens-Setup.html#v:defaultMainGeneratingSpecificProtos

Currently it filters on exposed-modules/other-modules like defaultMainGeneratingProtos does, but that seems like a mistake given the API (it already takes an explicit list of files). In your Setup.hs you could walk the proto directory (e.g., with callProcess "find") and pass the result into that function.

Alternately, another idea I can think of is to make Data.ProtoLens.Setup change its behavior based on a custom Cabal flag. For example, with hpack:

extra-source-files: proto/**/*.proto
verbatim:
  x-proto-lens-export-all: true

It has the benefit of not being a "breaking" change to defaultMainGeneratingSpecificProtos. It's also simpler for your case since you don't have to walk the tree yourself. The downside is that it adds more complexity to our UX and wouldn't be as flexible (e.g., if you want all protos except one or two).

@tim2CF
Copy link
Author

tim2CF commented Feb 28, 2020

I like option with custom Cabal (I guess will work for Stack as well?) flag for its simplicity of usage. Maybe we can make it more flexible with transition from boolean type to regex type? Then we can have features similar to filtering and negation which will be enough for most cases. Something like this (just dummy example)

extra-source-files: proto/**/*.proto
verbatim:
  x-proto-lens-export: ^proto\/(?!private).+\.proto$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants