Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAT-5950] Store source maps in $TMPDIR during Xcode build phases #1289

Merged
merged 4 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/react-native-cli/src/lib/Xcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const DOCS_LINK = 'https://docs.bugsnag.com/platforms/react-native/react-native/
const UNLOCATED_PROJ_MSG = `The Xcode project was not in the expected location and so couldn't be updated automatically.

Update the "Bundle React Native Code And Images" build phase with the following environment variables:
export EXTRA_PACKAGER_ARGS="--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map"
export EXTRA_PACKAGER_ARGS="--sourcemap-output $TMPDIR/$(md5 -qs "$CONFIGURATION_BUILD_DIR")-main.jsbundle.map""

See ${DOCS_LINK} for more information`

const EXTRA_PACKAGER_ARGS = 'export EXTRA_PACKAGER_ARGS="--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map"'
const EXTRA_PACKAGER_ARGS = 'export EXTRA_PACKAGER_ARGS="--sourcemap-output $TMPDIR/$(md5 -qs "$CONFIGURATION_BUILD_DIR")-main.jsbundle.map"'

export async function updateXcodeProject (projectRoot: string, endpoint: string|undefined, logger: Logger) {
const iosDir = path.join(projectRoot, 'ios')
Expand Down Expand Up @@ -76,7 +76,7 @@ async function addUploadSourceMapsTask (
}
}

let shellScript = '../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh'
let shellScript = 'SOURCE_MAP="$TMPDIR/$(md5 -qs "$CONFIGURATION_BUILD_DIR")-main.jsbundle.map" ../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh'

if (endpoint) {
shellScript = `export ENDPOINT='${endpoint}'\\n${shellScript}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
};
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -390,7 +390,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
};
3EBDF05F265B984FA826288C /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -566,7 +566,7 @@
outputPaths = (
);
shellPath = /bin/sh;
shellScript = "export ENDPOINT='https://upload.example.com'\n../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh";
shellScript = "export ENDPOINT='https://upload.example.com'\nSOURCE_MAP=\"$TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\" ../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
};
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -390,7 +390,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
shellScript = "export EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"\nexport NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
};
3EBDF05F265B984FA826288C /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -566,7 +566,7 @@
outputPaths = (
);
shellPath = /bin/sh;
shellScript = "../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh";
shellScript = "SOURCE_MAP=\"$TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\" ../node_modules/@bugsnag/react-native/bugsnag-react-native-xcode.sh";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
11 changes: 7 additions & 4 deletions packages/react-native/bugsnag-react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ if [ ! -f "$BUNDLE_FILE" ]; then
exit 0
fi

MAP_FILE="$BUNDLE_FILE.map"
if [ ! -f "$MAP_FILE" ]; then
echo "Error: Source map main.jsbundle.map could not be found."
if [ -z "$SOURCE_MAP" ]; then
echo "Warning: SOURCE_MAP was not specified, falling back to $BUNDLE_FILE.map"
SOURCE_MAP="$BUNDLE_FILE.map"
fi
if [ ! -f "$SOURCE_MAP" ]; then
echo "Error: SOURCE_MAP $SOURCE_MAP could not be found."
echo "Ensure the --sourcemap-output option is passed to the react-native bundle command."
exit 1
fi
Expand All @@ -39,7 +42,7 @@ ARGS=(
"--app-version" "$APP_VERSION"
"--bundle" "$BUNDLE_FILE"
"--platform" "ios"
"--source-map" "$MAP_FILE"
"--source-map" "$SOURCE_MAP"
"--project-root" "$PROJECT_ROOT"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -ex

fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_60.xcodeproj/project.pbxproj
fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_60.xcodeproj/project.pbxproj

if [ ! -z "$1" ]; then
fgrep "export ENDPOINT='$1'" ios/rn0_60.xcodeproj/project.pbxproj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -ex

fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_61.xcodeproj/project.pbxproj
fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_61.xcodeproj/project.pbxproj

if [ ! -z "$1" ]; then
fgrep "export ENDPOINT='$1'" ios/rn0_61.xcodeproj/project.pbxproj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -ex

fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_62.xcodeproj/project.pbxproj
fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_62.xcodeproj/project.pbxproj

if [ ! -z "$1" ]; then
fgrep "export ENDPOINT='$1'" ios/rn0_62.xcodeproj/project.pbxproj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -ex

fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"' ios/rn0_63.xcodeproj/project.pbxproj
fgrep 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"' ios/rn0_63.xcodeproj/project.pbxproj

if [ ! -z "$1" ]; then
fgrep "export ENDPOINT='$1'" ios/rn0_63.xcodeproj/project.pbxproj
Expand Down
2 changes: 1 addition & 1 deletion test/react-native-cli/features/steps/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def parse_package_json
Then("the iOS build has not been modified to upload source maps") do
filename = "ios/#{current_fixture}.xcodeproj/project.pbxproj"

step("the interactive file '#{filename}' does not contain 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map\"'")
step("the interactive file '#{filename}' does not contain 'EXTRA_PACKAGER_ARGS=\"--sourcemap-output $TMPDIR/$(md5 -qs \"$CONFIGURATION_BUILD_DIR\")-main.jsbundle.map\"'")
step("the interactive file '#{filename}' does not contain 'Upload source maps to Bugsnag'")
end

Expand Down