Parallelize build jobs according to CPU count

This commit is contained in:
Rangi
2026-07-05 20:58:50 -04:00
committed by Rangi
parent 5d5000011a
commit 189c679e13
9 changed files with 99 additions and 44 deletions
+12 -3
View File
@@ -9,6 +9,15 @@ else()
endif()
set(TESTS_OS_NAME "${TESTS_OS_NAME}" CACHE STRING "Skip running tests known to fail on this OS.")
include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(PROCESSOR_COUNT EQUAL 0)
set(PROCESSOR_COUNT 4)
message(STATUS "Could not determine CPU count; defaulting to ${PROCESSOR_COUNT}.")
else()
message(STATUS "Counted ${PROCESSOR_COUNT} logical CPU cores.")
endif()
add_executable(randtilegen gfx/randtilegen.cpp)
add_executable(rgbgfx_test gfx/rgbgfx_test.cpp)
set_target_properties(randtilegen rgbgfx_test PROPERTIES
@@ -29,7 +38,7 @@ foreach(component "asm" "link" "fix" "gfx")
COMMAND bash -- test.sh
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${component}")
set_tests_properties("rgb${component}" PROPERTIES REQUIRED_FILES "$<TARGET_FILE:rgb${component}>"
PROCESSORS 1
PROCESSORS 1 # These cannot be parallelized.
LABELS "internal;free")
endforeach()
set_tests_properties(rgbgfx PROPERTIES REQUIRED_FILES "$<TARGET_FILE:rgbgfx>;$<TARGET_FILE:randtilegen>;$<TARGET_FILE:rgbgfx_test>")
@@ -69,10 +78,10 @@ foreach(cfg_file IN LISTS ext_projects)
endif()
add_test(NAME "${project}"
COMMAND bash -- external/test.sh ${project}
COMMAND bash -- external/test.sh ${project} -j "${PROCESSOR_COUNT}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
set_tests_properties(${project} PROPERTIES DEPENDS "rgbasm;rgblink;rgbfix;rgbgfx" # Only attempt external tests after all individual tool tests.
PROCESSORS 4
PROCESSORS "${PROCESSOR_COUNT}"
LABELS "external;${freedom}"
FIXTURES_REQUIRED "${freedom}-repos")
endforeach()
+5 -4
View File
@@ -7,10 +7,11 @@ usage() {
cat <<"EOF"
Downloads source code of Game Boy project repos used as RGBDS test cases.
Options:
-h, --help show this help message
--only-free download only freely licensed codebases
--get-hash print repos' commit hashes instead of downloading them
--get-paths print repos' clone paths instead of downloading them
-h, --help show this help message
--only-free download only freely licensed codebases
--only-nonfree download only non-freely licensed codebases
--get-hash print repos' commit hashes instead of downloading them
--get-paths print repos' clone paths instead of downloading them
EOF
}
+8 -5
View File
@@ -8,13 +8,16 @@ export SOURCE_DATE_EPOCH=609165296
cd "$(dirname "$0")"
if [ ! -f "$1.cfg" ]; then
echo >&2 'External test file '"$1"'.cfg does not exist'
NAME="$1"
shift # Any remaining arguments get forwarded to `make`.
if [ ! -f "$NAME.cfg" ]; then
echo >&2 'External test file '"$NAME"'.cfg does not exist'
exit 1
fi
# Sourcing "$1.cfg" defines `EXT_TEST_*` variables used below.
. "$1.cfg"
# Sourcing "$NAME.cfg" defines `EXT_TEST_*` variables used below.
. "$NAME.cfg"
if ! cd "$EXT_TEST_REPO"; then
echo >&2 'Please fetch test deps before running any external test'
@@ -23,7 +26,7 @@ fi
RGBDS_PATH="RGBDS=../../../"
git clean -fdx # Clean any previous build products so `make` rebuilds everything from scratch.
make -j4 "$EXT_TEST_TARGET" $RGBDS_PATH
make "$@" "$EXT_TEST_TARGET" $RGBDS_PATH
hash="$(sha1sum -b "$EXT_TEST_FILE" | head -c 40)"
if [ "$hash" != "$EXT_TEST_HASH" ]; then
+7 -1
View File
@@ -16,6 +16,7 @@ Options:
--only-internal only run tests that build local examples
--only-external only run tests that build external codebases
--only-free skip tests that build nonfree codebases
--jobs <n> build external codebases with `make -j<n>`
--os <os> skip tests known to fail on <os> (e.g. `macos-14`)
--installed-rgbds use the system installed RGBDS
(only compatible with external codebases)
@@ -28,6 +29,7 @@ nonfree=true
internal=true
external=true
installedrgbds=false
make_jobs=
osname=
while [[ $# -gt 0 ]]; do
case "$1" in
@@ -47,6 +49,10 @@ while [[ $# -gt 0 ]]; do
--installed-rgbds)
installedrgbds=true
;;
--jobs)
shift
make_jobs="-j$1"
;;
--os)
shift
osname="$1"
@@ -122,6 +128,6 @@ for cfg in *.cfg; do (
# Run nonfree tests only if they are opted into.
if ! "$EXT_TEST_IS_NONFREE" || "$nonfree"; then
./test.sh "$test_name"
./test.sh "$test_name" "$make_jobs"
fi
); done