From 217f1108f14e135085ccaa9a85fe3596514e85b5 Mon Sep 17 00:00:00 2001 From: Ismael Luceno Date: Sat, 13 Feb 2021 18:35:48 +0100 Subject: 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. --- FUNCTIONS | 28 ------------- VDEPENDS | 74 +++++++++++++++++++++++++++++++++ devel/cppo/DEPENDS | 2 +- devel/ocaml-extlib/DEPENDS | 1 + devel/ocaml-gen/DEPENDS | 2 +- devel/ocaml-migrate-parsetree/DEPENDS | 2 +- devel/ocaml-ppx-derivers/DEPENDS | 2 +- devel/ocaml-ppx-tools-versioned/DEPENDS | 2 +- devel/ocaml-ptmap/DEPENDS | 2 +- devel/ocaml-sedlex/DEPENDS | 2 +- ftp/rtorrent/DEPENDS | 3 +- gnome2-libs/goffice/DEPENDS | 2 +- gnome2-libs/librsvg2/DEPENDS | 3 +- gnome2-libs/pangomm/DEPENDS | 2 +- graphics-libs/mesa/DEPENDS | 2 +- net/iptables/DEPENDS | 2 +- net/nftables/DEPENDS | 2 +- x11-toolkits/gtk+3/DEPENDS | 3 +- 18 files changed, 90 insertions(+), 46 deletions(-) create mode 100644 VDEPENDS diff --git a/FUNCTIONS b/FUNCTIONS index b93b30c605..1928748da8 100755 --- a/FUNCTIONS +++ b/FUNCTIONS @@ -933,34 +933,6 @@ function check_tmp_noexec() { fi } -#--- -## Versioned dependency list from stdin. -## Takes one dependency per line. Format: -## -#--- -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. 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 <= 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 <= 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 <= 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 && -- cgit v1.2.3