Class: Xcake::Project

Inherits:
Object
  • Object
show all
Includes:
Hooks, Hooks::InstanceHooks, Configurable, Visitable
Defined in:
lib/xcake/dsl/project.rb,
lib/xcake/dsl/project/hooks.rb,
lib/xcake/dsl/project/sugar.rb

Overview

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.

Configuring a project collapse

Attributes included from Configurable

#configurations

Creating a project collapse

Working with a project collapse

Conversion collapse

Visitable collapse

Instance Method Summary collapse

Methods included from Configurable

#all_configurations, #all_configurations=, #configuration, #configurations_of_type, #copy_parent_configurations, #debug_configuration, #default_settings_for_type, #parent_configurable, #release_configuration

Constructor Details

#initialize(name = 'Project') {|_self| ... } ⇒ Project

Returns a new instance of Project.

Examples:

Creating a Project.


Project.new do |c|
  c.application_for :ios, 8.0
end

Parameters:

  • name (String) (defaults to: 'Project')

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

  • block (Proc)

    an optional block that configures the project through the DSL.

Yields:

  • (_self)

Yield Parameters:



48
49
50
51
52
53
# File 'lib/xcake/dsl/project.rb', line 48

def initialize(name = 'Project')
  @name = name
  @targets = []

  yield(self) if block_given?
end

Instance Attribute Details

#class_prefixString

Returns the prefix used for Objective-C Classes. This is used by xcode when creating new files.

Returns:

  • (String)

    the prefix used for Objective-C Classes. This is used by xcode when creating new files.



23
24
25
# File 'lib/xcake/dsl/project.rb', line 23

def class_prefix
  @class_prefix
end

#nameString

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

Returns:

  • (String)

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



19
20
21
# File 'lib/xcake/dsl/project.rb', line 19

def name
  @name
end

#organizationString

Returns the name of your organization. This is used by xcode when creating new files.

Returns:

  • (String)

    the name of your organization. This is used by xcode when creating new files.



28
29
30
# File 'lib/xcake/dsl/project.rb', line 28

def organization
  @organization
end

#targetsArray<Target>

Returns the list of targets for the project.

Returns:

  • (Array<Target>)

    the list of targets for the project.



32
33
34
# File 'lib/xcake/dsl/project.rb', line 32

def targets
  @targets
end

Instance Method Details

#accept(visitor) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# 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) ⇒ Target

Defines a new application target.

Parameters:

  • platform (Symbol)

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

  • deployment_target (Float)

    the minimum deployment version for the platform.

  • language (Symbol) (defaults to: :objc)

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

  • block (Proc)

    an optional block that configures the target through the DSL.

Returns:

  • (Target)

    the application target the newly created application target



34
35
36
37
38
39
40
41
42
43
# 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

#configure_test_target_for_host_target(test_target, host_target) ⇒ Object (private)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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

#extension_for(host_target) {|target| ... } ⇒ Target

Defines a extension target.

Parameters:

  • host (Target)

    target host target for which the extension is for.

  • block (Proc)

    an optional block that configures the target through the DSL.

Yields:

Returns:

  • (Target)

    the extension target the newly created extension target



130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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| ... } ⇒ Object

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

Parameters:

  • block (Proc)

    an optional block that configures the project through the DSL.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
# File 'lib/xcake/dsl/project/sugar.rb', line 12

def project
  yield(self) if block_given?
  self
end

#target(&block) ⇒ Target

Defines a new target.

Parameters:

  • block (Proc)

    an optional block that configures the target through the DSL.

Returns:

  • (Target)

    the target the newly created target



65
66
67
68
69
# File 'lib/xcake/dsl/project.rb', line 65

def target(&block)
  target = Target.new(self, &block)
  targets << target
  target
end

#to_sObject



73
74
75
# File 'lib/xcake/dsl/project.rb', line 73

def to_s
  "Project<#{name}>"
end

#ui_tests_for(host_target) ⇒ Target

Defines a new ui test target.

Parameters:

  • host (Target)

    target host target for which the unit tests are for.

  • block (Proc)

    an optional block that configures the target through the DSL.

Returns:

  • (Target)

    the unit test target the newly created unit test target



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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) ⇒ Target

Defines a new unit test target.

Parameters:

  • host (Target)

    target host target for which the unit tests are for.

  • block (Proc)

    an optional block that configures the target through the DSL.

Returns:

  • (Target)

    the unit test target the newly created unit test target



82
83
84
85
86
87
88
89
90
91
# 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| ... } ⇒ Object

Defines targets for watch app.

Parameters:

  • watch (Target)

    app's compantion app iOS target for the watch app

  • block (Proc)

    an optional block that configures the targets through the DSL.

Yields:

  • (watch_app_target, watch_extension_target)

Returns:

  • Void



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# 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