From 5515f8a345a5558f363b33c45d4be23f650147c3 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 1 May 2023 15:14:58 +1000 Subject: [PATCH 1/9] Extract CocoaPods Gutenberg logic in dedicated file We'll soon be modifying the Gutenberg setup. I thought it would be a good occasion to extract that logic (make the change easy, then make the easy change) to also achieve making the `Podfile` easier to read without Gutenberg clutter. --- Gutenberg/cocoapods_helper.rb | 95 +++++++++++++++++++++++++++++++++++ Podfile | 91 ++------------------------------- Podfile.lock | 2 +- 3 files changed, 100 insertions(+), 88 deletions(-) create mode 100644 Gutenberg/cocoapods_helper.rb diff --git a/Gutenberg/cocoapods_helper.rb b/Gutenberg/cocoapods_helper.rb new file mode 100644 index 000000000000..a86728e834c0 --- /dev/null +++ b/Gutenberg/cocoapods_helper.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +# Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. + +TAG_MODE = { tag: 'v1.94.0' }.freeze +LOCAL_MODE = { path: '../../gutenberg-mobile' }.freeze +COMMIT_MODE = { commit: '' }.freeze + +MODE = TAG_MODE + +# Note that the pods in this array might seem unused if you look for +# `import` statements in this codebase. However, make sure to also check +# whether they are used in the gutenberg-mobile and Gutenberg projects. +# +# See https://github.com/wordpress-mobile/gutenberg-mobile/issues/5025 +DEPENDENCIES = %w[ + FBLazyVector + React + ReactCommon + RCTRequired + RCTTypeSafety + React-Core + React-CoreModules + React-RCTActionSheet + React-RCTAnimation + React-RCTBlob + React-RCTImage + React-RCTLinking + React-RCTNetwork + React-RCTSettings + React-RCTText + React-RCTVibration + React-callinvoker + React-cxxreact + React-jsinspector + React-jsi + React-jsiexecutor + React-logger + React-perflogger + React-runtimeexecutor + boost + Yoga + RCT-Folly + glog + react-native-safe-area + react-native-safe-area-context + react-native-video + react-native-webview + RNSVG + react-native-slider + BVLinearGradient + react-native-get-random-values + react-native-blur + RNScreens + RNReanimated + RNGestureHandler + RNCMaskedView + RNCClipboard + RNFastImage + React-Codegen + React-bridging +].freeze + +def gutenberg_pod(mode: MODE) + options = mode.dup + + local_gutenberg = ENV.fetch('LOCAL_GUTENBERG', nil) + if local_gutenberg + options = { path: local_gutenberg.include?('/') ? local_gutenberg : LOCAL_MODE[:path] } + else + options[:git] = 'https://github.com/wordpress-mobile/gutenberg-mobile.git' + options[:submodules] = true + end + + pod 'Gutenberg', options + pod 'RNTAztecView', options + + gutenberg_dependencies(options: options) +end + +def gutenberg_dependencies(options:) + if options[:path] + podspec_prefix = options[:path] + else + tag_or_commit = options[:tag] || options[:commit] + podspec_prefix = "https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/#{tag_or_commit}" + end + + # FBReactNativeSpec needs special treatment because of react-native-codegen code generation + pod 'FBReactNativeSpec', podspec: "#{podspec_prefix}/third-party-podspecs/FBReactNativeSpec/FBReactNativeSpec.podspec.json" + + DEPENDENCIES.each do |pod_name| + pod pod_name, podspec: "#{podspec_prefix}/third-party-podspecs/#{pod_name}.podspec.json" + end +end diff --git a/Podfile b/Podfile index 03bb9998ab90..652f090950ce 100644 --- a/Podfile +++ b/Podfile @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative './Gutenberg/cocoapods_helper' + # For security reasons, please always keep the wordpress-mobile source first and the CDN second. # For more info, see https://github.com/wordpress-mobile/cocoapods-specs#source-order-and-security-considerations install! 'cocoapods', warn_for_multiple_pod_sources: false @@ -77,7 +79,7 @@ end def shared_test_pods pod 'OHHTTPStubs/Swift', '~> 9.1.0' pod 'OCMock', '~> 3.4.3' - gutenberg_pods + gutenberg_pod end def shared_with_extension_pods @@ -90,91 +92,6 @@ def shared_style_pods pod 'Gridicons', '~> 1.1.0' end -def gutenberg_pods - gutenberg tag: 'v1.94.0' -end - -def gutenberg(options) - options[:git] = 'https://github.com/wordpress-mobile/gutenberg-mobile.git' - options[:submodules] = true - local_gutenberg = ENV.fetch('LOCAL_GUTENBERG', nil) - if local_gutenberg - options = { path: local_gutenberg.include?('/') ? local_gutenberg : '../gutenberg-mobile' } - end - pod 'Gutenberg', options - pod 'RNTAztecView', options - - gutenberg_dependencies options -end - -def gutenberg_dependencies(options) - # Note that the pods in this array might seem unused if you look for - # `import` statements in this codebase. However, make sure to also check - # whether they are used in the gutenberg-mobile and Gutenberg projects. - # - # See https://github.com/wordpress-mobile/gutenberg-mobile/issues/5025 - dependencies = %w[ - FBLazyVector - React - ReactCommon - RCTRequired - RCTTypeSafety - React-Core - React-CoreModules - React-RCTActionSheet - React-RCTAnimation - React-RCTBlob - React-RCTImage - React-RCTLinking - React-RCTNetwork - React-RCTSettings - React-RCTText - React-RCTVibration - React-callinvoker - React-cxxreact - React-jsinspector - React-jsi - React-jsiexecutor - React-logger - React-perflogger - React-runtimeexecutor - boost - Yoga - RCT-Folly - glog - react-native-safe-area - react-native-safe-area-context - react-native-video - react-native-webview - RNSVG - react-native-slider - BVLinearGradient - react-native-get-random-values - react-native-blur - RNScreens - RNReanimated - RNGestureHandler - RNCMaskedView - RNCClipboard - RNFastImage - React-Codegen - React-bridging - ] - if options[:path] - podspec_prefix = options[:path] - else - tag_or_commit = options[:tag] || options[:commit] - podspec_prefix = "https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/#{tag_or_commit}" - end - - # FBReactNativeSpec needs special treatment because of react-native-codegen code generation - pod 'FBReactNativeSpec', podspec: "#{podspec_prefix}/third-party-podspecs/FBReactNativeSpec/FBReactNativeSpec.podspec.json" - - dependencies.each do |pod_name| - pod pod_name, podspec: "#{podspec_prefix}/third-party-podspecs/#{pod_name}.podspec.json" - end -end - abstract_target 'Apps' do project 'WordPress/WordPress.xcodeproj' @@ -185,7 +102,7 @@ abstract_target 'Apps' do ## Gutenberg (React Native) ## ===================== ## - gutenberg_pods + gutenberg_pod ## Third party libraries ## ===================== diff --git a/Podfile.lock b/Podfile.lock index 24d215e41afb..40ddd52a3771 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -900,6 +900,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: ab88bd849ac377484fd7f0c4b079701ce16de5a3 +PODFILE CHECKSUM: 2c6431b034e07dc4772d2e3d30c413d965c41eac COCOAPODS: 1.11.3 From 3e73ebd397a2e10343296df29df140f7ae0c79e6 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 3 May 2023 21:52:47 +1000 Subject: [PATCH 2/9] Disable `Style/MutableConstant` to enable local Gutenberg usage ``` vendor/bundle/ruby/2.7.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface/error_report.rb:34: in `force_encoding': can't modify frozen String: "relative URI: /Users/gio/Developer/gutenberg-mobile/third-party-podspecs/BVLinearGradient.podspec.json" (FrozenError) ``` --- .rubocop.yml | 6 ++++++ Gutenberg/cocoapods_helper.rb | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d163b541fe1b..20d8432ea40a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,12 @@ Layout/LineLength: Layout/EmptyLines: Exclude: *xfiles +Style/MutableConstant: + Exclude: + # CocoaPods mutates some input values. + # It's simpler to relax this rule than to address each individually by passing mutable copies + - Gutenberg/cocoapods_helper.rb + Style/AsciiComments: Exclude: *xfiles diff --git a/Gutenberg/cocoapods_helper.rb b/Gutenberg/cocoapods_helper.rb index a86728e834c0..ce18d5c600ac 100644 --- a/Gutenberg/cocoapods_helper.rb +++ b/Gutenberg/cocoapods_helper.rb @@ -2,9 +2,9 @@ # Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. -TAG_MODE = { tag: 'v1.94.0' }.freeze -LOCAL_MODE = { path: '../../gutenberg-mobile' }.freeze -COMMIT_MODE = { commit: '' }.freeze +TAG_MODE = { tag: 'v1.94.0' } +LOCAL_MODE = { path: '../../gutenberg-mobile' } +COMMIT_MODE = { commit: '' } MODE = TAG_MODE From 39803cfc648246c30dc07a91751e852ce442ed8c Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 3 May 2023 21:56:02 +1000 Subject: [PATCH 3/9] Rename `cocoapods_helper.rb` to `cocoapods_helpers.rb` --- .rubocop.yml | 4 ++-- Gutenberg/{cocoapods_helper.rb => cocoapods_helpers.rb} | 0 Podfile | 2 +- Podfile.lock | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename Gutenberg/{cocoapods_helper.rb => cocoapods_helpers.rb} (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 20d8432ea40a..6f16ccfb8cfe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,8 +27,8 @@ Layout/EmptyLines: Style/MutableConstant: Exclude: # CocoaPods mutates some input values. - # It's simpler to relax this rule than to address each individually by passing mutable copies - - Gutenberg/cocoapods_helper.rb + # It's simpler to relax this rule than to address each individually by passing mutable copies. + - Gutenberg/cocoapods_helpers.rb Style/AsciiComments: Exclude: *xfiles diff --git a/Gutenberg/cocoapods_helper.rb b/Gutenberg/cocoapods_helpers.rb similarity index 100% rename from Gutenberg/cocoapods_helper.rb rename to Gutenberg/cocoapods_helpers.rb diff --git a/Podfile b/Podfile index 652f090950ce..fcf13aedd591 100644 --- a/Podfile +++ b/Podfile @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative './Gutenberg/cocoapods_helper' +require_relative './Gutenberg/cocoapods_helpers' # For security reasons, please always keep the wordpress-mobile source first and the CDN second. # For more info, see https://github.com/wordpress-mobile/cocoapods-specs#source-order-and-security-considerations diff --git a/Podfile.lock b/Podfile.lock index 40ddd52a3771..41405d133891 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -900,6 +900,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: 2c6431b034e07dc4772d2e3d30c413d965c41eac +PODFILE CHECKSUM: 1d5bcc38fed97cea23146642a10c28b83717b1ff COCOAPODS: 1.11.3 From 7aa7af433e9b46d450eefe012c810dce78682d86 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 3 May 2023 22:11:30 +1000 Subject: [PATCH 4/9] Tweak Gutenberg-CocoaPods logic for local setup --- Gutenberg/cocoapods_helpers.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index ce18d5c600ac..0e702d95a544 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -2,8 +2,9 @@ # Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. +DEFAULT_GUTENBERG_LOCATION = File.join(__dir__, '..', '..', 'gutenberg-mobile') + TAG_MODE = { tag: 'v1.94.0' } -LOCAL_MODE = { path: '../../gutenberg-mobile' } COMMIT_MODE = { commit: '' } MODE = TAG_MODE @@ -64,9 +65,12 @@ def gutenberg_pod(mode: MODE) options = mode.dup - local_gutenberg = ENV.fetch('LOCAL_GUTENBERG', nil) + local_gutenberg_key = 'LOCAL_GUTENBERG' + local_gutenberg = ENV.fetch(local_gutenberg_key, nil) if local_gutenberg - options = { path: local_gutenberg.include?('/') ? local_gutenberg : LOCAL_MODE[:path] } + options = { path: File.exist?(local_gutenberg) ? local_gutenberg : DEFAULT_GUTENBERG_LOCATION } + + raise "Could not find Gutenberg pod at #{options[:path]}. You can configure the path using the #{local_gutenberg_key} environment variable." unless File.exist?(options[:path]) else options[:git] = 'https://github.com/wordpress-mobile/gutenberg-mobile.git' options[:submodules] = true From 4c39c9a3e808c4035774a7249d517ce1f09f9d3a Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Wed, 3 May 2023 22:18:20 +1000 Subject: [PATCH 5/9] Refine the way we can switch between tag or commit for Gutenberg --- Gutenberg/cocoapods_helpers.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index 0e702d95a544..c754583a9a9d 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -2,12 +2,13 @@ # Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. -DEFAULT_GUTENBERG_LOCATION = File.join(__dir__, '..', '..', 'gutenberg-mobile') - -TAG_MODE = { tag: 'v1.94.0' } -COMMIT_MODE = { commit: '' } +# Either use commit or tag, if both are left uncommented, tag will take precedence. +GUTENBERG_CONFIG = { + # commit: '', + tag: 'v1.94.0' +} -MODE = TAG_MODE +DEFAULT_GUTENBERG_LOCATION = File.join(__dir__, '..', '..', 'gutenberg-mobile') # Note that the pods in this array might seem unused if you look for # `import` statements in this codebase. However, make sure to also check @@ -62,8 +63,8 @@ React-bridging ].freeze -def gutenberg_pod(mode: MODE) - options = mode.dup +def gutenberg_pod(config: GUTENBERG_CONFIG) + options = config local_gutenberg_key = 'LOCAL_GUTENBERG' local_gutenberg = ENV.fetch(local_gutenberg_key, nil) From 346e7a1e4ebeb80845ed3835c1aeadbf0be8c4ae Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 May 2023 15:06:47 +1000 Subject: [PATCH 6/9] Extract 3rd party podspecs and extension name in constants --- Gutenberg/cocoapods_helpers.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index c754583a9a9d..de99460d049f 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -91,10 +91,13 @@ def gutenberg_dependencies(options:) podspec_prefix = "https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/#{tag_or_commit}" end + podspec_prefix += '/third-party-podspecs' + podspec_extension = 'podspec.json' + # FBReactNativeSpec needs special treatment because of react-native-codegen code generation - pod 'FBReactNativeSpec', podspec: "#{podspec_prefix}/third-party-podspecs/FBReactNativeSpec/FBReactNativeSpec.podspec.json" + pod 'FBReactNativeSpec', podspec: "#{podspec_prefix}/FBReactNativeSpec/FBReactNativeSpec.#{podspec_extension}" DEPENDENCIES.each do |pod_name| - pod pod_name, podspec: "#{podspec_prefix}/third-party-podspecs/#{pod_name}.podspec.json" + pod pod_name, podspec: "#{podspec_prefix}/#{pod_name}.#{podspec_extension}" end end From 22caf71ae6b1569abd7c58d601971a45a0b8beed Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 5 May 2023 16:41:10 +1000 Subject: [PATCH 7/9] Extract Gutenberg version definition in dedicated file for future reuse --- .rubocop.yml | 1 + Gutenberg/cocoapods_helpers.rb | 6 +----- Gutenberg/version.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 Gutenberg/version.rb diff --git a/.rubocop.yml b/.rubocop.yml index 6f16ccfb8cfe..d0c5c1785752 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -29,6 +29,7 @@ Style/MutableConstant: # CocoaPods mutates some input values. # It's simpler to relax this rule than to address each individually by passing mutable copies. - Gutenberg/cocoapods_helpers.rb + - Gutenberg/version.rb Style/AsciiComments: Exclude: *xfiles diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index de99460d049f..8c5c9b5a9cd9 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -2,11 +2,7 @@ # Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. -# Either use commit or tag, if both are left uncommented, tag will take precedence. -GUTENBERG_CONFIG = { - # commit: '', - tag: 'v1.94.0' -} +require_relative './version' DEFAULT_GUTENBERG_LOCATION = File.join(__dir__, '..', '..', 'gutenberg-mobile') diff --git a/Gutenberg/version.rb b/Gutenberg/version.rb new file mode 100644 index 000000000000..46961baab3d5 --- /dev/null +++ b/Gutenberg/version.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# This file isolates the definition of which version of Gutenberg to use. +# This way, it can be accessed by multiple sources withou duplication. + +# Either use commit or tag, if both are left uncommented, tag will take precedence. +# +# If you want to use a local version, please use the LOCAL_GUTENBERG environment variable when calling CocoaPods. +# +# Example: +# +# LOCAL_GUTENBERG=../my-gutenberg-fork bundle exec pod install +GUTENBERG_CONFIG = { + # commit: '', + tag: 'v1.94.0' +} From d318ebc341c51ecf9ca813370b13204c5e492cf0 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Sun, 7 May 2023 22:32:59 +1000 Subject: [PATCH 8/9] Extract constants for Guntenberg mobile GitHub org and repo name --- Gutenberg/cocoapods_helpers.rb | 4 ++-- Gutenberg/version.rb | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index 8c5c9b5a9cd9..526f13c5446b 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -69,7 +69,7 @@ def gutenberg_pod(config: GUTENBERG_CONFIG) raise "Could not find Gutenberg pod at #{options[:path]}. You can configure the path using the #{local_gutenberg_key} environment variable." unless File.exist?(options[:path]) else - options[:git] = 'https://github.com/wordpress-mobile/gutenberg-mobile.git' + options[:git] = "https://github.com/#{GITHUB_ORG}/#{REPO_NAME}.git" options[:submodules] = true end @@ -84,7 +84,7 @@ def gutenberg_dependencies(options:) podspec_prefix = options[:path] else tag_or_commit = options[:tag] || options[:commit] - podspec_prefix = "https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/#{tag_or_commit}" + podspec_prefix = "https://raw.githubusercontent.com/#{GITHUB_ORG}/#{REPO_NAME}/#{tag_or_commit}" end podspec_prefix += '/third-party-podspecs' diff --git a/Gutenberg/version.rb b/Gutenberg/version.rb index 46961baab3d5..c1b15043b253 100644 --- a/Gutenberg/version.rb +++ b/Gutenberg/version.rb @@ -14,3 +14,6 @@ # commit: '', tag: 'v1.94.0' } + +GITHUB_ORG = 'wordpress-mobile' +REPO_NAME = 'gutenberg-mobile' From d52c45acd90e824eed104adb17a194d59b4d85ac Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 8 May 2023 16:27:38 +1000 Subject: [PATCH 9/9] Fix typo in `Gutenberg/version.rb` Co-authored-by: Carlos Garcia --- Gutenberg/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gutenberg/version.rb b/Gutenberg/version.rb index c1b15043b253..7f8dbeebd787 100644 --- a/Gutenberg/version.rb +++ b/Gutenberg/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # This file isolates the definition of which version of Gutenberg to use. -# This way, it can be accessed by multiple sources withou duplication. +# This way, it can be accessed by multiple sources without duplication. # Either use commit or tag, if both are left uncommented, tag will take precedence. #