深入浅出 Xcode 命令列(2) - xcrun
Xcode命令列 = Xcode Command Lines Tool
前言
回顾一下上一篇加餐,
libxcselect.dylib
->
_xcselect_invoke_xcrun
->
libxcrun.dylib
->
xcrun_main
我们最后发现所有Xcode Command Line 都会先被导向 xcrun_main,也就是 xcrun。
于是xcrun就成了第一个探讨对象
xcrun
xcrun 本名 : command-line tool runner,
如果把第一篇说的xcode-select形容成多组Command Line tools中的引路人,
xcrun就可以理解为某一组Command Line tools的敲门砖。
先来看xcrun的man, man xcrun
描述里说的,跟 xcode-select基本上大同小异,例如:
xcrun provides a means to locate or invoke developer tools from the command-line, without requiring users to modify Makefiles
or otherwise take inconvenient measures to support multiple Xcode tool chains
不外乎就是说可以再多组Command Line Tools里面找到定位到该执行的指令。
描述甚至在还提到了xcode-select
,就像我上面说的要走到真正的executable,
是 xcode-select(引路人)、xcrun(敲门砖) 两位相辅相成才走得到。
由xcode-selct -s 决定的xcode command Line路径,xcrun再依照这路径 定位/执行命令。
把第一篇的这张图扩充一下:
Usage
已 Command line tools 里的 clang
为例:
作为参考, xcode-select 的 path xcode-select -p /Applications/Xcode.app/Contents/Developer
-
xcrun clang
- 此指令等价于执行以下指令 ⬇️
- clang
- /usr/bin/clang == (which clang) 详情参考上一篇加餐
- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
- 此指令等价于执行以下指令 ⬇️
-
xcrun --find clang
- /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-
xcrun --find git
- /Applications/Xcode.app/Contents/Developer/usr/bin/git
Futher More
一般介绍xcrun的文章到这边大概就会止住了,大概的总结:xcrun 后面接指令就可以怎么样怎么样,然后接着介绍后面的指令。
但看到 xcrun --find clang
& xcrun --find git
的输出,
一个是 /Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
一个是 /usr/bin/git
给我一个感觉就是 xcrun 除了走xcode-select指引的大路,自己里面还有很多小路!
所以我想就这个问题在深挖 xcrun。
而的确一组command line Tools里还能在拆分成三类的指令
三大类指令
这三大类分别为 -
- Developer
- SDKs(Platforms)
- ToolChain
三大类文件夹路径在 Xcode
关于这三类之间的依赖,以及xcrun剩余的用法,请允许我拖更到下一篇文章😅
reference: