Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test-ios-spm-helloworld.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ jobs:
echo "::error::spm add did not inject SwiftPM: $XCODE_PROJECT/.spm-injected.json is missing"
exit 1
fi
if [[ -f Podfile ]] && grep -q 'use_react_native!' Podfile; then
echo "::error::spm add --deintegrate left use_react_native! in the Podfile"
if grep -q 'Pods-' "$XCODE_PROJECT/project.pbxproj"; then
echo "::error::spm add --deintegrate left CocoaPods references in $XCODE_PROJECT"
exit 1
fi
echo "SwiftPM injected in place; Podfile de-integrated."
echo "SwiftPM injected in place; CocoaPods de-integrated."
- name: Build ${{ env.XCODE_SCHEME }} (${{ matrix.flavor }})
shell: bash
working-directory: ${{ env.APP_IOS_DIR }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-ios-spm-newapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ jobs:
echo "::error::spm add did not inject SwiftPM: $XCODE_PROJECT/.spm-injected.json is missing"
exit 1
fi
if [[ -f Podfile ]] && grep -q 'use_react_native!' Podfile; then
echo "::error::spm add --deintegrate left use_react_native! in the Podfile"
if grep -q 'Pods-' "$XCODE_PROJECT/project.pbxproj"; then
echo "::error::spm add --deintegrate left CocoaPods references in $XCODE_PROJECT"
exit 1
fi
echo "SwiftPM injected in place; Podfile de-integrated."
echo "SwiftPM injected in place; CocoaPods de-integrated."
- name: Build ${{ env.XCODE_SCHEME }} (${{ matrix.flavor }})
shell: bash
working-directory: ${{ env.APP_IOS_DIR }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-ios-spm-rntester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ jobs:
echo "::error::spm add did not inject SwiftPM: $XCODE_PROJECT/.spm-injected.json is missing"
exit 1
fi
if [[ -f Podfile ]] && grep -q 'use_react_native!' Podfile; then
echo "::error::spm add --deintegrate left use_react_native! in the Podfile"
if grep -q 'Pods-' "$XCODE_PROJECT/project.pbxproj"; then
echo "::error::spm add --deintegrate left CocoaPods references in $XCODE_PROJECT"
exit 1
fi
echo "SwiftPM injected in place; Podfile de-integrated."
echo "SwiftPM injected in place; CocoaPods de-integrated."
- name: Build ${{ env.XCODE_SCHEME }} (${{ matrix.flavor }})
shell: bash
working-directory: ${{ env.APP_IOS_DIR }}
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/scripts/cocoapods/autolinking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,6 @@ def link_native_modules!(config)
# - config_command: the command to run to get the application's current config, e.g. ['npx', '@react-native-community/cli', 'config'],
# you can override this if you'd like to avoid the dependency. e.g. ['cat', 'your_config.json']
def use_native_modules!(config_command = $default_command)
ReactNativePodsUtils.error_if_spm_injected
return link_native_modules!(list_native_modules!(config_command))
end
18 changes: 18 additions & 0 deletions packages/react-native/scripts/cocoapods/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,24 @@ def self.create_xcode_env_if_missing(file_manager: File)
end
end

# Stops `pod install` on an app that `npx react-native spm add` converted to
# Swift Package Manager. Codegen would rewrite the app's generated
# Package.swift, and Xcode resolves packages before any build phase can
# report it, so this has to run before React Native writes any file.
# prepare_react_native_project!, use_native_modules! and use_react_native!
# all call it, because a Podfile need not call the first.
def self.error_if_spm_injected
podfile_dir = Pod::Config.instance.installation_root.to_s
xcodeproj = Dir.glob('*.xcodeproj', base: podfile_dir).sort.find do |name|
File.exist?(File.join(podfile_dir, name, '.spm-injected.json'))
end
return if xcodeproj.nil?

raise Pod::Informative, "This app uses Swift Package Manager for React Native " +
"(#{xcodeproj} has .spm-injected.json), so `pod install` would break the Xcode project. " +
"To go back to CocoaPods, run `npx react-native spm deinit` first, then `pod install`."
end

# It examines the target_definition property and sets the appropriate value for
# ENV['USE_FRAMEWORKS'] variable.
#
Expand Down
3 changes: 3 additions & 0 deletions packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def min_supported_versions
# This function prepares the project for React Native, before processing
# all the target exposed by the framework.
def prepare_react_native_project!
ReactNativePodsUtils.error_if_spm_injected

# Temporary solution to suppress duplicated GUID error & master specs repo warning.
# Can be removed once we move to generate files outside pod install.
install! 'cocoapods', :deterministic_uuids => false, :warn_for_unused_master_specs_repo => false
Expand Down Expand Up @@ -96,6 +98,7 @@ def use_react_native! (
config_file_dir: '',
privacy_file_aggregation_enabled: true
)
ReactNativePodsUtils.error_if_spm_injected
error_if_try_to_use_jsc_from_core()
warn_if_new_arch_disabled()

Expand Down
Loading
Loading