diff --git a/ios/keyman/Keyman/Keyman.xcodeproj/project.pbxproj b/ios/keyman/Keyman/Keyman.xcodeproj/project.pbxproj index a1397cb789..1307139722 100644 --- a/ios/keyman/Keyman/Keyman.xcodeproj/project.pbxproj +++ b/ios/keyman/Keyman/Keyman.xcodeproj/project.pbxproj @@ -968,8 +968,8 @@ outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/zsh; - shellScript = "# Uploads dSYM for use with Sentry.\n# Auto-generated at https://sentry.keyman.com/keyman/keyman-ios/getting-started/cocoa-swift/\n#\n# Note that we explicitly keep the SENTRY_AUTH_TOKEN parameter out of the project configs -\n# it should be placed for inclusion by the line below:\nsource ~/.zshrc\n\nif which sentry-cli >/dev/null; then\n export SENTRY_URL=\"https://sentry.keyman.com\"\n export SENTRY_ORG=keyman\n export SENTRY_PROJECT=keyman-ios\n ERROR=$(sentry-cli upload-dif \"$DWARF_DSYM_FOLDER_PATH\" 2>&1 >/dev/null)\n if [ ! $? -eq 0 ]; then\n echo \"warning: sentry-cli - $ERROR\"\n fi\nelse\n echo \"warning: sentry-cli not installed, download from https://github.com/getsentry/sentry-cli/releases\"\nfi\n"; + shellPath = /bin/bash; + shellScript = ". $KEYMAN_ROOT/resources/build/xcode-utils.sh\n\n# Calls resource script to perform the dSYM upload\nphaseSentryDsymUpload \"keyman-ios\"\n"; }; CE06AA671F161422006D91C3 /* Run Script */ = { isa = PBXShellScriptBuildPhase; diff --git a/resources/build/xcode-utils.sh b/resources/build/xcode-utils.sh index cd1c090edf..224ed86f6d 100755 --- a/resources/build/xcode-utils.sh +++ b/resources/build/xcode-utils.sh @@ -3,6 +3,13 @@ # This script will automatically have Xcode's build environment (and variables), # so there's no need to do anything extra to fetch them. +# Some fun details for interacting with Xcode: +# - echo "warning: foo" will generate an actual compile warning within Xcode: "foo" +# - echo "error: bar" will likewise generate a compile error within Xcode: "bar" +# +# As appropriate, make sure to take advantage of this feature! + +# Build Phase: "Set Bundle Versions" # Takes one parameter: "TAGGED". Defaults to false (iOS: KMEI, SWKeyboard), sets tagged info if true (iOS: Keyman) # # Thanks to https://medium.com/@bestiosdevelope/automatic-build-incrementation-technique-for-ios-release-94eb0d08785b @@ -45,4 +52,43 @@ function phaseSetBundleVersions() { /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $VERSION" "$DSYM_PLIST" /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" "$DSYM_PLIST" fi +} + +# Build Phase: Upload dSYM (debug) files to Sentry +# Takes one parameter - the SENTRY_PROJECT target. The other parameter needs to be set as an "input file" within Xcode. +function phaseSentryDsymUpload() { + + if [[ $# -gt 0 ]]; then + SENTRY_PROJECT_TARGET=$1 + else + echo "error: SENTRY_PROJECT parameter was not provided to Sentry upload utility function." + exit 1 + fi + + # Provides the needed definition for SENTRY_AUTH_TOKEN from TC configuration settings, since it is otherwise + # not forwarded (privately) through Xcode. + echo "warning: TODO: change .zshrc defintion of SENTRY_AUTH_TOKEN to something not requiring local configuration for each build agent" + source ~/.zshrc + + # Reference for this detection check for the input file: https://www.iosdev.recipes/xcode/input-output-files/ + if [ -z $SCRIPT_INPUT_FILE_0 ]; then + echo "error: Run Script must have an input file set: \${DWARF_DSYM_FOLDER_PATH}/\${DWARF_DSYM_FILE_NAME}/Contents/Resources/DWARF/\${TARGET_NAME}" + fi + + if [ -z $SENTRY_AUTH_TOKEN ]; then + echo "warning: Cannot successfully upload the dSYM to sentry if a Sentry auth token is not provided." + fi + + # The remaining update logic seen here was auto-generated at https://sentry.keyman.com/keyman/keyman-ios/getting-started/cocoa-swift/ + if which sentry-cli >/dev/null; then + export SENTRY_URL="https://sentry.keyman.com" + export SENTRY_ORG=keyman + export SENTRY_PROJECT=$SENTRY_PROJECT_TARGET + ERROR=$(sentry-cli upload-dif "$DWARF_DSYM_FOLDER_PATH" 2>&1 >/dev/null) + if [ ! $? -eq 0 ]; then + echo "warning: sentry-cli - $ERROR" + fi + else + echo "warning: sentry-cli not installed; please run `brew install getsentry/tools/sentry-cli` to remedy" + fi } \ No newline at end of file