Skip to content

Commit

Permalink
WIP – Workaround CP not finding XCArchives
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed May 22, 2023
1 parent ceb45dd commit cc51e8b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 5 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

source 'https://rubygems.org'

gem 'archive-tar-minitar'
gem 'cocoapods', '~> 1.11'
gem 'commonmarker'
gem 'danger', '~> 9.3'
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ GEM
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
archive-tar-minitar (0.8)
minitar (~> 0.8)
minitar-cli (~> 0.8)
artifactory (3.0.15)
ast (2.4.2)
atomos (0.1.3)
Expand Down Expand Up @@ -247,6 +250,7 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
hashie (5.0.0)
highline (2.0.3)
http-cookie (1.0.5)
domain_name (~> 0.5)
Expand All @@ -264,6 +268,10 @@ GEM
mini_magick (4.12.0)
mini_mime (1.1.2)
mini_portile2 (2.8.2)
minitar (0.8)
minitar-cli (0.8)
minitar (~> 0.8.0)
powerbar (~> 1.0)
minitest (5.18.0)
molinillo (0.8.0)
multi_json (1.15.0)
Expand All @@ -287,6 +295,8 @@ GEM
parser (3.1.2.0)
ast (~> 2.4.1)
plist (3.7.0)
powerbar (1.0.18)
hashie (>= 1.1.0)
progress_bar (1.3.3)
highline (>= 1.6, < 3)
options (~> 2.3.0)
Expand Down Expand Up @@ -369,6 +379,7 @@ PLATFORMS
ruby

DEPENDENCIES
archive-tar-minitar
cocoapods (~> 1.11)
commonmarker
danger (~> 9.3)
Expand Down
4 changes: 4 additions & 0 deletions Gutenberg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are the folders where our bespoke automatation downloads and unpacks the XCFrameworks archives.
# Ideally, CocoaPods should do this, but for some reason I haven't yet been able to make it work.
.downloads
.artifacts/
11 changes: 8 additions & 3 deletions Gutenberg/Gutenberg.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ Pod::Spec.new do |s|
s.authors = 'Automattic'

s.ios.deployment_target = '13.0' # TODO: Read from common source
s.swift_version = '5.0' # TODO: read from common source
s.swift_version = '5.7' # TODO: read from common source

s.requires_arc = true # TODO: Can this be omitted?

# Tell CocoaPods where to download the XCFramework(s) archive with `source` and what to use from its decompressed contents with `vendored_frameworks`.
#
# See https://github.com/CocoaPods/CocoaPods/issues/10288
s.source = { http: xcframework_archive_url }
#
# I thought I got this to work, but it was just that I inadvertenly put the frameworks in the current folder, so that worked...
#
# Next step I guess is try to find out where CP unpacks shit and see why mine isn't found...
# s.source = { http: xcframework_archive_url }
s.source = { http: "file://#{__dir__}/.downloads/Gutenberg-#{gutenberg_version}.tar.gz" }
s.vendored_frameworks = [
'Aztec.xcframework',
'Gutenberg.xcframework',
'React.xcframework',
'RNTAztecView.xcframework',
'yoga.xcframework'
].map { |f| "Gutenberg/#{f}" } # prefix with the name of the folder generated when unarchiving
].map { |f| ".artifacts/Frameworks/#{f}" } # prefix with the name of the folder generated when unarchiving
end
78 changes: 76 additions & 2 deletions Gutenberg/cocoapods_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# frozen_string_literal: true

require 'net/http'
require 'zlib'
require 'archive/tar/minitar'
require 'uri'
require 'ruby-progressbar'

# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength

# Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods.

require_relative './version'
Expand Down Expand Up @@ -59,7 +68,6 @@
React-bridging
].freeze

# rubocop:disable Metrics/AbcSize
def gutenberg_pod(config: GUTENBERG_CONFIG)
options = config

Expand Down Expand Up @@ -87,7 +95,6 @@ def gutenberg_pod(config: GUTENBERG_CONFIG)
pod 'Gutenberg', path: File.join(__dir__, 'gutenberg.podspec')
end
end
# rubocop:enable Metrics/AbcSize

def gutenberg_dependencies(options:)
if options[:path]
Expand All @@ -111,3 +118,70 @@ def gutenberg_dependencies(options:)
pod pod_name, podspec: "#{podspec_prefix}/#{pod_name}.#{podspec_extension}"
end
end

def archive_url(commit:)
xcframework_storage_url = 'https://d2twmm2nzpx3bg.cloudfront.net'
"#{xcframework_storage_url}/Gutenberg-#{commit}.tar.gz"
end

def gutenberg_pre_install_hook
# FIXME: Automatically switch between commit and tag outside this method
url = archive_url(commit: GUTENBERG_CONFIG[:commit])
archive_name = File.basename(url)
archive_folder = File.join(__dir__, '.downloads')
archive_path = File.join(archive_folder, archive_name)

if File.exist?(archive_path)
puts "Skipping download because archive for #{url} exists already at #{archive_path}."
else
puts "Will attempt downloading #{url} to #{archive_name}..."

FileUtils.mkdir_p(archive_folder)

# Perform HTTP HEAD request to retrieve file size
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.head(uri.path)

# Check if the response is successful and contains Content-Length header
raise "Failed to retrieve file information: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess) && response.key?('Content-Length')

file_size = response['Content-Length'].to_i

# Check file size
raise 'File size is 0. Aborting download.' if file_size.zero?

puts "File size: #{(file_size / (1024.0 * 1024.0)).round(2)} MB"

progress_bar = ProgressBar.create(title: 'Download', total: file_size, format: '%t |%B| %p%%')

http.request_get(uri.path) do |archive_response|
File.open(archive_path, 'wb') do |file|
archive_response.read_body do |chunk|
file.write(chunk)
progress_bar.progress += chunk.length
end
end
end

progress_bar.finish

puts 'Done downloading'
end

archive_extraction_folder = File.join(__dir__, '.artifacts')

FileUtils.rm_rf(archive_extraction_folder)
FileUtils.mkdir_p(archive_extraction_folder)

puts "Extracting #{archive_name} to #{archive_extraction_folder}..."

Zlib::GzipReader.open(archive_path) do |gzip_file|
Archive::Tar::Minitar.unpack(gzip_file, archive_extraction_folder)
end

puts 'Finished extracting.'
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
2 changes: 2 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ pre_install do |installer|
end
puts "Installing #{static.count} pods as static frameworks"
puts "Installing #{dynamic.count} pods as dynamic frameworks"

gutenberg_pre_install_hook
end

post_install do |installer|
Expand Down

0 comments on commit cc51e8b

Please sign in to comment.