fix bogus version constraint test - relates to #294

Sun, 17 Sep 2023 13:03:46 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 17 Sep 2023 13:03:46 +0200
changeset 63
ac47c2fb2c4a
parent 61
2c68549dabef
child 64
00586d892855

fix bogus version constraint test - relates to #294

src/main/java/de/unixwork/uwproj/PkgConfigPackage.java file | annotate | diff | comparison | revisions
src/test/resources/golden-sample/configure file | annotate | diff | comparison | revisions
src/test/resources/golden-sample/configure2 file | annotate | diff | comparison | revisions
test/configure file | annotate | diff | comparison | revisions
test/make/configure.vm file | annotate | diff | comparison | revisions
--- a/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java	Sun Sep 17 12:40:12 2023 +0200
+++ b/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java	Sun Sep 17 13:03:46 2023 +0200
@@ -2,16 +2,11 @@
 
 import org.w3c.dom.Element;
 
-import java.util.ArrayList;
-import java.util.stream.Collectors;
-
-import static de.unixwork.uwproj.Util.isNotNullOrBlank;
-
 public class PkgConfigPackage {
     private String name;
-    private String atLeastVersion;
-    private String exactVersion;
-    private String maxVersion;
+    private String atleast;
+    private String exact;
+    private String max;
 
     public static PkgConfigPackage parse(Element e) throws Exception {
         var p = new PkgConfigPackage();
@@ -21,9 +16,9 @@
         } else {
             p.setName(name);
         }
-        p.setAtLeastVersion(e.getAttribute("atleast"));
-        p.setExactVersion(e.getAttribute("exact"));
-        p.setMaxVersion(e.getAttribute("max"));
+        p.setAtleast(e.getAttribute("atleast"));
+        p.setExact(e.getAttribute("exact"));
+        p.setMax(e.getAttribute("max"));
         return p;
     }
 
@@ -35,52 +30,27 @@
         this.name = name;
     }
 
-    public String getAtLeastVersion() {
-        return atLeastVersion;
-    }
-
-    public void setAtLeastVersion(String atLeastVersion) {
-        this.atLeastVersion = atLeastVersion;
+    public String getAtleast() {
+        return atleast;
     }
 
-    public String getMaxVersion() {
-        return maxVersion;
+    public void setAtleast(String atleast) {
+        this.atleast = atleast;
     }
 
-    public void setMaxVersion(String maxVersion) {
-        this.maxVersion = maxVersion;
-    }
-
-    public String getExactVersion() {
-        return exactVersion;
-    }
-
-    public void setExactVersion(String exactVersion) {
-        this.exactVersion = exactVersion;
+    public String getMax() {
+        return max;
     }
 
-    public String getPkgConfigTestQuery() {
-        // pkg-config is a more broken piece of software than we thought
-        // it is not possible to combine any flags
-        // e.g. --atleast-version and --max-version together will return true,
-        // even when the max-version is violated
-        // or other example: combining any version flag with --cflags or
-        // --libs does not print the flags
-        // therefore we have to execute multiple query first, and obtain the flags later
+    public void setMax(String max) {
+        this.max = max;
+    }
 
-        final var commands = new ArrayList<String>();
-        if (isNotNullOrBlank(atLeastVersion)) {
-            commands.add("$PKG_CONFIG --atleast-version="+atLeastVersion+" "+name);
-        }
-        if (isNotNullOrBlank(exactVersion)) {
-            commands.add("$PKG_CONFIG --exact-version="+exactVersion+" "+name);
-        }
-        if (isNotNullOrBlank(maxVersion)) {
-            commands.add("$PKG_CONFIG --max-version="+maxVersion+" "+name);
-        }
-        if (commands.isEmpty()) {
-            commands.add("$PKG_CONFIG "+name);
-        }
-        return String.join(" && ", commands);
+    public String getExact() {
+        return exact;
+    }
+
+    public void setExact(String exact) {
+        this.exact = exact;
     }
 }
--- a/src/test/resources/golden-sample/configure	Sun Sep 17 12:40:12 2023 +0200
+++ b/src/test/resources/golden-sample/configure	Sun Sep 17 13:03:46 2023 +0200
@@ -210,6 +210,19 @@
 # create buffer for make variables required by dependencies
 echo > "$TEMP_DIR/make.mk"
 
+test_pkg_config()
+{
+    if "$PKG_CONFIG" --exists "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$2" ] && "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$3" ] && "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$4" ] && "$PKG_CONFIG" --max-version="$4" "$1" ; then :
+    else return 1 ; fi
+    return 0
+}
+
 dependency_error_libpq()
 {
     printf "checking for libpq... "
@@ -219,7 +232,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG libpq ; then
+        if test_pkg_config "libpq" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libpq`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libpq`"
         else
@@ -241,7 +254,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG openssl ; then
+        if test_pkg_config "openssl" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags openssl`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs openssl`"
         else
@@ -294,7 +307,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG libxml-2.0 ; then
+        if test_pkg_config "libxml-2.0" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libxml-2.0`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libxml-2.0`"
         else
--- a/src/test/resources/golden-sample/configure2	Sun Sep 17 12:40:12 2023 +0200
+++ b/src/test/resources/golden-sample/configure2	Sun Sep 17 13:03:46 2023 +0200
@@ -213,6 +213,19 @@
 # create buffer for make variables required by dependencies
 echo > "$TEMP_DIR/make.mk"
 
+test_pkg_config()
+{
+    if "$PKG_CONFIG" --exists "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$2" ] && "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$3" ] && "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$4" ] && "$PKG_CONFIG" --max-version="$4" "$1" ; then :
+    else return 1 ; fi
+    return 0
+}
+
 dependency_error_qt4()
 {
     printf "checking for qt4... "
@@ -272,7 +285,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG libcurl ; then
+        if test_pkg_config "libcurl" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libcurl`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libcurl`"
         else
@@ -294,7 +307,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG gtk+-2.0 ; then
+        if test_pkg_config "gtk+-2.0" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-2.0`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-2.0`"
         else
@@ -316,7 +329,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG sqlite3 ; then
+        if test_pkg_config "sqlite3" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags sqlite3`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs sqlite3`"
         else
@@ -366,7 +379,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG gtk+-5.0 ; then
+        if test_pkg_config "gtk+-5.0" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags gtk+-5.0`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs gtk+-5.0`"
         else
@@ -402,7 +415,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG --atleast-version=2.8 libxml-2.0 ; then
+        if test_pkg_config "libxml-2.0" "2.8" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libxml-2.0`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libxml-2.0`"
         else
--- a/test/configure	Sun Sep 17 12:40:12 2023 +0200
+++ b/test/configure	Sun Sep 17 13:03:46 2023 +0200
@@ -210,6 +210,19 @@
 # create buffer for make variables required by dependencies
 echo > "$TEMP_DIR/make.mk"
 
+test_pkg_config()
+{
+    if "$PKG_CONFIG" --exists "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$2" ] && "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$3" ] && "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$4" ] && "$PKG_CONFIG" --max-version="$4" "$1" ; then :
+    else return 1 ; fi
+    return 0
+}
+
 dependency_error_libpq()
 {
     printf "checking for libpq... "
@@ -219,7 +232,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG libpq ; then
+        if test_pkg_config "libpq" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libpq`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libpq`"
         else
@@ -241,7 +254,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG openssl ; then
+        if test_pkg_config "openssl" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags openssl`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs openssl`"
         else
@@ -294,7 +307,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        if $PKG_CONFIG libxml-2.0 ; then
+        if test_pkg_config "libxml-2.0" "" "" "" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags libxml-2.0`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs libxml-2.0`"
         else
--- a/test/make/configure.vm	Sun Sep 17 12:40:12 2023 +0200
+++ b/test/make/configure.vm	Sun Sep 17 13:03:46 2023 +0200
@@ -243,6 +243,19 @@
 # create buffer for make variables required by dependencies
 echo > "$TEMP_DIR/make.mk"
 
+test_pkg_config()
+{
+    if "$PKG_CONFIG" --exists "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$2" ] && "$PKG_CONFIG" --atleast-version="$2" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$3" ] && "$PKG_CONFIG" --exact-version="$3" "$1" ; then :
+    else return 1 ; fi
+    if [ -n "$4" ] && "$PKG_CONFIG" --max-version="$4" "$1" ; then :
+    else return 1 ; fi
+    return 0
+}
+
 #foreach( $dependency in $namedDependencies )
 dependency_error_${dependency.name}()
 {
@@ -274,7 +287,7 @@
         fi
         #end
         #foreach( $pkg in $sub.pkgconfig )
-        if $pkg.getPkgConfigTestQuery() ; then
+        if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"
         else
@@ -337,7 +350,7 @@
         #end
         #foreach( $pkg in $dependency.pkgconfig )
         printf "checking for pkg-config package $pkg.name... "
-        if $pkg.getPkgConfigTestQuery() ; then
+        if test_pkg_config "$pkg.name" "$pkg.atleast" "$pkg.exact" "$pkg.max" ; then
             echo yes
             TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags $pkg.name`"
             TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs $pkg.name`"

mercurial