Module: Xcode::Target

Defined in:
lib/xcode/target.rb

Overview

Within a project a user may define a number of targets. These targets may be to generate the application, generate a universal framework, or execute tests.

Creating a target is usually done within a Project. There a specific target type can be specified.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#projectProject

Returns the reference to the project for which these targets reside.

Returns:

  • (Project)

    the reference to the project for which these targets reside.



96
97
98
# File 'lib/xcode/target.rb', line 96

def project
  @project
end

Class Method Details

.aggregateHash

This is a generic properties hash for an aggregate target.

Examples:

Aggregate Target properties


/* Begin PBXAggregateTarget section */
    98E1216814CDEF42009CE4EE /* Facebook Universal Framework */ = {
      isa = PBXAggregateTarget;
      buildConfigurationList = 98E1216914CDEF42009CE4EE /* Build configuration list for PBXAggregateTarget "Facebook Universal Framework" */;
      buildPhases = (
        98E1216E14CDEF4C009CE4EE /* ShellScript */,
      );
      dependencies = (
        98A30E0414CDF2D800DF81EF /* PBXTargetDependency */,
      );
      name = "Facebook Universal Framework";
      productName = Facebook;
    };
/* End PBXAggregateTarget section */

Returns:

  • (Hash)

    the properties defalut to a aggregate target



86
87
88
89
90
91
92
93
# File 'lib/xcode/target.rb', line 86

def self.aggregate
  { 'isa' => 'PBXAggregateTarget',
    'buildConfigurationList' => nil,
    'buildPhases' => [],
    'dependencies' => [],
    'name' => '',
    'productName' => '' }
end

.bundleHash

This is a generic properties hash for an a bundle target. It shares numerous similarities with the native target, it simply has a bundle product type.

Returns:

  • (Hash)

    the properties default to a bundle target



60
61
62
# File 'lib/xcode/target.rb', line 60

def self.bundle
  self.native.merge('productType' => 'com.apple.product-type.bundle')
end

.nativeHash

This is a generic properties hash for a native target

Examples:

Native Target Properties


E21D8AA914E0F817002E56AA /* newtarget */ = {
   isa = PBXNativeTarget;
   buildConfigurationList = E21D8ABD14E0F817002E56AA /* Build configuration list for PBXNativeTarget "newtarget" */;
   buildPhases = (
     E21D8AA614E0F817002E56AA /* Sources */,
     E21D8AA714E0F817002E56AA /* Frameworks */,
     E21D8AA814E0F817002E56AA /* Resources */,
   );
   buildRules = (
   );
   dependencies = (
   );
   name = newtarget;
   productName = newtarget;
   productReference = E21D8AAA14E0F817002E56AA /* newtarget.app */;
   productType = "com.apple.product-type.application";
 };

Returns:

  • (Hash)

    the properties default to a native target



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xcode/target.rb', line 42

def self.native
  { 'isa' => 'PBXNativeTarget',
    'buildConfigurationList' => nil,
    'buildPhases' => [],
    'buildRules' => [],
    'dependencies' => [],
    'name' => '',
    'productName' => '',
    'productReference' => '',
    'productType' => 'com.apple.product-type.application' }
end

Instance Method Details

#add_dependency(target) ⇒ Object

Parameters:

  • target (Target)

    the target that the current target is dependent on for compilation.



200
201
202
203
204
205
206
207
208
# File 'lib/xcode/target.rb', line 200

def add_dependency(target)
  
  target_dependency = TargetDependency.default
  target_dependency = @registry.add_object target_dependency 
  target_dependency.create_dependency_on target
  
  target_dependency
  
end

#build_phase(type, &block) ⇒ Object



133
134
135
136
137
# File 'lib/xcode/target.rb', line 133

def build_phase(type,&block)
  found_build_phase = build_phases.find {|phase| phase.isa == type }
  found_build_phase.instance_eval(&block) if block_given?
  found_build_phase
end

#copy_headers_build_phase(&block) ⇒ BuildPhase

Returns the copy headers specific build phase of the target.

Returns:

  • (BuildPhase)

    the copy headers specific build phase of the target.



129
130
131
# File 'lib/xcode/target.rb', line 129

def copy_headers_build_phase(&block)
  build_phase 'PBXHeadersBuildPhase', &block
end

#create_build_phase(phase_name) {|build_phase| ... } ⇒ BuildPhase

Create a build phase with the given name. Available build phases:

  • sources

  • resources

  • framework

  • run_script

  • copy_headers

Examples:

Creating the sources build phase


target.create_build_phase :sources

Creating the resources build phase (with optional block)


target.create_build_phase :resources do |phase|
  # each phase that is created.
end

Parameters:

  • phase_name (String)

    the name of the phase to add to the target

Yields:

Returns:



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/xcode/target.rb', line 160

def create_build_phase(phase_name)
  
  # Register a BuildPhase with the default properties specified by the name.
  build_phase = @registry.add_object(BuildPhase.send("#{phase_name}"))
  
  # Add the build phase to the list of build phases for this target.
  # @todo this is being done commonly in the application in multiple places
  #   and it bugs me. Perhaps some special module could be mixed into the
  #   Array of results that are returned.
  @properties['buildPhases'] << build_phase.identifier
  
  yield build_phase if block_given?
  
  build_phase.save!
end

#create_build_phases(*base_phase_names) ⇒ Array

Create multiple build phases at the same time.

Parameters:

  • base_phase_names (Array<String,Symbol>)

    are the names of the phases that you want to create for a target.

Returns:

  • (Array)

    the phases created.



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/xcode/target.rb', line 184

def create_build_phases *base_phase_names
  
  base_phase_names.compact.flatten.map do |phase_name|
    build_phase = create_build_phase phase_name do |build_phase|
      yield build_phase if block_given?
    end
    
    build_phase.save!
  end
  
end

#create_product_reference(name) ⇒ Resource

Create a product reference file and add it to the product. This is by default added to the ‘Products’ group.

Parameters:

  • name (String)

    of the product reference to add to the product

Returns:



217
218
219
220
221
# File 'lib/xcode/target.rb', line 217

def create_product_reference(name)
  product = project.products_group.create_product_reference(name)
  product_reference = product.identifier
  product
end

#framework_build_phase(&block) ⇒ BuildPhase

Returns the framework specific build phase of the target.

Returns:

  • (BuildPhase)

    the framework specific build phase of the target.



101
102
103
# File 'lib/xcode/target.rb', line 101

def framework_build_phase(&block)
  build_phase 'PBXFrameworksBuildPhase', &block
end

#resources_build_phase(&block) ⇒ BuildPhase

Returns the resources specific build phase of the target.

Returns:

  • (BuildPhase)

    the resources specific build phase of the target.



115
116
117
# File 'lib/xcode/target.rb', line 115

def resources_build_phase(&block)
  build_phase 'PBXResourcesBuildPhase', &block
end

#run_script_build_phase(&block) ⇒ BuildPhase

Returns the run script specific build phase of the target.

Returns:

  • (BuildPhase)

    the run script specific build phase of the target.



122
123
124
# File 'lib/xcode/target.rb', line 122

def run_script_build_phase(&block)
  build_phase 'PBXShellScriptBuildPhase', &block
end

#sources_build_phase(&block) ⇒ BuildPhase

Returns the sources specific build phase of the target.

Returns:

  • (BuildPhase)

    the sources specific build phase of the target.



108
109
110
# File 'lib/xcode/target.rb', line 108

def sources_build_phase(&block)
  build_phase 'PBXSourcesBuildPhase', &block
end