Browse Source

Add contributing instructions for running clippy and using Foundry

merge-requests/2152/head
Kévin Commaille 1 week ago
parent
commit
62e9655d01
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B
  1. 3
      .gitignore
  2. 66
      CONTRIBUTING.md
  3. 8
      meson.build
  4. 19
      src/meson.build

3
.gitignore vendored

@ -6,10 +6,11 @@ builddir/
# Cargo # Cargo
target/ target/
# Flatpak # Supported build systems
.flatpak-builder .flatpak-builder
.flatpak .flatpak
.fenv .fenv
.foundry
# Temporary files # Temporary files
*.ui.in~ *.ui.in~

66
CONTRIBUTING.md

@ -51,15 +51,50 @@ If you are building the flatpak manually you will also need flatpak-builder on y
### GNOME Builder ### GNOME Builder
Using [GNOME Builder](https://apps.gnome.org/Builder/) with [flatpak](https://flatpak.org/) is Using [GNOME Builder](https://apps.gnome.org/Builder/) with [Flatpak](https://flatpak.org/) is
the recommended way of building and installing Fractal. the recommended way of building and installing Fractal.
You can find help on cloning and building a project in the [docs of Builder](https://builder.readthedocs.io/). You can find help on cloning and building a project in the [docs of Builder](https://builder.readthedocs.io/).
### Flatpak via fenv To open a build terminal to run commands like [Clippy](#pre-commit), you can use the “+” button at
the left of the header bar of the editor and select “New build terminal”, or use its keyboard
shortcut <kbd>Shift</kbd>+<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>T</kbd>. The terminal should open in
the `_build` directory.
As an alternative, [fenv](https://gitlab.gnome.org/ZanderBrown/fenv) allows to setup a flatpak ### Foundry
environment from the command line and execute commands in that environment.
As an alternative, [Foundry](https://gitlab.gnome.org/GNOME/foundry) is a command line tool with
a lot of features similar to an IDE, which we can also use to develop in a Flatpak environment. It
should be available as the `foundry` package in your distribution.
First, set up the project:
```sh
foundry init
```
Then, you can build and run the application directly:
```sh
foundry run
```
_Note that Foundry will use `.foundry/cache/build` as build directory._
To test changes you make to the code, re-run that last command.
To run commands like [Clippy](#pre-commit) in the build environment, use:
```sh
foundry devenv -- {COMMAND}
```
The command will run in the `.foundry/cache/build` directory by default.
### fenv
Another command line alternative is [fenv](https://gitlab.gnome.org/ZanderBrown/fenv), which focuses
only on developing with Flatpak.
First, install fenv: First, install fenv:
@ -67,7 +102,7 @@ First, install fenv:
cargo install --git https://gitlab.gnome.org/ZanderBrown/fenv fenv cargo install --git https://gitlab.gnome.org/ZanderBrown/fenv fenv
``` ```
After that, setup the project: After that, set up the project:
```sh ```sh
# Set up the flatpak environment # Set up the flatpak environment
@ -88,6 +123,14 @@ _Note that fenv will use `_build` as build directory._
To test changes you make to the code, re-run these two last commands. To test changes you make to the code, re-run these two last commands.
To run commands like [Clippy](#pre-commit) in the build environment, use:
```sh
fenv exec -- {COMMAND}
```
The command will run in the current directory by default.
### Install the flatpak ### Install the flatpak
Some features that interact with the system require the app to be installed to test them (i.e. Some features that interact with the system require the app to be installed to test them (i.e.
@ -134,8 +177,17 @@ quick script that makes sure that the code is correctly formatted with `rustfmt`
things. Make sure that this script is effectively run before submitting your merge request, things. Make sure that this script is effectively run before submitting your merge request,
otherwise CI will probably fail right away. otherwise CI will probably fail right away.
You should also run `cargo clippy` as that will catch common errors and improve the quality of your You should also run [Clippy](https://doc.rust-lang.org/stable/clippy/index.html) as that will catch
submissions and is once again checked by our CI. common errors and improve the quality of your submissions and is once again checked by our CI. To
reuse the same cache as when building Fractal, you should run the following command in a build
environment:
```sh
meson compile -C {BUILD_DIRECTORY} src/cargo-clippy
```
_ The `-C {BUILD_DIRECTORY}` option can be omitted when the command is run from the build
directory._
## Commit ## Commit

8
meson.build

@ -144,10 +144,14 @@ if profile == 'Devel'
message('Pre-commit hook installed') message('Pre-commit hook installed')
else else
if cp_bin_result.returncode() != 0 if cp_bin_result.returncode() != 0
message('Could not install pre-commit binary: ' + cp_bin_result.stderr()) message(
'Could not install pre-commit binary: ' + cp_bin_result.stderr(),
)
endif endif
if cp_hook_result.returncode() != 0 if cp_hook_result.returncode() != 0
message('Could not install pre-commit hook: ' + cp_hook_result.stderr()) message(
'Could not install pre-commit hook: ' + cp_hook_result.stderr(),
)
endif endif
endif endif
endif endif

19
src/meson.build

@ -87,12 +87,13 @@ run_command(
# Cargo settings # Cargo settings
cargo_options = ['--manifest-path', meson.project_source_root() / 'Cargo.toml'] cargo_options = ['--manifest-path', meson.project_source_root() / 'Cargo.toml']
cargo_build_options = cargo_options
if profile == 'Devel' if profile == 'Devel'
rust_target = 'debug' rust_target = 'debug'
message('Building in debug mode') message('Building in debug mode')
else else
cargo_options += ['--release'] cargo_build_options += ['--release']
rust_target = 'release' rust_target = 'release'
message('Building in release mode') message('Building in release mode')
endif endif
@ -112,7 +113,7 @@ if not build_env_only
command: [ command: [
cargo, cargo,
'build', 'build',
cargo_options, cargo_build_options,
'&&', '&&',
'cp', 'cp',
cargo_target_dir / rust_target / meson.project_name(), cargo_target_dir / rust_target / meson.project_name(),
@ -120,6 +121,17 @@ if not build_env_only
], ],
) )
# Lint Rust code with clippy
run_target(
'cargo-clippy',
env: cargo_env,
command: [
cargo,
'clippy',
cargo_options,
],
)
# Run Rust tests with cargo-nextest # Run Rust tests with cargo-nextest
custom_target( custom_target(
'cargo-test', 'cargo-test',
@ -127,8 +139,9 @@ if not build_env_only
output: 'junit.xml', output: 'junit.xml',
console: true, console: true,
depends: [resources, ui_resources], depends: [resources, ui_resources],
env: cargo_env,
command: [ command: [
'env',
cargo_env,
'cargo-nextest', 'cargo-nextest',
'nextest', 'nextest',
'run', 'run',

Loading…
Cancel
Save