From 5b7a7b736ddc759e7d9a2a58a95e2414d23b1404 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 2 Jun 2023 12:38:24 +1000 Subject: [PATCH] Remove `pre_install` download hook in favor of `prepare_command` The advantage of this approach is that downloading the archive is only necessary when using a local spec. Defining the logic in the local spec itself keeps everything self contained and saves us from having to conditionally call the `pre_install` hook. --- Gemfile | 1 - Gemfile.lock | 11 -- Gutenberg/Gutenberg.podspec | 31 +++-- Gutenberg/cocoapods_helpers.rb | 81 +------------ Podfile | 2 - Podfile.lock | 2 +- WordPress/WordPress.xcodeproj/project.pbxproj | 106 +++++++++--------- 7 files changed, 77 insertions(+), 157 deletions(-) diff --git a/Gemfile b/Gemfile index 1578b735fe6f..997a685009bf 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,6 @@ source 'https://rubygems.org' -gem 'archive-tar-minitar' gem 'cocoapods', '~> 1.11' gem 'commonmarker' gem 'danger', '~> 9.3' diff --git a/Gemfile.lock b/Gemfile.lock index cbdfa9793ce9..69e704dbd446 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,9 +13,6 @@ 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) @@ -250,7 +247,6 @@ 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) @@ -268,10 +264,6 @@ 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) @@ -295,8 +287,6 @@ GEM parser (3.2.2.1) 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) @@ -380,7 +370,6 @@ PLATFORMS ruby DEPENDENCIES - archive-tar-minitar cocoapods (~> 1.11) commonmarker danger (~> 9.3) diff --git a/Gutenberg/Gutenberg.podspec b/Gutenberg/Gutenberg.podspec index 4bf146527f4d..7476f038b8ce 100644 --- a/Gutenberg/Gutenberg.podspec +++ b/Gutenberg/Gutenberg.podspec @@ -37,15 +37,18 @@ Pod::Spec.new do |s| # 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 - # - # I can't get this to work out of the box, so instead of using a URL we take - # care of downloading and unarchiving and use a local source. + # Unfortunately, CocoaPods currently (1.12.1) does not work when it comes to local specs with http sources. # + # See https://github.com/CocoaPods/CocoaPods/issues/10288#issuecomment-1517711223 # s.source = { http: xcframework_archive_url } - path = Pathname.new("#{GUTENBERG_DOWNLOADS_DIRECTORY}/Gutenberg-#{gutenberg_version}.tar.gz") - .relative_path_from(__dir__).to_s - s.source = { http: "file://#{path}" } + archive_name = "Gutenberg-#{gutenberg_version}.tar.gz" + # Always use relative paths, otherwise the checksums in the lockfile will change from machine to machine + 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 = [ 'Aztec.xcframework', 'Gutenberg.xcframework', @@ -54,7 +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 #{relative_download_directory} + if [[ ! -f "#{relative_download_path}" ]]; then + curl --progress-bar #{xcframework_archive_url} -o #{relative_download_path} + fi + mkdir -p #{relative_extracted_archive_directory} + tar -xzf #{relative_download_path} --directory=#{relative_extracted_archive_directory} + CMD end diff --git a/Gutenberg/cocoapods_helpers.rb b/Gutenberg/cocoapods_helpers.rb index 9ed24c34ab21..7709e2e90024 100644 --- a/Gutenberg/cocoapods_helpers.rb +++ b/Gutenberg/cocoapods_helpers.rb @@ -2,7 +2,6 @@ # Helpers and configurations for integrating Gutenberg in Jetpack and WordPress via CocoaPods. -require 'archive/tar/minitar' require 'net/http' require 'pathname' require 'ruby-progressbar' @@ -91,7 +90,7 @@ def gutenberg_pod(config: GUTENBERG_CONFIG) gutenberg_dependencies(options: options) elsif options[:commit] # Notice the use of relative path, otherwise we'd get the full path of the user that run the `pod install` command tracked in Podfile.lock. - # Also notice the path is relative from Dir.pwd, that is, the location where the script running this code is invoked. + # Also notice the path is relative from Dir.pwd, that is, the location where the script running this code is invoked to avoid absolute paths making the checksum non determinstic. pod 'Gutenberg', path: Pathname.new(File.join(__dir__, 'Gutenberg.podspec')).relative_path_from(Dir.pwd).to_s end end @@ -124,81 +123,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 diff --git a/Podfile b/Podfile index 1224dd3b7d76..07988c318684 100644 --- a/Podfile +++ b/Podfile @@ -336,8 +336,6 @@ 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| diff --git a/Podfile.lock b/Podfile.lock index 97b54413bd9d..09b4f8930959 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -900,6 +900,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37 -PODFILE CHECKSUM: 8af441982acbc7fa8e1dd439890a23ee5bfaafe8 +PODFILE CHECKSUM: 8f3801df87501615cc7418c5a128cd9136848813 COCOAPODS: 1.12.1 diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index fe9dc64bab7a..c3d741637c6a 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -10420,7 +10420,7 @@ path = Classes; sourceTree = ""; }; - 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { + 29B97314FDCFA39411CA2CEA = { isa = PBXGroup; children = ( 3F20FDF3276BF21000DA3CAD /* Packages */, @@ -18415,7 +18415,7 @@ E16AB92514D978240047A2E5 /* Sources */, E16AB92614D978240047A2E5 /* Frameworks */, E16AB92714D978240047A2E5 /* Resources */, - 42C1BDE416A90FA718A28797 /* [CP] Copy Pods Resources */, + 5C9D9350019C99ACBD754CF3 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -18720,14 +18720,14 @@ bg, sk, ); - mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; + mainGroup = 29B97314FDCFA39411CA2CEA; packageReferences = ( 3FF1442E266F3C2400138163 /* XCRemoteSwiftPackageReference "ScreenObject" */, 3FC2C33B26C4CF0A00C6D98F /* XCRemoteSwiftPackageReference "XCUITestHelpers" */, 17A8858B2757B97F0071FCA3 /* XCRemoteSwiftPackageReference "AutomatticAbout-swift" */, 3F2B62DA284F4E0B0008CD59 /* XCRemoteSwiftPackageReference "Charts" */, 3F3B23C02858A1B300CACE60 /* XCRemoteSwiftPackageReference "test-collector-swift" */, - 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */, + 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */, 3F338B6F289BD3040014ADC5 /* XCRemoteSwiftPackageReference "Nimble" */, ); productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */; @@ -20002,52 +20002,6 @@ shellPath = /bin/sh; shellScript = "$SRCROOT/../Scripts/BuildPhases/GenerateCredentials.sh\n"; }; - 42C1BDE416A90FA718A28797 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-WordPressTest/Pods-WordPressTest-resources.sh", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/content-functions.js", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/editor-behavior-overrides.js", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/editor-style-overrides.css", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/gutenberg-observer.js", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/inject-css.js", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/insert-block.js", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/local-storage-overrides.json", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/prevent-autosaves.js", - "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/wp-bar-override.css", - "${PODS_ROOT}/Gutenberg/src/block-support/supported-blocks.json", - "${PODS_ROOT}/Gutenberg/resources/unsupported-block-editor/external-style-overrides.css", - "${PODS_ROOT}/Gutenberg/resources/unsupported-block-editor/extra-localstorage-entries.js", - "${PODS_ROOT}/Gutenberg/resources/unsupported-block-editor/remove-nux.js", - "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", - "${PODS_CONFIGURATION_BUILD_DIR}/WordPress-Aztec-iOS/WordPress-Aztec-iOS.bundle", - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/content-functions.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/editor-behavior-overrides.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/editor-style-overrides.css", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/gutenberg-observer.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inject-css.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/insert-block.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/local-storage-overrides.json", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/prevent-autosaves.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/wp-bar-override.css", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/supported-blocks.json", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/external-style-overrides.css", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/extra-localstorage-entries.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/remove-nux.js", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/WordPress-Aztec-iOS.bundle", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WordPressTest/Pods-WordPressTest-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; 4C304224F0F810A17D96A402 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -20114,6 +20068,52 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WordPressNotificationServiceExtension/Pods-WordPressNotificationServiceExtension-resources.sh\"\n"; showEnvVarsInLog = 0; }; + 5C9D9350019C99ACBD754CF3 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-WordPressTest/Pods-WordPressTest-resources.sh", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/content-functions.js", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/editor-behavior-overrides.js", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/editor-style-overrides.css", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/gutenberg-observer.js", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/inject-css.js", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/insert-block.js", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/local-storage-overrides.json", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/prevent-autosaves.js", + "${PODS_ROOT}/Gutenberg/gutenberg/packages/react-native-bridge/common/gutenberg-web-single-block/wp-bar-override.css", + "${PODS_ROOT}/Gutenberg/src/block-support/supported-blocks.json", + "${PODS_ROOT}/Gutenberg/resources/unsupported-block-editor/external-style-overrides.css", + "${PODS_ROOT}/Gutenberg/resources/unsupported-block-editor/extra-localstorage-entries.js", + "${PODS_ROOT}/Gutenberg/resources/unsupported-block-editor/remove-nux.js", + "${PODS_CONFIGURATION_BUILD_DIR}/React-Core/AccessibilityResources.bundle", + "${PODS_CONFIGURATION_BUILD_DIR}/WordPress-Aztec-iOS/WordPress-Aztec-iOS.bundle", + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/content-functions.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/editor-behavior-overrides.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/editor-style-overrides.css", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/gutenberg-observer.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/inject-css.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/insert-block.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/local-storage-overrides.json", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/prevent-autosaves.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/wp-bar-override.css", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/supported-blocks.json", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/external-style-overrides.css", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/extra-localstorage-entries.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/remove-nux.js", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AccessibilityResources.bundle", + "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/WordPress-Aztec-iOS.bundle", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-WordPressTest/Pods-WordPressTest-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; 72BB9EE3CC91D92F3735F4F3 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -30487,7 +30487,7 @@ minimumVersion = 0.3.0; }; }; - 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */ = { + 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/airbnb/lottie-ios.git"; requirement = { @@ -30568,12 +30568,12 @@ }; 3F411B6E28987E3F002513AE /* Lottie */ = { isa = XCSwiftPackageProductDependency; - package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */; + package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */; productName = Lottie; }; 3F44DD57289C379C006334CD /* Lottie */ = { isa = XCSwiftPackageProductDependency; - package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios" */; + package = 3F411B6D28987E3F002513AE /* XCRemoteSwiftPackageReference "lottie-ios.git" */; productName = Lottie; }; 3FC2C33C26C4CF0A00C6D98F /* XCUITestHelpers */ = {