Closed oryonatan closed 1 month ago
@johnno1962 notice two changes:
In fact, I don't think you need to change COPY to CODESIGNING_FOLDER_PATH if you're not linking the app directly with Nimble as by the time you inject the test, the bundle will have been loaded and if the testing libraries are in iOSInjection.bundle/Frameworks they will be used instead. It's probably better using "COPY" as then you don't have to worry about special casing macOS's different paths.
But for being able to inject tests on real device platforms (i.e. iphoneos for now) you'll also need to copy Nimble (and Quick?) frameworks into iOSInjection.bundle/Frameworks right? To have this work reliably, you might also want to have Nimble as a dependency of your main app's build (but not link with it.)
I have to be honest and say that I changed from COPY
to CODESIGNING_FOLDER_PATH
because you said that we should do this ... I am not exactly sure in what cases we need each one.
Additionally - the injection bundle works well on XCode16 after the change, without changing anything in the app dependencies / link setting, this might be just a fluke though, so I am willing to test a different version of the script if you think it'll be more correct.
I did try reverting the CODESIGNING_FOLDER_PATH change and it stopped working on device 🤷♂️
I did try reverting the CODESIGNING_FOLDER_PATH change and it stopped working on device 🤷♂️
Can you tell me what the error was please? You can't just change all $CODESIGNING_FOLDER_PATH to $COPY. Please post the script that didn't work here. At the end of the day I can merge this if you tell me it satisfies all your requirements, works on device and agree to support it. Without a small example project using Nimble, I'll have to take your word for it.
I'm at a loss to explain how tests would work on a device without copying the Nimble framework somewhere. Any chance you could humour me and alter the script to just move lines 30-39 out of the if without changing anything else and test it please.
Regarding the issue on device when using COPY instead of CODESIGNING_FOLDER_PATH Its the same issue we saw on simulator - dlopen failing due to missing nimble .
Regarding completely removing lines 30-39 It results in a recompile error of the following format:
error: no such module 'Nimble'
4 | @testable import XXXXXXX
5 |
6 | import Nimble
| `- error: no such module 'Nimble'
Whatever. You're not really following what I'm saying. Let me know when you're happy with the script and I'll merge it if you'll help support it. Just to be clear, I would have liked you to try the following version of the script:
#!/bin/bash -x
#
# copy_bundle.sh
# InjectionIII
#
# Copies injection bundle for on-device injection.
# Thanks @oryonatan
#
# $Id: //depot/HotReloading/copy_bundle.sh#14 $
#
if [ "$CONFIGURATION" == "Debug" ]; then
RESOURCES=${RESOURCES:-"$(dirname "$0")"}
COPY="$CODESIGNING_FOLDER_PATH/iOSInjection.bundle"
PLIST="$COPY/Info.plist"
if [ "$PLATFORM_NAME" == "macosx" ]; then
BUNDLE=${1:-macOSInjection}
COPY="$CODESIGNING_FOLDER_PATH/Contents/Resources/macOSInjection.bundle"
PLIST="$COPY/Contents/Info.plist"
elif [ "$PLATFORM_NAME" == "appletvsimulator" ]; then
BUNDLE=${1:-tvOSInjection}
elif [ "$PLATFORM_NAME" == "appletvos" ]; then
BUNDLE=${1:-tvOSDevInjection}
elif [ "$PLATFORM_NAME" == "xrsimulator" ]; then
BUNDLE=${1:-xrOSInjection}
elif [ "$PLATFORM_NAME" == "xros" ]; then
BUNDLE=${1:-xrOSDevInjection}
elif [ "$PLATFORM_NAME" == "iphoneos" ]; then
BUNDLE=${1:-iOSDevInjection}
else
BUNDLE=${1:-iOSInjection}
fi
# Copy frameworks for when injecting tests
rsync -a "$PLATFORM_DEVELOPER_LIBRARY_DIR"/{Frameworks,PrivateFrameworks}/XC* "$PLATFORM_DEVELOPER_USR_DIR/lib"/*.dylib "$COPY/Frameworks/" &&
codesign -f --sign "$EXPANDED_CODE_SIGN_IDENTITY" --timestamp\=none --preserve-metadata\=identifier,entitlements,flags --generate-entitlement-der "$COPY/Frameworks"/{XC*,*.dylib};
# Xcode 16's new way of bundling tests
TESTING="/tmp/Testing.$PLATFORM_NAME.framework"
if [ -d "$CODESIGNING_FOLDER_PATH/Frameworks/Testing.framework" ]; then
rsync -a "$CODESIGNING_FOLDER_PATH/Frameworks/Testing.framework"/* "$TESTING/"
elif [ -d "$TESTING" ]; then
rsync -a "$TESTING"/* "$COPY/Frameworks/Testing.framework/"
codesign -f --sign "$EXPANDED_CODE_SIGN_IDENTITY" --timestamp\=none --preserve-metadata\=identifier,entitlements,flags --generate-entitlement-der "$COPY/Frameworks/Testing.framework";
fi
rsync -a "$RESOURCES/$BUNDLE.bundle"/* "$COPY/" &&
/usr/libexec/PlistBuddy -c "Add :UserHome string $HOME" "$PLIST" &&
codesign -f --sign "$EXPANDED_CODE_SIGN_IDENTITY" --timestamp\=none --preserve-metadata\=identifier,entitlements,flags --generate-entitlement-der "$COPY" &&
defaults write com.johnholdsworth.InjectionNext codesigningIdentity "$EXPANDED_CODE_SIGN_IDENTITY"
fi
sorry, I've misread the previous instruction.
I will test this version and come back to you
Thanks @oryonatan
just checked this version - Injection fails with dlopen not finding s6Nimble15SyncExpectationVMn
Do you have time to zoom?
not today alas
What do you want to do? Merge it as you proposed or wait until you have time to investigate a few things I don't understand. We can always pick this up again later if problems emerge (e.g. testing on macOS or device)
I'll be glad if you can merge it and create a release, I'll send the release to a few people to make sure it works for them.
Release prepared: https://github.com/johnno1962/InjectionNext/releases/tag/1.2.1RC3. The SPM tags are a bit out of sync but we can resolve that when things settle down.
thanks!
This seems to solve the issue of missing test frameworks when attempting to reload tests on XCode16.