Xcode 脚本上的相对路径

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

Relative paths on Xcode scripts

iosxcode

提问by Gruntcakes

I'm experimenting running scripts with Xcode and have got a couple of questions:

我正在尝试使用 Xcode 运行脚本,但有几个问题:

1) Xcode says to drag n drop the script into the run script section but that creates an absolute path: /Users/Me/Desktop/Project/etc. which is obviously no use if somebody else or a CI machine checks out the code. How to specify a relative path?

1) Xcode 说要将脚本拖放到运行脚本部分,但这会创建一个绝对路径:/Users/Me/Desktop/Project/etc。如果其他人或 CI 机器检查代码,这显然没有用。如何指定相对路径?

2) There's a permission denied error during the build when the script gets executed.

2) 执行脚本时,在构建过程中出现权限被拒绝错误。

(I'm using scripts off here to experiment with https://gist.github.com/sekati/3172554)

(我在这里使用脚本来试验https://gist.github.com/sekati/3172554

回答by OhadM

"$SRCROOT" gives the project folder:

“$ SRCROOT”给出了项目文件夹:

i.e: Users/yourUserName/MyProject

即:用户/您的用户名/我的项目

but if you have a workspace folder with multiple projects inside: i.e: Users/yourUserName/MyWorkspace/MyProject

但如果您有一个包含多个项目的工作区文件夹:即:Users/yourUserName/MyWorkspace/MyProject

And you need just the workspace folder, use 2 dots:

您只需要工作区文件夹,使用 2 个点

"../SomeFodler"While someFolder will be created in the workspace folder.

" ../SomeFodler"而 someFolder 将在工作区文件夹中创建。

Simple as that.

就那么简单。

回答by herzbube

1) In an Xcode project of mine, I have the following script that generates the source code documentation. As you can see each line of the script uses a relative path. I don't even need to use ${SRCROOT}.

1) 在我的一个 Xcode 项目中,我有以下生成源代码文档的脚本。正如您所看到的,脚本的每一行都使用了一个相对路径。我什至不需要使用${SRCROOT}.

# change directory because Doxyfile is configured with a relative input path ".."
cd doxygen

# clean the directory
rm -rf html

# generate docs
/opt/local/bin/doxygen Doxyfile

# open the html documentation
open html/index.html

2) The reason for the "permission denied" error may be that you have not set the executable bit on the script. On the console, type this command to set the executable bit, then try again to run the script.

2) “permission denied”错误的原因可能是你没有在脚本上设置可执行位。在控制台上,键入此命令以设置可执行位,然后再次尝试运行脚本。

chmod +x /path/to/xcode-build-bump.sh

回答by Jano

1) Edit your script with the following:

1) 使用以下内容编辑您的脚本:

  • Root of the project: ${SRCROOT}
  • Root of the build: ${CONFIGURATION_BUILD_DIR}
  • 项目根: ${SRCROOT}
  • 构建的根: ${CONFIGURATION_BUILD_DIR}

2) Press ?+8, click Buildand read the error.

2) 按?+ 8,单击Build并阅读错误。

enter image description here

在此处输入图片说明