xcodes

安装和切换多个 Xcode 版本的最佳命令行工具。

如果您正在寻找 xcodes 的应用程序版本,请尝试 Xcodes.app

CI Status

Header Image

🎉 公告

Xcodes 现在是 XcodesOrg 的一部分 - 在此处阅读更多信息

安装

Homebrew(首选)

brew install xcodesorg/made/xcodes

这些是经过开发者 ID 签名和公证的发布版本,无需预先安装 Xcode 即可使用。

其他方法

下载发布版本

发布 页面下载最新版本。这些是经过开发者 ID 签名的发布版本,无需预先安装 Xcode 即可使用。

使用 Mint
mint install XcodesOrg/xcodes
从源代码构建

从源代码构建需要 Xcode 12.0 或更高版本,因此不适合从头开始设置计算机。

git clone https://github.com/XcodesOrg/xcodes
cd xcodes
make install
# or, if /usr/local/ isn't in your PATH
PREFIX=/your/install/directory make install

安装时,您可能会看到以下输出

swift build
error: terminated(72): xcrun --sdk macosx --find xctest output:

如果发生这种情况,则表示您需要选择一个 Xcode 版本。您可以使用 xcode-select 或在 Xcode 的偏好设置的“位置”选项卡中选择“命令行工具”选项来执行此操作。

用法

安装 Xcode

使用类似以下命令之一安装特定版本的 Xcode

xcodes install 10.2.1
xcodes install 11 Beta 7
xcodes install 11.2 GM seed
xcodes install 9.0 --path ~/Archive/Xcode_9.xip
xcodes install --latest-prerelease
xcodes install --latest --directory "/Volumes/Bag Of Holding/"
xcodes install --latest --experimental-unxip

然后,系统将提示您输入 Apple ID 用户名和密码。您还可以使用 XCODES_USERNAMEXCODES_PASSWORD 环境变量提供这些信息。

成功通过身份验证后,xcodes 会将您的 Apple ID 密码保存到钥匙串中,并在以后记住您的 Apple ID 以供使用。如果您需要使用与记住的 Apple ID 不同的 Apple ID,请设置 XCODES_USERNAME 环境变量。

xcodes 将下载并安装您要求的版本,以便您随时可以使用。

(1/6) Downloading Xcode 11.2.0: 100%
(2/6) Unarchiving Xcode (This can take a while)
(3/6) Moving Xcode to /Applications/Xcode-11.2.0.app
(4/6) Moving Xcode archive Xcode-11.2.0.xip to the Trash
(5/6) Checking security assessment and code signing
(6/6) Finishing installation
xcodes requires superuser privileges in order to finish installation.
macOS User Password:

Xcode 11.2.0 has been installed to /Applications/Xcode-11.2.0.app

如果您已安装 aria2(可在 Homebrew 中找到,brew install aria2),则 xcodes 默认使用它进行下载。它使用多达 16 个连接来下载 Xcode,速度比 URLSession 快 3-5 倍。

Xcode 默认安装到 /Applications,但您可以使用 --directory 选项或 XCODES_DIRECTORY 环境变量为不同的目录提供路径。 所有 xcodes 命令都支持此选项,例如 selectuninstall,因此您可以管理不在 /Applications 中的 Xcode 版本。xcodes 支持将所有 Xcode 版本安装在一个目录中,无论该目录在哪里。

安装运行时

运行此命令行以显示可用的运行时

xcodes runtimes --include-betas

安装所需的运行时(例如 iOS 17.0-beta1)

xcodes runtimes install "iOS 17.0-beta1"

.xcode-version

我们建议创建一个 .xcode-version 文件,以明确声明和存储您的 CI 环境和团队要使用的 Xcode 版本。

13.4.1

阅读 .xcode-version提案

命令

实验性 Unxip - 加快解压缩速度

感谢 saagarjhi 的出色工作 - Xcodes 现在包含 unxip 功能,在某些系统上,解压缩速度最高可提高 70%。

xcodes install --latest --experimental-unxip

Shell 补全脚本

xcodes 可以生成补全脚本,允许您在键入 xcodes 命令时按键盘上的 Tab 键来自动补全命令和参数。 安装补全脚本的步骤取决于您使用的 shell。 有关不同 shell 的安装说明和底层实现的更多信息,请参见 swift-argument-parser repo

Zsh,使用 oh-my-zsh

运行以下命令

mkdir ~/.oh-my-zsh/completions
xcodes --generate-completion-script > ~/.oh-my-zsh/completions/_xcodes

开发

您需要 Xcode 13 才能构建和运行 xcodes。

使用 Xcode即使 xcodes 是一个命令行应用程序,所有正常功能都可以在 Xcode 中工作,例如构建、运行和运行测试。 您甚至可以在 Xcode 的控制台中键入文本,当它提示您输入 Apple ID 或 2FA 代码时。

从 Xcode 运行 xcodes 时,如果要运行特定命令或传递一些参数,您可以按住 Option 键来显示包含更多选项的表单。 这意味着您将使用 Option + Command + R 或在单击“运行”按钮时按住 Option。 在这里,您可以添加、删除和切换将在启动 xcodes 时传递给它的参数。

Xcode Edit Scheme Screen

使用 Swift 命令行工具安装 Xcode 后,您还可以使用 Swift 命令行工具

有一个 Makefile 可以帮助构建 xcodes 以进行分发。 为了通过 Homebrew 提供开发者 ID 签名和公证的发布版本,我们已经为您完成了此操作(请参阅 安装)。

发布新版本的 xcodes
# Bump the version number in Version.swift, commit the change, and tag it
vim Sources/XcodesKit/Version.swift
git add Sources/XcodesKit/Version.swift
git commit -m "Bump version to $VERSION"
git tag -asm "$VERSION" "$VERSION"

# Clean first
make clean

# Make a release build of xcodes, sign it, and zip it
make zip
# Create a Homebrew bottle
make bottle VERSION="$VERSION"

# Notarize the release build
# This can take a while
make notarize \
    TEAMID="ABC123"

# Push the new version bump commit and tag
git push --follow-tags

# Edit the draft release created by Release Drafter to point at the new tag
# Set the release title to the new version
# Duplicate xcodes-$VERSION.mojave.tar.gz and rename to xcodes-$VERSION.arm64_mojave.tar.gz
# Add the xcodes.zip, xcodes-$VERSION.mojave.tar.gz, xcodes-$VERSION.arm64_mojave.tar.gz files to the release
# Publish the release

# Update the Homebrew Bottle: https://github.com/XcodesOrg/homebrew-made/blob/master/Formula/xcodes.rb

值得注意的设计决策记录在 DECISIONS.md 中。 Apple 身份验证流程在 Apple.paw 中进行了描述,这将允许您使用 Paw 应用程序来玩涉及到的 API 端点。

xcode-installfastlane/spaceship 都值得赞扬,因为它们弄清了使这成为可能的困难部分。

维护者

Matt Kiazyk - Twitter