]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
build: do not rebuild muon/samu every time
authorDaniel Wagner <dwagner@suse.de>
Thu, 16 Nov 2023 14:28:25 +0000 (15:28 +0100)
committerDaniel Wagner <wagi@monom.org>
Thu, 16 Nov 2023 16:56:07 +0000 (17:56 +0100)
There is not need to build the build tools everytime. Thus stage the
samurai and muon build into a new top level directory .build-tools and
only build them on demand.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
scripts/build.sh

index ec350b77343b42a4fc1c9fe5f19ad94282c496a6..6a36f009e1cdad35633f3d69d0c74b37477ffde6 100755 (executable)
@@ -59,6 +59,7 @@ CONFIG=${1:-"default"}
 cd "$(git rev-parse --show-toplevel)" || exit 1
 
 BUILDDIR="$(pwd)/.build-ci"
+TOOLDIR="$(pwd)/.build-tools"
 
 fn_exists() { declare -F "$1" > /dev/null; }
 
@@ -136,37 +137,47 @@ install_meson_appimage() {
 }
 
 tools_build_samurai() {
-    mkdir -p "${BUILDDIR}"/build-tools
-    git clone --depth 1 https://github.com/michaelforney/samurai.git \
-        "${BUILDDIR}/build-tools/samurai"
-    pushd "${BUILDDIR}/build-tools/samurai" || exit 1
+    if [ ! -d "${TOOLDIR}"/samurai ]; then
+        git clone --depth 1 https://github.com/michaelforney/samurai.git \
+            "${TOOLDIR}/samurai"
+    fi
 
-    CC="${CC}" make
-    SAMU="${BUILDDIR}/build-tools/samurai/samu"
+    if [[ -f "${TOOLDIR}/samurai/samu" ]]; then
+        return
+    fi
 
+    pushd "${TOOLDIR}/samurai" || exit 1
+    CC="${CC}" make
     popd || exit 1
 }
 
 tools_build_muon() {
-    mkdir -p "${BUILDDIR}"/build-tools
-    git clone --depth 1 https://git.sr.ht/~lattis/muon \
-        "${BUILDDIR}/build-tools/muon"
-    pushd "${BUILDDIR}/build-tools/muon" || exit 1
+    if [ ! -d "${TOOLDIR}/muon" ]; then
+        git clone --depth 1 https://git.sr.ht/~lattis/muon \
+            "${TOOLDIR}/muon"
+    fi
+
+    if [[ -f "${TOOLDIR}/build-muon/muon" ]]; then
+        return
+    fi
+
+    pushd "${TOOLDIR}/muon" || exit 1
 
     CC="${CC}" CFLAGS="${CFLAGS} -std=c99" ninja="${SAMU}" ./bootstrap.sh stage1
 
     CC="${CC}" ninja="${SAMU}" stage1/muon setup        \
-        -Dprefix="${BUILDDIR}/build-tools"              \
+        -Dprefix="${TOOLDIR}"                           \
         -Dlibcurl=enabled                               \
         -Dlibarchive=enabled                            \
         -Dlibpkgconf=enabled                            \
         -Ddocs=disabled                                 \
         -Dsamurai=disabled                              \
-        "${BUILDDIR}/build-tools/.build-muon"
-    "${SAMU}" -C "${BUILDDIR}/build-tools/.build-muon"
+        "${TOOLDIR}/build-muon"
+    "${SAMU}" -C "${TOOLDIR}/build-muon"
     MUON="${BUILDDIR}/build-tools/.build-muon/muon"
 
-    # "${MUON}" -C "${BUILDDIR}/build-tools/.build-muon" test
+    # "${TOOLDIR}/build-muon/muon" \
+    #    -C "${TOOLDIR}/build-muon" test
 
     popd || exit 1
 }
@@ -192,22 +203,25 @@ test_muon() {
     ldd "${BUILDDIR}/nvme" 2>&1 | grep 'not a dynamic executable' || exit 1
 }
 
-rm -rf "${BUILDDIR}"
-
 if [[ "${BUILDTOOL}" == "muon" ]]; then
-    if ! which samu ; then
+    SAMU="$(which samu 2> /dev/null)" || true
+    if [[ -z "${SAMU}" ]]; then
         tools_build_samurai
-    else
-        SAMU="$(which samu)"
+        SAMU="${TOOLDIR}/samurai/samu"
     fi
 
-    if ! which muon ; then
+    MUON="$(which muon 2> /dev/null)" || true
+    if [[ -z "${MUON}" ]]; then
         tools_build_muon
-    else
-        MUON="$(which muon)"
+        MUON="${TOOLDIR}/build-muon/muon"
     fi
 fi
 
+echo "samu: ${SAMU}"
+echo "muon: ${MUON}"
+
+rm -rf "${BUILDDIR}"
+
 config_"${BUILDTOOL}"_"${CONFIG}"
 fn_exists "build_${BUILDTOOL}_${CONFIG}" && "build_${BUILDTOOL}_${CONFIG}" || build_"${BUILDTOOL}"
 fn_exists "test_${BUILDTOOL}_${CONFIG}" && "test_${BUILDTOOL}_${CONFIG}" || test_"${BUILDTOOL}"