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. 149
      src/meson.build

2
.gitlab-ci.yml

@ -14,7 +14,7 @@ workflow:
- if: $CI_COMMIT_BRANCH - if: $CI_COMMIT_BRANCH
include: include:
- local: .gitlab-ci/run_checks.yml - local: .gitlab-ci/check.yml
- local: .gitlab-ci/build.yml - local: .gitlab-ci/build.yml
- local: .gitlab-ci/test.yml - local: .gitlab-ci/test.yml
- component: "gitlab.gnome.org/GNOME/citemplates/basic-deploy-docs@master" - 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' include: '.gitlab-ci/utils.yml'
# Custom checks and lints # Checks from the pre-commit hook
checks: pre-commit-checks:
stage: check stage: check
image: "rustlang/rust:nightly-slim" image: "rustlang/rust:nightly-slim"
interruptible: true interruptible: true
script: script:
- hooks/checks.sh --verbose --force-install - hooks/checks.sh --verbose --force-install
# Lint the code # Checks needing dependencies in the Flatpak runtime
cargo-clippy: flatpak-checks:
extends: extends:
- .remove_build_only_modules - .remove_build_only_modules
stage: check stage: check
@ -21,4 +21,7 @@ cargo-clippy:
interruptible: true interruptible: true
script: script:
- flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse --stop-at=${FLATPAK_MODULE} flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${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}
# Lint the Rust code
- echo "cargo clippy -- -D warnings" | flatpak-builder --disable-rofiles-fuse --build-shell=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH} - 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 fi
if [[ ${line:(-3):3} == '.ui' ]]; then if [[ ${line:(-3):3} == '.ui' ]]; then
ui_potfiles+=($line) ui_potfiles+=($line)
elif [[ ${line:(-4):4} == '.blp' ]]; then
blp_potfiles+=($line)
elif [[ ${line:(-3):3} == '.rs' ]]; then elif [[ ${line:(-3):3} == '.rs' ]]; then
rs_potfiles+=($line) rs_potfiles+=($line)
fi fi
@ -458,6 +460,8 @@ check_potfiles() {
fi fi
if [[ ${line:(-3):3} == '.ui' ]]; then if [[ ${line:(-3):3} == '.ui' ]]; then
ui_skip+=($line) ui_skip+=($line)
elif [[ ${line:(-4):4} == '.blp' ]]; then
blp_skip+=($line)
elif [[ ${line:(-3):3} == '.rs' ]]; then elif [[ ${line:(-3):3} == '.rs' ]]; then
rs_skip+=($line) rs_skip+=($line)
fi fi
@ -471,13 +475,16 @@ check_potfiles() {
fi fi
# Get UI files with 'translatable="yes"'. # 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)?\('. # 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!\('. # 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 # Remove common files
to_diff1=("${ui_skip[@]}") to_diff1=("${ui_skip[@]}")
@ -492,6 +499,18 @@ check_potfiles() {
ui_potfiles=("${to_diff1[@]}") ui_potfiles=("${to_diff1[@]}")
ui_files=("${to_diff2[@]}") 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_diff1=("${rs_skip[@]}")
to_diff2=("${rs_files[@]}") to_diff2=("${rs_files[@]}")
diff diff
@ -504,7 +523,7 @@ check_potfiles() {
rs_potfiles=("${to_diff1[@]}") rs_potfiles=("${to_diff1[@]}")
rs_files=("${to_diff2[@]}") rs_files=("${to_diff2[@]}")
potfiles_count=$((${#ui_potfiles[@]} + ${#rs_potfiles[@]})) potfiles_count=$((${#ui_potfiles[@]} + ${#blp_potfiles[@]} + ${#rs_potfiles[@]}))
if [[ $potfiles_count -eq 1 ]]; then if [[ $potfiles_count -eq 1 ]]; then
echo "" echo ""
echo -e "$error Found 1 file in POTFILES.in without translatable strings:" echo -e "$error Found 1 file in POTFILES.in without translatable strings:"
@ -517,11 +536,14 @@ check_potfiles() {
for file in ${ui_potfiles[@]}; do for file in ${ui_potfiles[@]}; do
echo $file echo $file
done done
for file in ${blp_potfiles[@]}; do
echo $file
done
for file in ${rs_potfiles[@]}; do for file in ${rs_potfiles[@]}; do
echo $file echo $file
done done
let files_count=$((${#ui_files[@]} + ${#rs_files[@]})) let files_count=$((${#ui_files[@]} + ${#blp_files[@]} + ${#rs_files[@]}))
if [[ $files_count -eq 1 ]]; then if [[ $files_count -eq 1 ]]; then
echo "" echo ""
echo -e "$error Found 1 file with translatable strings not present in POTFILES.in:" 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 for file in ${ui_files[@]}; do
echo $file echo $file
done done
for file in ${blp_files[@]}; do
echo $file
done
for file in ${rs_files[@]}; do for file in ${rs_files[@]}; do
echo $file echo $file
done done
@ -616,6 +641,45 @@ check_resources() {
fi 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 with cargo.
install_cargo_sort() { install_cargo_sort() {
echo -e "$Installing cargo-sort…" echo -e "$Installing cargo-sort…"
@ -728,6 +792,14 @@ else
check_resources "data/resources/resources.gresource.xml" check_resources "data/resources/resources.gresource.xml"
fi fi
echo "" 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 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` staged_files=`git diff --name-only --cached | xargs ls -d 2>/dev/null | grep src/ui-resources.gresource.xml`
if [[ -z $staged_files ]]; then if [[ -z $staged_files ]]; then

26
meson.build

@ -47,10 +47,10 @@ if build_machine.system() == 'linux'
dependency('libseccomp', version: '>= 2.5.0') dependency('libseccomp', version: '>= 2.5.0')
endif endif
glib_compile_resources = find_program('glib-compile-resources', required: true) # When the `build-env` profile is used, we only want to set up the build
glib_compile_schemas = find_program('glib-compile-schemas', required: true) # environment for the sandbox, we will not try to compile the app, so we can
desktop_file_validate = find_program('desktop-file-validate', required: false) # remove some build steps.
appstreamcli = find_program('appstreamcli', required: false) build_env_only = get_option('profile') == 'build-env'
cargo = find_program('cargo', required: true) cargo = find_program('cargo', required: true)
cargo_version = run_command(cargo, '--version', check: true).stdout().strip() 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() rustc_version = run_command('rustc', '--version', check: true).stdout().strip()
message(rustc_version) message(rustc_version)
blueprint_compiler = find_program('blueprint-compiler', required: true) if not build_env_only
blueprint_compiler_version = run_command('blueprint-compiler', '--version', check: true).stdout().strip() glib_compile_resources = find_program('glib-compile-resources', required: true)
message('blueprint-compiler ' + blueprint_compiler_version) 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') prefix = get_option('prefix')
bindir = prefix / get_option('bindir') bindir = prefix / get_option('bindir')
@ -72,11 +79,6 @@ iconsdir = datadir / 'icons'
podir = meson.project_source_root() / 'po' podir = meson.project_source_root() / 'po'
gettext_package = meson.project_name() 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 if get_option('profile') == 'development' or build_env_only
profile = 'Devel' profile = 'Devel'
application_id += '.Devel' application_id += '.Devel'

149
src/meson.build

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

Loading…
Cancel
Save