Xcode 似乎没有执行我的计划的后期操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16659590/
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
Xcode doesn't seem to execute my scheme's post-action
提问by Daij-Djan
I'm using Xcode (4.6.2) and my target is an external build tool. The auto generated scheme calls that just fine during build.
我正在使用 Xcode (4.6.2),我的目标是一个外部构建工具。自动生成的方案在构建期间调用就好了。
On RUNNING, I wanted the scheme to execute another shell script. It wasn't intuitive, but I managed it by setting /bin/bash
as executable and passing my script as parameter.
在运行时,我希望该方案执行另一个 shell 脚本。它不直观,但我通过设置/bin/bash
为可执行文件并将我的脚本作为参数传递来管理它。
The only step left is that I want to execute yet another script AFTER run. And here I thought it'd be easy and just tried to set it as a post-action.
剩下的唯一一步是我想在运行后执行另一个脚本。在这里,我认为这很容易,只是尝试将其设置为后期操作。
BUT no matter what, I can't get xcode to execute my post-action script.
No matter what it is. I tried echo hi > /tmp/testfile
even...
但无论如何,我无法让 xcode 执行我的后期操作脚本。不管它是什么。我echo hi > /tmp/testfile
什至试过...
I need that post-action to do a bit of cleanup.
我需要那个后期动作来做一些清理。
Again in short:
再次简而言之:
- I have a script
build_me
that is my external build tool - I have a script
run_me
that I set my scheme to run - I have a script
cleanup
that I want tohave as run post-action
- 我有一个脚本
build_me
是我的外部构建工具 - 我有一个脚本
run_me
,我将我的方案设置为运行 - 我有一个脚本
cleanup
,我想在运行后运行
Can't get Xcode to run my post-action script or any.
无法让 Xcode 运行我的动作后脚本或任何.
采纳答案by Dannie
This works on Xcode 5.0, tested, I figure it should work the same in 4.6.2.
这适用于 Xcode 5.0,经过测试,我认为它应该在 4.6.2 中工作。
Post-actions only works when you quit the program from within the program
后操作仅在您从程序内退出程序时才有效
It will not run when you click on Stop in Xcode, or terminate the program otherwise. For my case, it works when I press CMD-Q while the program is in focus.
当您在 Xcode 中单击停止时,它不会运行,否则将终止程序。就我而言,当我在程序处于焦点时按下 CMD-Q 时,它会起作用。
Using a bash script file for Post-actions
使用 bash 脚本文件进行后期操作
These settings work:
这些设置有效:
回答by Ondrej Rafaj
I suggest you enable logging to a file by adding exec > /tmp/xcode_build.log 2>&1
to the beginning of your run script phase.
我建议您通过添加exec > /tmp/xcode_build.log 2>&1
到运行脚本阶段的开头来启用记录到文件。
You can than see the log by running cat /tmp/xcode_build.log
in terminal
您可以通过cat /tmp/xcode_build.log
在终端中运行来查看日志
This will allow you to print out paths, etc and verify functionality of your scripts.
这将允许您打印路径等并验证脚本的功能。
To print location of the script, you can put following in your post-action:
要打印脚本的位置,您可以将以下内容放在您的后期操作中:
exec > /tmp/my_log_file.txt 2>&1
pwd
回答by Moose
It's a bit odd, but Archive executes pre and post scripts when called from command line.
这有点奇怪,但 Archive 在从命令行调用时执行 pre 和 post 脚本。
So I've made an archive.sh script in my project folder, I pass the name of project ( same as main target - but you can configure that as you like ) as a parameter:
所以我在我的项目文件夹中创建了一个 archive.sh 脚本,我将项目的名称(与主要目标相同 - 但您可以根据需要进行配置)作为参数:
xcodebuild clean -project .xcodeproj -configuration Release -target
xcodebuild archive -project .xcodeproj -scheme
Then I create an "External Build" target name "Archive", with ./archive.sh as script.
然后我创建一个“外部构建”目标名称“存档”,使用 ./archive.sh 作为脚本。
When I build this target, Project is cleaned, build and archived. and post script defined in the scheme is executed
当我构建这个目标时,项目被清理、构建和存档。并执行方案中定义的 post 脚本
Just a remark, since I'm building from a shell script, I've removed my post script in the archive scheme, and instead call it after my build commands in my archive.sh script.
This way gives me a better control on working directories, variables and all… It's much more convenient
请注意,因为我是从 shell 脚本构建的,所以我已经删除了存档方案中的 post 脚本,而是在我的 archive.sh 脚本中的构建命令之后调用它。
这种方式让我可以更好地控制工作目录、变量和所有......它更方便
回答by Maria
If anyone else comes across this, I was using a script file in my project directory and the file did not have the right permissions for the build process to run the script. I did the following in the pre/post action/Run Script area
如果其他人遇到这个问题,我在我的项目目录中使用了一个脚本文件,并且该文件没有构建过程运行脚本的正确权限。我在 pre/post action/Run Script 区域执行了以下操作
chmod 755 ${PROJECT_DIR}/BuildScripts/IncrementBuildNumber.sh
${PROJECT_DIR}/BuildScripts/IncrementBuildNumber.sh
回答by enedil
Depending on programming language you use you can do (it's pseudocode):
根据您使用的编程语言,您可以执行以下操作(它是伪代码):
system( <command> 2>&1 | tee run.log && exit $PIPESTATUS )