Skip to content

Commit b3caca5

Browse files
authored
react-native: fix sourcemap support on iOS (#324)
Co-authored-by: Sebastian Alex <sebastian.alex@saucelabs.com>
1 parent d868050 commit b3caca5

File tree

6 files changed

+60
-22
lines changed

6 files changed

+60
-22
lines changed
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
#/bin/bash
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
25

36
# This script shows how process your application code with source maps and hermesc. By using this script, Backtrace integration can process
47
# your source code to generate valid source map files. This script does exactly the same what the hermesc script does, with one exception -
58
# before the native library is generated, this script will process source code and source map to generate output needed in next steps for source map integration.
69

710

8-
HERMES_ENGINE_PATH="$PODS_ROOT/hermes-engine"
9-
[ -z "$HERMES_CLI_PATH_OVERRIDE" ] && HERMES_CLI_PATH_OVERRIDE="$HERMES_ENGINE_PATH/destroot/bin/hermesc"
10-
11+
hermes_engine_path="$PODS_ROOT/hermes-engine"
12+
[ -z "$HERMES_CLI_PATH_OVERRIDE" ] && HERMES_CLI_PATH_OVERRIDE="$hermes_engine_path/destroot/bin/hermesc"
1113

12-
APP_BUNDLE_FILE="${BASH_ARGV[0]}"
14+
app_bundle_file="${BASH_ARGV[0]}"
1315

14-
if [[ ! -f "$APP_BUNDLE_FILE" ]]; then
15-
echo "error: File $APP_BUNDLE_FILE does not exist. " >&2
16+
if [[ ! -f "$app_bundle_file" ]]; then
17+
echo "error: File $app_bundle_file does not exist. " >&2
1618
exit 2
1719
fi
1820

19-
npx --yes @backtrace/javascript-cli process --path=$APP_BUNDLE_FILE
21+
# check and assign NODE_BINARY env
22+
source "$REACT_NATIVE_PATH/scripts/node-binary.sh"
23+
24+
backtrace_js_path="${REACT_NATIVE_PATH}/../.bin/backtrace-js"
25+
26+
"$NODE_BINARY" "$backtrace_js_path" process --path="$app_bundle_file"
2027

21-
$HERMES_CLI_PATH_OVERRIDE $@
28+
$HERMES_CLI_PATH_OVERRIDE "$@"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# This script runs backtrace-js on given path and using given config.
4+
# In this example, backtrace-js will process and upload sourcemaps.
5+
# This should be executed by the iOS build after creating the .jsbundle file.
6+
7+
set -e
8+
set -x
9+
10+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
config_path=$BACKTRACE_JS_CONFIG
12+
bundle_path=$BACKTRACE_JS_BUNDLE_PATH
13+
14+
if [[ ! -f "$bundle_path" ]]; then
15+
echo "warn: File $bundle_path does not exist. \
16+
Try switching to a Release build. \
17+
Sourcemaps will not be processed."
18+
19+
exit 0
20+
fi
21+
22+
# path to react-native module dir relative from this script
23+
react_native_dir="${script_dir}/node_modules/react-native"
24+
backtrace_js_path="${script_dir}/node_modules/.bin/backtrace-js"
25+
26+
# check and assign NODE_BINARY env
27+
source "$react_native_dir/scripts/node-binary.sh"
28+
29+
# run backtrace-js on bundle
30+
"$NODE_BINARY" "$backtrace_js_path" run \
31+
--config "$config_path" \
32+
--path "$bundle_path"

examples/sdk/reactNative/ios/reactNative.xcodeproj/project.pbxproj

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
5DCACB8F33CDC322A6C60F78 /* libPods-reactNative.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-reactNative.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4646
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = reactNative/LaunchScreen.storyboard; sourceTree = "<group>"; };
4747
89C6BE57DB24E9ADA2F236DE /* Pods-reactNative-reactNativeTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-reactNative-reactNativeTests.release.xcconfig"; path = "Target Support Files/Pods-reactNative-reactNativeTests/Pods-reactNative-reactNativeTests.release.xcconfig"; sourceTree = "<group>"; };
48-
CFB9667E00B6B43022D1D583 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = reactNative/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
48+
CFB9667E00B6B43022D1D583 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = reactNative/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
4949
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
5050
/* End PBXFileReference section */
5151

@@ -269,7 +269,7 @@
269269
);
270270
runOnlyForDeploymentPostprocessing = 0;
271271
shellPath = /bin/sh;
272-
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
272+
shellScript = "set -e\nset -x\n# destination source map directory\nSOURCE_MAP_DIR=\"$(pwd)/../build\"\nmkdir -p $SOURCE_MAP_DIR\n\nexport SOURCEMAP_FILE=\"$SOURCE_MAP_DIR/main.js.map\";\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n# use hermesc script provided by Backtrace to populate source maps\n# if you dont use hermes support, please skip this step.\nexport HERMES_CLI_PATH=\"$(pwd)/../ios-hermesc.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n\n# copy javascript build output to the build directory\ncp \"$CONFIGURATION_BUILD_DIR/main.jsbundle\" $SOURCE_MAP_DIR \n\nPROCESS_SOURCEMAPS_SCRIPT=\"$(pwd)/../ios-sourcemaps.sh\"\nexport BACKTRACE_JS_CONFIG=\"$(pwd)/../.backtracejsrc\"\nexport BACKTRACE_JS_BUNDLE_PATH=\"$SOURCE_MAP_DIR/main.jsbundle\"\n \n# process source map with javascript code\n/bin/sh -c \"$WITH_ENVIRONMENT $PROCESS_SOURCEMAPS_SCRIPT\"\n";
273273
};
274274
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
275275
isa = PBXShellScriptBuildPhase;
@@ -590,10 +590,7 @@
590590
"-DFOLLY_CFG_NO_COROUTINES=1",
591591
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
592592
);
593-
OTHER_LDFLAGS = (
594-
"$(inherited)",
595-
" ",
596-
);
593+
OTHER_LDFLAGS = "$(inherited) ";
597594
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
598595
SDKROOT = iphoneos;
599596
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -666,10 +663,7 @@
666663
"-DFOLLY_CFG_NO_COROUTINES=1",
667664
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
668665
);
669-
OTHER_LDFLAGS = (
670-
"$(inherited)",
671-
" ",
672-
);
666+
OTHER_LDFLAGS = "$(inherited) ";
673667
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
674668
SDKROOT = iphoneos;
675669
USE_HERMES = true;

examples/sdk/reactNative/ios/reactNative.xcodeproj/xcshareddata/xcschemes/reactNative.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</Testables>
4242
</TestAction>
4343
<LaunchAction
44-
buildConfiguration = "Debug"
44+
buildConfiguration = "Release"
4545
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4646
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4747
launchStyle = "0"

examples/sdk/reactNative/package-lock.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/sdk/reactNative/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@babel/core": "^7.20.0",
1818
"@babel/preset-env": "^7.20.0",
1919
"@babel/runtime": "^7.20.0",
20+
"@backtrace/javascript-cli": "file:../../../tools/cli",
2021
"@react-native/babel-preset": "0.75.3",
2122
"@react-native/eslint-config": "0.75.3",
2223
"@react-native/metro-config": "0.75.3",

0 commit comments

Comments
 (0)