add support for pkgconf version constraints - fixes #294

Sun, 10 Sep 2023 14:29:20 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 10 Sep 2023 14:29:20 +0200
changeset 46
096f3105b3b1
parent 45
f4ec2feccebb
child 47
78ee95836412

add support for pkgconf version constraints - fixes #294

src/main/java/de/unixwork/uwproj/PkgConfigPackage.java file | annotate | diff | comparison | revisions
src/test/resources/golden-sample/configure2 file | annotate | diff | comparison | revisions
test/make/configure.vm file | annotate | diff | comparison | revisions
test/make/project2.xml file | annotate | diff | comparison | revisions
uwproj.xsd file | annotate | diff | comparison | revisions
--- a/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java	Sun Sep 10 13:12:54 2023 +0200
+++ b/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java	Sun Sep 10 14:29:20 2023 +0200
@@ -2,9 +2,15 @@
 
 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 atleast;
+    private String atLeastVersion;
+    private String exactVersion;
     private String maxVersion;
 
     public static PkgConfigPackage parse(Element e) throws Exception {
@@ -15,6 +21,9 @@
         } else {
             p.setName(name);
         }
+        p.setAtLeastVersion(e.getAttribute("atleast"));
+        p.setExactVersion(e.getAttribute("exact"));
+        p.setMaxVersion(e.getAttribute("max"));
         return p;
     }
 
@@ -26,12 +35,12 @@
         this.name = name;
     }
 
-    public String getAtleast() {
-        return atleast;
+    public String getAtLeastVersion() {
+        return atLeastVersion;
     }
 
-    public void setAtleast(String atleast) {
-        this.atleast = atleast;
+    public void setAtLeastVersion(String atLeastVersion) {
+        this.atLeastVersion = atLeastVersion;
     }
 
     public String getMaxVersion() {
@@ -42,7 +51,36 @@
         this.maxVersion = maxVersion;
     }
 
-    public String getPkgConfigParam() {
-        return name;
+    public String getExactVersion() {
+        return exactVersion;
+    }
+
+    public void setExactVersion(String exactVersion) {
+        this.exactVersion = exactVersion;
+    }
+
+    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
+
+        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);
     }
 }
--- a/src/test/resources/golden-sample/configure2	Sun Sep 10 13:12:54 2023 +0200
+++ b/src/test/resources/golden-sample/configure2	Sun Sep 10 14:29:20 2023 +0200
@@ -429,7 +429,7 @@
         if [ -z "$PKG_CONFIG" ]; then
             break
         fi
-        $PKG_CONFIG libxml-2.0
+        $PKG_CONFIG --atleast-version=2.8 libxml-2.0
         if [ $? -ne 0 ] ; then
             break
         fi
--- a/test/make/configure.vm	Sun Sep 10 13:12:54 2023 +0200
+++ b/test/make/configure.vm	Sun Sep 10 14:29:20 2023 +0200
@@ -349,12 +349,12 @@
         fi
         #end
         #foreach( $pkg in $sub.pkgconfig )
-        $PKG_CONFIG $pkg.getPkgConfigParam()
+        $pkg.getPkgConfigTestQuery()
         if [ $? -ne 0 ] ; then
             break
         fi
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags $pkg.getPkgConfigParam()`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs $pkg.getPkgConfigParam()`"
+        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags $pkg.name`"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs $pkg.name`"
         #end
         #foreach( $flags in $sub.flags )
         #if( $flags.exec )
@@ -413,15 +413,15 @@
         #end
         #foreach( $pkg in $dependency.pkgconfig )
         printf "checking for pkg-config package $pkg.name... "
-        $PKG_CONFIG $pkg.getPkgConfigParam()
+        $pkg.getPkgConfigTestQuery()
         if [ $? -ne 0 ]; then
             echo no
             ERROR=1
             break
         fi
         echo yes
-        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags $pkg.getPkgConfigParam()`"
-        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs $pkg.getPkgConfigParam()`"
+        TEMP_CFLAGS="$TEMP_CFLAGS `$PKG_CONFIG --cflags $pkg.name`"
+        TEMP_LDFLAGS="$TEMP_LDFLAGS `$PKG_CONFIG --libs $pkg.name`"
         #end
 
         #foreach( $flags in $dependency.flags )
--- a/test/make/project2.xml	Sun Sep 10 13:12:54 2023 +0200
+++ b/test/make/project2.xml	Sun Sep 10 14:29:20 2023 +0200
@@ -15,7 +15,7 @@
 		<pkgconfig>libcurl</pkgconfig>
 	</dependency>
 	<dependency name="libxml2">
-		<pkgconfig>libxml-2.0</pkgconfig>
+		<pkgconfig atleast="2.8">libxml-2.0</pkgconfig>
 		<make>xml = libxml2</make>
 	</dependency>
 	<dependency name="sqlite">
--- a/uwproj.xsd	Sun Sep 10 13:12:54 2023 +0200
+++ b/uwproj.xsd	Sun Sep 10 14:29:20 2023 +0200
@@ -30,12 +30,22 @@
         </xs:simpleContent>
     </xs:complexType>
 
+    <xs:complexType name="PkgConfigType">
+        <xs:simpleContent>
+            <xs:extension base="xs:string">
+                <xs:attribute name="atleast" type="xs:string"/>
+                <xs:attribute name="exact" type="xs:string"/>
+                <xs:attribute name="max" type="xs:string"/>
+            </xs:extension>
+        </xs:simpleContent>
+    </xs:complexType>
+
     <xs:complexType name="DependencyType">
         <xs:choice minOccurs="0" maxOccurs="unbounded">
             <xs:element name="lang" type="xs:string"/>
             <xs:element name="cflags" type="FlagsType"/>
             <xs:element name="ldflags" type="FlagsType"/>
-            <xs:element name="pkgconfig" type="xs:string"/>
+            <xs:element name="pkgconfig" type="PkgConfigType"/>
             <xs:element name="test" type="xs:string"/>
             <xs:element name="make" type="xs:string"/>
         </xs:choice>

mercurial