14

I recently checked out a fresh version of our iOS app from git and built from command line via xcodebuild. I then built a second time using the exact same command, while making no changes to files in the repo whatsoever (not even opening them).

I expected the second build to take no time at all, but it actually took longer than the first:

user$ time xcodebuild -sdk 'iphonesimulator' -scheme 'DemoApp' -configuration 'Debug' -target 'DemoApp' build > /dev/null

real    5m45.849s
user    0m15.270s
sys     0m5.640s

user$ time xcodebuild -sdk 'iphonesimulator' -scheme 'DemoApp' -configuration 'Debug' -target 'DemoApp' build > /dev/null

real    6m8.858s
user    0m12.904s
sys     0m4.198s

If I do builds in xcode with no changes, it builds and runs in a matter of seconds.

Here are things I've tried to get incremental builds on command line:

  • I tried adding -derivedDataPath ~/Library/Developer/Xcode/DerivedData, but got the same results.
  • I've added the -incremental flag to other Swift arguments.
  • I've turned off all shell scripts and ensured no files have changed between builds

Does xcodebuild not support incremental builds? Is there a way to figure out why this is happening?

I'm using the latest Xcode and the new Xcode 10 build system. Most of the code is in swift if that makes any difference.

Edit: changing back to the old build system builds incrementally via xcodebuild in under 30 seconds.


Update:

The way I'm testing this: I have a Jenkins job that will clone the repo and do a hard clean: running xcodebuild clean and deleting the build directory and and derived data directory by hand just in case. Then it does a build. Then it makes no changes and does a build again. The second build is the one I'm timing.

Jason
  • 13,563
  • 15
  • 74
  • 125
  • Is the project in a workspace? If it is, did you try to pass the workspace as an argument? In a test I just did, it drops to ~4 seconds for subsequent builds of a ~3 minute initial build. – Alladinian Apr 17 '19 at 15:45
  • Could you try removing `-target`? Target shouldn't be there since you are using scheme. – Sulthan Apr 19 '19 at 14:24
  • Is it possible some script (either in scheme or in project) is updating some files? e.g. are you using sourcery? Also make sure that your project does not have `Compilation Mode` set to `Whole Module`. – Sulthan Apr 19 '19 at 14:26
  • @Sulthan I'll give that a try – Jason Apr 21 '19 at 14:49
  • @Sulthan I tried removing -target, but that was no change. I also turned off swift optimization and changed complication mode to incremental but still no change. – Jason Apr 23 '19 at 01:21
  • And no scripts. I have a jenkins job set up and I run a finder command before and after a do-nothing build to ensure no files have changed at all. – Jason Apr 23 '19 at 01:31
  • 1
    if you are using Cocoapods. it will rebuild all the frameworks from scratch and cause the huge delay in building iOS project – Adelin Apr 24 '19 at 13:00
  • Will Cocoapods rebuild all the frameworks *even on incremental builds* ? I can't find any documentation online regarding this. – Moisés Olmedo Dec 11 '19 at 03:34

0 Answers0