How to add a build phase in a project template?
Asked Answered
J

2

7

I'm trying to add a Run Script Build Phase to a target in a custom Project Template for Xcode 4.

Does anyone have any examples, tutorials, or tips on how to do this?

I'm assuming that this will be done in TemplateInfo.plist - but my searches are comming up fruitless.

Juliajulian answered 5/4, 2011 at 11:18 Comment(0)
J
14

After quite a lot of trial-and-error I've worked it out. This is the extra key needed in the TemplateInfo.plist. This adds a script that will run after the other default build phases.

<key>Targets</key>
<array>
    <dict>
        <key>BuildPhases</key>
        <array>
            <dict>
                <key>Class</key>
                <string>ShellScript</string>
                <key>ShellPath</key>
                <string>/bin/sh</string>
                <key>ShellScript</key>
                <string># Just a comment</string>
            </dict>
        </array>
    </dict>
</array>
Juliajulian answered 5/4, 2011 at 14:7 Comment(5)
and what if I wanted to have it run before the Compile Sources phase?Hemihydrate
Any tips on running this script before the compile phase?Hamnet
To make it run before, you should open the ancestors til you find the other build phases. Then you just put it before the Source build phase.Gemmulation
@Juliajulian Do you know how to define the input and output files?Gemmulation
FYI: you can actually rename the Script's title within XCode by specifying the key "Name" (<key>Name</key><string>Some Title</string>)Nevski
S
1

To answer to @Paulo Faria question, I found a way to add input and output files to a Run script phase (My template uses R.swift, which requires input and output files):

<key>Targets</key>
<array>
    <dict>
        <key>BuildPhases</key>
        <array>
            <dict>
                <key>Class</key>
                <string>ShellScript</string>
                <key>ShellPath</key>
                <string>/bin/sh</string>
                <key>Name</key>
                <string>R.swift</string>
                <key>ShellScript</key>
                <string>"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"</string>
                <key>InputFiles</key>
                <array>
                    <string>$TEMP_DIR/rswift-lastrun</string>
                </array>
                <key>OutputFiles</key>
                <array>
                    <string>$SRCROOT/R.generated.swift</string>
                </array>
            </dict>
        </array>
    </dict>
</array>
Stringboard answered 23/5, 2019 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.