Browse Source

ci: Use meson to run cargo tests

This will allow to run tests that require the GResource files to be
compiled.
merge-requests/2136/head
Kévin Commaille 3 months ago
parent
commit
72804fa3e6
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B
  1. 10
      .gitlab-ci/test.yml
  2. 14
      meson.build
  3. 3
      nextest.toml.in
  4. 40
      src/meson.build

10
.gitlab-ci/test.yml

@ -20,8 +20,6 @@ lint-metainfo:
# Run the Rust tests.
rust-tests:
extends:
- .remove_build_only_modules
stage: test
image: 'quay.io/gnome_infrastructure/gnome-runtime-images:gnome-master'
tags:
@ -37,11 +35,11 @@ rust-tests:
# Initialize the Flatpak sandbox.
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${FLATPAK_MODULE} flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${MANIFEST_PATH}
# Run the tests.
- echo "cargo-nextest nextest run --config-file ../.gitlab-ci/nextest.toml" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH}
- echo "meson compile src/cargo-test" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH}
dependencies: []
artifacts:
reports:
junit: '.flatpak-builder/build/${FLATPAK_MODULE}/target/nextest/default/junit.xml'
junit: '.flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/src/junit.xml'
# Test that there are no errors in the docs.
build-docs:
@ -62,8 +60,8 @@ build-docs:
# Do not use the mold linker because it doesn't work with the rust-nightly extension at the moment
- sed -i 's|-C link-arg=-fuse-ld=mold||g' ${MANIFEST_PATH}
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${FLATPAK_MODULE} flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${MANIFEST_PATH}
- echo "ninja src/doc" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH}
- tar --auto-compress --create --file "${CI_PROJECT_DIR}/${CI_PROJECT_NAME}-docs.tar.gz" --directory ".flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/cargo-target/doc" .
- echo "meson compile src/cargo-doc" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH}
- tar --auto-compress --create --file "${CI_PROJECT_DIR}/${CI_PROJECT_NAME}-docs.tar.gz" --directory ".flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/src/doc" .
dependencies: []
artifacts:
paths:

14
meson.build

@ -3,7 +3,7 @@ project(
'rust',
version: '13',
license: 'GPL-3.0-or-later',
meson_version: '>= 1.2',
meson_version: '>= 1.4',
)
fs = import('fs')
@ -112,6 +112,18 @@ if profile == 'Devel'
run_command('cp', '-f', 'hooks/pre-commit.hook', '.git/hooks/pre-commit')
endif
# Generate nextest config file
# We generate it dynamically to put the test report inside the build directory,
# like all other artefacts
nextest_store_dir = meson.project_build_root() / 'nextest'
nextest_data = configuration_data()
nextest_data.set_quoted('STORE_DIR', nextest_store_dir)
nextest_config = configure_file(
input: 'nextest.toml.in',
output: 'nextest.toml',
configuration: nextest_data,
)
if not build_env_only
subdir('data')
subdir('po')

3
.gitlab-ci/nextest.toml → nextest.toml.in

@ -1,3 +1,6 @@
[store]
dir = @STORE_DIR@
[profile.default]
fail-fast = false

40
src/meson.build

@ -87,9 +87,6 @@ run_command(
# Cargo settings
cargo_options = ['--manifest-path', meson.project_source_root() / 'Cargo.toml']
target_dir = meson.project_build_root() / 'cargo-target'
cargo_options += ['--target-dir', target_dir]
if profile == 'Devel'
rust_target = 'debug'
message('Building in debug mode')
@ -99,7 +96,12 @@ else
message('Building in release mode')
endif
cargo_env = ['CARGO_HOME=' + meson.project_build_root() / 'cargo-home']
cargo_target_dir = meson.project_build_root() / 'cargo-target'
cargo_env = [
'CARGO_HOME=' + meson.project_build_root() / 'cargo-home',
'CARGO_TARGET_DIR=' + cargo_target_dir,
]
if not build_env_only
# Build binary with cargo
@ -120,7 +122,30 @@ if not build_env_only
cargo_options,
'&&',
'cp',
target_dir / rust_target / meson.project_name(),
cargo_target_dir / rust_target / meson.project_name(),
'@OUTPUT@',
],
)
# Run Rust tests with cargo-nextest
custom_target(
'cargo-test',
build_always_stale: true,
output: 'junit.xml',
console: true,
depends: [resources, ui_resources],
command: [
'env',
cargo_env,
'cargo-nextest',
'nextest',
'run',
cargo_options,
'--config-file',
nextest_config.full_path(),
'&&',
'cp',
nextest_store_dir / 'default/junit.xml',
'@OUTPUT@',
],
)
@ -169,5 +194,10 @@ custom_target(
cargo,
'doc',
cargo_options + doc_deps + ['--no-deps', '-Zrustdoc-map'],
'&&',
'cp',
'-r',
cargo_target_dir / 'doc',
'@OUTPUT@',
],
)

Loading…
Cancel
Save