class Xcake::Project

This class is used to describe the overall Xcode project structure; This forms part of the DSL and is usally stored in files named ‘Cakefile`.

The Project creates a hiearchy of targets and configurations necessary to generate a xcode project.

Attributes

class_prefix[RW]

@return [String] the prefix used for Objective-C Classes. This is

used by xcode when creating new files.
name[RW]

@return [String] the name of the project file. This is used as

the filename.
organization[RW]

@return [String] the name of your organization. This is used by xcode when

creating new files.
targets[RW]

@return [Array<Target>] the list of targets for the project.

Public Class Methods

new(name = 'Project') { |self| ... } click to toggle source

@param [String] name

the name of the project file. This is used as the filename.

@param [Proc] block

an optional block that configures the project through the DSL.

@example Creating a Project.

Project.new do |c|
  c.application_for :ios, 8.0
end
# File lib/xcake/dsl/project.rb, line 48
def initialize(name = 'Project')
  @name = name
  @targets = []

  yield(self) if block_given?
end

Public Instance Methods

accept(visitor) click to toggle source

@!group Visitable

# File lib/xcake/dsl/project.rb, line 79
def accept(visitor)
  visitor.visit(self)

  targets.each do |t|
    visitor.visit(t)
    visitor.leave(t)
  end

  visitor.leave(self)
end
application_for(platform, deployment_target, language = :objc) { |t| ... } click to toggle source

Defines a new application target.

@param [Symbol] platform

platform for the application, can be either `:ios`, `:osx`, `:tvos` or `:watchos`.

@param [Float] deployment_target

the minimum deployment version for the platform.

@param [Symbol] language

language for application, can be either `:objc` or `:swift`.

@param [Proc] block

an optional block that configures the target through the DSL.

@return [Target] the application target

the newly created application target
# File lib/xcake/dsl/project/sugar.rb, line 34
def application_for(platform, deployment_target, language = :objc)
  target do |t|
    t.type = :application
    t.platform = platform
    t.deployment_target = deployment_target
    t.language = language

    yield(t) if block_given?
  end
end
extension_for(host_target) { |target| ... } click to toggle source

Defines a extension target.

@param [Target] host target

host target for which the extension is for.

@param [Proc] block

an optional block that configures the target through the DSL.

@return [Target] the extension target

the newly created extension target
# File lib/xcake/dsl/project/sugar.rb, line 130
def extension_for(host_target)
  target = target do |t|
    t.type = :app_extension
    t.platform = host_target.platform
    t.deployment_target = host_target.deployment_target
    t.language = host_target.language
  end

  host_target.target_dependencies << target

  yield(target) if block_given?

  target
end
project() { |self| ... } click to toggle source

Passes the project instance to a block. This is used to easily modify the properties of the project in the DSL.

@param [Proc] block

an optional block that configures the project through the DSL.
# File lib/xcake/dsl/project/sugar.rb, line 12
def project
  yield(self) if block_given?
  self
end
target(&block) click to toggle source

Defines a new target.

@param [Proc] block

an optional block that configures the target through the DSL.

@return [Target] the target

the newly created target
# File lib/xcake/dsl/project.rb, line 65
def target(&block)
  target = Target.new(self, &block)
  targets << target
  target
end
to_s() click to toggle source

@!group Conversion

# File lib/xcake/dsl/project.rb, line 73
def to_s
  "Project<#{name}>"
end
ui_tests_for(host_target) { |t| ... } click to toggle source

Defines a new ui test target.

@param [Target] host target

host target for which the unit tests are for.

@param [Proc] block

an optional block that configures the target through the DSL.

@return [Target] the unit test target

the newly created unit test target
# File lib/xcake/dsl/project/sugar.rb, line 56
def ui_tests_for(host_target)
  target do |t|
    t.name = "#{host_target.name}UITests"

    t.type = :ui_test_bundle
    configure_test_target_for_host_target(t, host_target)

    t.all_configurations.each do |c|
      c.settings['TEST_TARGET_NAME'] = host_target.name
    end

    yield(t) if block_given?
  end
end
unit_tests_for(host_target) { |t| ... } click to toggle source

Defines a new unit test target.

@param [Target] host target

host target for which the unit tests are for.

@param [Proc] block

an optional block that configures the target through the DSL.

@return [Target] the unit test target

the newly created unit test target
# File lib/xcake/dsl/project/sugar.rb, line 82
def unit_tests_for(host_target)
  target do |t|
    t.name = "#{host_target.name}Tests"

    t.type = :unit_test_bundle
    configure_test_target_for_host_target(t, host_target)

    yield(t) if block_given?
  end
end
watch_app_for(host_target, deployment_target, language = :objc) { |watch_app_target, watch_extension_target| ... } click to toggle source

Defines targets for watch app.

@param [Target] watch app’s compantion app

iOS target for the watch app

@param [Proc] block

an optional block that configures the targets through the DSL.

@return Void

# File lib/xcake/dsl/project/sugar.rb, line 155
def watch_app_for(host_target, deployment_target, language = :objc)
  watch_app_target = target do |t|
    t.name = "#{host_target.name}-Watch"

    t.type = :watch2_app
    t.platform = :watchos
    t.deployment_target = deployment_target
    t.language = language
  end

  watch_extension_target = target do |t|
    t.name = "#{host_target.name}-Watch Extension"

    t.type = :watch2_extension
    t.platform = :watchos
    t.deployment_target = deployment_target
    t.language = language
  end

  host_target.target_dependencies << watch_app_target
  watch_app_target.target_dependencies << watch_extension_target

  yield(watch_app_target, watch_extension_target) if block_given?

  nil
end

Protected Instance Methods

default_debug_settings() click to toggle source
# File lib/xcake/dsl/project.rb, line 99
def default_debug_settings
  common_settings = Xcodeproj::Constants::PROJECT_DEFAULT_BUILD_SETTINGS
  default_settings.merge!(Xcodeproj::Project::ProjectHelper.deep_dup(common_settings[:debug]))
end
default_release_settings() click to toggle source
# File lib/xcake/dsl/project.rb, line 104
def default_release_settings
  common_settings = Xcodeproj::Constants::PROJECT_DEFAULT_BUILD_SETTINGS
  default_settings.merge!(Xcodeproj::Project::ProjectHelper.deep_dup(common_settings[:release]))
end
default_settings() click to toggle source

@!group Configurable

# File lib/xcake/dsl/project.rb, line 94
def default_settings
  common_settings = Xcodeproj::Constants::PROJECT_DEFAULT_BUILD_SETTINGS
  Xcodeproj::Project::ProjectHelper.deep_dup(common_settings[:all])
end

Private Instance Methods

configure_test_target_for_host_target(test_target, host_target) click to toggle source
# File lib/xcake/dsl/project/sugar.rb, line 95
def configure_test_target_for_host_target(test_target, host_target)
  test_target.target_dependencies << host_target
  test_target.platform = host_target.platform
  test_target.deployment_target = host_target.deployment_target
  test_target.language = host_target.language

  return unless host_target.type == :application

  test_target.all_configurations.each do |c|
    # Do nothing as they break UITests
    # For more details https://github.com/jcampbell05/xcake/issues/115
    next if test_target.type == :ui_test_bundle

    c.settings['BUNDLE_LOADER'] = '$(TEST_HOST)'
    c.settings['TEST_HOST'] = if host_target.platform == :osx
                                "$(BUILT_PRODUCTS_DIR)/#{host_target.name}.app/Contents/MacOS/#{host_target.name}"
                              else
                                "$(BUILT_PRODUCTS_DIR)/#{host_target.name}.app/#{host_target.name}"
                              end
  end
end