diff --git a/.rubocop.yml b/.rubocop.yml index d163b541fe1b..d0c5c1785752 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,13 @@ 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_helpers.rb + - Gutenberg/version.rb + Style/AsciiComments: Exclude: *xfiles diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb new file mode 100644 index 000000000000..526f13c5446b --- /dev/null +++ b/Gutenberg/cocoapods_helpers.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: true + +# Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. + +require_relative './version' + +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 +# 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(config: GUTENBERG_CONFIG) + options = config + + local_gutenberg_key = 'LOCAL_GUTENBERG' + local_gutenberg = ENV.fetch(local_gutenberg_key, nil) + if local_gutenberg + 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/#{GITHUB_ORG}/#{REPO_NAME}.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/#{GITHUB_ORG}/#{REPO_NAME}/#{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}/FBReactNativeSpec/FBReactNativeSpec.#{podspec_extension}" + + DEPENDENCIES.each do |pod_name| + pod pod_name, podspec: "#{podspec_prefix}/#{pod_name}.#{podspec_extension}" + end +end diff --git a/Gutenberg/version.rb b/Gutenberg/version.rb new file mode 100644 index 000000000000..7f8dbeebd787 --- /dev/null +++ b/Gutenberg/version.rb @@ -0,0 +1,19 @@ +# 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 without 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' +} + +GITHUB_ORG = 'wordpress-mobile' +REPO_NAME = 'gutenberg-mobile' diff --git a/Podfile b/Podfile index b9e993312b4e..ba1aa644388b 100644 --- a/Podfile +++ b/Podfile @@ -1,5 +1,7 @@ # frozen_string_literal: true +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 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 4d3a6b8f812d..7957ce5b4e5b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -900,6 +900,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: ac8407b62c2bf59ec0fb956c850239e5193066ed +PODFILE CHECKSUM: e50160a649d94dcab9a9727eab8d626d4c9a7f51 COCOAPODS: 1.11.3