Xcode 构建后复制文件操作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1331517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:45:17  来源:igfitidea点击:

Xcode Post Build Copy File Actions

perlxcodexcodebuild

提问by ISDi

In Xcode, how can I call a 'shell script' which is a PERL script that copies the .appand .dsymfiles to a different directory?

在 Xcode 中,我如何调用“shell 脚本”,它是一个将.app.dsym文件复制到不同目录的 PERL 脚本?

I want to pass the name of the project and/or the project's root directory to the script. I want to have the script called every time I build in release and distribution modes but not in debug mode.

我想将项目的名称和/或项目的根目录传递给脚本。我希望每次在发布和分发模式下构建时都调用该脚本,而不是在调试模式下。

回答by Chris Conover

For anyone else who is wondering, you can also do a simple copy via

对于其他想知道的人,您也可以通过以下方式进行简单的复制

[Click on Scheme Name] -> Edit Scheme... -> [Select Scheme] -> Run "Target" -> Post-actions

[单击方案名称] -> 编辑方案... -> [选择方案] -> 运行“目标”-> 后操作

and add a cp command. In my case, for quick testing and ease of use, I wanted to copy my binary back to the project directory so that I could process some data files. I used the following:

并添加一个cp命令。就我而言,为了快速测试和易用性,我想将我的二进制文件复制回项目目录,以便我可以处理一些数据文件。我使用了以下内容:

cp ${TARGET_BUILD_DIR}/${TARGET_NAME} ${PROJECT_DIR}/"binaryFileName"

回答by Shaggy Frog

Right-click on your target and choose Add->New Build Phase->New Run Script Build Phase.

右键单击您的目标并选择 Add->New Build Phase->New Run Script Build Phase。

Inside the "Script" text area, add:

在“脚本”文本区域内,添加:

if [ ${CONFIGURATION} != "Debug" ]
then
    /usr/bin/perl "${PROJECT_DIR}/myperlscript.pl" "${PRODUCT_NAME}" "${PROJECT_DIR}"
fi

Change the location and name of myperlscript.plto be the location and name of your script.

将位置和名称更改为myperlscript.pl脚本的位置和名称。

Make sure to move the Run Scriptstep to be after Link Binary With Libraries, since you're copying the built .app.

确保将Run Script步骤移到之后Link Binary With Libraries,因为您正在复制构建的 .app。

(Might also want to add the "perl" tag to the question)

(可能还想在问题中添加“perl”标签)