Welcome to little lamb

Code » comain » commit 9243a5e

getdeps: Add recursive dependencies support

author Olivier Brunel
2023-05-17 13:12:38 UTC
committer Olivier Brunel
2023-06-20 07:07:15 UTC
parent 925236162bdd76bd6f3abcf0e36e0f2bbc75c01d

getdeps: Add recursive dependencies support

configure +29 -10
getdeps +62 -13
initprj +0 -1

diff --git a/configure b/configure
index 3350008..1e44fed 100755
--- a/configure
+++ b/configure
@@ -180,12 +180,15 @@ procdep()
     if test -e "$dep/library"; then library="$(cat $dep/library)"; fi
     local internal=0
     local found=0
+    local depdir=
 
     if test "$cpnt" -ne 1; then
         type="Dependency"
+        depdir="deps/$depname"
     else
         type="Component"
         internal=1
+        depdir="./$depname"
     fi
 
     if procneeddep "$depname"; then
@@ -195,14 +198,14 @@ procdep()
         return
     fi
 
-    if test -d "./$depname"; then
+    if test -d "$depdir"; then
         found=1
         internal=1
         # internal deps defaults to static linking
         link=2
         path="include"
         if test -e "$dep/incdir"; then path="$(cat $dep/incdir)"; fi
-        path="$depname/$path"
+        path="$depdir/$path"
     fi
 
     echon "  -> $type $depname "
@@ -210,8 +213,8 @@ procdep()
     local l="$(eval "echo \$link$depname")"
     if test -n "$l" && test "$l" -ge 0; then link="$l"; fi
 
-    local vpathso=$depname
-    local vpatha=$depname
+    local vpathso="$depdir"
+    local vpatha="$depdir"
     if test $cpnt -ne 1 && test $found -eq 0; then
         local ln="lib$library"
         local d="$(cat $dep/dynlibdir 2>/dev/null)"
@@ -230,8 +233,8 @@ procdep()
     fi
     echon "found"
 
-    if test -e "./$depname/meta/version"; then
-        depver="$(cat ./$depname/meta/version)"
+    if test -e "$depdir/meta/version"; then
+        depver="$(cat $depdir/meta/version)"
     fi
     if test -z "$depver"; then
         depver="$($dep/get_version "$path" 2>/dev/null)"
@@ -299,14 +302,28 @@ vpath lib$library.a $vpatha"
         else
             path="include"
             if test -e "$dep/incdir"; then path="$(cat $dep/incdir)"; fi
-            path="$depname/$path"
+            path="$depdir/$path"
 
             if test -e "$dep/configure"; then
-                BUILD_DEPS="$BUILD_DEPS $depname.built"
+                local f=
+                local e=
+                if test $link -eq 1; then
+                    f="$vpathso"
+                    e=so
+                else
+                    f="$vpatha"
+                    e=a
+                fi
+                f="$f/lib$library.$e"
+                if test -e "$f"; then
+                    touch "$depdir.built"
+                fi
+
+                BUILD_DEPS="$BUILD_DEPS $depdir.built"
             fi
 
             if test $depname = "skalibs"; then
-                sysdeps="$depname/sysdeps.cfg"
+                sysdeps="$depdir/sysdeps.cfg"
             fi
         fi
         COMMON_CPPFLAGS="$COMMON_CPPFLAGS -isystem $path"
