xctool是facebook开源的一个命令行工具,用来替代苹果的xcodebuild工具。
功能如下:
- 像xcode一样跑测试用例
- 结构化输出编译测试结果
- 彩色且方便阅读的编译内容输出
示例截图:

如何安装xctool
最简单的办法是通过homebrew安装xctool
brew update
brew install xctool
************注意****************
$ brew tap oclint/formulae
$ brew install oclint (不走上面的命令直接install oclint的话, 下载的版本不是最新版, 文档将不能正常生成)
搞定
如何使用xctool
打包
path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
archive
build
path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
build
测试
path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
test
使用命令如下,上面的命令参照
切换到工程目录下,然后输入如下命令:
xctool -workspace taoappios.xcworkspace -scheme taoappios archive
生成archive文件
xctool -workspace taoappios.xcworkspace -scheme taoappios build
编译
usage: xctool [BASE OPTIONS] [ACTION [ACTION ARGUMENTS]] ...
Examples:
xctool [BASE OPTIONS] clean
xctool [BASE OPTIONS] build
xctool [BASE OPTIONS] build-tests [-only TARGET] [-skip-deps]
xctool [BASE OPTIONS] run-tests [-test-sdk SDK] [-only SPEC] [-freshSimulator] [-freshInstall]
xctool [BASE OPTIONS] test [-test-sdk SDK] [-only SPEC] [-skip-deps] [-freshSimulator] [-freshInstall]
xctool [BASE OPTIONS] archive
Base Options:
-help show help
-workspace PATH path to workspace
-project PATH path to project
-scheme NAME scheme to use for building or testing
-find-target TARGET Search for the workspace/project/scheme to build the target
-find-target-path PATH Path to search for -find-target.
-find-target-exclude-pathColon-separated list of paths to exclude for -find-target.
-sdk VERSION sdk to use for building (e.g. 6.0, 6.1)
-configuration NAME configuration to use (e.g. Debug, Release)
-jobs NUMBER number of concurrent build operations to run
-arch ARCH arch to build for (e.g. i386, armv7)
-toolchain PATH path to toolchain
-xcconfig PATH path to an xcconfig
-reporter TYPE[:FILE] add reporter
-showBuildSettings display a list of build settings and values
-version print version and exit
SETTING=VALUE Set the build 'setting' to 'value'
Options for 'build-tests' action:
-only TARGET build only a specific test TARGET
-skip-deps Only build the target, not its dependencies
Options for 'run-tests' action:
-test-sdk SDK SDK to test with
-only SPEC SPEC is TARGET[:Class/case[,Class2/case2]]
-freshSimulator Start fresh simulator for each application test target
-freshInstall Use clean install of TEST_HOST for every app test run
Options for 'test' action:
-test-sdk SDK SDK to test with
-only SPEC SPEC is TARGET[:Class/case[,Class2/case2]]
-skip-deps Only build the target, not its dependencies
-freshSimulator Start fresh simulator for each application test target
-freshInstall Use clean install of TEST_HOST for every app test run
*****************************************具体使用*************************************
- xctool [BASE OPTIONS] [ACTION [ACTION ARGUMENTS]] ...
- Examples:
- xctool [BASE OPTIONS] clean
- xctool [BASE OPTIONS] build [-dry-run] [-skipUnavailableActions]
- xctool [BASE OPTIONS] build-tests [-only TARGET] [-omit TARGET] [-skip-deps]
- xctool [BASE OPTIONS] run-tests [-test-sdk SDK] [-only SPEC] [-omit SPEC] [-freshSimulator] [-resetSimulator] [-newSimulatorInstance] [-noResetSimulatorOnFailure] [-freshInstall] [-parallelize] [-logicTestBucketSize N] [-appTestBucketSize N] [-bucketBy BUCKETBY] [-failOnEmptyTestBundles] [-listTestsOnly] [-targetedDeviceFamily FAMILY] [-testTimeout N] [-logicTest BUNDLE] [-appTest BUNDLE:HOST_APP]
- xctool [BASE OPTIONS] test [-test-sdk SDK] [-only SPEC] [-omit SPEC] [-skip-deps] [-freshSimulator] [-resetSimulator] [-newSimulatorInstance] [-noResetSimulatorOnFailure] [-freshInstall] [-parallelize] [-failOnEmptyTestBundles] [-logicTestBucketSize N] [-appTestBucketSize N] [-bucketBy BUCKETBY] [-listTestsOnly] [-testTimeout N]
- xctool [BASE OPTIONS] archive [-archivePath PATH]
- xctool [BASE OPTIONS] analyze [-only TARGET] [-skip-deps] [-failOnWarnings]
- xctool [BASE OPTIONS] install
- Base Options:
- -help show help
- -workspace PATH path to workspace
- -project PATH path to project
- -scheme NAME scheme to use for building or testing
- -resultBundlePath PATH path to bundle to write results from performing a build action
- -find-target TARGET Search for the workspace/project/scheme to build the target
- -find-target-path PATH Path to search for -find-target.
- -find-target-exclude-paths Colon-separated list of paths to exclude for -find-target.
- -sdk ALIAS alias or path to sdk to use for building (e.g. iphonesimulator, iphonesimulator8.4)
- -configuration NAME configuration to use (e.g. Debug, Release)
- -destination DESTINATION use the destination described by DESTINATION (a comma-separated set of key=value pairs describing the destination to use)
- -destination-timeout DESTINwait for TIMEOUT seconds while searching for the destination device
- -jobs NUMBER number of concurrent build operations to run
- -arch ARCH arch to build for (e.g. i386, armv7)
- -toolchain PATH path to toolchain
- -xcconfig PATH path to an xcconfig
- -reporter TYPE[:FILE] add reporter
- -showBuildSettings display a list of build settings and values
- -showTasks show all tasks being spawned by xctool
- -actionScripts run pre and post action scripts defined in the scheme
- -version print version and exit
- -derivedDataPath PATH override the default derived data path
- -launch-timeout TIMEOUT simulator launch timeout in seconds (default is 30 seconds)
- SETTING=VALUE Set the build 'setting' to 'value'
- -DEFAULT=VALUE Set the user default 'default' to 'value'
- Available Reporters:
- json-compilation-database
- json-stream
- junit
- phabricator
- plain
- pretty
- teamcity
- user-notifications
- Options for 'build' action:
- -dry-run print the commands that would be executed, but do not execute them
- -skipUnavailableActions skip build actions that cannot be performed instead of failing. This option is only honored if -scheme is passed
- Options for 'build-tests' action:
- -only TARGET build only a specific test TARGET
- -omit TARGET omit building a specific test TARGET
- -skip-deps Only build the target, not its dependencies
- Options for 'run-tests' action:
- -test-sdk SDK SDK to test with
- -only SPEC SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
- -omit SPEC SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
- -freshSimulator Start fresh simulator for each application test target
- -resetSimulator Reset simulator content and settings and restart it before running every app test run.
- -newSimulatorInstance Start new instance of simulator for each application test target.
- -noResetSimulatorOnFailure Do not reset simulator content and settings if running failed.
- -freshInstall Use clean install of TEST_HOST for every app test run
- -parallelize Parallelize execution of tests
- -logicTestBucketSize N Break logic test bundles in buckets of N test cases.
- -appTestBucketSize N Break app test bundles in buckets of N test cases.
- -bucketBy BUCKETBY Either 'case' (default) or 'class'.
- -failOnEmptyTestBundles Fail when an empty test bundle was run.
- -listTestsOnly Skip actual test running and list them only.
- -targetedDeviceFamily FAMILTarget specific type of simulator when running tests (1=iPhone, 2=iPad, 4=Apple Watch)
- -testTimeout N Force individual test cases to be killed after specified timeout.
- -logicTest BUNDLE Add a path to a logic test bundle to run
- -appTest BUNDLE:HOST_APP Add a path to an app test bundle with the path to its host app
- <pre name="code" class="objc">Options for 'test' action:
- -test-sdk SDK SDK to test with
- -only SPEC SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
- -omit SPEC SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.
- -skip-deps Only build the target, not its dependencies
- -freshSimulator Start fresh simulator for each application test target
- -resetSimulator Reset simulator content and settings and restart it before running every app test run.
- -newSimulatorInstance Create new simulator instance for each application test target
- -noResetSimulatorOnFailure Do not reset simulator content and settings if running failed.
- -freshInstall Use clean install of TEST_HOST for every app test run
- -parallelize Parallelize execution of tests
- -failOnEmptyTestBundles Fail when an empty test bundle was run.
- -logicTestBucketSize N Break logic test bundles in buckets of N test cases.
- -appTestBucketSize N Break app test bundles in buckets of N test cases.
- -bucketBy BUCKETBY Either 'case' (default) or 'class'.
- -listTestsOnly Skip actual test running and list them only.
- -testTimeout N Force individual test cases to be killed after specified timeout.
- <pre name="code" class="objc">Options for 'archive' action:
- -archivePath PATH PATH where created archive will be placed.
- <pre name="code" class="objc">Options for 'analyze' action:
- -only TARGET only analyze selected targets, can be used more than once.
- If this option is specified, its dependencies are assumed to be built.
- -skip-deps Skip initial build of the scheme
- -failOnWarnings Fail builds if analyzer warnings are found
- 使用场景,如进行脚本生成ipa包(使用终端执行脚本)
- <pre name="code" class="objc">#<------------------------------------------------------->
- # xcodebuild + xctool
-
- pwd
-
- echo "<----------开始删除旧文件---------->"
-
- # 删除旧文件
- rm -rf "archive/log.txt"
- rm -rf "archive/zsyDemo.xcarchive"
- rm -rf "archive/zsyDemo.ipa"
-
- echo "<----------成功删除旧文件---------->"
-
- echo "<----------开始清除旧项目---------->"
-
- # 重要,执行xcodebuild命令时,必须进入项目目录
- # 清空前一次build的项目缓存
- xctool clean -workspace zsyDemo.xcworkspace -scheme zsyDemo -configuration Release >> archive/log.txt
-
- echo "<----------成功清除旧项目---------->"
-
- echo "<----------开始归档archive包---------->"
-
- # 归档(其他参数不指定的话,默认用的是.xcworkspace或.xcodeproj文件里的配置)
- # 根据指定的项目、scheme、configuration与输出路径打包出archive文件
- xctool -workspace zsyDemo.xcworkspace -scheme zsyDemo archive -archivePath archive/zsyDemo.xcarchive >> archive/log.txt
-
- echo "<----------成功归档archive包---------->"
-
- echo "<----------开始导出ipa包---------->"
-
- # 导出IPA 使用指定的provisioning profile导出ipa
- xcodebuild -exportArchive -archivePath archive/zsyDemo.xcarchive -exportPath archive/zsyDemo.ipa -exportFormat ipa -exportProvisioningProfile "zsyDemoDevelopProfile" >> archive/log.txt
-
- echo "<----------成功导出ipa包---------->"
-
- # 输出总用时
- echo "<----------Finished. Total time: ${SECONDS}s---------->"
-
- #<------------------------------------------------------->