newrelic / newrelic-ios-agent-spm

This repository hosts the Swift Package Manager deployment of the iOS agent
Apache License 2.0
15 stars 9 forks source link

Build phase script not working - wrong path to newrelic_postbuild.sh #3

Closed mantuness closed 5 months ago

mantuness commented 3 years ago

Description

Currently, the described build phase script does not have into account that with SPM the dependency will be inside DerivedData/.../SourcePackages/.../NewRelic.xcframework/Resources/newrelic_postbuild.sh and with the current suggestion the script always fail. We managed to work around the problem but I think this should be addressed from your side. Maybe one possible way of solving the issue would be to include the script inside every NewRelic.framework that are inside NewRelic.xcframework. That way we would have access to the script without much trouble because it would be inside the app bundle ;)

Steps to Reproduce

Just integrate with SPM, add the script build phase as described, and check what happens. The script will fail 😕

Expected Behavior

The script should work

Relevant Logs / Console output

Screenshot 2021-07-07 at 10 53 46

Your Environment

N/A

Additional context

TizianoCoroneo commented 3 years ago

~Replacing "${SRCROOT}" with ${BUILD_ROOT}/../.. also works~ No it doesn't work! See Miguel's post below.

SCRIPT=`/usr/bin/find "${BUILD_ROOT}/../.." -name newrelic_postbuild.sh | head -n 1`
/bin/sh "${SCRIPT}" "<var>AAbc5de7f96ddb93ae97435e60450b137ed5ea6786-NRMA</var>"
mantuness commented 3 years ago

Replacing "${SRCROOT}" with ${BUILD_ROOT}/../.. also works:

SCRIPT=`/usr/bin/find "${BUILD_ROOT}/../.." -name newrelic_postbuild.sh | head -n 1`
/bin/sh "${SCRIPT}" "<var>AAbc5de7f96ddb93ae97435e60450b137ed5ea6786-NRMA</var>"

It will, but IMO is not the best way to handle it. If for some reason the path for SourcePackages changes it will not work again...

TizianoCoroneo commented 3 years ago

Of course this is not something that can stay long term. But also... there isn't really a stable way of getting the SPM build path right now. The correct way to handle this is to turn the new relic upload tool in a SPM build tool, but I guess that will take some time.

mantuness commented 3 years ago

Of course this is not something that can stay long term. But also... there isn't really a stable way of getting the SPM build path right now. The correct way to handle this is to turn the new relic upload tool in a SPM build tool, but I guess that will take some time.

Yes I agree. But for now, a more suitable option would be to include the script inside the NewRelic .framework(s) that are inside .xcframework. That way and until the SPM build tool is not available we would have 100% sure that we would always find the script 😉

miguel-batista commented 3 years ago

Replacing "${SRCROOT}" with ${BUILD_ROOT}/../.. also works:

SCRIPT=`/usr/bin/find "${BUILD_ROOT}/../.." -name newrelic_postbuild.sh | head -n 1`
/bin/sh "${SCRIPT}" "<var>AAbc5de7f96ddb93ae97435e60450b137ed5ea6786-NRMA</var>"

That was our first approach, but it failed when archiving release builds as it seems that environment variable's value changes and so going back 2 directories is not enough and it ends failing. The solution we currently have is a script that searches for the project's root directory inside the DerivedData folder in order to then search the SourcePackages folder for the NewRelic post build script.

TizianoCoroneo commented 3 years ago

I went for the "copy script in source" solution. No surprises there 😄 thanks everyone!

miguel-batista commented 3 years ago

I went for the "copy script in source" solution. No surprises there 😄 thanks everyone!

So each time there's a new NewRelic release you will need to check if the original script was updated and then update the one in the build phase? 🤔

TizianoCoroneo commented 3 years ago

So each time there's a new NewRelic release you will need to check if the original script was updated and then update the one in the build phase? 🤔

Almost: so that next time there is a NewRelic release I hope to actually have time to fix it the proper way...

Sim-newrelic commented 3 years ago

We are in the process of updating our documentation. In the meantime, you can replace your post-build step