@@ -648,7 +665,9 @@ setupobjs()
         while IFS= read -r depname; do
             depname=${depname##*/+}
             local idx=$(($(eval echo \$idx$depname) + 0))
-            deps=$(($deps | (1 << ($idx - 1))))
+            if test $idx -ge 1; then
+                deps=$(($deps | (1 << ($idx - 1))))
+            fi
         done < $tmp
         rm -r $tmp
         local i=1
diff --git a/getdeps b/getdeps
index 1b2ecfd..613ad75 100755
--- a/getdeps
+++ b/getdeps
@@ -30,14 +30,24 @@ showdep()
     local depname="${dep##*/}"
     local needed
     eval needed=\"\$need$depname\"
-    echon "- $depname version $(cat $dep/version)"
-    if test "$needed" != "1"; then
+    local rec="$3"
+    echon "$rec- $depname version $(cat $dep/version)"
+    if test -z "$rec" && test "$needed" != "1"; then
         echon " [optional: --with-$(echo $needed | sed "s/ /, --with-/g")]"
     fi
     echo
-    if test -f "$dep/site"; then echo "  site : $(cat $dep/site)"; fi
-    if test -f "$dep/git" ; then echo "  repo : $(cat $dep/git)" ; fi
-    if test -f "$dep/ref" ; then echo "  ref  : $(cat $dep/ref)" ; fi
+    if test -f "$dep/site"; then echo "$rec  site : $(cat $dep/site)"; fi
+    if test -f "$dep/git" ; then echo "$rec  repo : $(cat $dep/git)" ; fi
+    if test -f "$dep/ref" ; then echo "$rec  ref  : $(cat $dep/ref)" ; fi
+
+    local dst=
+    if ! test -e "$dep/cpnt"; then dst="deps"; fi
+    # recursive lila dependency
+    if ! test -d "$dst/$depname/meta/deps"; then return; fi
+    for d in "$dst/$depname"/meta/deps/*; do
+        if ! test -d "$d"; then continue; fi
+        showdep 0 "$d" "$rec  "
+    done
 }
 
 list()
@@ -54,15 +64,54 @@ getdep()
     local dep=$2
     local depname="${dep##*/}"
     local intonly=$3
+    local rec=$4
+    if test -z "$rec"; then rec="."; fi
+    local cpnt=
+    if test -z "$rec" && test -e "$dep/cpnt"; then
+        cpnt=1
+        dst="$depname"
+    else
+        cpnt=0
+        dst="deps/$depname"
+    fi
     if test $intonly -eq 1 && test ! -e "$dep/files"; then return; fi
-    if test -e "$depname"; then
-        warn "cannot clone $depname: file already exists"
-        return
+    echo "getting $depname..."
+    if ! test -e "deps"; then run mkdir "deps"; fi
+    if test -e "$dst"; then
+        warn "cannot clone: '$dst' already exists"
+        if test -z "$rec" && test $cpnt -eq 1 && ! test -e "deps/$depname"; then
+            run ln -s "../$depname" "deps/$depname"
+        fi
+    else
+        run git clone "$(cat $dep/git)" "deps/$depname"
+        local ref="$(cat $dep/ref 2>/dev/null)"
+        if test -z "$ref"; then ref="$(cat $dep/version)"; fi
+        run git -C "deps/$depname" checkout -b "$prjname" "$ref"
+
+        if test $cpnt -eq 1; then ln -s "deps/$depname" "$depname"; fi
     fi
-    run git clone "$(cat $dep/git)" "$depname"
-    local ref="$(cat $dep/ref 2>/dev/null)"
-    if test -z "$ref"; then ref="$(cat $dep/version)"; fi
-    run git -C $depname checkout -b $prjname "$ref"
+
+    # recursive lila dependency
+    if test $cpnt -eq 1; then return; fi
+    if ! test -d "deps/$depname/meta/deps"; then return; fi
+    if ! test -d "deps/$depname/deps"; then run mkdir "deps/$depname/deps"; fi
+    for d in "deps/$depname/meta/deps/"*; do
+        if ! test -d "$d"; then continue; fi
+        local int=$intonly
+        if test -e "$d/cpnt"; then int=0; fi
+        getdep 0 "$d" "$int" "../$rec"
+        if test "$int" -eq 1 && ! test -e "$d/files"; then continue; fi
+        local n="${d##*/}"
+        local p="$(realpath "deps/$n")"
+        if test -e "$d/cpnt"; then
+            n="deps/$depname/$n"
+        else
+            n="deps/$depname/deps/$n"
+        fi
+        if ! test -e "$n"; then
+            run ln -s "$p" "$n"
+        fi
+    done
 }
 
 loadoptions
@@ -72,7 +121,7 @@ isdep=0
 for arg ; do
     if test $isdep -eq 1; then
         if test ! -d meta/deps/$arg; then error 2 "unknown dependency '$arg'"; fi
-        getdep meta/deps/$arg 0
+        getdep 0 meta/deps/$arg 0
         continue
     fi
     case "$arg" in
diff --git a/initprj b/initprj
index 39b4ba1..e19cb15 100755
--- a/initprj
+++ b/initprj
@@ -38,7 +38,6 @@ git checkout -b dev-wip
 git add h
 git commit -m 'wip: Add h'
 
-run cp -a comain/meta/deps.tpl/skalibs meta/deps
 run cp -a comain/meta/deps.tpl/limb meta/deps
 
 run mkdir src/$name