Skip to content

Commit

Permalink
Exclude Gutenberg source map file from binary (#22862)
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot authored Mar 20, 2024
2 parents 25bc8de + 9934e24 commit 4111a53
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
25 changes: 25 additions & 0 deletions Gutenberg/cocoapods_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

GUTENBERG_CONFIG_PATH = File.join(__dir__, '..', 'Gutenberg', 'config.yml')

# We skip the simulator architecture as we only need to extract the bundle and source map for installable builds.
GUTENBERG_FRAMEWORK_FOLDER = File.join(__dir__, '..', 'Pods', 'Gutenberg', 'Frameworks', 'Gutenberg.xcframework', 'ios-arm64', 'Gutenberg.framework')
GUTENBERG_BUNDLE_SOURCE_MAP_TARGET = File.join(__dir__, '..', 'Pods', 'Gutenberg', 'react-native-bundle-source-map')

LOCAL_GUTENBERG_KEY = 'LOCAL_GUTENBERG'

# Note that the pods in this array might seem unused if you look for
Expand Down Expand Up @@ -115,6 +119,8 @@ def apply_rnreanimated_workaround!(dependencies:, gutenberg_path:)
end

def gutenberg_post_install(installer:)
extract_bundle_source_map_files unless should_use_local_gutenberg

return unless should_use_local_gutenberg

raise "[Gutenberg] Could not find local Gutenberg at given path #{local_gutenberg_path}" unless File.exist?(local_gutenberg_path)
Expand Down Expand Up @@ -207,3 +213,22 @@ def workaround_broken_search_paths
end
project.save
end

# Copy Gutenberg bundle and source map files so they can be upload it to Sentry during the build process.
def extract_bundle_source_map_files
puts '[Gutenberg] Extracting bundle and source map files'

FileUtils.mkdir_p(GUTENBERG_BUNDLE_SOURCE_MAP_TARGET)
bundle_from_path = File.join(GUTENBERG_FRAMEWORK_FOLDER, 'App.js')
bundle_destination_path = File.join(GUTENBERG_BUNDLE_SOURCE_MAP_TARGET, 'main.jsbundle')
FileUtils.cp(bundle_from_path, bundle_destination_path)

# Source map file is moved instead of copied to avoid including it in the binary.
source_map_from_path = File.join(GUTENBERG_FRAMEWORK_FOLDER, 'App.composed.js.map')
source_map_destination_path = File.join(GUTENBERG_BUNDLE_SOURCE_MAP_TARGET, 'main.jsbundle.map')
if File.exist?(source_map_from_path)
FileUtils.mv(source_map_from_path, source_map_destination_path)
elsif !File.exist?(source_map_destination_path)
raise "[Gutenberg] Source map \"#{source_map_from_path}\" could not be found. Please verify that the Gutenberg version includes the file or reinstall the pod."
end
end
60 changes: 26 additions & 34 deletions fastlane/lanes/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -532,39 +532,31 @@ def upload_build_to_app_center(
end

def upload_gutenberg_sourcemaps(sentry_project_slug:, release_version:, build_version:, app_identifier:)
# The bundle and source map files are the same for all architectures.
gutenberg_bundle = File.join(PROJECT_ROOT_FOLDER, 'Pods/Gutenberg/Frameworks/Gutenberg.xcframework/ios-arm64/Gutenberg.framework')

Dir.mktmpdir do |sourcemaps_folder|
# It's important that the bundle and source map files have specific names, otherwise, Sentry
# won't symbolicate the stack traces.
FileUtils.cp(File.join(gutenberg_bundle, 'App.js'), File.join(sourcemaps_folder, 'main.jsbundle'))
FileUtils.cp(File.join(gutenberg_bundle, 'App.composed.js.map'), File.join(sourcemaps_folder, 'main.jsbundle.map'))

# To generate the full release version string to attach the source maps, we need to specify:
# - App identifier
# - Release version
# - Build version
# This conforms to the following format: <app_identifier>@<release_version>+<build_version>
# Here are a couple of examples:
# - Prototype build: [email protected]+pr22654-07765b3
# - App Store build: [email protected]+24.1.0.3

sentry_upload_sourcemap(
auth_token: get_required_env('SENTRY_AUTH_TOKEN'),
org_slug: SENTRY_ORG_SLUG,
project_slug: sentry_project_slug,
version: release_version,
dist: build_version,
build: build_version,
app_identifier:,
# When the React native bundle is generated, the source map file references
# include the local machine path, with the `rewrite` and `strip_common_prefix`
# options Sentry automatically strips this part.
rewrite: true,
strip_common_prefix: true,
sourcemap: sourcemaps_folder
)
end
gutenberg_bundle_source_map_folder = File.join(PROJECT_ROOT_FOLDER, 'Pods', 'Gutenberg', 'react-native-bundle-source-map')

# To generate the full release version string to attach the source maps, we need to specify:
# - App identifier
# - Release version
# - Build version
# This conforms to the following format: <app_identifier>@<release_version>+<build_version>
# Here are a couple of examples:
# - Prototype build: [email protected]+pr22654-07765b3
# - App Store build: [email protected]+24.1.0.3

sentry_upload_sourcemap(
auth_token: get_required_env('SENTRY_AUTH_TOKEN'),
org_slug: SENTRY_ORG_SLUG,
project_slug: sentry_project_slug,
version: release_version,
dist: build_version,
build: build_version,
app_identifier:,
# When the React native bundle is generated, the source map file references
# include the local machine path, with the `rewrite` and `strip_common_prefix`
# options Sentry automatically strips this part.
rewrite: true,
strip_common_prefix: true,
sourcemap: gutenberg_bundle_source_map_folder
)
end
end

0 comments on commit 4111a53

Please sign in to comment.