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

test executable always built even when build_by_default is false #2518

Closed
adrianjohnson opened this issue Oct 22, 2017 · 10 comments
Closed

test executable always built even when build_by_default is false #2518

adrianjohnson opened this issue Oct 22, 2017 · 10 comments

Comments

@adrianjohnson
Copy link

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.

@nirbheek
Copy link
Member

This makes sense, we should not build executables that are explicitly not build-by-default till the test is run.

@pdietl
Copy link
Contributor

pdietl commented Feb 7, 2019

Any hope of this getting fixed?

@tp-m
Copy link
Member

tp-m commented Feb 7, 2019

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?

@dcbaker
Copy link
Member

dcbaker commented Feb 7, 2019

There's actually a fixme about doing this in the ninja backend.

@pdietl
Copy link
Contributor

pdietl commented Feb 7, 2019

I can give it a go if you'll point me to it

@mthuurne
Copy link
Contributor

The fixme is here; it's in the generic backend code rather than the ninja-specific backend module.

@kayakMike
Copy link
Contributor

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.

@dcbaker dcbaker self-assigned this Aug 30, 2019
bgilbert added a commit to bgilbert/jxrlib that referenced this issue Dec 16, 2022
Ideally download and test would be split into two separate build rules,
but currently that would cause cases to be downloaded during a normal
build: mesonbuild/meson#2518
@MarkWieczorek
Copy link

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.

@eli-schwartz
Copy link
Member

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.

simo5 added a commit to simo5/pkcs11-provider that referenced this issue Apr 23, 2024
This way they get built before the tests are run if not already

We mark these binary as not build by default, but that does nothing
because mesonbuild/meson#2518 which has
been open for only 6+ years now [face-palm.gif]

Signed-off-by: Simo Sorce <[email protected]>
simo5 added a commit to simo5/pkcs11-provider that referenced this issue Apr 23, 2024
This way they get built before the tests are run if not already

We mark these binary as not build by default, but that does nothing
because mesonbuild/meson#2518 which has
been open for only 6+ years now [face-palm.gif]

Signed-off-by: Simo Sorce <[email protected]>
simo5 added a commit to simo5/pkcs11-provider that referenced this issue Apr 23, 2024
This way they get built before the tests are run if not already

We mark these binary as not build by default, but that does nothing
because mesonbuild/meson#2518 which has
been open for only 6+ years now [face-palm.gif]

Signed-off-by: Simo Sorce <[email protected]>
simo5 added a commit to latchset/pkcs11-provider that referenced this issue Apr 24, 2024
This way they get built before the tests are run if not already

We mark these binary as not build by default, but that does nothing
because mesonbuild/meson#2518 which has
been open for only 6+ years now [face-palm.gif]

Signed-off-by: Simo Sorce <[email protected]>
@evelikov
Copy link

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?

meator added a commit to enkore/j4-dmenu-desktop that referenced this issue Nov 30, 2024
It does not make sense to tell users to build the main target
(j4-dmenu-desktop) specifically when `meson install` will build
everything anyway.

I would prefer j4-dmenu-tests **not** being built during install, but
that's how Meson works for now. See mesonbuild/meson#2518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet