Blame SOURCES/pacemaker-borrow-schemas

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