xcodebuild not doing incremental builds
Asked Answered
I

0

16

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.

Inherit answered 27/3, 2019 at 12:6 Comment(8)
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.Wellbeing
Could you try removing -target? Target shouldn't be there since you are using scheme.Unsocial
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.Unsocial
@Unsocial I'll give that a tryInherit
@Unsocial 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.Inherit
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.Inherit
if you are using Cocoapods. it will rebuild all the frameworks from scratch and cause the huge delay in building iOS projectPurree
Will Cocoapods rebuild all the frameworks even on incremental builds ? I can't find any documentation online regarding this.Sidky

© 2022 - 2024 — McMap. All rights reserved.