XCTool介绍

来源:互联网 发布:《大数据时代》好句 编辑:程序博客网 时间:2024/06/05 10:34

xctool是facebook开源的一个命令行工具,用来替代苹果的xcodebuild工具。

功能如下:

  • 像xcode一样跑测试用例
  • 结构化输出编译测试结果
  • 彩色且方便阅读的编译内容输出

示例截图:

xctool

如何安装xctool

最简单的办法是通过homebrew安装xctool

brew updatebrew 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

*****************************************具体使用*************************************

[objc] view plain copy
  1. xctool [BASE OPTIONS] [ACTION [ACTION ARGUMENTS]] ...  
[objc] view plain copy
  1. Examples:  
  2.     xctool [BASE OPTIONS] clean  
  3.     xctool [BASE OPTIONS] build [-dry-run] [-skipUnavailableActions]  
  4.     xctool [BASE OPTIONS] build-tests [-only TARGET] [-omit TARGET] [-skip-deps]  
  5.     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]  
  6.     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]  
  7.     xctool [BASE OPTIONS] archive [-archivePath PATH]  
  8.     xctool [BASE OPTIONS] analyze [-only TARGET] [-skip-deps] [-failOnWarnings]  
  9.     xctool [BASE OPTIONS] install  
[objc] view plain copy
  1. Base Options:  
  2.     -help                      show help  
  3.     -workspace PATH            path to workspace  
  4.     -project PATH              path to project  
  5.     -scheme NAME               scheme to use for building or testing  
  6.     -resultBundlePath PATH     path to bundle to write results from performing a build action  
  7.     -find-target TARGET        Search for the workspace/project/scheme to build the target  
  8.     -find-target-path PATH     Path to search for -find-target.  
  9.     -find-target-exclude-paths Colon-separated list of paths to exclude for -find-target.  
  10.     -sdk ALIAS                 alias or path to sdk to use for building (e.g. iphonesimulator, iphonesimulator8.4)  
  11.     -configuration NAME        configuration to use (e.g. Debug, Release)  
  12.     -destination DESTINATION   use the destination described by DESTINATION (a comma-separated set of key=value pairs describing the destination to use)  
  13.     -destination-timeout DESTINwait for TIMEOUT seconds while searching for the destination device  
  14.     -jobs NUMBER               number of concurrent build operations to run  
  15.     -arch ARCH                 arch to build for (e.g. i386, armv7)  
  16.     -toolchain PATH            path to toolchain  
  17.     -xcconfig PATH             path to an xcconfig  
  18.     -reporter TYPE[:FILE]      add reporter  
  19.     -showBuildSettings         display a list of build settings and values  
  20.     -showTasks                 show all tasks being spawned by xctool  
  21.     -actionScripts             run pre and post action scripts defined in the scheme  
  22.     -version                   print version and exit  
  23.     -derivedDataPath PATH      override the default derived data path  
  24.     -launch-timeout TIMEOUT    simulator launch timeout in seconds (default is 30 seconds)  
  25.     SETTING=VALUE              Set the build 'setting' to 'value'  
  26.     -DEFAULT=VALUE             Set the user default 'default' to 'value'  
[objc] view plain copy
  1. Available Reporters:  
  2.     json-compilation-database  
  3.     json-stream  
  4.     junit  
  5.     phabricator  
  6.     plain  
  7.     pretty  
  8.     teamcity  
  9.     user-notifications  
[objc] view plain copy
  1. Options for 'build' action:  
  2.     -dry-run                   print the commands that would be executed, but do not execute them  
  3.     -skipUnavailableActions    skip build actions that cannot be performed instead of failing. This option is only honored if -scheme is passed  
[objc] view plain copy
  1. Options for 'build-tests' action:  
  2.     -only TARGET               build only a specific test TARGET  
  3.     -omit TARGET               omit building a specific test TARGET  
  4.     -skip-deps                 Only build the target, not its dependencies  
[objc] view plain copy
  1. Options for 'run-tests' action:  
  2.     -test-sdk SDK              SDK to test with  
  3.     -only SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.  
  4.     -omit SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.  
  5.     -freshSimulator            Start fresh simulator for each application test target  
  6.     -resetSimulator            Reset simulator content and settings and restart it before running every app test run.  
  7.     -newSimulatorInstance      Start new instance of simulator for each application test target.  
  8.     -noResetSimulatorOnFailure Do not reset simulator content and settings if running failed.  
  9.     -freshInstall              Use clean install of TEST_HOST for every app test run  
  10.     -parallelize               Parallelize execution of tests  
  11.     -logicTestBucketSize N     Break logic test bundles in buckets of N test cases.  
  12.     -appTestBucketSize N       Break app test bundles in buckets of N test cases.  
  13.     -bucketBy BUCKETBY         Either 'case' (default) or 'class'.  
  14.     -failOnEmptyTestBundles    Fail when an empty test bundle was run.  
  15.     -listTestsOnly             Skip actual test running and list them only.  
  16.     -targetedDeviceFamily FAMILTarget specific type of simulator when running tests (1=iPhone, 2=iPad, 4=Apple Watch)  
  17.     -testTimeout N             Force individual test cases to be killed after specified timeout.  
  18.     -logicTest BUNDLE          Add a path to a logic test bundle to run  
  19.     -appTest BUNDLE:HOST_APP   Add a path to an app test bundle with the path to its host app  
[objc] view plain copy
  1. <pre name="code" class="objc">Options for 'test' action:  
  2.     -test-sdk SDK              SDK to test with  
  3.     -only SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.  
  4.     -omit SPEC                 SPEC is TARGET[:Class/case[,Class2/case2]]; use * when specifying class or case prefix.  
  5.     -skip-deps                 Only build the target, not its dependencies  
  6.     -freshSimulator            Start fresh simulator for each application test target  
  7.     -resetSimulator            Reset simulator content and settings and restart it before running every app test run.  
  8.     -newSimulatorInstance      Create new simulator instance for each application test target  
  9.     -noResetSimulatorOnFailure Do not reset simulator content and settings if running failed.  
  10.     -freshInstall              Use clean install of TEST_HOST for every app test run  
  11.     -parallelize               Parallelize execution of tests  
  12.     -failOnEmptyTestBundles    Fail when an empty test bundle was run.  
  13.     -logicTestBucketSize N     Break logic test bundles in buckets of N test cases.  
  14.     -appTestBucketSize N       Break app test bundles in buckets of N test cases.  
  15.     -bucketBy BUCKETBY         Either 'case' (default) or 'class'.  
  16.     -listTestsOnly             Skip actual test running and list them only.  
  17.     -testTimeout N             Force individual test cases to be killed after specified timeout.  

[objc] view plain copy
  1. <pre name="code" class="objc">Options for 'archive' action:  
  2.     -archivePath PATH          PATH where created archive will be placed.  
[objc] view plain copy
  1. <pre name="code" class="objc">Options for 'analyze' action:  
  2.     -only TARGET               only analyze selected targets, can be used more than once.  
  3.     If this option is specified, its dependencies are assumed to be built.  
  4.     -skip-deps                 Skip initial build of the scheme  
  5.     -failOnWarnings            Fail builds if analyzer warnings are found  
[objc] view plain copy
  1.   
[objc] view plain copy
  1.   
[objc] view plain copy
  1. 使用场景,如进行脚本生成ipa包(使用终端执行脚本)  
[objc] view plain copy
  1. <pre name="code" class="objc">#<------------------------------------------------------->  
  2. # xcodebuild + xctool  
  3.   
  4. pwd  
  5.   
  6. echo "<----------开始删除旧文件---------->"  
  7.   
  8. # 删除旧文件  
  9. rm -rf "archive/log.txt"  
  10. rm -rf "archive/zsyDemo.xcarchive"  
  11. rm -rf "archive/zsyDemo.ipa"  
  12.   
  13. echo "<----------成功删除旧文件---------->"  
  14.   
  15. echo "<----------开始清除旧项目---------->"  
  16.   
  17. # 重要,执行xcodebuild命令时,必须进入项目目录  
  18. # 清空前一次build的项目缓存   
  19. xctool clean -workspace zsyDemo.xcworkspace -scheme zsyDemo -configuration Release >> archive/log.txt  
  20.   
  21. echo "<----------成功清除旧项目---------->"  
  22.   
  23. echo "<----------开始归档archive包---------->"  
  24.   
  25. # 归档(其他参数不指定的话,默认用的是.xcworkspace或.xcodeproj文件里的配置)  
  26. # 根据指定的项目、scheme、configuration与输出路径打包出archive文件  
  27. xctool -workspace zsyDemo.xcworkspace -scheme zsyDemo archive -archivePath archive/zsyDemo.xcarchive >> archive/log.txt  
  28.   
  29. echo "<----------成功归档archive包---------->"  
  30.   
  31. echo "<----------开始导出ipa包---------->"  
  32.   
  33. # 导出IPA 使用指定的provisioning profile导出ipa  
  34. xcodebuild -exportArchive -archivePath archive/zsyDemo.xcarchive -exportPath archive/zsyDemo.ipa -exportFormat ipa -exportProvisioningProfile "zsyDemoDevelopProfile" >> archive/log.txt  
  35.   
  36. echo "<----------成功导出ipa包---------->"  
  37.   
  38. # 输出总用时  
  39. echo "<----------Finished. Total time: ${SECONDS}s---------->"  
  40.   
  41. #<------------------------------------------------------->  

原创粉丝点击