Class: Xcodeproj::Project::Object::PBXNativeTarget

Inherits:
AbstractTarget show all
Defined in:
lib/xcodeproj/project/object/native_target.rb

Overview

Represents a target handled by Xcode.

Attributes (collapse)

Attributes inherited from AbstractTarget

#build_configuration_list, #comments, #name, #product_name

Attributes inherited from AbstractObject

#isa, #project, #uuid

Attributes (collapse)

Helpers (collapse)

AbstractObject Hooks (collapse)

Methods inherited from AbstractTarget

#add_build_configuration, #add_dependency, #add_system_framework, #add_system_library, #build_configurations, #build_settings, #common_resolved_build_setting, #copy_files_build_phases, #dependencies, #deployment_target, #frameworks_build_phases, #new_copy_files_build_phase, #new_shell_script_build_phase, #platform_name, #pretty_print, #resolved_build_setting, #sdk, #sdk_version, #shell_script_build_phases

Methods inherited from AbstractObject

#<=>, #==, #display_name, #inspect, isa, #pretty_print, #remove_from_project, #sort_recursively, #to_hash

Instance Attribute Details

- (String) product_install_path



357
# File 'lib/xcodeproj/project/object/native_target.rb', line 357

attribute :product_install_path, String

- (PBXFileReference) product_reference



353
# File 'lib/xcodeproj/project/object/native_target.rb', line 353

has_one :product_reference, PBXFileReference

- (String) product_type



349
# File 'lib/xcodeproj/project/object/native_target.rb', line 349

attribute :product_type, String

Instance Method Details

- (void) add_file_references(file_references, compiler_flags = {})

This method returns an undefined value.

Adds source files to the target.



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/xcodeproj/project/object/native_target.rb', line 392

def add_file_references(file_references, compiler_flags = {})
  file_references.each do |file|
    build_file = project.new(PBXBuildFile)
    build_file.file_ref = file

    extension = File.extname(file.path)
    header_extensions = Constants::HEADER_FILES_EXTENSIONS
    if (header_extensions.include?(extension))
      headers_build_phase.files << build_file
    else
      if compiler_flags && !compiler_flags.empty?
        build_file.settings = { 'COMPILER_FLAGS' => compiler_flags }
      end
      source_build_phase.files << build_file
    end
  end
end

- (void) add_resources(resource_file_references)

This method returns an undefined value.

Adds resource files to the resources build phase of the target.



417
418
419
420
421
422
423
# File 'lib/xcodeproj/project/object/native_target.rb', line 417

def add_resources(resource_file_references)
  resource_file_references.each do |file|
    build_file = project.new(PBXBuildFile)
    build_file.file_ref = file
    resources_build_phase.files << build_file
  end
end

- (ObjectList<AbstractBuildPhase>) build_phases

Note:

Apparently only PBXCopyFilesBuildPhase and PBXShellScriptBuildPhase can appear multiple times in a target.

Returns the build phases of the target.



366
# File 'lib/xcodeproj/project/object/native_target.rb', line 366

has_many :build_phases, AbstractBuildPhase

- (PBXBuildRule) build_rules



345
# File 'lib/xcodeproj/project/object/native_target.rb', line 345

has_many :build_rules, PBXBuildRule

- (PBXFrameworksBuildPhase) frameworks_build_phase

Note:

A target should have only one frameworks build phase.

Finds or creates the frameworks build phase of the target.



471
472
473
474
475
476
477
478
# File 'lib/xcodeproj/project/object/native_target.rb', line 471

def frameworks_build_phase
  phase = build_phases.find { |bp| bp.class == PBXFrameworksBuildPhase }
  unless phase
    phase= project.new(PBXFrameworksBuildPhase)
    build_phases << phase
  end
  phase
end

- (PBXHeadersBuildPhase) headers_build_phase

Note:

A target should have only one headers build phase.

Finds or creates the headers build phase of the target.



431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/xcodeproj/project/object/native_target.rb', line 431

def headers_build_phase
  unless @headers_build_phase
    headers_build_phase = build_phases.find { |bp| bp.class == PBXHeadersBuildPhase }
    unless headers_build_phase
      # Working around a bug in Xcode 4.2 betas, remove this once the
      # Xcode bug is fixed:
      # https://github.com/alloy/cocoapods/issues/13
      # phase = copy_header_phase || headers_build_phases.first
      headers_build_phase = project.new(PBXHeadersBuildPhase)
      build_phases << headers_build_phase
    end
    @headers_build_phase = headers_build_phase
  end
  @headers_build_phase
end

- (PBXResourcesBuildPhase) resources_build_phase

Note:

A target should have only one resources build phase.

Finds or creates the resources build phase of the target.



486
487
488
489
490
491
492
493
# File 'lib/xcodeproj/project/object/native_target.rb', line 486

def resources_build_phase
  phase = build_phases.find { |bp| bp.class == PBXResourcesBuildPhase }
  unless phase
    phase = project.new(PBXResourcesBuildPhase)
    build_phases << phase
  end
  phase
end

- (Object) sort(options = nil)

Sorts the to many attributes of the object according to the display name.

Build phases are not sorted as they order is relevant.



506
507
508
509
510
511
512
513
514
# File 'lib/xcodeproj/project/object/native_target.rb', line 506

def sort(options = nil)
  attributes_to_sort = to_many_attributes.reject { |attr| attr.name == :build_phases }
  attributes_to_sort.each do |attrb|
    list = attrb.get_value(self)
    list.sort! do |x, y|
      x.display_name <=> y.display_name
    end
  end
end

- (PBXSourcesBuildPhase) source_build_phase

Note:

A target should have only one source build phase.

Finds or creates the source build phase of the target.



453
454
455
456
457
458
459
460
461
462
463
# File 'lib/xcodeproj/project/object/native_target.rb', line 453

def source_build_phase
  unless @source_build_phase
    source_build_phase = build_phases.find { |bp| bp.class == PBXSourcesBuildPhase }
    unless source_build_phase
      source_build_phase = project.new(PBXSourcesBuildPhase)
      build_phases << source_build_phase
    end
    @source_build_phase = source_build_phase
  end
  @source_build_phase
end

- (Symbol) symbol_type



376
377
378
379
# File 'lib/xcodeproj/project/object/native_target.rb', line 376

def symbol_type
  pair = Constants::PRODUCT_TYPE_UTI.find { |key, value| value == product_type }
  pair.first
end