From 9cd35c624f24b978cdcae9e24a1ca87bad88bf9e Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Tue, 11 Dec 2012 11:30:13 -0800 Subject: [PATCH] Enforce that only the first --atleast/exact/max-version option honored This provides the user with output matching the behavior of the code. When multiple --atleast/exact/max-version options are supplied, only the first will be honored. --- check/check-version | 5 +++++ main.c | 7 ++++++- pkg-config.1 | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/check/check-version b/check/check-version index e52cf4d..a940c37 100755 --- a/check/check-version +++ b/check/check-version @@ -90,3 +90,8 @@ run_test --print-errors simple \<= $v3 EXPECT_RETURN=0 RESULT="" run_test --print-errors --max-version=$v3 simple + +# mixing version compare testing is not allowed +EXPECT_RETURN=0 +RESULT='Ignoring incompatible output option "--exact-version"' +run_test --atleast-version=1.0.0 --exact-version=1.0.0 simple diff --git a/main.c b/main.c index edc6a78..8365213 100644 --- a/main.c +++ b/main.c @@ -156,6 +156,8 @@ static gboolean output_opt_cb (const char *opt, const char *arg, gpointer data, GError **error) { + static gboolean vercmp_opt_set = FALSE; + /* only allow one output mode, with a few exceptions */ if (output_opt_set) { @@ -178,7 +180,7 @@ output_opt_cb (const char *opt, const char *arg, gpointer data, bad_opt = FALSE; /* --exists allowed with --atleast/exact/max-version */ - if (want_exists && + if (want_exists && !vercmp_opt_set && (strcmp (opt, "--atleast-version") == 0 || strcmp (opt, "--exact-version") == 0 || strcmp (opt, "--max-version") == 0)) @@ -222,16 +224,19 @@ output_opt_cb (const char *opt, const char *arg, gpointer data, { required_atleast_version = g_strdup (arg); want_exists = TRUE; + vercmp_opt_set = TRUE; } else if (strcmp (opt, "--exact-version") == 0) { required_exact_version = g_strdup (arg); want_exists = TRUE; + vercmp_opt_set = TRUE; } else if (strcmp (opt, "--max-version") == 0) { required_max_version = g_strdup (arg); want_exists = TRUE; + vercmp_opt_set = TRUE; } else if (strcmp (opt, "--list-all") == 0) want_list = TRUE; diff --git a/pkg-config.1 b/pkg-config.1 index 530ddb2..a5c1513 100644 --- a/pkg-config.1 +++ b/pkg-config.1 @@ -186,7 +186,9 @@ command line are known to \fIpkg-config\fP, and optionally whether the version number of a package meets certain constraints. If all packages exist and meet the specified version constraints, .I pkg-config -exits successfully. Otherwise it exits unsuccessfully. +exits successfully. Otherwise it exits unsuccessfully. Only the first +VERSION comparing option will be honored. Subsequent options of this +type will be ignored. Rather than using the version-test options, you can simply give a version constraint after each package name, for example: