From 9fd504e24a74225388031a71da4a257cfc2e320a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 18 May 2024 04:53:31 +0100 Subject: [PATCH] git.sh: Remove .git if XBMK_RELEASE=y The build system already deletes .git in all source directories for each given release, but does so at the very end; it still does, but now it is deleted one by one per project, to save space during very large builds (release sizes vary wildly, depending on how many trees exist for coreboot basically). If you're building entirely in tmpfs (as I do), this could be a problem if you have lots of .git/ directories. This change reduces disk usage, or in the above example, memory usage when running the build system from tmpfs. This complements another recent change, where ROM images are compressed per target during release builds, rather than all at the very end of the process. It is part of a series of optimisations, to reduce the memory and disk usage of the build system, and to reduce I/O wastage in general. This change will not be the last of such changes! Signed-off-by: Leah Rowe --- build | 3 +-- include/git.sh | 2 ++ include/option.sh | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/build b/build index b7ea635..d585029 100755 --- a/build +++ b/build @@ -152,8 +152,7 @@ fetch_trees() [ ! -f "$x" ] || [ -L "$xp" ] || x_ rm -Rf "src/$xp/$xp" done - find . -name ".git" -exec rm -Rf {} + || $err "$_xm: rm .git" - find . -name ".gitmodules" -exec rm -Rf {} + || $err "$_xm: rm .gitmod" + rmgit . rm -Rf tmp .git src/u-boot/*/test/lib/strlcat.c || $err "$_xm !rm" } diff --git a/include/git.sh b/include/git.sh index 60dcb7b..dbb447e 100755 --- a/include/git.sh +++ b/include/git.sh @@ -116,6 +116,8 @@ git_prep() fi fi + [ "$xbmk_release" = "y" ] && rmgit "$tmpgit" + [ "$_loc" = "${_loc%/*}" ] || x_ mkdir -p "${_loc%/*}" mv "$tmpgit" "$_loc" || $err "git_prep: !mv $tmpgit $_loc" [ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \ diff --git a/include/option.sh b/include/option.sh index b2e94a6..1114611 100755 --- a/include/option.sh +++ b/include/option.sh @@ -178,3 +178,12 @@ mksha512sum() $err "!sha512sum \"${1}\" > \"${2}\"" ) || $err "failed to create tarball checksum" } + +rmgit() +{ + ( + cd "$1" || $err "!cd gitrepo $1" + find . -name ".git" -exec rm -Rf {} + || $err "!rm .git $1" + find . -name ".gitmodules" -exec rm -Rf {} + || $err "!rm .gitmod $1" + ) || $err "Cannot remove .git/.gitmodules in $1" +}