summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsmael Luceno2021-02-13 18:35:48 +0100
committerIsmael Luceno2021-02-13 19:02:43 +0100
commit217f1108f14e135085ccaa9a85fe3596514e85b5 (patch)
treeab44e7be8fd5b53d6668263de149f00245b5d045
parentd523cfc301c17731bde576b86a0cea5f30dcade2 (diff)
Add improved vdepends implementation
Example: LANGS="ADA,FORTRAN" LANGFLAGS="--enable-ada --enable-fortran" vdepends << EOF gcc[$LANGS] >= 6.0 < 7.0 flags: $LANGFLAGS binutils[LIBERTY] >= 2.35 flags: --with-liberty EOF This changes the format and adds support for: - chained comparisons - sub-dependencies - comment lines Now the check is done against the grimoire version of the spell too, to avoid casting a spell that can't satisfy the dependency.
-rwxr-xr-xFUNCTIONS28
-rw-r--r--VDEPENDS74
-rwxr-xr-xdevel/cppo/DEPENDS2
-rwxr-xr-xdevel/ocaml-extlib/DEPENDS1
-rwxr-xr-xdevel/ocaml-gen/DEPENDS2
-rwxr-xr-xdevel/ocaml-migrate-parsetree/DEPENDS2
-rwxr-xr-xdevel/ocaml-ppx-derivers/DEPENDS2
-rwxr-xr-xdevel/ocaml-ppx-tools-versioned/DEPENDS2
-rwxr-xr-xdevel/ocaml-ptmap/DEPENDS2
-rwxr-xr-xdevel/ocaml-sedlex/DEPENDS2
-rwxr-xr-xftp/rtorrent/DEPENDS3
-rwxr-xr-xgnome2-libs/goffice/DEPENDS2
-rwxr-xr-xgnome2-libs/librsvg2/DEPENDS3
-rwxr-xr-xgnome2-libs/pangomm/DEPENDS2
-rwxr-xr-xgraphics-libs/mesa/DEPENDS2
-rwxr-xr-xnet/iptables/DEPENDS2
-rwxr-xr-xnet/nftables/DEPENDS2
-rwxr-xr-xx11-toolkits/gtk+3/DEPENDS3
18 files changed, 90 insertions, 46 deletions
diff --git a/FUNCTIONS b/FUNCTIONS
index b93b30c605..1928748da8 100755
--- a/FUNCTIONS
+++ b/FUNCTIONS
@@ -934,34 +934,6 @@ function check_tmp_noexec() {
}
#---
-## Versioned dependency list from stdin.
-## Takes one dependency per line. Format:
-## <dependency> <comparison operator> <version> <flags>
-#---
-vdepends(){
- while read dep op depver flags; do
- case "$op" in
- '>'|'>='|'<'|'<='|'='|'!='|'') ;;
- *)
- message "${PROBLEM_COLOR}Unsupported operator \"$op\".$DEFAULT_COLOR"
- return 1
- ;;
- esac
- depends "$dep" "$flags" || return
- spell_ok "$dep" || continue
- local iver="$(installed_version "$dep")"
- case "$op" in
- '>') ! is_version_less "$iver" "$depver" && [ "x$iver" != "x$depver" ] ;;
- '>=') ! is_version_less "$iver" "$depver" ;;
- '<') is_version_less "$iver" "$depver" ;;
- '<=') is_version_less "$iver" "$depver" || [ "x$iver" = "x$depver" ] ;;
- '=') [ "x$iver" = "x$depver" ] ;;
- '!=') [ "x$iver" != "x$depver" ] ;;
- esac || force_depends "$dep"
- done
-}
-
-#---
## Find a file matching some pattern(s) as installed by the chosen
## provider, e.g. /usr/bin/python3 for python3 providing PYTHON.
## @params $1 - spell at hand
diff --git a/VDEPENDS b/VDEPENDS
new file mode 100644
index 0000000000..825856bb12
--- /dev/null
+++ b/VDEPENDS
@@ -0,0 +1,74 @@
+# -*- mode: sh -*-
+# Parse a versioned dependency list from stdin.
+# Takes one dependency per line. Format:
+# spell[subdep...] version... flags:...
+#
+# Example:
+# LANGS="ADA,FORTRAN" LANGFLAGS="--enable-ada --enable-fortran"
+# vdepends << EOF
+# gcc[$LANGS] >= 6.0 < 7.0 flags: $LANGFLAGS
+# binutils[LIBERTY] >= 2.35 flags: --with-liberty
+# EOF
+
+is_version_less() {
+ local v="$1
+$2"
+ [ "$(sort -V <<< "$v")" = "$v" ] && [ "$1" != "$2" ]
+}
+
+vdepends_vercheck() {
+ case "$2" in
+ ('>') is_version_less "$3" "$1" ;;
+ ('>=') ! is_version_less "$1" "$3" ;;
+ ('<') is_version_less "$1" "$3" ;;
+ ('<=') ! is_version_less "$3" "$1" ;;
+ ('=') [ "x$1" = "x$3" ] ;;
+ ('!=') [ "x$1" != "x$3" ] ;;
+ (*) message vdepends: \
+ "${PROBLEM_COLOR}Unsupported operator \"$2\".$DEFAULT_COLOR"
+ return 1
+ ;;
+ esac
+}
+
+vdepends() {
+ local dep features flags rest
+ local op depver iver gver
+ while read dep rest; do
+ case "$dep" in
+ (\#*) # comment line
+ continue
+ ;;
+ (*\]) # subdependencies; split them
+ features="${dep#*[}"
+ dep="${dep%[*}"
+ features="${features%]}"
+ features="${features//,/ }"
+ ;;
+ esac
+ # split configuration flags
+ rest=" $rest"
+ case "$rest" in
+ (*\ flags:*)
+ flags="${rest#* flags:}"
+ rest="${rest% flags:*}"
+ ;;
+ esac
+ depends -sub "$features" "$dep" "$flags" || return
+ # remove whitespace
+ read rest <<< "$rest"
+ # parse and check versions
+ iver="$(spell_ok "$dep" && installed_version "$dep")"
+ gver="$(codex_set_current_spell "$dep" && echo "$VERSION")"
+ while [ -n "$rest" ] && read op depver rest <<< "$rest"; do
+ [ -n "$iver" ] && vdepends_vercheck "$iver" "$op" "$depver" && continue
+ if [ "$gver" = "$iver" ] || ! vdepends_vercheck "$gver" "$op" "$depver"
+ then
+ message "${PROBLEM_COLOR}Unsatisfied dependency:$DEFAULT_COLOR" \
+ "$dep $gver $op $depver"
+ return 1
+ fi
+ force_depends "$dep"
+ done
+ done
+}
diff --git a/devel/cppo/DEPENDS b/devel/cppo/DEPENDS
index d2c3686e8f..cc14659dd1 100755
--- a/devel/cppo/DEPENDS
+++ b/devel/cppo/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
dune
ocaml
diff --git a/devel/ocaml-extlib/DEPENDS b/devel/ocaml-extlib/DEPENDS
index 00e3978ab4..5c72d90893 100755
--- a/devel/ocaml-extlib/DEPENDS
+++ b/devel/ocaml-extlib/DEPENDS
@@ -1,3 +1,4 @@
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
cppo
ocaml
diff --git a/devel/ocaml-gen/DEPENDS b/devel/ocaml-gen/DEPENDS
index 9d58d56dfa..8881aee2d5 100755
--- a/devel/ocaml-gen/DEPENDS
+++ b/devel/ocaml-gen/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
ocaml
dune
diff --git a/devel/ocaml-migrate-parsetree/DEPENDS b/devel/ocaml-migrate-parsetree/DEPENDS
index 4615942bc9..29cde23a62 100755
--- a/devel/ocaml-migrate-parsetree/DEPENDS
+++ b/devel/ocaml-migrate-parsetree/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
dune
ocaml
diff --git a/devel/ocaml-ppx-derivers/DEPENDS b/devel/ocaml-ppx-derivers/DEPENDS
index 2ea7a4b982..2d187a6744 100755
--- a/devel/ocaml-ppx-derivers/DEPENDS
+++ b/devel/ocaml-ppx-derivers/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
dune
ocaml
diff --git a/devel/ocaml-ppx-tools-versioned/DEPENDS b/devel/ocaml-ppx-tools-versioned/DEPENDS
index e9b2e85bf2..f38ee66ace 100755
--- a/devel/ocaml-ppx-tools-versioned/DEPENDS
+++ b/devel/ocaml-ppx-tools-versioned/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
dune
ocaml
diff --git a/devel/ocaml-ptmap/DEPENDS b/devel/ocaml-ptmap/DEPENDS
index fd8d2434da..55e3590128 100755
--- a/devel/ocaml-ptmap/DEPENDS
+++ b/devel/ocaml-ptmap/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
ocaml >= 4.08
dune
diff --git a/devel/ocaml-sedlex/DEPENDS b/devel/ocaml-sedlex/DEPENDS
index 40371f7d1d..62990412c0 100755
--- a/devel/ocaml-sedlex/DEPENDS
+++ b/devel/ocaml-sedlex/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
dune
ocaml
diff --git a/ftp/rtorrent/DEPENDS b/ftp/rtorrent/DEPENDS
index 888fe448b6..e7cbddb4c0 100755
--- a/ftp/rtorrent/DEPENDS
+++ b/ftp/rtorrent/DEPENDS
@@ -1,5 +1,4 @@
-. $GRIMOIRE/FUNCTIONS
-
+. "$GRIMOIRE"/VDEPENDS &&
vdepends << ! &&
libtorrent >= 0.12.9
!
diff --git a/gnome2-libs/goffice/DEPENDS b/gnome2-libs/goffice/DEPENDS
index 7b63ede56c..7d4aa67732 100755
--- a/gnome2-libs/goffice/DEPENDS
+++ b/gnome2-libs/goffice/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends << ! &&
gdk-pixbuf2 >= 2.22.0
glib2 >= 2.40.0
diff --git a/gnome2-libs/librsvg2/DEPENDS b/gnome2-libs/librsvg2/DEPENDS
index 7ee04c95e2..d4c2eeff5a 100755
--- a/gnome2-libs/librsvg2/DEPENDS
+++ b/gnome2-libs/librsvg2/DEPENDS
@@ -1,5 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
-
+. "$GRIMOIRE"/VDEPENDS &&
depends llvm &&
depends -sub "CAIRO_DEVEL PNG" cairo &&
depends fontconfig &&
diff --git a/gnome2-libs/pangomm/DEPENDS b/gnome2-libs/pangomm/DEPENDS
index 8d0b41cfef..452b12738c 100755
--- a/gnome2-libs/pangomm/DEPENDS
+++ b/gnome2-libs/pangomm/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF &&
cairo
cairomm
diff --git a/graphics-libs/mesa/DEPENDS b/graphics-libs/mesa/DEPENDS
index 3a4cc7d75d..e03f1793f3 100755
--- a/graphics-libs/mesa/DEPENDS
+++ b/graphics-libs/mesa/DEPENDS
@@ -1,4 +1,4 @@
-. "${GRIMOIRE}/FUNCTIONS" &&
+. "$GRIMOIRE"/VDEPENDS &&
depends meson &&
depends ninja-build-system &&
depends python3 &&
diff --git a/net/iptables/DEPENDS b/net/iptables/DEPENDS
index b48bd0b82d..f9e0cdd94f 100755
--- a/net/iptables/DEPENDS
+++ b/net/iptables/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
depends libmnl &&
optional_depends libnftnl '' '--disable-nftables' 'nftabels support' &&
if is_depends_enabled "$SPELL" libnftnl; then
diff --git a/net/nftables/DEPENDS b/net/nftables/DEPENDS
index de7d59633c..8e75eb2c6a 100755
--- a/net/nftables/DEPENDS
+++ b/net/nftables/DEPENDS
@@ -1,4 +1,4 @@
-. "$GRIMOIRE"/FUNCTIONS &&
+. "$GRIMOIRE"/VDEPENDS &&
vdepends <<EOF
libmnl
libnftnl >= 1.1.8
diff --git a/x11-toolkits/gtk+3/DEPENDS b/x11-toolkits/gtk+3/DEPENDS
index 95752704c5..872d78eabb 100755
--- a/x11-toolkits/gtk+3/DEPENDS
+++ b/x11-toolkits/gtk+3/DEPENDS
@@ -1,5 +1,4 @@
-. "$GRIMOIRE/FUNCTIONS" &&
-
+. "$GRIMOIRE"/VDEPENDS &&
depends meson &&
depends python3 &&
depends ninja-build-system &&