Skip to content

Commit

Permalink
Remove an absolute path that messed up the checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
mokagio committed Jun 1, 2023
1 parent 0d25a30 commit 1a26964
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 85 deletions.
14 changes: 8 additions & 6 deletions Gutenberg/Gutenberg.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ Pod::Spec.new do |s|
# See https://github.com/CocoaPods/CocoaPods/issues/10288#issuecomment-1517711223
# s.source = { http: xcframework_archive_url }
archive_name = "Gutenberg-#{gutenberg_version}.tar.gz"
absolute_download_path = File.join(GUTENBERG_DOWNLOADS_DIRECTORY, archive_name)
# Always use relative paths, otherwise the checksums in the lockfile will change from machine to machine
relative_download_path = Pathname.new(absolute_download_path).relative_path_from(__dir__).to_s
relative_extracted_archive_directory = Pathname.new("#{GUTENBERG_ARCHIVE_DIRECTORY}").relative_path_from(__dir__).to_s
relative_download_directory = Pathname.new(GUTENBERG_DOWNLOADS_DIRECTORY).relative_path_from(__dir__).to_s
relative_download_path = File.join(relative_download_directory, archive_name)

s.source = { http: "file://#{relative_download_path}" }

s.vendored_frameworks = [
Expand All @@ -55,17 +57,17 @@ Pod::Spec.new do |s|
'yoga.xcframework'
].map do |f|
# This needs to be a relative path to the local extraction location and account for the archive folder structure.
Pathname.new("#{GUTENBERG_ARCHIVE_DIRECTORY}/Frameworks/#{f}").relative_path_from(__dir__).to_s
File.join(relative_extracted_archive_directory, 'Frameworks', f)
end

# Print the message here because the prepare_command output is not forwarded by CocoaPods
puts "Will skip downloading Gutenberg archive because it already exists at #{relative_download_path}" if File.exist? relative_download_path
s.prepare_command = <<-CMD
mkdir -p #{GUTENBERG_DOWNLOADS_DIRECTORY}
mkdir -p #{relative_download_directory}
if [[ ! -f "#{relative_download_path}" ]]; then
curl --progress-bar #{xcframework_archive_url} -o #{relative_download_path}
fi
mkdir -p #{GUTENBERG_ARCHIVE_DIRECTORY}
tar -xzf #{relative_download_path} --directory=#{GUTENBERG_ARCHIVE_DIRECTORY}
mkdir -p #{relative_extracted_archive_directory}
tar -xzf #{relative_download_path} --directory=#{relative_extracted_archive_directory}
CMD
end
78 changes: 0 additions & 78 deletions Gutenberg/cocoapods_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,81 +127,3 @@ def archive_url(commit:)
xcframework_storage_url = 'https://d2twmm2nzpx3bg.cloudfront.net'
"#{xcframework_storage_url}/Gutenberg-#{commit}.tar.gz"
end

def gutenberg_pre_install_hook
# At this time, we only support XCFramework-commit builds
commit = GUTENBERG_CONFIG[:commit]
if commit.nil?
puts 'Skipping Gutenberg XCFramework download because no commit was given.'
return
end

url = archive_url(commit: commit)
archive_download_path = File.join(GUTENBERG_DOWNLOADS_DIRECTORY, File.basename(url))

if File.exist?(archive_download_path)
puts "Skipping download for #{url} because archive already exists at #{archive_download_path}."
else
download(archive_url: url, destination: archive_download_path)
end

extract(
archive: archive_download_path,
destination: GUTENBERG_ARCHIVE_DIRECTORY
)
end

private

# rubocop:disable Metrics/AbcSize
def download(archive_url:, destination:)
puts "Attempting to download #{archive_url} to #{destination}..."

FileUtils.mkdir_p(File.dirname(destination))

# Perform HTTP HEAD request to retrieve file size
uri = URI.parse(archive_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
content_length_key = 'Content-Length'
raise "Failed to retrieve file information: #{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess) && response.key?(content_length_key)

file_size = response[content_length_key].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: 'Downloading Gutenberg XCFrameworks archive', total: file_size, format: '%t |%B| %p%%')

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

progress_bar.finish

puts 'Finished downloading.'
end
# rubocop:enable Metrics/AbcSize

def extract(archive:, destination:)
FileUtils.rm_rf(destination)
FileUtils.mkdir_p(destination)

puts "Extracting #{archive} to #{destination}..."

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

puts 'Finished extracting.'
end
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ SPEC CHECKSUMS:
Gridicons: 17d660b97ce4231d582101b02f8280628b141c9a
GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
Gutenberg: 1f44813dc914ad38cccf0bd9eb3044c05922e3c7
Gutenberg: f6ab396a049c97e753a6af5a61b0223e9c881d22
JTAppleCalendar: 932cadea40b1051beab10f67843451d48ba16c99
Kanvas: f932eaed3d3f47aae8aafb6c2d27c968bdd49030
MediaEditor: 20cdeb46bdecd040b8bc94467ac85a52b53b193a
Expand Down

0 comments on commit 1a26964

Please sign in to comment.