From 254644290c088bdf6781bbbf3b18f4e051c38963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Sun, 8 Mar 2026 13:09:00 +0100 Subject: [PATCH] build: Clean up meson files Use `env` parameter instead of adding it to the command, and copy the hook rather than adding a symbolic link to it to avoid losing it with `cargo clean`. --- meson.build | 48 +++++++++++++++++++++++++----------------------- src/meson.build | 10 +++------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/meson.build b/meson.build index d3127987..84c25075 100644 --- a/meson.build +++ b/meson.build @@ -116,36 +116,38 @@ if profile == 'Devel' release_date = run_command('git', 'show', '-s', '--format=%cI', check: true).stdout().strip() # Setup pre-commit hook for ensuring coding style is always consistent - checks_build_result = run_command( - 'env', - cargo_env, + message('Compiling pre-commit binary…') + run_command( cargo, 'build', '--manifest-path', 'hooks/checks/Cargo.toml', check: true, + env: cargo_env, + ) + cp_bin_result = run_command( + 'cp', + '-f', + cargo_target_dir / 'debug/checks', + 'hooks/checks-bin', + check: false, + ) + cp_hook_result = run_command( + 'cp', + '-f', + 'hooks/pre-commit.hook', + '.git/hooks/pre-commit', + check: false, ) - if checks_build_result.returncode() == 0 - run_command( - 'ln', - '-s', - cargo_target_dir / 'debug/checks', - 'hooks/checks-bin', - check: false, - ) - cp_result = run_command( - 'cp', - '-f', - 'hooks/pre-commit.hook', - '.git/hooks/pre-commit', - check: false, - ) - - if cp_result.returncode() == 0 - message('Pre-commit hook installed') - else - message('Could not install pre-commit hook: ' + cp_result.stderr()) + if cp_bin_result.returncode() == 0 and cp_hook_result.returncode() == 0 + message('Pre-commit hook installed') + else + if cp_bin_result.returncode() != 0 + message('Could not install pre-commit binary: ' + cp_bin_result.stderr()) + endif + if cp_hook_result.returncode() != 0 + message('Could not install pre-commit hook: ' + cp_hook_result.stderr()) endif endif endif diff --git a/src/meson.build b/src/meson.build index e9c3c943..855a0cf8 100644 --- a/src/meson.build +++ b/src/meson.build @@ -108,9 +108,8 @@ if not build_env_only install: true, install_dir: bindir, depends: [resources, ui_resources], + env: cargo_env, command: [ - 'env', - cargo_env, cargo, 'build', cargo_options, @@ -128,9 +127,8 @@ if not build_env_only output: 'junit.xml', console: true, depends: [resources, ui_resources], + env: cargo_env, command: [ - 'env', - cargo_env, 'cargo-nextest', 'nextest', 'run', @@ -180,13 +178,11 @@ cargo_doc_options = ['--package=fractal', '--no-deps', '-Zrustdoc-map'] custom_target( 'cargo-doc', - build_by_default: false, build_always_stale: true, output: 'doc', console: true, + env: cargo_env + cargo_doc_env, command: [ - 'env', - cargo_env + cargo_doc_env, cargo, 'doc', cargo_options + cargo_doc_options,