spotify / XCRemoteCache

Other
827 stars 50 forks source link

Fix error that moves the Prebuild phase script after the source phase #116

Closed samuelsainz closed 2 years ago

samuelsainz commented 2 years ago

Description

Once I configure XCRemoteCache using the cocoapods plugin, when I reinstall the pods the script moves the "Prebuild" phase after the "Compile sources" phase.

Screen Shot 2022-04-11 at 11 17 37

Solution

Moving the Prebuild build phase is needed only the first time we insert it in the target build phases. When the build phase exists then it is already in the right order.

polac24 commented 2 years ago

From what I see, the cocoapods plugin doesn't reorder build phases but it just shuffles them in the .pbxproj. Am I right?

If so, can we integrate also a check that ensures that Xcode build phases order is valid (as expected) and indeed we don't have to modify .pbxproj at all? I am just afraid that without that, we could lead to a wrong order if someone used a version prior to #74.

samuelsainz commented 2 years ago

Hi @polac24, thanks for reviewing this :)

I am not sure if I follow but the order in the .pbxproj actually defines the build phases order—i.e. If I move the order of the build phases for a target in the Xcode it is modified in the .pbxproj and viceversa.

To clarify a bit, what is happening is this:

The bug is because of this code being executed every time we run pod install—assuming the Prebuild phase is after the Sources phase:

compile_phase_index = target.build_phases.index(target.source_build_phase) 
target.build_phases.insert(compile_phase_index, target.build_phases.delete(prebuild_script)) 
  1. First it gets the Sources build phase index, which is 2 in my example
  2. Deletes the prebuild phase, which was at index 1, leaving the Sources build phase at index 1
  3. Inserts the prebuild phase at index 2
polac24 commented 2 years ago

Thanks, now it makes sense. I was able to reproduce that every second time, the order is indeed incorrect.