allow to specify thread counts (sync,build)

when DOS_MAX_THREADS_REPO and/or DOS_MAX_THREADS_BUILD are defined
in init.sh they will be used. otherwise the max threads are calculated
based on the cpu cores count.

if that calculation fails (depends on nproc) a default fallback of:

- 4 is used for repo sync (which reflects the current state for repo sync)
- `<empty>` is used for make - which yields to no limitation (which reflects the current state for mka / make)

to avoid issues regarding being rate limited a max value for repo sync processes
will overwrite DOS_MAX_THREADS_REPO when set greater than MAX_THREADS_REPO_RATE (8).

Signed-off-by: steadfasterX <steadfasterX@gmail.com>
This commit is contained in:
steadfasterX 2023-03-30 13:32:30 +00:00
parent 5f783a6618
commit b3bef085f8
No known key found for this signature in database
GPG Key ID: D97F436B1A616F5D
9 changed files with 51 additions and 10 deletions

View File

@ -23,7 +23,7 @@ export -f startPatcher;
resetWorkspace() {
umask 0022;
repo forall -c 'git add -A && git reset --hard' && rm -rf out DOS_PATCHED_FLAG && repo sync -j8 --force-sync --detach;
repo forall -j${DOS_MAX_THREADS_REPO} -c 'git add -A && git reset --hard' && rm -rf out DOS_PATCHED_FLAG && repo sync -j${DOS_MAX_THREADS_REPO} --force-sync --detach;
}
export -f resetWorkspace;
@ -33,7 +33,7 @@ patchWorkspace() {
export -f patchWorkspace;
verifyAllPlatformTags() {
repo forall -v -c 'sh -c "source $DOS_WORKSPACE_ROOT/Scripts/Common/Tag_Verifier.sh && verifyTagIfPlatform $REPO_PROJECT $REPO_PATH"';
repo forall -j${DOS_MAX_THREADS_REPO} -v -c 'sh -c "source $DOS_WORKSPACE_ROOT/Scripts/Common/Tag_Verifier.sh && verifyTagIfPlatform $REPO_PROJECT $REPO_PATH"';
}
export -f verifyAllPlatformTags;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
pkill java && sleep 10; #XXX: ugly hack
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
pkill java && sleep 10; #XXX: ugly hack
}
export -f buildDevice;
@ -43,7 +43,7 @@ buildDeviceUserDebug() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-userdebug" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-userdebug" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -34,7 +34,7 @@ buildDevice() {
cd "$DOS_BUILD_BASE";
if [[ -d "$DOS_SIGNING_KEYS/$1" ]]; then
#export OTA_KEY_OVERRIDE_DIR="$DOS_SIGNING_KEYS/$1";
breakfast "lineage_$1-user" && mka target-files-package otatools && processRelease $1 true $2;
breakfast "lineage_$1-user" && mka -j${DOS_MAX_THREADS_BUILD} target-files-package otatools && processRelease $1 true $2;
else
echo -e "\e[0;31mNo signing keys available for $1\e[0m";
fi;

View File

@ -21,6 +21,8 @@
#START OF USER CONFIGURABLE OPTIONS
#
#General
#export DOS_MAX_THREADS_REPO=8; #Max amount of threads used for sync, e.g. used by repo (shouldn't exceed your CPU cores count, due to rate limit restrictions this cannot be set higher then 8)
#export DOS_MAX_THREADS_BUILD="nolimit"; #Max amount of threads used for build, e.g. used by make (shouldn't exceed your CPU cores count)
export DOS_WORKSPACE_ROOT="/mnt/dos/"; #XXX: THIS MUST BE CORRECT TO BUILD!
#export DOS_BUILDS=$DOS_WORKSPACE_ROOT"Builds/";
export DOS_BUILDS="/mnt/Drive-4/DOS/Builds/"; #XXX: THIS MUST BE CORRECT TO BUILD!
@ -109,6 +111,45 @@ export DOS_THEME_700="E64A19"; #Deep Orange 700
umask 0022;
# by default we will calculate the max CPU count automatically (used by e.g. repo commands)
# if the required tool "nproc" is not found a default is used.
export FALLBACK_MAX_THREADS_REPO=4;
export MAX_THREADS_REPO_RATE=8; #to avoid being rate limited we never go above this for syncing
export FALLBACK_MAX_THREADS_BUILD="nolimit"; #if nothing specified we will use all CPU power available
calcThreads(){
unset _MAX_THREADS
DEFAULT_COUNT=$1
nproc --version > /dev/null 2>&1
if [ $? -eq 10 ];then
_MAX_THREADS_ALL=$(nproc --all)
_MAX_THREADS=$(( _MAX_THREADS_ALL - 1))
fi
if [ -z "$_MAX_THREADS" ];then
echo $DEFAULT_COUNT
return 9
else
echo $_MAX_THREADS
fi
}
export -f calcThreads;
if [ -z "$DOS_MAX_THREADS_REPO" ];then
export DOS_MAX_THREADS_REPO=$(calcThreads $FALLBACK_MAX_THREADS_REPO) \
|| echo -e "\e[0;33mWARNING: could not calculate thread count and no user defined amount specified. This could slow down the SYNC processes.\e[0m"
fi
if [ "$DOS_MAX_THREADS_REPO" -gt "$MAX_THREADS_REPO_RATE" ];then
echo -e "\e[0;33mWARNING: Your specified DOS_MAX_THREADS_REPO value ($DOS_MAX_THREADS_REPO) could raise rate limits so has been decreased to >$MAX_THREADS_REPO_RATE<.\e[0m"
export DOS_MAX_THREADS_REPO=$MAX_THREADS_REPO_RATE
fi
if [ -z "$DOS_MAX_THREADS_BUILD" ];then
export DOS_MAX_THREADS_BUILD=$(calcThreads $FALLBACK_MAX_THREADS_BUILD)\
|| echo -e "\e[0;33mWARNING: could not calculate thread count and no user defined amount specified. This could slow down the BUILD processes.\e[0m"
fi
echo "Activated CPU count (sync): $DOS_MAX_THREADS_REPO"
echo "Activated CPU count (build): $DOS_MAX_THREADS_BUILD"
[ "$DOS_MAX_THREADS_BUILD" == "nolimit" ] && export DOS_MAX_THREADS_BUILD="" #actually means "all" when empty
gpgVerifyGitHead() {
if [ -r "$DOS_TMP_GNUPG/pubring.kbx" ]; then
if git -C "$1" verify-commit HEAD &>/dev/null; then