From e59a52198f3d961d9fc5ba59447684b8b46fa8d2 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 21 Apr 2012 11:08:12 -0700 Subject: [PATCH] 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 the --print-errors is respected. Fixes Freedesktop #8653 --- check/Makefile.am | 2 +- check/check-version | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 48 +++++++++------------- 3 files changed, 128 insertions(+), 29 deletions(-) create mode 100755 check/check-version diff --git a/check/Makefile.am b/check/Makefile.am index 29ec729..0ce476a 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -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 \ diff --git a/check/check-version b/check/check-version new file mode 100755 index 0000000..6e92077 --- /dev/null +++ b/check/check-version @@ -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 diff --git a/main.c b/main.c index 95ce69d..252ad42 100644 --- a/main.c +++ b/main.c @@ -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; -- 1.7.7.6