Class: Xcake::Target

Inherits:
Object
  • Object
show all
Includes:
Configurable, Visitable
Defined in:
lib/xcake/dsl/target.rb,
lib/xcake/dsl/target/sugar.rb,
lib/xcake/dsl/target/configurable.rb

Overview

This class is used to describe a target for a Xcode project; This forms part of the DSL and is usually stored in files named Cakefile.

File patterns collapse

Frameworks collapse

getters collapse

Instance Attribute Summary collapse

Attributes included from Configurable

#configurations

Frameworks collapse

Working with a target collapse

getters collapse

Conversion collapse

Instance Method Summary collapse

Methods included from Visitable

#accept

Methods included from Configurable

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

Constructor Details

#initialize(project) {|_self| ... } ⇒ Target

Returns a new instance of Target.

Examples:

Creating a Target.


Target.new(project) do |t|
  t.name "test"
end

Parameters:

  • project (Project)

    the project the target belongs to.

  • block (Proc)

    an optional block that configures the target through the DSL.

Yields:

  • (_self)

Yield Parameters:

  • _self (Xcake::Target)

    the object that the method was called on



197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/xcake/dsl/target.rb', line 197

def initialize(project)
  @pinned_build_phases = []
  @build_phases = []
  @build_rules = []
  @exclude_files = []
  @linked_targets = []
  @system_libraries = []
  @target_dependencies = []
  @schemes = []
  @project = project

  yield(self) if block_given?
end

Instance Attribute Details

#build_phasesArray<BuildPhase>

Returns the list of build phases for the project.

Returns:

  • (Array<BuildPhase>)

    the list of build phases for the project.



43
44
45
# File 'lib/xcake/dsl/target.rb', line 43

def build_phases
  @build_phases
end

#build_rulesArray<BuildRule>

Returns the list of build rules for the project.

Returns:

  • (Array<BuildRule>)

    the list of build rules for the project.



48
49
50
# File 'lib/xcake/dsl/target.rb', line 48

def build_rules
  @build_rules
end

#deployment_targetString

Returns the minimum deployment version for the target's platform.

Returns:

  • (String)

    the minimum deployment version for the target's platform.



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

def deployment_target
  @deployment_target
end

#exclude_filesArray or String

Returns files to exclude for the target. Supports regular expressions.

Examples:


spec.exclude_files = ["Classes/**/unused.{h,m}"]

Returns:

  • (Array or String)

    files to exclude for the target. Supports regular expressions



148
149
150
# File 'lib/xcake/dsl/target.rb', line 148

def exclude_files
  @exclude_files
end

#include_filesObject



229
230
231
232
# File 'lib/xcake/dsl/target.rb', line 229

def include_files
  # Import files in folder with same name as target by default
  @include_files ||= ["./#{@name}/**/*.*"]
end

#languageString

Returns the language for the target. Can be :objc, :swift.

Returns:

  • (String)

    the language for the target. Can be :objc, :swift.



33
34
35
# File 'lib/xcake/dsl/target.rb', line 33

def language
  @language
end

#linked_targetsArray<Target>

Returns targets to link to, use this when you want to use a library or framework target in another target.

Returns:

  • (Array<Target>)

    targets to link to, use this when you want to use a library or framework target in another target



179
180
181
# File 'lib/xcake/dsl/target.rb', line 179

def linked_targets
  @linked_targets
end

#nameString

Returns the name of the target.

Returns:

  • (String)

    the name of the target.



12
13
14
# File 'lib/xcake/dsl/target.rb', line 12

def name
  @name
end

#pinned_build_phasesArray<BuildPhase>

Returns the list of build phases to place first for the project.

Returns:

  • (Array<BuildPhase>)

    the list of build phases to place first for the project.



38
39
40
# File 'lib/xcake/dsl/target.rb', line 38

def pinned_build_phases
  @pinned_build_phases
end

#platformString

Returns the platform for the target. Can be :ios, :osx, :tvos, :watchos.

Returns:

  • (String)

    the platform for the target. Can be :ios, :osx, :tvos, :watchos.



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

def platform
  @platform
end

#schemesArray<Scheme>

Returns schemes for the target.

Returns:

  • (Array<Scheme>)

    schemes for the target



183
184
185
# File 'lib/xcake/dsl/target.rb', line 183

def schemes
  @schemes
end

#system_frameworksObject



234
235
236
237
# File 'lib/xcake/dsl/target.rb', line 234

def system_frameworks
  # Use default frameworks by default
  @system_frameworks ||= default_system_frameworks_for(platform)
end

#system_librariesArray<String>

Returns system libraries to include for the target.

Examples:


spec.system_libraries = ["z", "sqlite3"]

Returns:

  • (Array<String>)

    system libraries to include for the target



169
170
171
# File 'lib/xcake/dsl/target.rb', line 169

def system_libraries
  @system_libraries
end

#target_dependenciesArray<Target>

Returns targets to use as dependencies.

Returns:

  • (Array<Target>)

    targets to use as dependencies



