diff --git a/src/commands/react_native/xcode.rs b/src/commands/react_native/xcode.rs index 4747c4451d..7aa5c7c7b5 100644 --- a/src/commands/react_native/xcode.rs +++ b/src/commands/react_native/xcode.rs @@ -201,12 +201,6 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { return Ok(()); } - info!("Parsing Info.plist"); - let plist = match InfoPlist::discover_from_env()? { - Some(plist) => plist, - None => bail!("Could not find info.plist"), - }; - info!("Parse result from Info.plist: {:?}", &plist); let report_file = TempFile::create()?; let node = find_node(); info!("Using node interpreter '{}'", &node); @@ -371,21 +365,34 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { chunk_upload_options: chunk_upload_options.as_ref(), })?; } else { - let dist = dist_from_env.unwrap_or_else(|_| plist.build().to_string()); - let release_name = release_from_env.unwrap_or(format!( - "{}@{}+{}", - plist.bundle_id(), - plist.version(), - dist - )); + let (dist, release_name) = match (&dist_from_env, &release_from_env) { + (Err(_), Err(_)) => { + // Neither environment variable is present, attempt to parse Info.plist + info!("Parsing Info.plist"); + match InfoPlist::discover_from_env() { + Ok(Some(plist)) => { + // Successfully discovered and parsed Info.plist + let dist_string = plist.build().to_string(); + let release_string = format!("{}@{}+{}", plist.bundle_id(), plist.version(), dist_string); + info!("Parse result from Info.plist: {:?}", &plist); + (Some(dist_string), Some(release_string)) + }, + _ => { + bail!("Info.plist was not found or an parsing error occurred"); + } + } + } + // At least one environment variable is present, use the values from the environment + _ => (dist_from_env.ok(), release_from_env.ok()), + }; match matches.get_many::("dist") { None => { processor.upload(&UploadContext { org: &org, project: Some(&project), - release: Some(&release_name), - dist: Some(&dist), + release: release_name.as_deref(), + dist: dist.as_deref(), note: None, wait, max_wait, @@ -398,7 +405,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> { processor.upload(&UploadContext { org: &org, project: Some(&project), - release: Some(&release_name), + release: release_name.as_deref(), dist: Some(dist), note: None, wait, diff --git a/tests/integration/_cases/react_native/xcode-upload-source-maps-invalid-plist.trycmd b/tests/integration/_cases/react_native/xcode-upload-source-maps-invalid-plist.trycmd new file mode 100644 index 0000000000..faf097c98a --- /dev/null +++ b/tests/integration/_cases/react_native/xcode-upload-source-maps-invalid-plist.trycmd @@ -0,0 +1,15 @@ +``` +$ CONFIGURATION=Release sentry-cli react-native xcode tests/integration/_fixtures/react_native/react-native-xcode.sh --force-foreground +? failed +react-native-xcode.sh called with args: +Using React Native Packager bundle and source map. +Processing react-native sourcemaps for Sentry upload. +> Analyzing 2 sources +> Rewriting sources +> Adding source map references +error: Info.plist was not found or an parsing error occurred + +Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. +Please attach the full debug log to all bug reports. + +``` diff --git a/tests/integration/_cases/react_native/xcode-upload-source-maps-release_and_dist_from_env.trycmd b/tests/integration/_cases/react_native/xcode-upload-source-maps-release_and_dist_from_env.trycmd new file mode 100644 index 0000000000..951d393d50 --- /dev/null +++ b/tests/integration/_cases/react_native/xcode-upload-source-maps-release_and_dist_from_env.trycmd @@ -0,0 +1,26 @@ +``` +$ CONFIGURATION=Release SENTRY_RELEASE=test-release SENTRY_DIST=test-dist sentry-cli react-native xcode tests/integration/_fixtures/react_native/react-native-xcode.sh --force-foreground +? success +react-native-xcode.sh called with args: +Using React Native Packager bundle and source map. +Processing react-native sourcemaps for Sentry upload. +> Analyzing 2 sources +> Rewriting sources +> Adding source map references +> Bundled 2 files for upload +> Bundle ID: [..]-[..]-[..]-[..]-[..] +> Uploaded files to Sentry +> File upload complete (processing pending on server) +> Organization: wat-org +> Project: wat-project +> Release: test-release +> Dist: test-dist +> Upload type: artifact bundle + +Source Map Upload Report + Scripts + ~/react-native-xcode-bundle.js.map + Minified Scripts + ~/react-native-xcode-bundle.js (sourcemap at react-native-xcode-bundle.map) + +``` diff --git a/tests/integration/_fixtures/react_native/react-native-xcode-bundle.js b/tests/integration/_fixtures/react_native/react-native-xcode-bundle.js new file mode 100644 index 0000000000..a9da8b02ea --- /dev/null +++ b/tests/integration/_fixtures/react_native/react-native-xcode-bundle.js @@ -0,0 +1,3 @@ +console.log("Fake bundle!"); + +//# sourceMappingURL=react-native-xcode-bundle.map diff --git a/tests/integration/_fixtures/react_native/react-native-xcode-bundle.js.map b/tests/integration/_fixtures/react_native/react-native-xcode-bundle.js.map new file mode 100644 index 0000000000..09e76ff015 --- /dev/null +++ b/tests/integration/_fixtures/react_native/react-native-xcode-bundle.js.map @@ -0,0 +1 @@ +{"version":3,"file":"react-native-xcode-bundle.js"} diff --git a/tests/integration/_fixtures/react_native/react-native-xcode.sh b/tests/integration/_fixtures/react_native/react-native-xcode.sh new file mode 100755 index 0000000000..432d67cfe6 --- /dev/null +++ b/tests/integration/_fixtures/react_native/react-native-xcode.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +echo "react-native-xcode.sh called with args: $@" + +echo '{ + "packager_bundle_path": "tests/integration/_fixtures/react_native/react-native-xcode-bundle.js", + "packager_sourcemap_path": "tests/integration/_fixtures/react_native/react-native-xcode-bundle.js.map" +}' > "$SENTRY_RN_SOURCEMAP_REPORT" diff --git a/tests/integration/react_native/mod.rs b/tests/integration/react_native/mod.rs index c99208524d..668650f5b9 100644 --- a/tests/integration/react_native/mod.rs +++ b/tests/integration/react_native/mod.rs @@ -1,6 +1,8 @@ #[cfg(target_os = "macos")] use crate::integration::register_test; +mod xcode; + #[test] #[cfg(target_os = "macos")] fn xcode_wrap_call_minimum() { diff --git a/tests/integration/react_native/xcode.rs b/tests/integration/react_native/xcode.rs new file mode 100644 index 0000000000..d1d5598d4d --- /dev/null +++ b/tests/integration/react_native/xcode.rs @@ -0,0 +1,30 @@ +#[cfg(target_os = "macos")] +use crate::integration::register_test; +#[cfg(target_os = "macos")] +use crate::integration::{mock_common_upload_endpoints, ChunkOptions, ServerBehavior}; +#[cfg(target_os = "macos")] +use mockito::Mock; + +#[test] +#[cfg(target_os = "macos")] +fn xcode_upload_source_maps_missing_plist() { + let _upload_endpoints = + mock_common_upload_endpoints(ServerBehavior::Modern, ChunkOptions::default()); + register_test("react_native/xcode-upload-source-maps-invalid-plist.trycmd"); +} + +#[test] +#[cfg(target_os = "macos")] +fn xcode_upload_source_maps_release_and_dist_from_env() { + let upload_endpoints = + mock_common_upload_endpoints(ServerBehavior::Modern, ChunkOptions::default()); + register_test("react_native/xcode-upload-source-maps-release_and_dist_from_env.trycmd"); + assert_endpoints(&upload_endpoints); +} + +#[cfg(target_os = "macos")] +pub fn assert_endpoints(mocks: &[Mock]) { + for mock in mocks { + mock.assert(); + } +}