From 0e824f58d5531665443aaa4c90cdc1d41581ada3 Mon Sep 17 00:00:00 2001 From: oskarth Date: Wed, 31 Jan 2024 11:41:37 +0800 Subject: [PATCH] fix(scripts): Make dylib lib an argument --- mopro-core/README.md | 5 +++-- scripts/update_bindings.sh | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/mopro-core/README.md b/mopro-core/README.md index 452109f1..c096de02 100644 --- a/mopro-core/README.md +++ b/mopro-core/README.md @@ -36,9 +36,10 @@ Note that: ### Script -Add third argument: `dylib`: +- Add third argument `dylib` +- Add forth argument with name of dylib, e.g. `rsa` if you want `rsa.dylib` -`./scripts/update_bindings.sh device release dylib` +`./scripts/update_bindings.sh device release dylib rsa` Note that `APPLE_SIGNING_IDENTITY` must be set. diff --git a/scripts/update_bindings.sh b/scripts/update_bindings.sh index 79fa3177..ef56bd81 100755 --- a/scripts/update_bindings.sh +++ b/scripts/update_bindings.sh @@ -73,10 +73,17 @@ else exit 1 fi -# Check if the third argument is 'dylib' -USE_DYLIB=false +# Check if the third argument is 'dylib' and validate the fourth argument if [[ $# -ge 3 ]] && [[ "$3" == "dylib" ]]; then USE_DYLIB=true + # Check if the fourth argument is provided + if [[ $# -lt 4 ]]; then + echo -e "${RED}Error: Please specify the name of the dylib file as the fourth argument.${DEFAULT}" + exit 1 + fi + DYLIB_NAME="$4.dylib" # Assuming the extension is always .dylib +else + USE_DYLIB=false fi print_action "Updating mopro-ffi bindings and library ($BUILD_MODE $DEVICE_TYPE)..." @@ -134,16 +141,15 @@ cp ${TARGET_DIR}/SwiftBindings/mopro.swift ${MOPROKIT_DIR}/Bindings/ cp ${TARGET_DIR}/SwiftBindings/moproFFI.modulemap ${MOPROKIT_DIR}/Resources/ cp ${TARGET_DIR}/libmopro_ffi.a ${MOPROKIT_DIR}/Libs/ +# TODO: Improve CLI, positional arguments a bit messy # Dylib assets -# TODO: Hardcoded to rsa for now if [[ "$USE_DYLIB" == true ]]; then - print_action "Copying dynamic library asset (rsa)..." - cp ${PROJECT_DIR}/mopro-core/target/${ARCHITECTURE}/${LIB_DIR}/rsa.dylib ${TARGET_DIR}/ - cp ${TARGET_DIR}/rsa.dylib ${MOPROKIT_DIR}/Libs/ + print_action "Copying dynamic library asset (${DYLIB_NAME})..." + cp "${PROJECT_DIR}/mopro-core/target/${ARCHITECTURE}/${LIB_DIR}/${DYLIB_NAME}" "${TARGET_DIR}/" + cp "${TARGET_DIR}/${DYLIB_NAME}" "${MOPROKIT_DIR}/Libs/" # Fix dynamic lib install paths - # NOTE: Xcode might already do this for us - install_name_tool -id @rpath/rsa.dylib ${MOPROKIT_DIR}/Libs/rsa.dylib - codesign -f -s "${APPLE_SIGNING_IDENTITY}" ${MOPROKIT_DIR}/Libs/rsa.dylib -fi + # NOTE: Xcode might already do this for us; verify this + install_name_tool -id "@rpath/${DYLIB_NAME}" "${MOPROKIT_DIR}/Libs/${DYLIB_NAME}" + codesign -f -s "${APPLE_SIGNING_IDENTITY}" "${MOPROKIT_DIR}/Libs/${DYLIB_NAME}" print_action "Done! Please re-build your project in Xcode." \ No newline at end of file