173
174
175
# File 'lib/xcake/dsl/target.rb', line 173

def target_dependencies
  @target_dependencies
end

#typeString

Returns the type of the target. Can be :application, :dynamic_library, framework or :static_library.

Returns:

  • (String)

    the type of the target. Can be :application, :dynamic_library, framework or :static_library.



18
19
20
# File 'lib/xcake/dsl/target.rb', line 18

def type
  @type
end

Instance Method Details

#build_rule(name, file_type, output_files, output_files_compiler_flags, script, &block) ⇒ BuildRule

Creates a new build rule for the target

Parameters:

  • name (String)

    the name to use for the build rule

  • block (Proc)

    an optional block that configures the build rule through the DSL.

Returns:



86
87
88
89
90
91
92
93
94
95
# File 'lib/xcake/dsl/target/sugar.rb', line 86

def build_rule(name, file_type, output_files, output_files_compiler_flags, script, &block)
  rule = BuildRule.new(&block)
  rule.name = name
  rule.file_type = file_type
  rule.output_files = output_files
  rule.output_files_compiler_flags = output_files_compiler_flags
  rule.script = script
  build_rules << rule
  rule
end

#copy_files_build_phase(name, &block) ⇒ CopyFilesBuildPhase

Creates a new Copy Files build phase for the target

Parameters:

  • name (String)

    the name to use for the build phase

  • block (Proc)

    an optional block that configures the build phase through the DSL.

Returns:



16
17
18
19
20
21
# File 'lib/xcake/dsl/target/sugar.rb', line 16

def copy_files_build_phase(name, &block)
  phase = CopyFilesBuildPhase.new(&block)
  phase.name = name
  build_phases << phase
  phase
end

#default_debug_settingsObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/xcake/dsl/target/configurable.rb', line 13

def default_debug_settings
  Xcake::Constants
    .common_build_settings(:debug,
                           platform,
                           deployment_target.to_s,
                           type,
                           language)
    .merge!(default_settings)
    .merge('SWIFT_OPTIMIZATION_LEVEL' => '-Onone')
end

#default_release_settingsObject



24
25
26
27
28
29
30
31
32
# File 'lib/xcake/dsl/target/configurable.rb', line 24

def default_release_settings
  Xcake::Constants
    .common_build_settings(:release,
                           platform,
                           deployment_target.to_s,
                           type,
                           language)
    .merge!(default_settings)
end

#default_settingsObject



7
8
9
10
11
# File 'lib/xcake/dsl/target/configurable.rb', line 7

def default_settings
  {
    'INFOPLIST_FILE' => "#{name}/Supporting Files/Info.plist"
  }
end

#headers_build_phase(&block) ⇒ HeadersBuildPhase

Creates a new Copy Headers build phase for the target

Parameters:

  • block (Proc)

    an optional block that configures the build phase through the DSL.

Returns:



31
32
33
34
35
# File 'lib/xcake/dsl/target/sugar.rb', line 31

def headers_build_phase(&block)
  phase = HeadersBuildPhase.new(&block)
  build_phases << phase
  phase
end

#info_plist_pathsObject



239
240
241
# File 'lib/xcake/dsl/target.rb', line 239

def info_plist_paths
  all_configurations.map { |config| config.settings['INFOPLIST_FILE'] }.uniq
end

#parent_configurableObject



3
4
5
# File 'lib/xcake/dsl/target/configurable.rb', line 3

def parent_configurable
  @project
end

#pre_shell_script_build_phase(name, script, &block) ⇒ ShellScriptBuildPhase

Creates a new Shell Script build phase for the target before all of the other build phases

Parameters:

  • name (String)

    the name to use for the build phase

  • block (Proc)

    an optional block that configures the build phase through the DSL.

Returns:



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

def pre_shell_script_build_phase(name, script, &block)
  phase = ShellScriptBuildPhase.new(&block)
  phase.name = name
  phase.script = script
  pinned_build_phases << phase
  phase
end

#scheme(name, &block) ⇒ Scheme

Creates a new scheme for the target

Parameters:

  • name (String)

    the name of the new scheme

Returns:

  • (Scheme)

    the scheme the newly created scheme



221
222
223
224
225
# File 'lib/xcake/dsl/target.rb', line 221

def scheme(name, &block)
  scheme = Scheme.new(name, &block)
  schemes << scheme
  scheme
end

#shell_script_build_phase(name, script, &block) ⇒ ShellScriptBuildPhase

Creates a new Shell Script build phase for the target

Parameters:

  • name (String)

    the name to use for the build phase

  • block (Proc)

    an optional block that configures the build phase through the DSL.

Returns:



67
68
69
70
71
72
73
# File 'lib/xcake/dsl/target/sugar.rb', line 67

def shell_script_build_phase(name, script, &block)
  phase = ShellScriptBuildPhase.new(&block)
  phase.name = name
  phase.script = script
  build_phases << phase
  phase
end

#to_sObject



245
246
247
# File 'lib/xcake/dsl/target.rb', line 245

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