aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-05-18 01:12:13 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-06-13 17:19:34 -0400
commitf3ba24f2892fa4ccf1c6c198190f43d4da44a761 (patch)
treebbc6ada8ffdb27248b0c50c84f99dbf3e40ab31c
parent036181ef6a3e9890a2e50a3b4d84851b15c52e94 (diff)
downloadmeson-f3ba24f2892fa4ccf1c6c198190f43d4da44a761.zip
meson-f3ba24f2892fa4ccf1c6c198190f43d4da44a761.tar.gz
meson-f3ba24f2892fa4ccf1c6c198190f43d4da44a761.tar.bz2
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`.
-rw-r--r--mesonbuild/backend/backends.py11
-rw-r--r--mesonbuild/backend/ninjabackend.py24
-rw-r--r--mesonbuild/backend/vs2010backend.py1
3 files changed, 24 insertions, 12 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 53fd6da..8524bf9 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.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
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 24b7e3c..bcc4c53 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -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'])
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index fd95a6a..32800b5 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -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.