Files
shmake/source_code/shmake_clone_test_library.sh
2026-04-05 15:09:32 -05:00

73 lines
2.8 KiB
Bash

#!/bin/sh
# shmake_testlib.sh - Test library cloning for shmake
# Author: Emilia Marigold
clone_test_library()
{
test_lib="$1"
LIBRARY_DIR="external_code/test_only/source_code"
LIB_URL=""
LIB_NAME=""
case "$test_lib" in
Unity|unity)
LIB_URL="https://github.com/ThrowTheSwitch/Unity.git"
LIB_NAME="Unity"
;;
CMocka|cmocka|CMOCKA)
LIB_URL="https://github.com/clibs/cmocka.git"
LIB_NAME="cmocka"
;;
Check|check)
LIB_URL="https://github.com/libcheck/check.git"
LIB_NAME="check"
;;
None|none)
return 0
;;
*)
printf "Warning: Unknown test library '%s'. Skipping auto-clone.\n" "$test_lib"
return 0
;;
esac
printf "\nAuto-cloning test library '%s' to %s...\n" "$test_lib" "$LIBRARY_DIR"
if ! command -v git >/dev/null 2>&1; then
printf "Warning: 'git' not found. Library '%s' will need to be added manually.\n" "$test_lib"
printf "URL: %s\n" "$LIB_URL"
mkdir -p "shmake_config"
printf "%s\n" "$LIB_URL" > "shmake_config/project_external_libraries.config"
return 1
fi
if [ -d "$LIBRARY_DIR/$LIB_NAME" ]; then
printf "Note: '%s' already exists in %s\n" "$LIB_NAME" "$LIBRARY_DIR"
printf "Overwrite? [y/N]: "
read -r overwrite
case "$overwrite" in
y|Y)
rm -rf "$LIBRARY_DIR/$LIB_NAME"
;;
*)
printf "Keeping existing installation.\n"
printf "%s\n" "$LIB_URL" > "shmake_config/project_external_libraries.config"
return 0
;;
esac
fi
mkdir -p "$LIBRARY_DIR"
printf "Cloning %s (shallow)...\n" "$LIB_NAME"
if git clone "$LIB_URL" "$LIBRARY_DIR/$LIB_NAME"; then
printf "Test library '%s' cloned successfully!\n" "$test_lib"
printf "%s\n" "$LIB_URL" > "shmake_config/project_external_libraries.config"
else
printf "Warning: Failed to clone '%s'. You may need to add it manually.\n" "$test_lib"
printf "URL: %s\n" "$LIB_URL"
printf "%s\n" "$LIB_URL" > "shmake_config/project_external_libraries.config"
return 1
fi
}