2016-11-24 13:29:42 +03:00
#!/bin/sh
2017-11-18 20:18:16 +03:00
# SPDX-License-Identifier: LGPL-2.1+
#
# Call built systemd-hwdb update on our hwdb files to ensure that they parse
2016-11-24 13:29:42 +03:00
# without error
#
# (C) 2016 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
2017-11-18 20:18:16 +03:00
#
2016-11-24 13:29:42 +03:00
# systemd is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
set -e
ROOTDIR = $( dirname $( dirname $( readlink -f $0 ) ) )
2017-09-26 14:44:04 +03:00
SYSTEMD_HWDB = ./systemd-hwdb
2016-11-24 13:29:42 +03:00
if [ ! -x " $SYSTEMD_HWDB " ] ; then
echo " $SYSTEMD_HWDB does not exist, please build first "
exit 1
fi
D = $( mktemp --directory)
trap " rm -rf ' $D ' " EXIT INT QUIT PIPE
mkdir -p " $D /etc/udev "
ln -s " $ROOTDIR /hwdb " " $D /etc/udev/hwdb.d "
2016-11-30 06:41:52 +03:00
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 18:55:32 +03:00
# Test "good" properties" — no warnings or errors allowed
2016-11-30 06:41:52 +03:00
err = $( " $SYSTEMD_HWDB " update --root " $D " 2>& 1 >/dev/null) && rc = || rc = $?
2016-11-24 13:29:42 +03:00
if [ -n " $err " ] ; then
echo " $err "
2016-11-30 06:41:52 +03:00
exit ${ rc :- 1 }
2016-11-24 13:29:42 +03:00
fi
2016-11-30 06:41:52 +03:00
if [ -n " $rc " ] ; then
echo " $SYSTEMD_HWDB returned $rc "
exit $rc
fi
2016-11-24 13:29:42 +03:00
if [ ! -e " $D /etc/udev/hwdb.bin " ] ; then
echo " $D /etc/udev/hwdb.bin was not generated "
exit 1
fi
hwdb: improve and test syntax error messages
Since syntax error are non-fatal, downgrade them to warnings.
Use log_syntax to have uniform formatting including the line number.
State machine states like DATA and MATCH are internal, user-facing
messages should use the names from hwdb(7): match, property, record.
Also change "key/value" to "key-value", since there's no alternative
here, both parts must be present.
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:2] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:5] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:9] Property expected, ignoring record with no properties
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:11] Key/value pair expected but got " NO_VALUE", ignoring
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:18] Property or empty line expected, got "BAD:7:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:22] Property or empty line expected, got "BAD:8:match at wrong place", ignoring record
[/tmp/tmp.KFwEhm74n4/etc/udev/hwdb.d/10-bad.hwdb:23] Match expected but got indented property " Z=z", ignoring line
squash! hwdb: improve syntax error messages
2016-12-01 18:55:32 +03:00
# Test "bad" properties" — warnings required, errors not allowed
rm -f " $D /etc/udev/hwdb.bin " " $D /etc/udev/hwdb.d "
ln -s " $ROOTDIR /test/hwdb " " $D /etc/udev/hwdb.d "
err = $( " $SYSTEMD_HWDB " update --root " $D " 2>& 1 >/dev/null) && rc = || rc = $?
if [ -n " $rc " ] ; then
echo " $SYSTEMD_HWDB returned $rc "
exit $rc
fi
if [ -n " $err " ] ; then
echo "Expected warnings"
echo " $err "
else
echo " $SYSTEMD_HWDB unexpectedly printed no warnings "
exit 1
fi
if [ ! -e " $D /etc/udev/hwdb.bin " ] ; then
echo " $D /etc/udev/hwdb.bin was not generated "
exit 1
fi