-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow configure_file, custom_target and generator output to subdirectories under build dir #2613
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
Allow configure_file, custom_target and generator output to subdirectories under build dir #2613
Conversation
This should allow correct and efficient compilation of protobuf and other source generators that assumes its output is a directory tree instead of a flatten dir. Should also import Java source generation since we can now write java code to subdirectories according to its package.
Also add a @RootName@ substitution which is replaced by full input path name with extensions removed.
Tests added: - unittest for @RootName@ substitution, configure_file - test case for configure_file into subdirectories - replace over-simplified protobuf test case with a complex one to test custom_target and generator that outputs to subdirs
|
No! The layout of the build directory is not something users should have control over. It is fully chosen by the backend and different backends do things differently. We can not allow people to throw things in the build dir at random because that breaks things in subtle ways. If there are problems with some tools or frameworks, then we need to come up with proper solutions for those. |
…utputting to subdir is now allowed with this patch. Test "output escaping" make sure people cannot make their output escape by adding '..' in output path name.
|
The problem is that even though perhaps people should not be given the control over the entire build directory layout (e.g. the object files), they should and need to have control to at least their generated sources, or all kinds of problems will occur. The problem about having to install a |
|
In what way does the Protobuf compiler require a directory tree for its output? I tested this and the generated code has include statements that look like the following: |
|
Protobuf definitions themselves may have directory structures, which is quite a common practice. For example, you can have and in foo.proto you This will generate a source subtree that mirrors the proto tree structure. And in the generated foo.pb.h, it will |
mesonbuild/build.py
Outdated
| raise InvalidArguments('"outputs" must not contain a directory separator.') | ||
| if '@BASENAME@' not in rule and '@PLAINNAME@' not in rule and '@ROOTNAME@' not in rule: | ||
| raise InvalidArguments('Every element of "output" must contain @BASENAME@, @PLAINNAME@ or @ROOTNAME@.') | ||
| if '..' in path_norm_split(rule): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just use pathlib.PurePath and then check .parts for ...
…ng --layout flat builds. Note that currently building complex protobuf with --layout flat still WON'T work, since @CURRENT_SOURCE_DIR@ will be incorrectly substituted with '../meson-out', which is obviously not our source dir. Backend.get_target_source_dir seems a little buggy right now. It seems not taking layout --flat into consideration. Maybe I should also try to fix it?
|
I created a bug report on Protobuf to support exporting a flat layout, which seems like the correct solution. However that might not get fixed soon (or possibly ever :( ) so we should probably come up with some interim solution. First of all protobuf seems such a complicated thing that we should probably create a proper module for it so people can just do: rather than playing around with generators and the like. Secondly, even though we won't let people write randomly to the build dir, we can do that inside the target private directory. |
|
To be honest, making Protobuf (and perhaps other source generators like aidl in #2539) change their way of generating codes to just fit meson the build system does not seem to be the correct solution to me. There are too much existing codes out there (and inside google perhaps) which may not fit into this change. After all, build systems are there to provide people tools to build things, not to teach people how to do things correctly or make them cope with the build system. It should be more important to first allow people to build these existing projects up, isn't it? And I really do not feel we can ever push all these IDLs , code generators and custom commands to change their way just for one of our design choices. As for the target private directory approach, I still feel if we really hate giving away a little control over the build dir so much we should fix it by inventing something like And for the proto module approach, I appreciate that, though I still would like a clean solution to install a |
You can already do this with, roughly: and then using pblib. Hmmm, thinking more about it, there might be some dependency issue if you need to use the pb headers directly.
You really should not install a |
Yes, pb headers are almost always used directly in application code, and occasionly installed as public headers for other projects.
The boost guys install a ton of |
|
Travis issues seems to be the compatibility between protobuf 3.0.0 and meson's unity build mode, since the error is a compilation one involving redefinition of protobuf internal functions. The issue emerged because I replaced the single-file test case with a complex one that involved some seven or more |
|
I agree with jasonszang, not every projects or gentools need or support a flat layout, everyone like creating a subdir to hold some files with same name, rather than give different name in a same directory. |
|
Are there any more thoughts on this pr, or other solutions to our protobuf problem (that everyone will bump on when they begin to use complex protos)? Since it looks like that the protobuf guys are not quite keen to adopt a flat output layout. |
|
Closed because meson does not satisfy our requirements of building complex proto based projects and there seem to be zero chance to change that in foreseeable future. |
|
It's a bummer this never got merged. Doing script acrobatics in order to satisfy the build system is not how the build system should be working. |
This patch improve flexibility in source code generation by allowing these three source generating functions output to subdirectories of the current build dir. This is needed for protobuf and other generators / languages that assume generated code to be a subtree instead of a flat directory.
It also allows configuring headers like
config.handversion.hinto a project specific subdir and then#include <your_prg/config.h>. No longer needed to config and installfoo-config.hdirectly into/usr/local/include.This fixes #2320. And hopefully #2539, or at least should make things closer.