Xcode 方案预动作脚本未运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42482457/
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-15 09:48:55  来源:igfitidea点击:

Xcode scheme pre-action script not running

xcodebash

提问by foundry

Hit build and nothing gets printed in build log. What gives?

点击构建,构建日志中没有打印任何内容。是什么赋予了?

Xcode Version 8.2.1 (8C1002)

Xcode 版本 8.2.1 (8C1002)

enter image description here

在此处输入图片说明

回答by foundry

Pre-action takes place before the build, so output doesn't go to the build log, it goes to stdErr. You can copy the output to a file:

预操作发生在构建之前,因此输出不会进入构建日志,而是进入 stdErr。您可以将输出复制到文件:

exec > ${PROJECT_DIR}/prebuild.log 2>&1
echo "hello world"

To get the environment variables to work, you also need to set "Provide build settings from" to the appropriate target.

要使环境变量起作用,您还需要将“Provide build settings from”设置为适当的目标。

enter image description here

在此处输入图片说明

That should write hello worldto a file named "prebuild.log" in your project folder.

这应该写入hello world项目文件夹中名为“prebuild.log”的文件。

If you want these activities to end up in the build log, consider adding a run script to your target's build phase instead.

如果您希望这些活动最终出现在构建日志中,请考虑将运行脚本添加到目标的构建阶段。

回答by Alex Zavatone

To add to the answer, https://stackoverflow.com/a/42497746/1058199, it's important to not clutter up the project.pbxproj (where build scripts go) or your scheme file (where these scripts go) as much as possible.

要添加到答案,https://stackoverflow.com/a/42497746/1058199,重要的是不要尽可能地将 project.pbxproj(构建脚本所在的位置)或您的方案文件(这些脚本所在的位置)弄乱.

With this in mind, I create a Build-Scripts folder in the project root where I put the app build scripts and pre-action scripts. This folder is dragged into the root of the project as a folderso that any script I add to it is automatically added to project.

考虑到这一点,我在项目根目录中创建了一个 Build-Scripts 文件夹,我将应用程序构建脚本和预操作脚本放在其中。这个文件夹作为一个文件夹被拖到项目的根目录中,这样我添加到它的任何脚本都会自动添加到项目中。

Assuming that your pre-action script is called That_pre-action_script.sh, this is what I put in Pre-actions script based on the approved answer.

假设您的预操作脚本名为That_pre-action_script.sh,这就是我根据批准的答案放入预操作脚本中的内容。

say "Pre build scripts running."
exec > "${PROJECT_DIR}/prebuild.log" 2>&1
echo "Starting build scheme Pre-actions"
"${PROJECT_DIR}/Build-Phases/That_pre-action_script.sh"

As a test, make sure to echo some message from your script so you can see it in the prebuild.logfile.

作为测试,请确保从您的脚本中回显一些消息,以便您可以在prebuild.log文件中看到它。

Hope this helps.

希望这可以帮助。

And don't forget to chmod u+x your script so that it will run.

并且不要忘记 chmod u+x 您的脚本,以便它运行。

The important part is if you can't make sure if your build script is running or not. This is where the saycommand us useful so that you know it's actually being issued before a build.

重要的部分是您是否无法确定您的构建脚本是否正在运行。这是say命令我们有用的地方,以便您知道它实际上是在构建之前发出的。

It's a good idea to put quotes around the path to the script in case there are any space characters (or otherwise) in the path to your project.

最好在脚本路径周围加上引号,以防项目路径中有任何空格字符(或其他字符)。