cocoapods-xcremotecache 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8929b95b00fd3885898cf18700dddc98fc22b6918f806dae77dd999848a26a35
4
- data.tar.gz: f1e5cdb7db24fbc0c3b29e048424643621dc7c5fea985d0a29d26689e4441deb
3
+ metadata.gz: be0f0312463e793e7f6afccd9ae49ea0a0ed5f740adade59c780a0e6873f05a5
4
+ data.tar.gz: adbc9a76871be26f0fe19e53f92b67554db4f55a69d0e3d88118ed0c1b5cf9e5
5
5
  SHA512:
6
- metadata.gz: d79a51a5c7c21a472caa1311e7208b25322b13a9190cbc29f06d302f1e8d445073d1d985ed5d6626b78de93f28ac08ffb2866195fcd80dc1fecdad4817a971a5
7
- data.tar.gz: bfd2ef88c899f0e6be31ea12109aaffcc09e30582fee638d2b1a206d2e7460fe0249d5695223abcc9220a4425363ebd4deb49102f5df0b9e4daed32e594796cf
6
+ metadata.gz: 0ce9ed4249f55c838501321dadb012ea556441836fb07edaac8db88ff7ccd8510ab0debccbf1c92c98d9537680874a0416c68d33cdfad4c7620a52ca6d4608dd
7
+ data.tar.gz: 2cfed964db8d3078f35b48758e8be756938e77fd4b3937e7032327cf703cbcc5268cca67c96b6c82d1013cedac26cabc9efaae3ecb20da231ea812ba29da5687
@@ -3,9 +3,9 @@
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
- #
6
+ #
7
7
  # http://www.apache.org/licenses/LICENSE-2.0
8
- #
8
+ #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,15 +29,15 @@ module CocoapodsXCRemoteCacheModifier
29
29
  FAT_ARCHIVE_NAME_INFIX = 'arm64-x86_64'
30
30
  XCRC_COOCAPODS_ROOT_KEY = 'XCRC_COOCAPODS_ROOT'
31
31
 
32
- # List of plugins' user properties that should not be copied to .rcinfo
32
+ # List of plugins' user properties that should not be copied to .rcinfo
33
33
  CUSTOM_CONFIGURATION_KEYS = [
34
- 'enabled',
34
+ 'enabled',
35
35
  'xcrc_location',
36
36
  'exclude_targets',
37
37
  'exclude_build_configurations',
38
38
  'final_target',
39
- 'check_build_configuration',
40
- 'check_platform',
39
+ 'check_build_configuration',
40
+ 'check_platform',
41
41
  'modify_lldb_init',
42
42
  'fake_src_root',
43
43
  ]
@@ -45,19 +45,19 @@ module CocoapodsXCRemoteCacheModifier
45
45
  class XCRemoteCache
46
46
  @@configuration = nil
47
47
 
48
- def self.configure(c)
48
+ def self.configure(c)
49
49
  @@configuration = c
50
50
  end
51
51
 
52
52
  def self.set_configuration_default_values
53
53
  default_values = {
54
54
  'mode' => 'consumer',
55
- 'enabled' => true,
55
+ 'enabled' => true,
56
56
  'xcrc_location' => "XCRC",
57
57
  'exclude_build_configurations' => [],
58
58
  'check_build_configuration' => 'Debug',
59
- 'check_platform' => 'iphonesimulator',
60
- 'modify_lldb_init' => true,
59
+ 'check_platform' => 'iphonesimulator',
60
+ 'modify_lldb_init' => true,
61
61
  'xccc_file' => "#{BIN_DIR}/xccc",
62
62
  'remote_commit_file' => "#{BIN_DIR}/arc.rc",
63
63
  'exclude_targets' => [],
@@ -75,12 +75,12 @@ module CocoapodsXCRemoteCacheModifier
75
75
 
76
76
  def self.validate_configuration()
77
77
  required_values = [
78
- 'cache_addresses',
78
+ 'cache_addresses',
79
79
  'primary_repo',
80
80
  'check_build_configuration',
81
81
  'check_platform'
82
82
  ]
83
-
83
+
84
84
  missing_configuration_values = required_values.select { |v| !@@configuration.key?(v) }
85
85
  unless missing_configuration_values.empty?
86
86
  throw "XCRemoteCache not fully configured. Make sure all required fields are provided. Missing fields are: #{missing_configuration_values.join(', ')}."
@@ -105,7 +105,7 @@ module CocoapodsXCRemoteCacheModifier
105
105
  end
106
106
 
107
107
  # @param target [Target] target to apply XCRemoteCache
108
- # @param repo_distance [Integer] distance from the git repo root to the target's $SRCROOT
108
+ # @param repo_distance [Integer] distance from the git repo root to the target's $SRCROOT
109
109
  # @param xc_location [String] path to the dir with all XCRemoteCache binaries, relative to the repo root
110
110
  # @param xc_cc_path [String] path to the XCRemoteCache clang wrapper, relative to the repo root
111
111
  # @param mode [String] mode name ('consumer', 'producer', 'producer-fast' etc.)
@@ -128,6 +128,7 @@ module CocoapodsXCRemoteCacheModifier
128
128
  config.build_settings['LIBTOOL'] = ["$SRCROOT/#{srcroot_relative_xc_location}/xclibtool"]
129
129
  config.build_settings['LD'] = ["$SRCROOT/#{srcroot_relative_xc_location}/xcld"]
130
130
  config.build_settings['LDPLUSPLUS'] = ["$SRCROOT/#{srcroot_relative_xc_location}/xcldplusplus"]
131
+ config.build_settings['LIPO'] = ["$SRCROOT/#{srcroot_relative_xc_location}/xclipo"]
131
132
  config.build_settings['SWIFT_USE_INTEGRATED_DRIVER'] = ['NO']
132
133
 
133
134
  config.build_settings['XCREMOTE_CACHE_FAKE_SRCROOT'] = fake_src_root
@@ -156,7 +157,7 @@ module CocoapodsXCRemoteCacheModifier
156
157
  prebuild_script.dependency_file = "$(TARGET_TEMP_DIR)/prebuild.d"
157
158
 
158
159
  # Move prebuild (last element) to the position before compile sources phase (to make it real 'prebuild')
159
- if !existing_prebuild_script
160
+ if !existing_prebuild_script
160
161
  compile_phase_index = target.build_phases.index(target.source_build_phase)
161
162
  target.build_phases.insert(compile_phase_index, target.build_phases.delete(prebuild_script))
162
163
  end
@@ -184,7 +185,7 @@ module CocoapodsXCRemoteCacheModifier
184
185
  ]
185
186
  postbuild_script.dependency_file = "$(TARGET_TEMP_DIR)/postbuild.d"
186
187
  # Move postbuild (last element) to the position after compile sources phase (to make it real 'postbuild')
187
- if !existing_postbuild_script
188
+ if !existing_postbuild_script
188
189
  compile_phase_index = target.build_phases.index(target.source_build_phase)
189
190
  target.build_phases.insert(compile_phase_index + 1, target.build_phases.delete(postbuild_script))
190
191
  end
@@ -214,6 +215,7 @@ module CocoapodsXCRemoteCacheModifier
214
215
  config.build_settings.delete('CC') if config.build_settings.key?('CC')
215
216
  config.build_settings.delete('SWIFT_EXEC') if config.build_settings.key?('SWIFT_EXEC')
216
217
  config.build_settings.delete('LIBTOOL') if config.build_settings.key?('LIBTOOL')
218
+ config.build_settings.delete('LIPO') if config.build_settings.key?('LIPO')
217
219
  config.build_settings.delete('LD') if config.build_settings.key?('LD')
218
220
  config.build_settings.delete('LDPLUSPLUS') if config.build_settings.key?('LDPLUSPLUS')
219
221
  config.build_settings.delete('SWIFT_USE_INTEGRATED_DRIVER') if config.build_settings.key?('SWIFT_USE_INTEGRATED_DRIVER')
