Relax tmpfs ram limits while building stuff
authorDaniel Abrecht <public@danielabrecht.ch>
Sun, 22 May 2022 15:18:11 +0000 (15:18 +0000)
committerDaniel Abrecht <public@danielabrecht.ch>
Sun, 22 May 2022 15:18:11 +0000 (15:18 +0000)
script/with-repo.sh

index b8404450f60fdd774807da237d7b192c3443cdd0..6c4165bab7ab6d180a5f534ca0a087b460065e6e 100755 (executable)
@@ -7,10 +7,18 @@ fi
 
 mkdir -p "$project_root/build/repo/"
 
+# Note: tmpfs size is set to 50% of ram, including swap.
+# Default is 50% without swap, but that may not be enough on devices with only 4GB ram or so.
+# On those devices, it's also possible to set KEEP_BUILD_REPO, but that's slower and leaves the repo directories behind. THat can sometimes be useful too, though. 
+
 unshare -mr /bin/bash -ex -c '
 cleanup(){ umount "$project_root/build/repo/"; }
 trap cleanup EXIT TERM INT
-mount -t tmpfs none "$project_root/build/repo/"
+if [ -z "$KEEP_BUILD_REPO" ]
+then
+  size=$(($(free -tm | sed -n "s/^Total:[ \t]*\([0-9]\+\).*/\1/p") / 2))
+  mount -t tmpfs -o size="$size"m none "$project_root/build/repo/"
+fi
 clone_repo(){
   name="$1"
   repo_branch="$(printenv -- "repo-branch@$name")"
@@ -19,7 +27,7 @@ clone_repo(){
   git clone --shared -n "$gitrepo" "$repodir/$name"
   ( cd "$repodir/$name"; git checkout "$repo_branch"; )
 }
-export repodir="$project_root/build/repo"
+export repodir="$(mktemp -d -p "$project_root/build/repo" "repo.XXXXXXXXXX")"
 while IFS=, read name; do clone_repo "$name"; done <<<"$1"
 shift
 read _ uid _ </proc/self/uid_map