mac xcworkspace xcodebuild


xcodebuild

  在介紹xcodebuild之前,需要先弄清楚一些在XCode環境下的一些概念【4】:

  • Workspace:簡單來說,Workspace就是一個容器,在該容器中可以存放多個你創建的Xcode Project, 以及其他的項目中需要使用到的文件。使用Workspace的好處有,1),擴展項目的可視域,即可以在多個項目之間跳轉,重構,一個項目可以使用另一個項目的輸出。Workspace會負責各個Project之間提供各種相互依賴的關系;2),多個項目之間共享Build目錄。
  • Project:指一個項目,該項目會負責管理生成一個或者多個軟件產品的全部文件和配置,一個Project可以包含多個Target。
  • Target:一個Target是指在一個Project中構建的一個產品,它包含了構建該產品的所有文件,以及如何構建該產品的配置。
  • Scheme:一個定義好構建過程的Target成為一個Scheme。可在Scheme中定義的Target的構建過程有:Build/Run/Test/Profile/Analyze/Archive
  • BuildSetting:配置產品的Build設置,比方說,使用哪個Architectures?使用哪個版本的SDK?。在Xcode Project中,有Project級別的Build Setting,也有Target級別的Build Setting。Build一個產品時一定是針對某個Target的,因此,XCode中總是優先選擇Target的Build Setting,如果Target沒有配置,則會使用Project的Build Setting。

  弄清楚上面的這些概念之后,xcodebuild就很好理解了,官網上對其作用的描述如下:

xcodebuild builds one or more targets contained in an Xcode 
project, or builds a scheme contained in an Xcode workspace or 
Xcode project.

  xcodebuild就是用了構建產品的命令行工具,其用法可以歸結為3個部分:

  • 可構建的對象
  • 構建行為
  • 一些其他的輔助命令

  可以構建的對象有,默認情況下會運行project下的第一個target:

  • workspace:必須和“-scheme”一起使用,構建該workspace下的一個scheme。
  • project:當根目錄下有多個Project的時候,必須使用“-project”指定project,然后會運行
  • target:構建某個Target
  • scheme:和“-workspace”一起使用,指定構建的scheme。
  • ……

  構建行為包括:

  • clean:清除build目錄下的
  • build: 構建
  • test: 測試某個scheme,必須和"-scheme"一起使用
  • archive:打包,必須和“-scheme”一起使用
  • ……

  輔助命令包括:

  • -sdk:指定構建使用的SDK
  • -list:列出當前項目下所有的Target和scheme。
  • -version:版本信息
  • …...

  關於xcodebuild更多詳細的命令行請參見:https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html

  下圖是使用XcodeBuild運行一個scheme的build的結果:

  

  了解了xcodebuild的用法之后,接下來分析一下xcodebuild的主要缺陷:

  • 從上圖直接可以得到的感覺,其腳本輸出的可讀性極差,
  • 只能要么完整的運行一個target或者scheme,要么全部不運行。不能指定運行Target中特定的測試。
  • 最令人發指的是,XCode 4中的xcodebuild居然不支持iOSUnitTest的Target【5】,當我嘗試運行一個iOS App的測試target時,得到如下的錯誤:

      

文章來源:

http://jishu.zol.com.cn/12244.html?qq-pf-to=pcqq.c2c

xcodebuild命令:

Usage: xcodebuild [-project <projectname>] [[-target <targetname>]...|-alltargets] [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...

       xcodebuild [-project <projectname>] -scheme <schemeName> [-destination <destinationspecifier>]... [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...

       xcodebuild -workspace <workspacename> -scheme <schemeName> [-destination <destinationspecifier>]... [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...

       xcodebuild -version [-sdk [<sdkfullpath>|<sdkname>] [<infoitem>] ]

       xcodebuild -list [[-project <projectname>]|[-workspace <workspacename>]]

       xcodebuild -showsdks

       xcodebuild -exportArchive -exportFormat <format> -archivePath <xcarchivepath> -exportPath <destinationpath> [-exportProvisioningProfile <profilename>] [-exportSigningIdentity <identityname>] [-exportInstallerIdentity <identityname>]

Options:

    -usage                                    print brief usage

    -help                                     print complete usage

    -verbose                                  provide additional status output

    -license                                  show the Xcode and SDK license agreements

    -checkFirstLaunchStatus                   Check if any First Launch tasks need to be performed

    -project NAME                             build the project NAME

    -target NAME                              build the target NAME

    -alltargets                               build all targets

    -workspace NAME                           build the workspace NAME

    -scheme NAME                              build the scheme NAME

    -configuration NAME                       use the build configuration NAME for building each target

    -xcconfig PATH                            apply the build settings defined in the file at PATH as overrides

    -arch ARCH                                build each target for the architecture ARCH; this will override architectures defined in the project

    -sdk SDK                                  use SDK as the name or path of the base SDK when building the project

    -toolchain NAME                           use the toolchain with identifier or name NAME

    -destination DESTINATIONSPECIFIER         use the destination described by DESTINATIONSPECIFIER (a comma-separated set of key=value pairs describing the destination to use)

    -destination-timeout TIMEOUT              wait for TIMEOUT seconds while searching for the destination device

    -parallelizeTargets                       build independent targets in parallel

    -jobs NUMBER                              specify the maximum number of concurrent build operations

    -dry-run                                  do everything except actually running the commands

    -showsdks                                 display a compact list of the installed SDKs

    -showBuildSettings                        display a list of build settings and values

    -list                                     lists the targets and configurations in a project, or the schemes in a workspace

    -find-executable NAME                     display the full path to executable NAME in the provided SDK and toolchain

    -find-library NAME                        display the full path to library NAME in the provided SDK and toolchain

    -version                                  display the version of Xcode; with -sdk will display info about one or all installed SDKs

    -resultBundlePath PATH                    specifies the directory where a result bundle describing what occurred will be placed

    -derivedDataPath PATH                     specifies the directory where build products and other derived data will go

    -archivePath PATH                         specifies the directory where any created archives will be placed, or the archive that should be exported

    -exportArchive                            specifies that an archive should be exported

    -exportFormat FORMAT                      specifies the format that the archive should be exported as (e.g. ipa, pkg, app)

    -exportPath PATH                          specifies the destination for the product exported from an archive

    -exportProvisioningProfile PROFILE NAME   specifies the provisioning profile that should be used when re-signing the exported archive; if possible, implies a signing identity

    -exportSigningIdentity IDENTITY NAME      specifies the codesigning identity that should be used to re-sign the exported archive

    -exportInstallerIdentity IDENTITY NAME    specifies the installer signing identity that should be used during export; this may be inferable from -exportSigningIdentity

    -exportWithOriginalSigningIdentity        specifies that the signing identity used to create the archive should be used to sign the exported product

    -skipUnavailableActions                   specifies that scheme actions that cannot be performed should be skipped instead of causing a failure

xcodebuild: error: If you specify a workspace then you must also specify a scheme.  Use -list to see the schemes in this workspace.

xcodebuild -workspace xx.xcworkspace -list:查看xcworkspace下所有的scheme


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM