Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic update of RCT-Folly #32659

Closed
wants to merge 5 commits into from
Closed
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
52 changes: 52 additions & 0 deletions scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ def use_react_native! (options={})
pod 'hermes-engine', '~> 0.9.0'
pod 'libevent', '~> 2.1.12'
end

pods_to_update = LocalPodspecPatch.pods_to_update(options)
if !pods_to_update.empty?
if Pod::Lockfile.public_instance_methods.include?(:detect_changes_with_podfile)
Pod::Lockfile.prepend(LocalPodspecPatch)
else
Pod::UI.warn "Automatically updating #{pods_to_update.join(", ")} has failed, please run `pod update #{pods_to_update.join(" ")} --no-repo-update` manually to fix the issue."
end
end
end

def use_flipper!(versions = {}, configurations: ['Debug'])
Expand Down Expand Up @@ -558,3 +567,46 @@ def __apply_Xcode_12_5_M1_post_install_workaround(installer)
# See https://github.com/facebook/flipper/issues/834 for more details.
`sed -i -e $'s/__IPHONE_10_0/__IPHONE_12_0/' Pods/RCT-Folly/folly/portability/Time.h`
end

# Monkeypatch of `Pod::Lockfile` to ensure automatic update of dependencies integrated with a local podspec when their version changed.
# This is necessary because local podspec dependencies must be otherwise manually updated.
module LocalPodspecPatch
# Returns local podspecs whose versions differ from the one in the `react-native` package.
def self.pods_to_update(react_native_options)
prefix = react_native_options[:path] ||= "../node_modules/react-native"
@@local_podspecs = Dir.glob("#{prefix}/third-party-podspecs/*").map { |file| File.basename(file, ".podspec") }
@@local_podspecs = @@local_podspecs.select do |podspec_name|
# Read local podspec to determine the cached version
local_podspec_path = File.join(
Dir.pwd, "Pods/Local Podspecs/#{podspec_name}.podspec.json"
)

# Local podspec cannot be outdated if it does not exist, yet
next unless File.file?(local_podspec_path)

local_podspec = File.read(local_podspec_path)
local_podspec_json = JSON.parse(local_podspec)
local_version = local_podspec_json["version"]

# Read the version from a podspec from the `react-native` package
podspec_path = "#{prefix}/third-party-podspecs/#{podspec_name}.podspec"
current_podspec = Pod::Specification.from_file(podspec_path)

current_version = current_podspec.version.to_s
current_version != local_version
end
@@local_podspecs
end

# Patched `detect_changes_with_podfile` method
def detect_changes_with_podfile(podfile)
changes = super(podfile)
@@local_podspecs.each do |local_podspec|
next unless changes[:unchanged].include?(local_podspec)

changes[:unchanged].delete(local_podspec)
changes[:changed] << local_podspec
end
changes
end
end