Blame SOURCES/pacemaker-borrow-schemas

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