Unify handling of operator and command line option version checking

The code for --exact/atleast/max-version was taking a different path
than the handling of operators like =/>=/<=. Make the long option
versions override the operators and take place during the standard
package checking stage. This also means that --print-errors is
respected.

Fixes Freedesktop #8653
This commit is contained in:
Dan Nicholson 2012-04-21 11:08:12 -07:00
parent 5fc77a96b7
commit a83a14c291
3 changed files with 128 additions and 29 deletions

View file

@ -2,7 +2,7 @@
TESTS = check-cflags check-libs check-define-variable \
check-libs-private check-requires-private check-includedir \
check-conflicts check-missing check-idirafter check-whitespace \
check-cmd-options
check-cmd-options check-version
EXTRA_DIST = $(TESTS) common simple.pc requires-test.pc public-dep.pc \
private-dep.pc includedir.pc missing-requires-private.pc \

107
check/check-version Executable file
View file

@ -0,0 +1,107 @@
#! /bin/sh
# Make sure we're POSIX
if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then
PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@"
fi
set -e
. ${srcdir}/common
v1=0.9.9
v2=1.0.0
v3=1.0.1
# exact version testing
ARGS="--exists --print-errors simple = $v1"
EXPECT_RETURN=1
RESULT="Requested 'simple = $v1' but version of Simple test is $v2"
run_test
ARGS="--exists --print-errors --exact-version=$v1 simple"
EXPECT_RETURN=1
RESULT="Requested 'simple = $v1' but version of Simple test is $v2"
run_test
ARGS="--exists --print-errors simple = $v2"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors --exact-version=$v2 simple"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors simple = $v3"
EXPECT_RETURN=1
RESULT="Requested 'simple = $v3' but version of Simple test is $v2"
run_test
ARGS="--exists --print-errors --exact-version=$v3 simple"
EXPECT_RETURN=1
RESULT="Requested 'simple = $v3' but version of Simple test is $v2"
run_test
# atleast version testing
ARGS="--exists --print-errors simple >= $v1"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors --atleast-version=$v1 simple"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors simple >= $v2"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors --atleast-version=$v2 simple"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors simple >= $v3"
EXPECT_RETURN=1
RESULT="Requested 'simple >= $v3' but version of Simple test is $v2"
run_test
ARGS="--exists --print-errors --atleast-version=$v3 simple"
EXPECT_RETURN=1
RESULT="Requested 'simple >= $v3' but version of Simple test is $v2"
run_test
# max version testing
ARGS="--exists --print-errors simple <= $v1"
EXPECT_RETURN=1
RESULT="Requested 'simple <= $v1' but version of Simple test is $v2"
run_test
ARGS="--exists --print-errors --max-version=$v1 simple"
EXPECT_RETURN=1
RESULT="Requested 'simple <= $v1' but version of Simple test is $v2"
run_test
ARGS="--exists --print-errors simple <= $v2"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors --max-version=$v2 simple"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors simple <= $v3"
EXPECT_RETURN=0
RESULT=""
run_test
ARGS="--exists --print-errors --max-version=$v3 simple"
EXPECT_RETURN=0
RESULT=""
run_test

48
main.c
View file

@ -469,6 +469,26 @@ main (int argc, char **argv)
Package *req;
RequiredVersion *ver = iter->data;
/* override requested versions with cmdline options */
if (required_exact_version)
{
g_free (ver->version);
ver->comparison = EQUAL;
ver->version = g_strdup (required_exact_version);
}
else if (required_atleast_version)
{
g_free (ver->version);
ver->comparison = GREATER_THAN_EQUAL;
ver->version = g_strdup (required_atleast_version);
}
else if (required_max_version)
{
g_free (ver->version);
ver->comparison = LESS_THAN_EQUAL;
ver->version = g_strdup (required_max_version);
}
if (want_short_errors)
req = get_package_quiet (ver->name);
else
@ -656,34 +676,6 @@ main (int argc, char **argv)
}
}
if (required_exact_version)
{
Package *pkg = packages->data;
if (compare_versions (pkg->version, required_exact_version) == 0)
return 0;
else
return 1;
}
else if (required_atleast_version)
{
Package *pkg = packages->data;
if (compare_versions (pkg->version, required_atleast_version) >= 0)
return 0;
else
return 1;
}
else if (required_max_version)
{
Package *pkg = packages->data;
if (compare_versions (pkg->version, required_max_version) <= 0)
return 0;
else
return 1;
}
/* Print all flags; then print a newline at the end. */
need_newline = FALSE;