Repository: mesonbuild/meson

Issue:
build_by_default:false is ignored by mesontest.
I have many targets, all flagged as "build_by_default: false". When I do ninja <target_name> it correctly builds only what is required for that target. But if I do mesontest <test_name> it seems to build everything.


Discussion:
`ninja targetname` will *always* only build what is required for a target. However, `mesontest` will run a `ninja all` before running the test. We might provide an option to turn this off [in the future](https://github.com/mesonbuild/meson/issues/1704), but in the meantime you can run `mesontest --no-rebuild`.

`build_by_default:` is only used for custom targets. It is ignored everywhere else.
Thanks, --no-rebuild is a useful workaround.

In my experience build_by_default is NOT ignored for executables. It is remarkable that Meson builds all targets by default, I think this is a "good thing" in general but build_by_default:false should always work on any target IMO.
Just tried:

mesontest --no-rebuild test-name

It still ended up rebuilding all.
> In my experience build_by_default is NOT ignored for executables. 

Right, we added that feature recently, I forgot about that.

> It still ended up rebuilding all.

That would be a bug, but I cannot reproduce it here with 0.41.1
I was on 0.41.0. Upgraded to 0.41.1, still --no-rebuild rebuilds all.

Even though you said it is ignored, I was still specifying build_by_default:false on the test executables AND the test targets, so I removed that too, still --no-rebuild rebuilds all.
What are the exact steps that you are taking while doing this?
I was on 0.41.0. Upgraded to 0.41.1, still --no-rebuild rebuilds all.

Even though you said it is ignored, I was still specifying build_by_default:false on the test executables AND the test targets, so I removed that too, still --no-rebuild rebuilds all.
It seems there was a misunderstanding what --no-rebuild does: it seems to not build even the test i want to run. Please confirm -- if this is correct, then --no-rebuild is a useless option because there is little value in running unit tests that are out of date.

When I say "mesontest foo", I need it to build foo (and NOT build any other unit test), then run foo. Is there any way to get this behavior? The reason it is needed is that if I am working on one of very many unit tests, I don't want to have to wait for hundreds of files to build (possibly fail to build), just so I can run the one unit test I want to run.
That is currently the case. Either you rebuild all targets or none of them. There has been interest in adding functionality to specify a single test and only compile that one  (and other things it depends on) and then run it.

Until that is done if you know your specific target executable you can do `ninja path/to/targetname` followed by your test command with `--no-rebuild`. It's not great usability but it works.
The suggested workaround does not work for me. After changing a single CPP file, the ninja build compiles just that one file and links, as it should:

`ninja maya_test-error_anim_no_name`
`[2/2] Linking target maya_test-error_anim_no_name.`

Immediately after that, if I issue

`mesontest --no-rebuild maya_test-error_anim_no_name`

it builds/links 106 other targets that use the modified CPP file, then runs maya_test-error_anim_no_name.

P.S. I can't run the unit test directly (outside of mesontest) as it requires specific environment which meson.build sets correctly.
That would be a bug then. Strange.
I don't think there is anything special to reproducing this, but If you need a test case, you can look at https://github.com/zajo/boost-noexcept.git: if you do e.g. `ninja error_test`, it'll build just that, then `mesontest --no-rebuild error_test` builds all other unit tests (warning, the wrap files will download boost as a subproject). I'm on 0.41.1.

Thanks!

Resolving patch:
diff --git a/mesontest.py b/mesontest.py
--- a/mesontest.py
+++ b/mesontest.py
@@ -513,8 +513,6 @@ def run_special(self):
         'Tests run by the user, usually something like "under gdb 1000 times".'
         if self.is_run:
             raise RuntimeError('Can not use run_special after a full run.')
-        if os.path.isfile('build.ninja'):
-            subprocess.check_call([environment.detect_ninja(), 'all'])
         tests = self.get_tests()
         if not tests:
             return 0


Test patch: