-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Thinking: inference of import paths and package names #47
Comments
Proposal: extend the code generator to accept a few command line flags. We can then distinguish the above cases by passing e.g. This would require inverting the control flow with the capnp compile command, but it's easy enough to just invoke it as We can derive the import path from wherever the generated files end up, relative to $GOPATH. The package name can be derived from the last path segment, with some mangling rules to ensure it's a valid name. We can deal with duplication by having the generated packages always give their imports names, so they don't have to care what the "real" package name is. The way those names are generated is less critical, since developers won't have to type them very much. Inverting the control flow with the capnp compiler would also open the door for some other nice things, like adding |
The problem with the command-line flag approach is that other files need to know the file's import path. In seeing the complexity from Go's protoc interaction, I'm thinking that the explicit import path is a good idea. Perhaps just making the output file path logic smarter would help here. |
Yeah, maybe the way to go is to output the files to It would still be nice to not have to patch every schema to use it with Go. |
Was thinking about this again recently, having tackled the path inference problem in the Haskell implementation I'm working on. I'm dubious of the importance of (2); all of the schema I've seen have been variants (1) or (3). And I think people doing (3) will fall into one of two cases:
I'm tempted to suggest that we just require an annotation to do anything but (1). Since we currently require import paths for everything, this is backwards compatible. We require schema to be under $GOPATH, and the import path to Thoughts? |
The discussion in #122 got me thinking again about this issue, but I'd mis-remebered the state of the discussion. I'm still curious as to your thoughts on the above. |
With the upcoming Go Modules and removal of |
I think it works with modules without much modification -- just instead of looking for where you are inside |
I don't have a good solution for this yet, but it has been suggested to me that capnpc-go can/should be inferring the import path and package name for the generated code. This can certainly be introduced in a backward-compatible way, since we currently require import paths and package names to be explicitly annotated, so this is just relaxing the rule. Note that solving this would make #41 obsolete.
Experience has shown me that finding the appropriate Go package boundaries is challenging. Finding a good solution should address the following three use-cases:
The text was updated successfully, but these errors were encountered: