Browse Source

Add checks for Blueprint files

To the pre-commit checks, we add the checks about translatable strings,
as well as the check about sorting in blp-resources.in.

We also run `blueprint-compiler format` in CI to make sure that we have
consistent formatting.
fractal-13
Kévin Commaille 7 months ago
parent
commit
7d849ffdf4
No known key found for this signature in database
GPG Key ID: F26F4BE20A08255B
  1. 2
      .gitlab-ci.yml
  2. 11
      .gitlab-ci/check.yml
  3. 82
      hooks/checks.sh
  4. 26
      meson.build
  5. 57
      src/meson.build

2
.gitlab-ci.yml

@ -14,7 +14,7 @@ workflow:
- if: $CI_COMMIT_BRANCH
include:
- local: .gitlab-ci/run_checks.yml
- local: .gitlab-ci/check.yml
- local: .gitlab-ci/build.yml
- local: .gitlab-ci/test.yml
- component: "gitlab.gnome.org/GNOME/citemplates/basic-deploy-docs@master"

11
.gitlab-ci/run_checks.yml → .gitlab-ci/check.yml

@ -2,16 +2,16 @@
include: '.gitlab-ci/utils.yml'
# Custom checks and lints
checks:
# Checks from the pre-commit hook
pre-commit-checks:
stage: check
image: "rustlang/rust:nightly-slim"
interruptible: true
script:
- hooks/checks.sh --verbose --force-install
# Lint the code
cargo-clippy:
# Checks needing dependencies in the Flatpak runtime
flatpak-checks:
extends:
- .remove_build_only_modules
stage: check
@ -21,4 +21,7 @@ cargo-clippy:
interruptible: true
script:
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${FLATPAK_MODULE} flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${MANIFEST_PATH}
# Lint the Rust code
- echo "cargo clippy -- -D warnings" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH}
# Lint the Blueprint files
- echo "blueprint-compiler format ../src" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH}

82
hooks/checks.sh

