How to add a build phase in a project template?

爱⌒轻易说出口 提交于 2019-12-02 18:37:27

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>

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!