Welcome to little lamb

Code » comain » commit d53b77a

mktarball: Only include components (no more "internal"..

author Olivier Brunel
2023-07-06 07:29:03 UTC
committer Olivier Brunel
2023-07-07 17:07:37 UTC
parent a30b274873bf04cba035c089118054b7c19dca6a

mktarball: Only include components (no more "internal"..

..dependencies), actually limit to the files listed in "files" if any,
don't about if a command fails, and allow creation from a branch other
than master (for testing purposes).

libcomain +9 -0
mktarball +44 -33

diff --git a/libcomain b/libcomain
index c5d2260..ec59e93 100644
--- a/libcomain
+++ b/libcomain
@@ -93,6 +93,15 @@ run()
     fi
 }
 
+tryrun()
+{
+    "$@"
+    local r=$?
+    if test $r -ne 0; then
+        warn "Failed ($r): $@"
+    fi
+}
+
 foreach()
 {
     local name="$1"
diff --git a/mktarball b/mktarball
index f1dae03..32ac20a 100755
--- a/mktarball
+++ b/mktarball
@@ -2,66 +2,77 @@
 
 . "$(dirname $0)"/libcomain
 
+tbname="$name-$version"
+
+if test $# -ge 1; then
+    from="$1"
+    tbname="$tbname++$from"
+    shift
+else
+    from=master
+fi
+
+if test $# -gt 0; then die 1 "usage: $0 [branch]"; fi
+
 echo " => Prepare new directory..."
-tb="$(pwd)/$name-$version"
+tb="$(pwd)/$tbname"
 if test -e $tb; then error 2 "File '$tb' already exists"; fi
 if test -e $tb.tar.xz; then error 2 "File '$tb.tar.xz' already exists"; fi
 if test ! -e meta/desc; then error 2 "File 'meta/desc' missing"; fi
 
-echo "  -> Check out new worktree (branch tarball from master)..."
-run git worktree add $tb -b tarball master
+echo "  -> Check out new worktree (branch tarball from $from)..."
+run git worktree add $tb -b tarball $from
 
-adddep()
+addcpnt()
 {
     local dep=$2
     local depname="${dep##*/}"
-    local intonly=$3
-    if test $intonly -eq 1 && test ! -e "$dep/files"; then return; fi
 
     local ref="$(cat $dep/ref 2>/dev/null)"
     if test -z "$ref"; then ref="$(cat $dep/version)"; fi
     echo "  -> Check out $depname new worktree (branch tarball from $ref)..."
-    run git -C ../$depname worktree add $tb/$depname -b tarball $ref
+    tryrun mkdir -p $tb/deps
+    local dst=$tb/$depname
+    tryrun git -C ../deps/$depname worktree add $dst.full -b tarball $ref
+    tryrun ln -s ../$depname $tb/deps
+    if test -e $dep/files; then
+        echo "  -> Copy needed files..."
+        tryrun mkdir $dst
+        while IFS= read -r file; do
+            tryrun mkdir -p $dst/$(dirname $file)
+            tryrun cp $dst.full/$file $dst/$file
+        done < $dep/files
+        tryrun mkdir $dst/meta
+        tryrun cp $dep/version $dst/meta
+    else
+        echo "  -> Copy files..."
+        tryrun cp -aR $dst.full $dst
+    fi
+    echo "  -> Remove $depname worktree..."
+    tryrun git -C ../deps/$depname worktree remove --force $dst.full
+    tryrun git -C ../deps/$depname branch -D tarball
 }
-echo "  -> Add components & \"internal\" dependencies..."
+echo "  -> Add components..."
 cd $tb
 loaddeps
-foreach cpnt $nb_cpnt adddep 0
-foreach deps $nb_deps adddep 1
+foreach cpnt $nb_cpnt addcpnt 0
 cd ..
 
 echo "  -> Set up configure & common.mk..."
 make -C $tb
 
 echo "  -> Generate README..."
-run rm $tb/README
-run comain/mkreadme > $tb/README
+tryrun rm $tb/README
+tryrun comain/mkreadme > $tb/README
 
-if ! test -e $tb/include; then mkdir $tb/include; fi
+if ! test -e $tb/src/include; then mkdir $tb/src/include; fi
 
 echo " => Create tarball..."
-run tar -cJp --owner=0 --group=0 --numeric-owner --exclude=".git"* -f $tb.tar.xz "$prjname-$prjver"
+tryrun tar -cJp --owner=0 --group=0 --numeric-owner --exclude=".git"* -f $tb.tar.xz "$tbname"
 
 echo " => Clean up..."
-deldep()
-{
-    local dep=$2
-    local depname="${dep##*/}"
-    local intonly=$3
-    if test $intonly -eq 1 && test ! -e "$dep/files"; then return; fi
-
-    local ref="$(cat $dep/ref 2>/dev/null)"
-    if test -z "$ref"; then ref="$(cat $dep/version)"; fi
-    run git -C ../$depname worktree remove --force $tb/$depname
-    run git -C ../$depname branch -D tarball
-}
-echo "  -> Remove components & \"internal\" dependencies..."
-cd $tb
-foreach cpnt $nb_cpnt deldep 0
-foreach deps $nb_deps deldep 1
-cd ..
 echo "  -> Remove worktree & branch tarball..."
-run git worktree remove --force $tb
-run git branch -D tarball
+tryrun git worktree remove --force $tb
+tryrun git branch -D tarball
 
 echo "done."