Xcode often rebuilds the entire project, even if a single line has been changed in a single file

Originator:root.darkstar
Number:rdar://28501724 Date Originated:
Status:Open Resolved:
Product:Xcode Product Version:8.0
Classification:Bug Reproducible:Sometimes
 
Summary:
I have a medium sized project that has very inconsistent build behaviour. Sometimes it does an incremental build that is very fast, sometimes it goes on to recompile everything. The build process can be uncomfortably long, which adds friction to the development process...

The project is written in Swift 2.3 and utilizes Cocoapods. The project file settings are as close to default as possible.

It happens both with device and simulator

Steps to Reproduce:
Not entirely sure what and when causes the issue

Expected Results:
Change a file. Hit run. Recompile only the changed file and any other immediately affected files.

Actual Results:
The entire project is rebuilt

Version:
Xcode 8.0 (8A218a), macOS 10.12 (16A323)

Notes:
The project folder is on an iCloud Drive folder. The DerivedData is in it's default location (the issue happens with deleted DerivedData too)

I have run "defaults write com.apple.dt.Xcode ExplainWhyBuildCommandsAreRun -bool YES"
The attached build log is with it. According to it 

Compile Swift source files
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
    (running because command line arguments are different from the last time)

Configuration:

Comments

I have run this command in terminal "defaults write com.apple.dt.Xcode ExplainWhyBuildCommandsAreRun -bool YES", restarted xCode, and here is the CompileC logs for two builds which should be incremental but second time build is began because of this "running because command line arguments are different from the last time". Please find in the attachment two CompileC logs. We have investigated the log, it seems the difference are this parts:

"-I/Users/hov/Library/Developer/Xcode/DerivedData/picsart-fbjlvrumznmhnmdurbbfrszmcpsm/Build/Intermediates/picsart.build/Debug-iphoneos/picsart.build/PicsArt-all-non-framework-target-headers.hmap -ivfsoverlay /Users/hov/Library/Developer/Xcode/DerivedData/picsart-fbjlvrumznmhnmdurbbfrszmcpsm/Build/Intermediates/picsart.build/all-product-headers.yaml -iquote" - this appears when building first time

"-I/Users/hov/Library/Developer/Xcode/DerivedData/picsart-fbjlvrumznmhnmdurbbfrszmcpsm/Build/Intermediates/picsart.build/Debug-iphoneos/picsart.build/PicsArt-all-target-headers.hmap" - this appears when building second time

'logs_for_two_commands.txt' was successfully uploaded.

I have run this command in terminal "defaults write com.apple.dt.Xcode ExplainWhyBuildCommandsAreRun -bool YES", restarted xCode, and here is the CompileC logs for two builds which should be incremental but second time build is began because of this "running because command line arguments are different from the last time". Please find in the attachment two CompileC logs. We have investigated the log, it seems the difference are this parts:

"-I/Users/hov/Library/Developer/Xcode/DerivedData/picsart-fbjlvrumznmhnmdurbbfrszmcpsm/Build/Intermediates/picsart.build/Debug-iphoneos/picsart.build/PicsArt-all-non-framework-target-headers.hmap -ivfsoverlay /Users/hov/Library/Developer/Xcode/DerivedData/picsart-fbjlvrumznmhnmdurbbfrszmcpsm/Build/Intermediates/picsart.build/all-product-headers.yaml -iquote" - this appears when building first time

"-I/Users/hov/Library/Developer/Xcode/DerivedData/picsart-fbjlvrumznmhnmdurbbfrszmcpsm/Build/Intermediates/picsart.build/Debug-iphoneos/picsart.build/PicsArt-all-target-headers.hmap" - this appears when building second time

'logs_for_two_commands.txt' was successfully uploaded.

Our project does not contain any swift code, but we encounter the same issue. We also using CocoaPods.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!