diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index 2d47184..504e8ef 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -892,6 +892,7 @@ typedef struct { typedef struct { const pkgconf_vercmp_res_func_t depcmp; const pkgconf_vercmp_res_func_t rulecmp[PKGCONF_CMP_COUNT]; + const bool check_a[PKGCONF_CMP_COUNT]; } pkgconf_pkg_provides_vermatch_rule_t; static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_rules[] = { @@ -909,7 +910,13 @@ static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_ [PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte, [PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_any, [PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne - } + }, + .check_a = { + [PKGCONF_CMP_GREATER_THAN] = true, + [PKGCONF_CMP_GREATER_THAN_EQUAL] = true, + [PKGCONF_CMP_EQUAL] = true, + [PKGCONF_CMP_NOT_EQUAL] = true, + }, }, [PKGCONF_CMP_GREATER_THAN] = { .depcmp = pkgconf_pkg_comparator_gt, @@ -921,7 +928,13 @@ static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_ [PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte, [PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_any, [PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne - } + }, + .check_a = { + [PKGCONF_CMP_LESS_THAN] = true, + [PKGCONF_CMP_LESS_THAN_EQUAL] = true, + [PKGCONF_CMP_EQUAL] = true, + [PKGCONF_CMP_NOT_EQUAL] = true, + }, }, [PKGCONF_CMP_LESS_THAN_EQUAL] = { .depcmp = pkgconf_pkg_comparator_lte, @@ -933,7 +946,13 @@ static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_ [PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte, [PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_any, [PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne - } + }, + .check_a = { + [PKGCONF_CMP_GREATER_THAN] = true, + [PKGCONF_CMP_GREATER_THAN_EQUAL] = true, + [PKGCONF_CMP_EQUAL] = true, + [PKGCONF_CMP_NOT_EQUAL] = true, + }, }, [PKGCONF_CMP_GREATER_THAN_EQUAL] = { .depcmp = pkgconf_pkg_comparator_gte, @@ -945,7 +964,13 @@ static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_ [PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte, [PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_any, [PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne - } + }, + .check_a = { + [PKGCONF_CMP_LESS_THAN] = true, + [PKGCONF_CMP_LESS_THAN_EQUAL] = true, + [PKGCONF_CMP_EQUAL] = true, + [PKGCONF_CMP_NOT_EQUAL] = true, + }, }, [PKGCONF_CMP_EQUAL] = { .depcmp = pkgconf_pkg_comparator_eq, @@ -963,12 +988,12 @@ static const pkgconf_pkg_provides_vermatch_rule_t pkgconf_pkg_provides_vermatch_ .depcmp = pkgconf_pkg_comparator_ne, .rulecmp = { [PKGCONF_CMP_ANY] = pkgconf_pkg_comparator_none, - [PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_lt, - [PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_gt, - [PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_lte, - [PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_gte, - [PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_any, - [PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_ne + [PKGCONF_CMP_LESS_THAN] = pkgconf_pkg_comparator_ne, + [PKGCONF_CMP_GREATER_THAN] = pkgconf_pkg_comparator_ne, + [PKGCONF_CMP_LESS_THAN_EQUAL] = pkgconf_pkg_comparator_ne, + [PKGCONF_CMP_GREATER_THAN_EQUAL] = pkgconf_pkg_comparator_ne, + [PKGCONF_CMP_EQUAL] = pkgconf_pkg_comparator_ne, + [PKGCONF_CMP_NOT_EQUAL] = pkgconf_pkg_comparator_eq } }, }; @@ -988,7 +1013,7 @@ pkgconf_pkg_scan_provides_vercmp(const pkgconf_dependency_t *pkgdep, const pkgco if (rule == NULL) return false; - if (!rule->depcmp(provider->version, pkgdep->version)) + if (rule->check_a[provider->compare] && !rule->depcmp(provider->version, pkgdep->version)) return false; if (rule->rulecmp[provider->compare] != NULL && diff --git a/tests/lib1/provides.pc b/tests/lib1/provides.pc index 24481ba..0e1bf75 100644 --- a/tests/lib1/provides.pc +++ b/tests/lib1/provides.pc @@ -3,4 +3,4 @@ Description: A testing pkg-config file Version: 1.2.3 Libs: -lfoo Cflags: -I/usr/include/foo -Provides: provides-test-foo = 1.0.0, provides-test-baz >= 1.1.0, provides-test-moo <= 1.2.0 +Provides: provides-test-foo = 1.0.0, provides-test-bar > 1.1.0, provides-test-baz >= 1.1.0, provides-test-quux < 1.2.0, provides-test-moo <= 1.2.0 diff --git a/tests/run.sh.in b/tests/run.sh.in index 186c7cf..aeb9344 100644 --- a/tests/run.sh.in +++ b/tests/run.sh.in @@ -316,6 +316,105 @@ run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-foo > 1.0 run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-foo < 1.0.0'; echo \$?" \ "1" +# provides-test-bar > 1.1.0 +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar = 1.1.1'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar >= 1.1.1'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar <= 1.1.1'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar != 1.1.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar != 1.1.1'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar > 1.1.1'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar <= 1.1.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar < 1.2.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-bar > 1.2.0'; echo \$?" \ + "0" + +# provides-test-baz >= 1.1.0 +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz = 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz >= 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz <= 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz != 1.1.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz != 1.0.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz > 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz < 1.1.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-baz < 1.2.0'; echo \$?" \ + "0" + +# provides-test-quux < 1.2.0 +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux = 1.1.9'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux >= 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux >= 1.1.9'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux >= 1.2.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux <= 1.2.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux <= 1.1.9'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux != 1.2.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux != 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux != 1.0.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux > 1.1.9'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux > 1.2.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux < 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-quux < 1.2.0'; echo \$?" \ + "1" + +# provides-test-moo <= 1.2.0 +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo = 1.2.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo >= 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo >= 1.2.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo >= 1.2.1'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo <= 1.2.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo != 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo != 1.0.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo > 1.1.9'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo > 1.2.0'; echo \$?" \ + "1" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo < 1.1.0'; echo \$?" \ + "0" +run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} --libs 'provides-test-moo < 1.2.0'; echo \$?" \ + "0" + + # 11) tests for internal getopt implementation with options at the end if [ "x@STRICT_MODE@" = "xno" ]; then run_test "PKG_CONFIG_PATH='${selfdir}/lib1' ${1} foo --libs" \