From d161a5842465a9528dad75ae6c0ec3062c668faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 5 May 2025 12:59:56 +0200 Subject: [PATCH] ci: Don't build unnecessary Flatpak modules when they are not needed --- .gitlab-ci/run_checks.yml | 4 ++++ .gitlab-ci/test.yml | 22 ++++++++++++++++------ .gitlab-ci/utils.yml | 16 ++++++++++++++++ meson.build | 14 +++++++++++--- meson.options | 1 + src/meson.build | 8 +++++++- 6 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 .gitlab-ci/utils.yml diff --git a/.gitlab-ci/run_checks.yml b/.gitlab-ci/run_checks.yml index 88260e50..05cfde70 100644 --- a/.gitlab-ci/run_checks.yml +++ b/.gitlab-ci/run_checks.yml @@ -1,5 +1,7 @@ # Configure and run code checks +include: '.gitlab-ci/utils.yml' + # Custom checks and lints checks: stage: check @@ -9,6 +11,8 @@ checks: # Lint the code cargo-clippy: + extends: + - .remove_build_only_modules stage: check image: 'quay.io/gnome_infrastructure/gnome-runtime-images:gnome-master' tags: diff --git a/.gitlab-ci/test.yml b/.gitlab-ci/test.yml index 2f87447b..f8871d75 100644 --- a/.gitlab-ci/test.yml +++ b/.gitlab-ci/test.yml @@ -1,5 +1,7 @@ # Tests after the app is built. +include: '.gitlab-ci/utils.yml' + # Validate the metainfo with Flathub's tool. lint-metainfo: stage: test @@ -17,17 +19,23 @@ 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: - flatpak - variables: - TMP_MANIFEST_PATH: "build-aux/org.gnome.Fractal.CiRust.json" script: - # Add a module for nextest to the Flatpak manifest - - jq --slurpfile nextest .gitlab-ci/nextest.module.json '.modules = [$nextest[], .modules[]]' ${MANIFEST_PATH} > ${TMP_MANIFEST_PATH} - - flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${FLATPAK_MODULE} flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${TMP_MANIFEST_PATH} - - echo "cargo-nextest nextest run --config-file ../.gitlab-ci/nextest.toml" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${TMP_MANIFEST_PATH} + # Create a temporary file. + - TMP_FILE=$(mktemp) + # Add a module for nextest to the Flatpak manifest and write it to the temporary file. + - jq --slurpfile nextest .gitlab-ci/nextest.module.json '.modules = [$nextest[], .modules[]]' ${MANIFEST_PATH} > ${TMP_FILE} + # Replace the manifest with the temporary file. + - mv $TMP_FILE ${MANIFEST_PATH} + # 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} dependencies: [] artifacts: reports: @@ -35,6 +43,8 @@ rust-tests: # Test that there are no errors in the docs. build-docs: + extends: + - .remove_build_only_modules stage: test image: 'quay.io/gnome_infrastructure/gnome-runtime-images:gnome-master' tags: diff --git a/.gitlab-ci/utils.yml b/.gitlab-ci/utils.yml new file mode 100644 index 00000000..7a66477e --- /dev/null +++ b/.gitlab-ci/utils.yml @@ -0,0 +1,16 @@ +# Utilities to include in other jobs. + +# Remove the Flatpak modules that are only necessary when building the app with meson. +.remove_build_only_modules: + variables: + # JSON array of the names of the Flatpak modules to remove. + MODULES_TO_REMOVE: '["grass", "glycin-loaders"]' + before_script: + # Create a temporary file. + - TMP_FILE=$(mktemp) + # Remove the modules in the manifest and write the output to the temporary file. + - jq --argjson modules_to_remove "${MODULES_TO_REMOVE}" 'del(.modules[] | select(IN(.name; $modules_to_remove | .[])))' ${MANIFEST_PATH} > $TMP_FILE + # Replace the manifest with the temporary file. + - mv $TMP_FILE ${MANIFEST_PATH} + # Use meson's build-env profile. + - sed -i "s|-Dprofile=development|-Dprofile=build-env|g" ${MANIFEST_PATH} diff --git a/meson.build b/meson.build index 0edc6523..5d3d0685 100644 --- a/meson.build +++ b/meson.build @@ -66,7 +66,12 @@ iconsdir = datadir / 'icons' podir = meson.project_source_root() / 'po' gettext_package = meson.project_name() -if get_option('profile') == 'development' +# When the `build-env` profile is used, we only want to set up the build +# environment for the sandbox, we will not try to compile the app, so we can +# remove some build steps. +build_env_only = get_option('profile') == 'build-env' + +if get_option('profile') == 'development' or build_env_only profile = 'Devel' application_id += '.Devel' elif get_option('profile') == 'hack' @@ -94,8 +99,11 @@ if profile == 'Devel' run_command('cp', '-f', 'hooks/pre-commit.hook', '.git/hooks/pre-commit') endif -subdir('data') -subdir('po') +if not build_env_only + subdir('data') + subdir('po') +endif + subdir('src') gnome.post_install( diff --git a/meson.options b/meson.options index 25860d47..5b482bf7 100644 --- a/meson.options +++ b/meson.options @@ -6,6 +6,7 @@ option( 'beta', 'development', 'hack', + 'build-env', ], value: 'default', description: 'The build profile for Fractal. One of "default", "beta", "development" or "hack".' diff --git a/src/meson.build b/src/meson.build index 0210c295..4f7c3c2b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -42,6 +42,12 @@ endif cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ] +if build_env_only + depends = [] +else + depends = [resources, ui_resources] +endif + custom_target( 'cargo-build', build_by_default: true, @@ -50,7 +56,7 @@ custom_target( console: true, install: true, install_dir: bindir, - depends: [resources, ui_resources], + depends: depends, command: [ 'env', cargo_env,