e.g. SCRIPT=/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1

/bin/sh "${SCRIPT}" "AA1a6027867c2cdf81fb6f86817596de4df490ea25-NRMA"

with this new post-build step

SCRIPT=/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1

if [ -z "${SCRIPT}"]; then ARTIFACT_DIR="${BUILD_DIR%Build/*}SourcePackages/artifacts" SCRIPT=/usr/bin/find "${ARTIFACT_DIR}" -name newrelic_postbuild.sh | head -n 1 fi

/bin/sh "${SCRIPT}" "AA1a6027867c2cdf81fb6f86817596de4df490ea25-NRMA"

Sim-newrelic commented 3 years ago

@mantuness I commented above

virgilius-santos commented 3 years ago

I went for the "copy script in source" solution. No surprises there 😄 thanks everyone!

Hi! could you explain how can I do this?

Sim-newrelic commented 3 years ago

@virgilius-santos Go into the build phases section and you should be able to do it there. Where all the build phases scripts are you may need to expand some columns to show them.

JZDesign commented 3 years ago

I use bash. This script works for me from XCode:

SCRIPT=`/usr/bin/find "$SRCROOT" -name newrelic_postbuild.sh | head -n 1`
SCRIPT "YOUR NR TOKEN"
JZDesign commented 3 years ago

I take that back. I don't get a failure anymore, but it's not working.

Sim-newrelic commented 3 years ago

Could you help us out by giving us the failure or what may be causing the issue so we can help investigate

doublerebel commented 2 years ago

Took me a second to realize the markdown formatting made the script hard to copy+paste. Unformatted:

SCRIPT=`/usr/bin/find "${SRCROOT}" -name newrelic_postbuild.sh | head -n 1`

if [ -z "${SCRIPT}"]; then
ARTIFACT_DIR="${BUILD_DIR%Build/*}SourcePackages/artifacts"
SCRIPT=`/usr/bin/find "${ARTIFACT_DIR}" -name newrelic_postbuild.sh | head -n 1`
fi

/bin/sh "${SCRIPT}" "<YOUR NEW RELIC TOKEN>"

Thanks for a useful service. Please update the docs!

ccedacero-nr commented 2 years ago

Linking New Relic Documentation to bring visibility to this solution 📜

AnitKumar-iPhone commented 1 year ago

I was also facing the same issue.

RenRelic-Path 7 4 0

For iOS Agent 7.4.0+: Build script should be - "${BUILD_DIR%/Build/*}/SourcePackages/artifacts/newrelic-ios-agent-spm/NewRelic.xcframework/Resources/run-symbol-tool" "APP_TOKEN"

But when I was looking at the folders ${BUILD_DIR%/Build/*}/SourcePackages/artifacts/ the folder named newrelic-ios-agent-spm was missing then I found another folder named newrelic-ios Saw -sdk and I found NewRelice.xcframework

According to me the following documents should be revised

  1. https://github.com/newrelic/newrelic-ios-agent-spm - README.md
  2. https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-ios/installation/spm-installation/

"${BUILD_DIR%/Build/*}/SourcePackages/artifacts/newrelic-ios-sdk/NewRelic.xcframework/Resources/run-symbol-tool" "APP_TOKEN"

NewRelic Run Script - `# Type a script or drag a script file from your workspace to insert its path. if [ ${CONFIGURATION} = "Debug" ]; then echo "Skipping DSYM upload CONFIGURATION: ${CONFIGURATION}" exit 0 fi

if [ "${CONFIGURATION}" == "Release" ] ; then "${BUILD_DIR%/Build/}/SourcePackages/artifacts/newrelic-ios-sdk/NewRelic.xcframework/Resources/run-symbol-tool" "APP_TOKEN" else "${BUILD_DIR%/Build/}/SourcePackages/artifacts/newrelic-ios-sdk/NewRelic.xcframework/Resources/run-symbol-tool" "APP_TOKEN" fi`

cdillard-NewRelic commented 5 months ago

Closed legacy dSYM upload script issue.