@ -437,6 +437,8 @@ check_potfiles() {
fi
if [[ ${line:(-3):3} == '.ui' ]]; then
ui_potfiles+=($line)
elif [[ ${line:(-4):4} == '.blp' ]]; then
blp_potfiles+=($line)
elif [[ ${line:(-3):3} == '.rs' ]]; then
rs_potfiles+=($line)
fi
@ -458,6 +460,8 @@ check_potfiles() {
fi
if [[ ${line:(-3):3} == '.ui' ]]; then
ui_skip+=($line)
elif [[ ${line:(-4):4} == '.blp' ]]; then
blp_skip+=($line)
elif [[ ${line:(-3):3} == '.rs' ]]; then
rs_skip+=($line)
fi
@ -471,13 +475,16 @@ check_potfiles() {
fi
# Get UI files with 'translatable="yes"'.
ui_files=(`grep -lIr 'translatable="yes"' src/*`)
ui_files=(`grep -lIr --include=*.ui 'translatable="yes"' src`)
# Get blueprint files with '_('.
blp_files=(`grep -lIr --include=*.blp '_(' src`)
# Get Rust files with regex 'gettext(_f)?\('.
rs_files=(`grep -lIrE 'gettext(_f)?\(' src/*`)
rs_files=(`grep -lIrE --include=*.rs 'gettext(_f)?\(' src`)
# Get Rust files with macros, regex 'gettext!\('.
rs_macro_files=(`grep -lIrE 'gettext!\(' src/*`)
rs_macro_files=(`grep -lIrE --include=*.rs 'gettext!\(' src`)
# Remove common files
to_diff1=("${ui_skip[@]}")
@ -492,6 +499,18 @@ check_potfiles() {
ui_potfiles=("${to_diff1[@]}")
ui_files=("${to_diff2[@]}")
to_diff1=("${blp_skip[@]}")
to_diff2=("${blp_files[@]}")
diff
blp_skip=("${to_diff1[@]}")
blp_files=("${to_diff2[@]}")
to_diff1=("${blp_potfiles[@]}")
to_diff2=("${blp_files[@]}")
diff
blp_potfiles=("${to_diff1[@]}")
blp_files=("${to_diff2[@]}")
to_diff1=("${rs_skip[@]}")
to_diff2=("${rs_files[@]}")
diff
@ -504,7 +523,7 @@ check_potfiles() {
rs_potfiles=("${to_diff1[@]}")
rs_files=("${to_diff2[@]}")
potfiles_count=$((${#ui_potfiles[@]} + ${#rs_potfiles[@]}))
potfiles_count=$((${#ui_potfiles[@]} + ${#blp_potfiles[@]} + ${#rs_potfiles[@]}))
if [[ $potfiles_count -eq 1 ]]; then
echo ""
echo -e "$error Found 1 file in POTFILES.in without translatable strings:"
@ -517,11 +536,14 @@ check_potfiles() {
for file in ${ui_potfiles[@]}; do
echo $file
done
for file in ${blp_potfiles[@]}; do
echo $file
done
for file in ${rs_potfiles[@]}; do
echo $file
done
let files_count=$((${#ui_files[@]} + ${#rs_files[@]}))
let files_count=$((${#ui_files[@]} + ${#blp_files[@]} + ${#rs_files[@]}))
if [[ $files_count -eq 1 ]]; then
echo ""
echo -e "$error Found 1 file with translatable strings not present in POTFILES.in:"
@ -534,6 +556,9 @@ check_potfiles() {
for file in ${ui_files[@]}; do
echo $file
done
for file in ${blp_files[@]}; do
echo $file
done
for file in ${rs_files[@]}; do
echo $file
done
@ -616,6 +641,45 @@ check_resources() {
fi
}
# Check if files in blp-resources.in are sorted alphabetically.
check_blp_resources() {
echo -e "$Checking blp-resources.in…"
local ret=0
local files=()
# Get files.
while read -r line; do
if [[ -n $line && ${line::1} != '#' ]]; then
if [[ ! -f "src/${line}" ]]; then
echo -e "$error File '$line' in blp-resources.in does not exist"
ret=1
fi
files+=($line)
fi
done < src/blp-resources.in
# Check sorted alphabetically
local to_sort=("${files[@]}")
sort
for i in ${!files[@]}; do
if [[ "${files[$i]}" != "${to_sort[$i]}" ]]; then
echo -e "$error Found file '${files[$i]#src/}' before '${to_sort[$i]#src/}' in blp-resources.in"
ret=1
break
fi
done
if [[ ret -eq 1 ]]; then
echo ""
echo -e " Checking blp-resources.in result: $fail"
echo "Please fix the above issues"
exit 1
else
echo -e " Checking blp-resources.in result: $ok"
fi
}
# Install cargo-sort with cargo.
install_cargo_sort() {
echo -e "$Installing cargo-sort…"
@ -728,6 +792,14 @@ else
check_resources "data/resources/resources.gresource.xml"
fi
echo ""
if [[ -n $staged_files ]]; then
if [[ $staged_files = *src/blp-resources.in* ]]; then
check_blp_resources
fi
else
check_blp_resources
fi
echo ""
if [[ $git_staged -eq 1 ]]; then
staged_files=`git diff --name-only --cached | xargs ls -d 2>/dev/null | grep src/ui-resources.gresource.xml`
if [[ -z $staged_files ]]; then

26
meson.build

@ -47,10 +47,10 @@ if build_machine.system() == 'linux'
dependency('libseccomp', version: '>= 2.5.0')
endif
glib_compile_resources = find_program('glib-compile-resources', required: true)
glib_compile_schemas = find_program('glib-compile-schemas', required: true)
desktop_file_validate = find_program('desktop-file-validate', required: false)
appstreamcli = find_program('appstreamcli', required: false)
# 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'
cargo = find_program('cargo', required: true)
cargo_version = run_command(cargo, '--version', check: true).stdout().strip()
@ -58,9 +58,16 @@ message(cargo_version)
rustc_version = run_command('rustc', '--version', check: true).stdout().strip()
message(rustc_version)
blueprint_compiler = find_program('blueprint-compiler', required: true)
blueprint_compiler_version = run_command('blueprint-compiler', '--version', check: true).stdout().strip()
message('blueprint-compiler ' + blueprint_compiler_version)
if not build_env_only
glib_compile_resources = find_program('glib-compile-resources', required: true)
glib_compile_schemas = find_program('glib-compile-schemas', required: true)
desktop_file_validate = find_program('desktop-file-validate', required: false)
appstreamcli = find_program('appstreamcli', required: false)
blueprint_compiler = find_program('blueprint-compiler', required: true)
blueprint_compiler_version = run_command('blueprint-compiler', '--version', check: true).stdout().strip()
message('blueprint-compiler ' + blueprint_compiler_version)
endif
prefix = get_option('prefix')
bindir = prefix / get_option('bindir')
@ -72,11 +79,6 @@ iconsdir = datadir / 'icons'
podir = meson.project_source_root() / 'po'
gettext_package = meson.project_name()
# 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'

57
src/meson.build

@ -1,47 +1,49 @@
# Compile Blueprint resources
blp_files = []
foreach line : fs.read('blp-resources.in').splitlines()
if not build_env_only
# Compile Blueprint resources
blp_files = []
foreach line : fs.read('blp-resources.in').splitlines()
if not line.startswith('#') and line.strip() != ''
blp_files += line
endif
endforeach
endforeach
blueprints = custom_target(
blueprints = custom_target(
'blueprints',
input: blp_files,
output: '.',
command: [blueprint_compiler, 'batch-compile', '@OUTPUT@', '@CURRENT_SOURCE_DIR@', '@INPUT@'],
)
)
# Populate the GResource file for the compiled Blueprint files dynamically,
# using the same file list
compiled_ui_files = ''
foreach file : blp_files
# Populate the GResource file for the compiled Blueprint files dynamically,
# using the same file list
compiled_ui_files = ''
foreach file : blp_files
compiled_ui_files += '\n <file compressed="true" preprocess="xml-stripblanks">' + file.replace('.blp', '.ui') + '</file>'
endforeach
blp_resources_xml = configure_file(
endforeach
blp_resources_xml = configure_file(
input: 'blp-resources.gresource.xml.in',
output: 'blp-resources.gresource.xml',
configuration: { 'UI_FILES': compiled_ui_files }
)
)
blp_resources = gnome.compile_resources(
blp_resources = gnome.compile_resources(
'blp-resources',
blp_resources_xml,
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
dependencies: [blueprints, blp_resources_xml],
)
)
# Compile UI resources
ui_resources = gnome.compile_resources(
# Compile UI resources
ui_resources = gnome.compile_resources(
'ui-resources',
'ui-resources.gresource.xml',
gresource_bundle: true,
install: true,
install_dir: pkgdatadir,
)
)
endif
# Generate config.rs
global_conf = configuration_data()
@ -64,7 +66,7 @@ run_command(
check: true
)
# Build binary with cargo
# Cargo settings
cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ]
cargo_options += [ '--target-dir', meson.project_build_root() / 'src' ]
@ -79,13 +81,9 @@ endif
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
if build_env_only
depends = []
else
depends = [resources, blp_resources, ui_resources]
endif
custom_target(
if not build_env_only
# Build binary with cargo
custom_target(
'cargo-build',
build_by_default: true,
build_always_stale: true,
@ -93,7 +91,7 @@ custom_target(
console: true,
install: true,
install_dir: bindir,
depends: depends,
depends: [resources, blp_resources, ui_resources],
command: [
'env',
cargo_env,
@ -102,7 +100,8 @@ custom_target(
'&&',
'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@',
]
)
)
endif
# Build docs with rustdoc
rustdoc_flags = ' '.join([
@ -146,4 +145,4 @@ custom_target(
cargo, 'doc',
cargo_options + doc_deps + ['--no-deps', '-Zrustdoc-map'] ,
],
)
)

Loading…
Cancel
Save