feat(gschema-overrides): Make include array truly optional & includ… (#360)

* feat(gschema-overrides): Make `include` array truly optional & include all gschemas by default

* chore(gschema-overrides): Make recipe input matching log a bit clearer

* docs(gschema-overrides): Make some points clearer

* docs(gschema-overrides): Fix some unfinished line

* docs(gschema-override): Some indentation fixes

* docs(gschema-overrides): Remove redundant comment in module.yml
This commit is contained in:
fiftydinar 2024-11-14 21:08:48 +01:00 committed by GitHub
parent 9368c5dc5e
commit f176a3516e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 35 deletions

View file

@ -7,7 +7,7 @@ This module is similar to using `dconf` configuration, but is better because it
What does this module do?
- It copies all content from `/usr/share/glib-2.0/schemas/`, except existing gschema.overrides to avoid conflicts, into temporary test location.
- It copies your gschema.overrides you provided in this module from `files/gschema-overrides/` into temporary test location.
- It copies all your included gschema.overrides by default or schemas you strictly specified in the module recipe from `files/gschema-overrides/` into temporary test location.
- It tests them for errors in temporary test location by using `glib-compile-schemas` with `--strict` flag. If errors are found, build will fail.
- If test is passed successfully, it copies your gschema.overrides to `/usr/share/glib-2.0/schemas/`.
- It compiles gschema using `glib-compile-schemas` in `/usr/share/glib-2.0/schemas/` location to include your changes.
@ -22,7 +22,9 @@ To use this module, you need to include your gschema.override file(s) in this lo
`files/gschema-overrides/`
Then you need to include those file(s) in recipe file, like in example configuration.
Then you can just set `type: gschema-overrides` in module recipe & be good to go.
Optionally, you can include only specific file(s) in the module recipe, if you don't want every gschema override, like in example configuration.
It is highly recommended to use `zz1-` prefix before your gschema.override name, to ensure that your changes are going to be applied.

View file

@ -4,49 +4,87 @@ set -euo pipefail
get_yaml_array INCLUDE '.include[]' "$1"
schema_include_location="${CONFIG_DIRECTORY}/gschema-overrides"
schema_test_location="/tmp/bluebuild-schema-test"
schema_location="/usr/share/glib-2.0/schemas"
gschema_extension=false
SCHEMA_INCLUDE_LOCATION="${CONFIG_DIRECTORY}/gschema-overrides"
SCHEMA_TEST_LOCATION="/tmp/bluebuild-schema-test"
SCHEMA_LOCATION="/usr/share/glib-2.0/schemas"
readarray -t MODULE_FILES < <(find "${SCHEMA_INCLUDE_LOCATION}" -type f)
readarray -t SCHEMA_MODULE_FILES < <(find "${SCHEMA_INCLUDE_LOCATION}" -type f -name "*.gschema.override" -printf "%f\n")
echo "Installing gschema-overrides module"
# Abort build if file in module is not included
if [[ ${#INCLUDE[@]} == 0 ]]; then
echo "Module failed because gschema-overrides aren't included into the module."
# Abort the build if no files are found in ${SCHEMA_INCLUDE_LOCATION}
if [[ ${#MODULE_FILES[@]} -eq 0 ]]; then
echo "ERROR: You don't have any files in '${SCHEMA_INCLUDE_LOCATION/#\/tmp/}/' location inside the repo"
echo " Please make sure that you put at least 1 file in that location before using this module"
exit 1
fi
# Abort build if included file does not have .gschema.override extension
# Abort the build if no gschema.override files are found in ${SCHEMA_INCLUDE_LOCATION}
if [[ ${#SCHEMA_MODULE_FILES[@]} -eq 0 ]]; then
echo "ERROR: Files found, but you don't have any '.gschema.override' files in '${SCHEMA_INCLUDE_LOCATION/#\/tmp/}/' location inside the repo"
echo " Please make sure that you named the files correctly"
exit 1
fi
# Abort the build if recipe input does not match any of the included files
if [[ ${#INCLUDE[@]} -gt 0 ]]; then
for file in "${INCLUDE[@]}"; do
if [[ "$file" == *.gschema.override ]]; then
gschema_extension=true
else
echo "Module failed because included files in module don't have .gschema.override extension."
for input in "${INCLUDE[@]}"; do
match_found=false
for file in "${SCHEMA_MODULE_FILES[@]}"; do
if [[ "${input}" == "${file}" ]]; then
match_found=true
break
fi
done
if [[ "${match_found}" == false ]]; then
echo "ERROR: Module failed because '${input}' file specified in module recipe doesn't match any of the included files in '${SCHEMA_INCLUDE_LOCATION/#\/tmp/}/' location inside the repo"
exit 1
fi
fi
done
fi
# Apply gschema-override when all conditions above are satisfied
if [[ ${#INCLUDE[@]} -gt 0 ]] && $gschema_extension; then
printf "Applying the following gschema-overrides:\n"
printf "Applying the following gschema-overrides:\n"
if [[ ${#INCLUDE[@]} -gt 0 ]]; then
for file in "${INCLUDE[@]}"; do
printf "%s\n" "$file"
printf "%s\n" "${file}"
done
mkdir -p "$schema_test_location" "$schema_location"
find "$schema_location" -type f ! -name "*.gschema.override" -exec cp {} "$schema_test_location" \;
for file in "${INCLUDE[@]}"; do
file_path="${schema_include_location}/${file}"
cp "$file_path" "$schema_test_location"
else
for file in "${SCHEMA_MODULE_FILES[@]}"; do
printf "%s\n" "${file}"
done
echo "Running error-checking test for your gschema-overrides. If test fails, build also fails."
glib-compile-schemas --strict "$schema_test_location"
echo "Compiling gschema to include your changes with gschema-override"
for file in "${INCLUDE[@]}"; do
file_path="${schema_test_location}/${file}"
cp "$file_path" "$schema_location"
done
glib-compile-schemas "$schema_location" &>/dev/null
fi
mkdir -p "${SCHEMA_TEST_LOCATION}" "${SCHEMA_LOCATION}"
find "${SCHEMA_LOCATION}" -type f ! -name "*.gschema.override" -exec cp {} "${SCHEMA_TEST_LOCATION}" \;
if [[ ${#INCLUDE[@]} -gt 0 ]]; then
for file in "${INCLUDE[@]}"; do
file_path="${SCHEMA_INCLUDE_LOCATION}/${file}"
cp "${file_path}" "${SCHEMA_TEST_LOCATION}"
done
else
for file in "${SCHEMA_MODULE_FILES[@]}"; do
file_path="${SCHEMA_INCLUDE_LOCATION}/${file}"
cp "${file_path}" "${SCHEMA_TEST_LOCATION}"
done
fi
echo "Running error-checking test for your gschema-overrides. If test fails, build also fails."
glib-compile-schemas --strict "${SCHEMA_TEST_LOCATION}"
echo "Compiling gschema to include your changes with gschema-override"
if [[ ${#INCLUDE[@]} -gt 0 ]]; then
for file in "${INCLUDE[@]}"; do
file_path="${SCHEMA_TEST_LOCATION}/${file}"
cp "${file_path}" "${SCHEMA_LOCATION}"
done
else
for file in "${SCHEMA_MODULE_FILES[@]}"; do
file_path="${SCHEMA_TEST_LOCATION}/${file}"
cp "${file_path}" "${SCHEMA_LOCATION}"
done
fi
glib-compile-schemas "${SCHEMA_LOCATION}" &>/dev/null

View file

@ -3,4 +3,4 @@ shortdesc: The `gschema-overrides` module can be used for including system-setti
example: |
type: gschema-overrides
include:
- zz1-myoverride.gschema.override # test & compile the override file included in files/gschema-overrides/zz1-myoverride.gschema.override
- zz1-myoverride.gschema.override # test & compile specific override file included in files/gschema-overrides/zz1-myoverride.gschema.override