Xcode custom shell scripts are slowing down the compiling time
Asked Answered
E

8

33

Testing any changes to my Xcode project has become an exercise in patience whenever I build. After all the source files have compiled, I get the following message in the activity window at the top of Xcode:

"Running 3 of 3 Custom Shell Scripts"

I have not added any of my own custom shell scripts but I am using quite a few dependencies via Cocoapods and I am using 2 frameworks for the build environment, Crashlytics and Tapstream. Crashlytics requires you add a run script in the build phases, other than that I don't know where the other ones are coming from and they appear to be the bottleneck in my build time.

Can anyone enlighten me as to what is going on and how i possibly speed it up?

Emmaline answered 18/12, 2013 at 3:45 Comment(2)
Its Xcode ;). I think it's their one and only product that does not start with a lower case character.Woodard
I had the same problem and I posted a solution for my case here : #40532045.Bicipital
A
58

I can't enlighten you but I can tell you how I stopped mine from running. This also happened after installing Cocoapods. In my main project's Target, under Build Phases, I noticed two entries entitled Check Pods Manifest.lock and another called Copy Pods Resources.

Under both there was an unchecked option Run script only when installing. I checked both and at least for now my projects build and run fine without running the scripts.

This is kind of a crappy answer because I can't really give you any more information, and it might not even work for your case, so hopefully someone comes along and enlightens us.


POSSIBLE EXTERNAL BUNDLE ISSUES

So I just had a frustrating experience debugging an issue where a pod installed library's NSLocalized strings file weren't working. Turns out it was because I checked the option mentioned above. Pods-resources.sh, which had the lines to install the bundle, wasn't running in debug mode. It was only running when installing - of course! Something to watch out for.

More info in this question:

NSLocalizedStringFromTable not working in CocoaPod dependency

Aprilette answered 23/1, 2014 at 19:56 Comment(5)
I have been developing under this trudging pace for a year, I had forgotten what it was like to be able to press build and run and not have time to do my taxes, get a haircut, start a band and maybe possibly go to the toilet, and come back just to tell me its doing a script...I am in your debt, thank youEmmaline
I'm new to xcode - when you say Target are you referring to "Edit Scheme" for the project, then where? I can't find the Pod related stuff to uncheck.Gatias
@Gatias are you using cocoapods in your project?Emmaline
I found the project settings (click the project name in project window). Yes, the guy I'm working with setup the project and uses cocoapods and build time is awful.Gatias
It seems if you turn that to 'run only when installing' it's nice and fast but you might not have localized strings or xcassets if you're building from a clean, non derived data state. but if you're doing lots of iterating you can turn that back on and the derived data / cache should hold onto the assets you need.. just be sure if you do a clean the next time you have to turn that option back offAnchylose
M
19

To fix the slow "Copy pods resources" problem I figured out a solution to only copy the resources if they haven't been copied before.

For this purpose we have to patch the *-resources.sh files that are created by cocoapods such that the copy procedure only happens if a generated file in the target directory doesn't exist (it is created upon first copy). As long as this target directory exists and includes this autogenerated file, the copy resources phase is skipped. This saves me about 30 seconds in my project (of course depends on your project size). To accomplish this do the following:

Create a patch file called 'copy_pod_resources_once.patch' in your project root dir with the following contents:

5a6,13
> NONCE_FILE="${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/copyresources-done.nonce"
> if [ -f "$NONCE_FILE" ]; then
>    echo "already copied resources"
>    exit 0
> else
>    touch "$NONCE_FILE"
> fi
> 

In the Podfile for your project add the following post install hook:

post_install do |installer_representation|
    system('find "./Pods/Target Support Files" -name "*-resources.sh" | xargs -I{} patch -p0 {} -i ./copy_pod_resources_once.patch')

    <other post install stuff>
end
Maure answered 9/11, 2016 at 17:0 Comment(8)
@werner-altewischer you should submit a PR for this in the cocoapods project on Github!Schoening
@Werner Altewischer I created the patch file and copied the content you have asked to include and also modified the pod file. However the build time did not reduce. What I might be missing?Orthogenic
This will only decrease the time for the "Copy pods resources" phase, not for other parts of the build process. Do you see the statement "already copied resources" in your build log for subsequent builds (not the first one, because initially the resources do have to be copied)? If so, the patch is working.Maure
@WernerAltewischer thanks for your proposed patch! Very nice idea. I was just curious: since you're using this, Have you ever run into issues caused by this change? Cheers.Dumpy
I made that last comment in CocoaPods issue #2439 and this is exactly what I was imagining. Excellent job and thank you so much. Definitely consider offering to CP as a patch.Baculiform
@WernerAltewischer for me it doesn't work. It gives me the waring: "patch: **** `>' expected at line 9 of patch" Do you have any suggestion? ThanksDenten
@Denten I had to create a new patch file. I added the NONCE script stuff above to a copy of one of my Pods-TARGETNAME-resources.sh files, and then ran 'diff -u original.sh copy.sh > copy_resources.patch - and used this output as the patch file.Bossuet
@Bossuet The .xcassets file will not work, because the changes (add image) will not be listed.Highhanded
R
2

For me, it was Crashlytics. There were some outstanding changes, as Crashlytics does auto-updating of its files. I reset/removed them and rebuilt and got past it.

So the general answer may be to check any third party components and make sure they're working properly.

Rowenarowland answered 17/10, 2014 at 0:51 Comment(1)
Could you be more specific about what files you reset?Hautbois
R
0

As Ramsel has said in this answer, https://mcmap.net/q/440813/-xcode-custom-shell-scripts-are-slowing-down-the-compiling-time I also went to Build Phases and cleared out all the possible links to PODs, after trying most of the other solutions and the three build issues shown regarding Pods were cleared out.

But then one file which was not list under the XCode Project navigator was missing, but they were in the Downloaded Git Zip folder! Obviously, I copied it and put into the XCode project and try running it runs cleanly! :)

Righteousness answered 23/3, 2014 at 17:41 Comment(0)
E
0

I had a similar issue in my project (however not using Cocoapods). It ended up being an issue with an application external to Xcode (Spritebuilder) somehow holding onto a resource within my Xcode project when it crashed. I forced the non-xcode application to close and now the issue is gone

Entrenchment answered 16/7, 2014 at 5:35 Comment(0)
K
0

Check your project folder name have any space.Because space creates problem in directory path like "SRCROOT".I removed spaces and project run fine.

Kelda answered 21/6, 2016 at 7:1 Comment(0)
C
0

I've found that this happens to me frequently. Exact cause unknown, but appears to be switching between git branches that have differences in what pods are being used. In my case simply touching the Pods-xxx-Resources.sh shell script file causes it to speed back up.

Chiasmus answered 23/6, 2016 at 13:17 Comment(0)
E
-1

Probably not going to work for you, but cleaning the project fixed it for me (Product -> Clean)

Enter answered 9/3, 2014 at 9:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.