@@ -226,9 +228,9 @@ module CocoapodsXCRemoteCacheModifier
226
228
  end
227
229
 
228
230
  # User project is not generated from scratch (contrary to `Pods`), delete all previous XCRemoteCache phases
229
- target.build_phases.delete_if {|phase|
231
+ target.build_phases.delete_if {|phase|
230
232
  # Some phases (e.g. PBXSourcesBuildPhase) don't have strict name check respond_to?
231
- if phase.respond_to?(:name)
233
+ if phase.respond_to?(:name)
232
234
  phase.name != nil && phase.name.start_with?("[XCRC]")
233
235
  end
234
236
  }
@@ -240,9 +242,9 @@ module CocoapodsXCRemoteCacheModifier
240
242
  end
241
243
 
242
244
  def self.download_xcrc_if_needed(local_location)
243
- required_binaries = ['xcld', 'xcldplusplus', 'xclibtool', 'xcpostbuild', 'xcprebuild', 'xcprepare', 'xcswiftc']
245
+ required_binaries = ['xcld', 'xcldplusplus', 'xclibtool', 'xclipo', 'xcpostbuild', 'xcprebuild', 'xcprepare', 'xcswiftc']
244
246
  binaries_exist = required_binaries.reduce(true) do |exists, filename|
245
- file_path = File.join(local_location, filename)
247
+ file_path = File.join(local_location, filename)
246
248
  exists = exists && File.exist?(file_path)
247
249
  end
248
250
 
@@ -256,13 +258,13 @@ module CocoapodsXCRemoteCacheModifier
256
258
 
257
259
  if !system("unzip #{local_package_location} -d #{local_location}")
258
260
  throw "Unzipping XCRemoteCache failed"
259
- end
261
+ end
260
262
  end
261
263
 
262
264
  def self.download_latest_xcrc_release(local_package_location)
263
265
  release_url = 'https://api.github.com/repos/spotify/XCRemoteCache/releases/latest'
264
266
  asset_url = nil
265
-
267
+
266
268
  URI.open(release_url) do |f|
267
269
  assets_array = JSON.parse(f.read)['assets']
268
270
  # Pick fat archive
@@ -270,7 +272,7 @@ module CocoapodsXCRemoteCacheModifier
270
272
  asset_url = asset_array['url']
271
273
  end
272
274
 
273
- if asset_url.nil?
275
+ if asset_url.nil?
274
276
  throw "Downloading XCRemoteCache failed"
275
277
  end
276
278
 
@@ -283,7 +285,7 @@ module CocoapodsXCRemoteCacheModifier
283
285
 
284
286
  def self.add_cflags!(options, key, value)
285
287
  return if options.fetch('OTHER_CFLAGS',[]).include?(value)
286
- options['OTHER_CFLAGS'] = remove_cflags!(options, key) << "#{key}=#{value}"
288
+ options['OTHER_CFLAGS'] = remove_cflags!(options, key) << "#{key}=#{value}"
287
289
  end
288
290
 
289
291
  def self.remove_cflags!(options, key)
@@ -295,7 +297,7 @@ module CocoapodsXCRemoteCacheModifier
295
297
 
296
298
  def self.add_swiftflags!(options, key, value)
297
299
  return if options.fetch('OTHER_SWIFT_FLAGS','').include?(value)
298
- options['OTHER_SWIFT_FLAGS'] = remove_swiftflags!(options, key) + " #{key} #{value}"
300
+ options['OTHER_SWIFT_FLAGS'] = remove_swiftflags!(options, key) + " #{key} #{value}"
299
301
  end
300
302
 
301
303
  def self.remove_swiftflags!(options, key)
@@ -336,7 +338,7 @@ module CocoapodsXCRemoteCacheModifier
336
338
  File.open(lldbinit_path) { |file|
337
339
  while(line = file.gets) != nil
338
340
  line = line.strip
339
- if line == LLDB_INIT_COMMENT
341
+ if line == LLDB_INIT_COMMENT
340
342
  # skip current and next lines
341
343
  file.gets
342
344
  next
@@ -351,7 +353,7 @@ module CocoapodsXCRemoteCacheModifier
351
353
  def self.add_lldbinit_rewrite(lines_content, user_proj_directory,fake_src_root)
352
354
  all_lines = lines_content.clone
353
355
  all_lines << LLDB_INIT_COMMENT
354
- all_lines << "settings set target.source-map #{fake_src_root} #{user_proj_directory}"
356
+ all_lines << "settings set target.source-map #{fake_src_root} #{user_proj_directory}"
355
357
  all_lines << ""
356
358
  all_lines
357
359
  end
@@ -362,15 +364,76 @@ module CocoapodsXCRemoteCacheModifier
362
364
  File.write(LLDB_INIT_PATH, lldbinit_lines.join("\n"), mode: "w")
363
365
  end
364
366
 
365
- Pod::HooksManager.register('cocoapods-xcremotecache', :post_install) do |installer_context|
367
+ Pod::HooksManager.register('cocoapods-xcremotecache', :pre_install) do |installer_context|
368
+ # The main responsibility of that hook is forcing Pods regeneration when XCRemoteCache is enabled for the first time
369
+ # In the post_install hook, this plugin adds extra build settings and steps to all Pods targets, but only when XCRemoteCache
370
+ # is enabled and all artifacts are available (i.e. xcprepare returns 0).
371
+ # If Pods projects/targets are cached from previous `pod install` action that didn't enable XCRemoteCache (e.g. artifacts
372
+ # are not available in the remote cache), these projects/targets should be invalidated to include XCRemoteCache-related
373
+ # build steps and build settings.
366
374
  if @@configuration.nil?
367
375
  Pod::UI.puts "[XCRC] Warning! XCRemoteCache not configured. Call xcremotecache({...}) in Podfile to enable XCRemoteCache"
368
376
  next
369
377
  end
370
378
 
379
+ begin
380
+ # `user_pod_directory`` and `user_proj_directory` in the 'postinstall' should be equal
381
+ user_pod_directory = File.dirname(installer_context.podfile.defined_in_file)
382
+ set_configuration_default_values
383
+
384
+ unless @@configuration['enabled']
385
+ # No need to check if enabling remote cache for the first time
386
+ next
387
+ end
388
+
389
+ validate_configuration()
390
+ mode = @@configuration['mode']
391
+ remote_commit_file = @@configuration['remote_commit_file']
392
+ xcrc_location = @@configuration['xcrc_location']
393
+ check_build_configuration = @@configuration['check_build_configuration']
394
+ check_platform = @@configuration['check_platform']
395
+
396
+ xcrc_location_absolute = "#{user_pod_directory}/#{xcrc_location}"
397
+ remote_commit_file_absolute = "#{user_pod_directory}/#{remote_commit_file}"
398
+
399
+ # Download XCRC
400
+ download_xcrc_if_needed(xcrc_location_absolute)
401
+
402
+ # Save .rcinfo
403
+ root_rcinfo = generate_rcinfo()
404
+ save_rcinfo(root_rcinfo, user_pod_directory)
405
+
406
+ # Create directory for xccc & arc.rc location
407
+ Dir.mkdir(BIN_DIR) unless File.exist?(BIN_DIR)
408
+
409
+ # Remove previous xccc & arc.rc
410
+ was_previously_enabled = File.exist?(remote_commit_file_absolute)
411
+ File.delete(remote_commit_file_absolute) if File.exist?(remote_commit_file_absolute)
412
+
413
+ prepare_result = YAML.load`#{xcrc_location_absolute}/xcprepare --configuration #{check_build_configuration} --platform #{check_platform}`
414
+ if !prepare_result['result'] && mode == 'consumer'
415
+ # Remote cache is still disabled - no need to force Pods projects/targets regeneration
416
+ next
417
+ end
418
+
419
+ # Force rebuilding all Pods project, because XCRC build steps and settings need to be added to Pods project/targets
420
+ # It is relevant only when 'incremental_installation' is enabled, otherwise installed_cache_path does not exist on a disk
421
+ installed_cache_path = installer_context.sandbox.project_installation_cache_path
422
+ if !was_previously_enabled && File.exist?(installed_cache_path)
423
+ Pod::UI.puts "[XCRC] Forces Pods project regenerations because XCRC is enabled for the first time."
424
+ File.delete(installed_cache_path)
425
+ end
426
+ end
427
+ end
428
+
429
+ Pod::HooksManager.register('cocoapods-xcremotecache', :post_install) do |installer_context|
430
+ if @@configuration.nil?
431
+ next
432
+ end
433
+
371
434
  user_project = installer_context.umbrella_targets[0].user_project
372
435
 
373
- begin
436
+ begin
374
437
  user_proj_directory = File.dirname(user_project.path)
375
438
  set_configuration_default_values
376
439
 
@@ -394,20 +457,12 @@ module CocoapodsXCRemoteCacheModifier
394
457
 
395
458
  xccc_location_absolute = "#{user_proj_directory}/#{xccc_location}"
396
459
  xcrc_location_absolute = "#{user_proj_directory}/#{xcrc_location}"
397
- remote_commit_file_absolute = "#{user_proj_directory}/#{remote_commit_file}"
398
-
399
- # Download XCRC
400
- download_xcrc_if_needed(xcrc_location_absolute)
401
460
 
402
461
  # Save .rcinfo
403
462
  root_rcinfo = generate_rcinfo()
404
463
  save_rcinfo(root_rcinfo, user_proj_directory)
405
464
 
406
- # Create directory for xccc & arc.rc location
407
- Dir.mkdir(BIN_DIR) unless File.exist?(BIN_DIR)
408
-
409
- # Remove previous xccc & arc.rc
410
- File.delete(remote_commit_file_absolute) if File.exist?(remote_commit_file_absolute)
465
+ # Remove previous xccc
411
466
  File.delete(xccc_location_absolute) if File.exist?(xccc_location_absolute)
412
467
 
413
468
  # Prepare XCRC
@@ -441,12 +496,12 @@ module CocoapodsXCRemoteCacheModifier
441
496
  end
442
497
 
443
498
  # Manual Pods/.rcinfo generation
444
-
499
+
445
500
  # all paths in .rcinfo are relative to the root so paths used in Pods.xcodeproj need to be aligned
446
501
  pods_path = Pathname.new(pods_proj_directory)
447
502
  root_path = Pathname.new(user_proj_directory)
448
503
  root_path_to_pods = root_path.relative_path_from(pods_path)
449
-
504
+
450
505
  pods_rcinfo = root_rcinfo.merge({
451
506
  'remote_commit_file' => "#{root_path_to_pods}/#{remote_commit_file}",
452
507
  'xccc_file' => "#{root_path_to_pods}/#{xccc_location}"
@@ -458,6 +513,7 @@ module CocoapodsXCRemoteCacheModifier
458
513
 
459
514
  # Enabled/disable XCRemoteCache for the main (user) project
460
515
  begin
516
+ # TODO: Do not compile xcc again. `xcprepare` compiles it in pre-install anyway
461
517
  prepare_result = YAML.load`#{xcrc_location_absolute}/xcprepare --configuration #{check_build_configuration} --platform #{check_platform}`
462
518
  unless prepare_result['result'] || mode != 'consumer'
463
519
  # Uninstall the XCRemoteCache for the consumer mode
@@ -3,9 +3,9 @@
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
- #
6
+ #
7
7
  # http://www.apache.org/licenses/LICENSE-2.0
8
- #
8
+ #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module CocoapodsXcremotecache
16
- VERSION = "0.0.13"
16
+ VERSION = "0.0.15"
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-xcremotecache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Polaczyk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-06 00:00:00.000000000 Z
12
+ date: 2023-03-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: CocoaPods plugin that enables XCRemoteCache with the project.
15
15
  email: