-
Notifications
You must be signed in to change notification settings - Fork 52
Description
Problem
While integrating XCRemoteCache into my project, I was getting vague error messages about nil objects:
NoMethodError - undefined method `uuid' for nil:NilClass
Nanaimo::String.new(object.uuid, object.ascii_plist_annotation)
Some deeper investigation revealed that these errors were only happening for targets related to running tests. Excluding these targets allowed me to enable XCRemoteCache for my project, but it was unclear what about these targets was causing issues.
Cause
Eventually I found the root cause was the following line for inserting the postbuild script at the very end of the build phases:
| target.build_phases.insert(compile_phase_index + 1, target.build_phases.delete(postbuild_script)) |
In most cases this logic is correct, however I discovered that target.source_build_phase will either return a PBXSourcesBuildPhase if it exists, or create one if it doesn't. In the case of my test targets, I did not have a PBXSourcesBuildPhase by default, so it would create one for me. Prior to moving the postbuild script, my target.build_phases looked like this:
[
<PBXFrameworksBuildPhase UUID=`3FD09B4D78E7D6E98FEE6B62`>,
<PBXShellScriptBuildPhase name=`[XCRC] Postbuild UnitTests` UUID=`52A7EAFA724B9FB94DE7DE96`>,
<PBXSourcesBuildPhase UUID=`8CF1A801DA0F6A4AF286BED0`>
]And then after this line, my target.build_phases looks like this:
[
<PBXFrameworksBuildPhase UUID=`3FD09B4D78E7D6E98FEE6B62`>,
<PBXSourcesBuildPhase UUID=`8CF1A801DA0F6A4AF286BED0`>,
nil,
<PBXShellScriptBuildPhase name=`[XCRC] Postbuild UnitTests` UUID=`52A7EAFA724B9FB94DE7DE96`>
]