【问题标题】:Where does xcode-select store informationxcode-select 在哪里存储信息
【发布时间】:2015-02-17 08:53:09
【问题描述】:

我正在编写一个从 Xcode 路径运行 clang 的工具。这个工具通过运行 /usr/bin/xcode-select 获取 Xcode 的位置,但我想重新制作它,以便它直接从磁盘读取 Xcode 位置,而不是运行 xcode-select。我试图调试 xcode-select (这是 xcrun 的符号链接),但没有设法找到它如何存储/读取 Xcode 的位置(它是存储在环境还是文件中?)。如果您知道如何在不运行 xcode-select(和 xcrun)的情况下获取 Xcode 的位置,请帮助!提前致谢!

【问题讨论】:

    标签: xcode


    【解决方案1】:

    使用 NSWorkspace,您可以:

    [NSWorkspace sharedWorkspace]fullPathForApplication:@"Xcode"];
    

    当它安装在默认位置时返回/Applications/Xcode.app

    // …or, as I have seen in the documentation, there's also
    - (NSURL *)URLForApplicationWithBundleIdentifier:(NSString *)bundleIdentifier
    // which returns the URL for the application with the specified identifier.
    

    【讨论】:

    • 问题是,我不知道应用程序的名称(它可以是 Xcode2 或其他任何东西)。如果用户有多个版本的 Xcode,他可以 xcode-select -switch 到另一个位置。
    【解决方案2】:

    使用dtruss 命令打印所有打开的 xcode-select 系统调用。

    dtruss -f -t open xcode-select -print-path
    

    发现它尝试读取 /usr/share/xcode-select/xcode_dir_path 并从那里获取 Xcode 位置。如果不存在,则采用默认的 Xcode 位置,即 /Applications/Xcode.app/。

    【讨论】:

      【解决方案3】:

      从 Xcode 6 开始,该位置是/var/db/xcode_select_link 的符号链接。您可以使用命令readlink /var/db/xcode_select_link 将链接的目标输出到终端。如果没有链接(例如,您运行xcode-select --reset),则使用默认的xcode 安装。

      【讨论】:

      • 这没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
      • @chouaib 我非常不同意。问题的标题是“xcode-select 在哪里存储信息”。 OP 声明“我试图调试 xcode-select (这是 xcrun 的符号链接),但没有设法找到它如何存储/读取 Xcode 的位置(它是否将其存储在环境或文件中?)。”我回答了这个问题,尽管我已经编辑了我的答案以澄清我所指的文件是一个符号链接。 xcode-select 创建用于重定向的符号链接并在--reset 上删除。您可以使用readlink阅读链接。
      猜你喜欢
      • 2013-10-04
      • 2014-11-14
      • 2011-10-26
      • 2012-10-05
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      相关资源
      最近更新 更多