test executable always built even when build_by_default is false
I have an executable used for testing that has build_by_default set to false because the sources for the test executable are three times the size of the rest of the code and most of the time I don't need it built.
If I create a test() that uses the executable it is always built. I would expect it to only get built if I run ninja test.
This makes sense, we should not build executables that are explicitly not build-by-default till the test is run.
Any hope of this getting fixed?
This makes sense, we should not build executables that are explicitly not build-by-default till the test is run.
I thought it was a conscious design choice in Meson to make sure any test executables get built as part of the build stage and not "on demand" later?
There's actually a fixme about doing this in the ninja backend.
I can give it a go if you'll point me to it
The fixme is here; it's in the generic backend code rather than the ninja-specific backend module.
The fixme implies that "sometime in the future, these (assuming test executables) are only built right before running tests." That might solve the issue, but the build by default setting for the test executable would be redundant.
Suggestion on this expected functionality might be
- if the test executable is build_by_default == True, build it even when not testing.
- if the test executable is build_by_default == False, build it only before a test.
Is there any chance of getting this issued fixed? I am using meson 1.3.1, and if I set build_by default: false in a test executable, it still gets compiled when using meson compile. As noted above, the expected behavior would be that the test should be compiled only when the test is run. The reason I don't want to compile the tests, is that they are not needed for some of my CI runs.
In the current state, it appears that "build_by_default" does nothing, so if this issue isn't resolved, perhaps it would be best to simply remove this option.
I've done some cleanup work on the backend in the past to make it easier to implement this, although I've never gotten around to the final step. I think it's valuable to do, indeed.
Note that the option does do something for targets that aren't used by tests, for example, it's common to have example programs that are only built if you do ninja examples/foobar.exe -- so it cannot be removed from the meson.build language.
The issue is purely, while build_by_default: false does remove a target from being a direct dependency of ninja all, it still has an additional indirect dependency via ninja meson-test-prereq.
You can get the same "problem" if you mark a library as build_by_default: false, then use it as a subproject where the parent project creates an executable that links to the library. The library end up being built by default, but only in a subproject configuration, depending on whether the superproject makes it do so.
That (non test related example) could be a simple documentation issue.
Fwiw I would love to see this tackled and I'm happy to help testing. I won't be able to hack on meson itself though.
On a meson port that I'm working on, apart from the 3-4x longer build times, extra space required, etc the tests have additional dependencies missing on the average person's (or maintainer) setup. I'd really love to avoid having the extra "build-tests" meson toggle, especially since everything is properly annotated as build_by_default:false...
Is there another way to work around this bug?
With the issue fixed (thank you) should the documentation be updated as well?
Currently it states "Those targets are built before test is executed even if they have build_by_default : false."
Hm, I don't think so? Isn't it saying that just like any other dependency relationship between two targets, the dependency will be built when running ninja test even if it is not built when running ninja