|
|
5706e2 |
#!/bin/sh
|
|
|
5706e2 |
# Copyright 2017 Red Hat, Inc.
|
|
|
5706e2 |
# Part of clufter project
|
|
|
5706e2 |
# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
|
|
|
5706e2 |
|
|
|
5706e2 |
# A helper for "borrow validation schemas from pacemaker" process.
|
|
|
5706e2 |
|
|
|
5706e2 |
die() { echo; echo "$@"; exit 1; }
|
|
|
5706e2 |
|
|
|
5706e2 |
# $1 ... input directory with original pacemaker schemas
|
|
|
5706e2 |
# $2 ... output directory with consolidated schemas
|
|
|
5706e2 |
# $3 ... schemas to skip (as posix-egrep expression)
|
|
|
5706e2 |
# $4 ... postprocess XSLT
|
|
|
5706e2 |
# $5 ... clobber existing files? (true if set and non-null)
|
|
|
5706e2 |
consolidate() {
|
|
|
5706e2 |
inputdir="${1}"; outputdir="${2}"; skipschemas="${3}"; postprocess="${4}"
|
|
|
5706e2 |
test "${#}" -lt 5 || clobber="${5}"
|
|
|
5706e2 |
mkdir -p -- "${outputdir}"
|
|
|
5706e2 |
# for all the schema versions at the boundary of the "major" bump,
|
|
|
5706e2 |
# except for the lower boundary of the first one (i.e. pacemaker-1.0)
|
|
|
5706e2 |
# -- the versions in between are not interesting from validation POV
|
|
|
5706e2 |
for base in $(
|
|
|
5706e2 |
find "${inputdir}" -regextype posix-egrep -regex "${skipschemas}" -prune \
|
|
|
5706e2 |
-o -name 'pacemaker-*.rng' -printf '%P\n' | sort -V \
|
|
|
5706e2 |
| sed -e 'N;/^\(pacemaker-[0-9]\)\.\([0-9][0-9]*\)\.rng\n\1\.\([0-9][0-9]*\)\.rng$/!p;D'); do
|
|
|
5706e2 |
f="${inputdir}/${base}"
|
|
|
5706e2 |
printf "processing: ${f} ... "
|
|
|
5706e2 |
test -f "${f}" || continue
|
|
|
5706e2 |
sentinel=10; old=/dev/null; new="${f}"
|
|
|
5706e2 |
# until the jing output converged (simplification gets idempotent)
|
|
|
5706e2 |
# as prescribed by did-size-change heuristic (or sentinel is hit)
|
|
|
5706e2 |
while [ "$(stat -c '%s' "${old}")" != "$(stat -c '%s' "${new}")" ]; do
|
|
|
5706e2 |
[ "$((sentinel -= 1))" -gt 0 ] || break
|
|
|
5706e2 |
[ "${old}" = "${f}" ] && old="${outputdir}/${base}";
|
|
|
5706e2 |
[ "${new}" = "${f}" ] \
|
|
|
5706e2 |
&& { old="${f}"; new="${outputdir}/${base}.new"; } \
|
|
|
5706e2 |
|| cp -f "${new}" "${old}"
|
|
|
5706e2 |
jing -is "${old}" > "${new}"
|
|
|
5706e2 |
#printf "(%d -> %d) " "$(stat -c '%s' "${old}")" "$(stat -c '%s' "${new}")"
|
|
|
5706e2 |
done
|
|
|
5706e2 |
printf "%d iterations" "$((10 - ${sentinel}))"
|
|
|
5706e2 |
test -z "${clobber-}" && test -s "${old}" && die "file ${old} already exists" || :
|
|
|
5706e2 |
if [ -z "${postprocess}" ]; then
|
|
|
5706e2 |
mv "${new}" "${old}"
|
|
|
5706e2 |
printf ", moved\n"
|
|
|
5706e2 |
else
|
|
|
5706e2 |
# xmllint drops empty lines caused by the applied transformation
|
|
|
5706e2 |
xsltproc --stringparam filename-or-version "${base}" \
|
|
|
5706e2 |
"${postprocess}" "${new}" \
|
|
|
5706e2 |
| xmllint --format - > "${old}"
|
|
|
5706e2 |
rm -f -- "${new}"
|
|
|
5706e2 |
printf ", postprocessed\n"
|
|
|
5706e2 |
fi
|
|
|
5706e2 |
done
|
|
|
5706e2 |
}
|
|
|
5706e2 |
|
|
|
5706e2 |
which jing >/dev/null 2>&1 || die "jing (from jing-trang project) required"
|
|
|
5706e2 |
|
|
|
5706e2 |
: "${INPUTDIR=$(pkg-config --variable schemadir pacemaker)}"
|
|
|
5706e2 |
test -n "${INPUTDIR}" || die "Input dir with pacemaker schemas not known"
|
|
|
5706e2 |
|
|
|
5706e2 |
: "${OUTPUTDIR=schemas-consolidated}"
|
|
|
5706e2 |
test -n "${OUTPUTDIR}" || die "Output dir for consolidated schemas not known"
|
|
|
5706e2 |
|
|
|
5706e2 |
: "${POSTPROCESS=$(dirname "${0}")/fix-jing-simplified-rng.xsl}"
|
|
|
5706e2 |
|
|
|
5706e2 |
# skip non-defaults of upstream releases
|
|
|
5706e2 |
#: "${SKIPSCHEMAS=.*/pacemaker-(1\.0|2\.[126]).rng}"
|
|
|
5706e2 |
: "${SKIPSCHEMAS=".*/pacemaker-next\.rng"}" # only skip WIP schema by default
|
|
|
5706e2 |
|
|
|
5706e2 |
consolidate "${INPUTDIR}" "${OUTPUTDIR}" "${SKIPSCHEMAS}" "${POSTPROCESS}" "${@}"
|