From aed4a124cdefe1a474f14c6e59bdf8f0fcfc06d5 Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Mon, 11 Jul 2022 21:10:57 +0200 Subject: [PATCH 1/3] [CocoaPodsPlugin] Regenerate cached projects when XCRC is finally enabled --- .../cocoapods-xcremotecache/command/hooks.rb | 75 +++++++++++++++---- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb b/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb index 474064f..fa5786c 100644 --- a/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb +++ b/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb @@ -362,12 +362,73 @@ module CocoapodsXCRemoteCacheModifier File.write(LLDB_INIT_PATH, lldbinit_lines.join("\n"), mode: "w") end - Pod::HooksManager.register('cocoapods-xcremotecache', :post_install) do |installer_context| + Pod::HooksManager.register('cocoapods-xcremotecache', :pre_install) do |installer_context| + # The main responsibility of that hook is forcing Pods regeneration when XCRemoteCache is enabled for the first time + # In the post_install hook, this plugin adds extra build settings and steps to all Pods targets, but only when XCRemoteCache + # is enabled and all artifacts are available (i.e. xcprepare returns 0). + # If Pods projects/targets are cached from previous `pod install` action that didn't enable XCRemoteCache (e.g. artifacts + # are not available in the remote cache), these projects/targets should be invalidated to include XCRemoteCache-related + # build steps and build settings. if @@configuration.nil? Pod::UI.puts "[XCRC] Warning! XCRemoteCache not configured. Call xcremotecache({...}) in Podfile to enable XCRemoteCache" next end + begin + # `user_pod_directory`` and `user_proj_directory` in the 'postinstall' should be equal + user_pod_directory = File.dirname(installer_context.podfile.defined_in_file) + set_configuration_default_values + + unless @@configuration['enabled'] + # No need to check if enabling remote cache for the first time + next + end + + validate_configuration() + mode = @@configuration['mode'] + remote_commit_file = @@configuration['remote_commit_file'] + xcrc_location = @@configuration['xcrc_location'] + check_build_configuration = @@configuration['check_build_configuration'] + check_platform = @@configuration['check_platform'] + + xcrc_location_absolute = "#{user_pod_directory}/#{xcrc_location}" + remote_commit_file_absolute = "#{user_pod_directory}/#{remote_commit_file}" + + # Download XCRC + download_xcrc_if_needed(xcrc_location_absolute) + + # Save .rcinfo + root_rcinfo = generate_rcinfo() + save_rcinfo(root_rcinfo, user_pod_directory) + + # Create directory for xccc & arc.rc location + Dir.mkdir(BIN_DIR) unless File.exist?(BIN_DIR) + + # Remove previous xccc & arc.rc + was_previously_enabled = File.exist?(remote_commit_file_absolute) + File.delete(remote_commit_file_absolute) if File.exist?(remote_commit_file_absolute) + + prepare_result = YAML.load`#{xcrc_location_absolute}/xcprepare --configuration #{check_build_configuration} --platform #{check_platform}` + unless prepare_result['result'] && mode != 'consumer' + # Remote cache is still disabled - no need to force Pods projects/targets regeneration + next + end + + # Force rebuilding all Pods project, because XCRC build steps and settings need to be added to Pods project/targets + # It is relevant only when 'incremental_installation' is enabled, otherwise installed_cache_path does not exist on a disk + installed_cache_path = installer_context.sandbox.project_installation_cache_path + if !was_previously_enabled && File.exist?(installed_cache_path) + Pod::UI.puts "[XCRC] Forces Pods project regenerations because XCRC is enabled for the first time." + File.delete(installed_cache_path) + end + end + end + + Pod::HooksManager.register('cocoapods-xcremotecache', :post_install) do |installer_context| + if @@configuration.nil? + next + end + user_project = installer_context.umbrella_targets[0].user_project begin @@ -396,22 +457,10 @@ module CocoapodsXCRemoteCacheModifier xcrc_location_absolute = "#{user_proj_directory}/#{xcrc_location}" remote_commit_file_absolute = "#{user_proj_directory}/#{remote_commit_file}" - # Download XCRC - download_xcrc_if_needed(xcrc_location_absolute) - # Save .rcinfo root_rcinfo = generate_rcinfo() save_rcinfo(root_rcinfo, user_proj_directory) - # Create directory for xccc & arc.rc location - Dir.mkdir(BIN_DIR) unless File.exist?(BIN_DIR) - - # Remove previous xccc & arc.rc - File.delete(remote_commit_file_absolute) if File.exist?(remote_commit_file_absolute) - File.delete(xccc_location_absolute) if File.exist?(xccc_location_absolute) - - # Prepare XCRC - # Pods projects can be generated only once (if incremental_installation is enabled) # Always integrate XCRemoteCache to all Pods, in case it will be needed later unless installer_context.pods_project.nil? From 2d7c881b3bee263e7803fb9c2f7dd115b2ecf13c Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Mon, 11 Jul 2022 22:48:45 +0200 Subject: [PATCH 2/3] Do not skip install cache invalidation in consumer --- .../lib/cocoapods-xcremotecache/command/hooks.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb b/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb index fa5786c..1cdefce 100644 --- a/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb +++ b/cocoapods-plugin/lib/cocoapods-xcremotecache/command/hooks.rb @@ -409,7 +409,7 @@ module CocoapodsXCRemoteCacheModifier File.delete(remote_commit_file_absolute) if File.exist?(remote_commit_file_absolute) prepare_result = YAML.load`#{xcrc_location_absolute}/xcprepare --configuration #{check_build_configuration} --platform #{check_platform}` - unless prepare_result['result'] && mode != 'consumer' + if !prepare_result['result'] && mode == 'consumer' # Remote cache is still disabled - no need to force Pods projects/targets regeneration next end @@ -455,12 +455,16 @@ module CocoapodsXCRemoteCacheModifier xccc_location_absolute = "#{user_proj_directory}/#{xccc_location}" xcrc_location_absolute = "#{user_proj_directory}/#{xcrc_location}" - remote_commit_file_absolute = "#{user_proj_directory}/#{remote_commit_file}" # Save .rcinfo root_rcinfo = generate_rcinfo() save_rcinfo(root_rcinfo, user_proj_directory) + # Remove previous xccc + File.delete(xccc_location_absolute) if File.exist?(xccc_location_absolute) + + # Prepare XCRC + # Pods projects can be generated only once (if incremental_installation is enabled) # Always integrate XCRemoteCache to all Pods, in case it will be needed later unless installer_context.pods_project.nil? @@ -507,6 +511,7 @@ module CocoapodsXCRemoteCacheModifier # Enabled/disable XCRemoteCache for the main (user) project begin + # TODO: Do not compile xcc again. `xcprepare` compiles it in pre-install anyway prepare_result = YAML.load`#{xcrc_location_absolute}/xcprepare --configuration #{check_build_configuration} --platform #{check_platform}` unless prepare_result['result'] || mode != 'consumer' # Uninstall the XCRemoteCache for the consumer mode From 36fc5ae1e45a293cf3a689dac2fd4cebf46ad3ad Mon Sep 17 00:00:00 2001 From: Bartosz Polaczyk Date: Mon, 11 Jul 2022 22:49:13 +0200 Subject: [PATCH 3/3] Bump plugin version --- cocoapods-plugin/lib/cocoapods-xcremotecache/gem_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocoapods-plugin/lib/cocoapods-xcremotecache/gem_version.rb b/cocoapods-plugin/lib/cocoapods-xcremotecache/gem_version.rb index d1a041b..9f3f113 100644 --- a/cocoapods-plugin/lib/cocoapods-xcremotecache/gem_version.rb +++ b/cocoapods-plugin/lib/cocoapods-xcremotecache/gem_version.rb @@ -13,5 +13,5 @@ # limitations under the License. module CocoapodsXcremotecache - VERSION = "0.0.13" + VERSION = "0.0.14" end