ninja backend: generate additional meta-rules for test/benchmarks targets

'meson-test-prereq' now depends on any targets that were formerly added
directly to 'all'. Behavior is not changed -- the all target still
depends on this other meta-rule, and thus indirectly depends on all
targets it used to depend on.

It is now possible to build just the targets needed for the testsuite
and then e.g. run `meson test --no-rebuild`.
pull/10404/head
Eli Schwartz 3 years ago
parent 036181ef6a
commit f3ba24f289
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 11
      mesonbuild/backend/backends.py
  2. 24
      mesonbuild/backend/ninjabackend.py
  3. 1
      mesonbuild/backend/vs2010backend.py

@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from collections import OrderedDict
from dataclasses import dataclass, InitVar
@ -1244,10 +1245,12 @@ class Backend:
for name, b in self.build.get_targets().items():
if b.build_by_default:
result[name] = b
# Get all targets used as test executables and arguments. These must
# also be built by default. XXX: Sometime in the future these should be
# built only before running tests.
for t in self.build.get_tests():
return result
def get_testlike_targets(self, benchmark: bool = False) -> T.OrderedDict[str, T.Union[build.BuildTarget, build.CustomTarget]]:
result: T.OrderedDict[str, T.Union[build.BuildTarget, build.CustomTarget]] = OrderedDict()
targets = self.build.get_benchmarks() if benchmark else self.build.get_tests()
for t in targets:
exe = t.exe
if isinstance(exe, (build.CustomTarget, build.BuildTarget)):
result[exe.get_id()] = exe

@ -3272,14 +3272,22 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
self.add_build(elem)
def generate_ending(self):
targetlist = []
for t in self.get_build_by_default_targets().values():
# Add the first output of each target to the 'all' target so that
# they are all built
targetlist.append(os.path.join(self.get_target_dir(t), t.get_outputs()[0]))
elem = NinjaBuildElement(self.all_outputs, 'all', 'phony', targetlist)
self.add_build(elem)
for targ, deps in [
('all', self.get_build_by_default_targets()),
('meson-test-prereq', self.get_testlike_targets()),
('meson-benchmark-prereq', self.get_testlike_targets(True))]:
targetlist = []
# These must also be built by default.
# XXX: Sometime in the future these should be built only before running tests.
if targ == 'all':
targetlist.extend(['meson-test-prereq', 'meson-benchmark-prereq'])
for t in deps.values():
# Add the first output of each target to the 'all' target so that
# they are all built
targetlist.append(os.path.join(self.get_target_dir(t), t.get_outputs()[0]))
elem = NinjaBuildElement(self.all_outputs, targ, 'phony', targetlist)
self.add_build(elem)
elem = self.create_phony_target(self.all_outputs, 'clean', 'CUSTOM_COMMAND', 'PHONY')
elem.add_item('COMMAND', self.ninja_command + ['-t', 'clean'])

@ -358,6 +358,7 @@ class Vs2010Backend(backends.Backend):
def generate_solution(self, sln_filename, projlist):
default_projlist = self.get_build_by_default_targets()
default_projlist.update(self.get_testlike_targets())
sln_filename_tmp = sln_filename + '~'
# Note using the utf-8 BOM requires the blank line, otherwise Visual Studio Version Selector fails.
# Without the BOM, VSVS fails if there is a blank line.

Loading…
Cancel
Save