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