Class: Xcodeproj::Project::Object::PBXNativeTarget
- Inherits:
-
AbstractTarget
- Object
- AbstractObject
- AbstractTarget
- Xcodeproj::Project::Object::PBXNativeTarget
- Defined in:
- lib/xcodeproj/project/object/native_target.rb
Overview
Represents a target handled by Xcode.
Attributes collapse
-
#product_install_path ⇒ String
The install path of the product.
-
#product_reference ⇒ PBXFileReference
The reference to the product file.
-
#product_type ⇒ String
The build product type identifier.
Attributes inherited from AbstractTarget
#build_configuration_list, #comments, #name, #product_name
Attributes inherited from AbstractObject
Attributes collapse
-
#build_phases ⇒ ObjectList<AbstractBuildPhase>
The build phases of the target.
-
#build_rules ⇒ PBXBuildRule
The build rules of this target.
-
#file_system_synchronized_groups ⇒ ObjectList<PBXFileSystemSynchronizedRootGroup>
The file system synchronized groups containing files to include to build this target.
-
#package_product_dependencies ⇒ ObjectList<XCSwiftPackageProductDependency>
The Swift package products necessary to build this target.
Helpers collapse
-
#add_file_references(file_references, compiler_flags = {}) ⇒ Array<PBXBuildFile>
Adds source files to the target.
-
#add_on_demand_resources(on_demand_resource_tag_files) ⇒ void
Adds on demand resources to the resources build phase of the target.
-
#add_resources(resource_file_references) ⇒ void
Adds resource files to the resources build phase of the target.
-
#extension_target_type? ⇒ Boolean
Whether the target is an extension.
-
#frameworks_build_phase ⇒ PBXFrameworksBuildPhase
Finds or creates the frameworks build phase of the target.
-
#headers_build_phase ⇒ PBXHeadersBuildPhase
Finds or creates the headers build phase of the target.
-
#launchable_target_type? ⇒ Boolean
Whether the target is launchable.
-
#remove_on_demand_resources(on_demand_resource_tag_files) ⇒ void
Remove on demand resources from the resources build phase of the target.
-
#resources_build_phase ⇒ PBXResourcesBuildPhase
Finds or creates the resources build phase of the target.
-
#source_build_phase ⇒ PBXSourcesBuildPhase
Finds or creates the source build phase of the target.
-
#symbol_type ⇒ Symbol
The type of the target expressed as a symbol.
-
#test_target_type? ⇒ Boolean
Whether the target is a test target.
AbstractObject Hooks collapse
-
#excluded_keys_for_serialization_when_empty ⇒ Array<String>
Array of keys to exclude from serialization when the value is empty.
-
#sort(_options = nil) ⇒ Object
Sorts the to many attributes of the object according to the display name.
- #to_ascii_plist ⇒ Object
- #to_hash_as(method = :to_hash) ⇒ Object
Methods inherited from AbstractTarget
#add_build_configuration, #add_dependency, #add_system_framework, #add_system_library, #add_system_library_tbd, #build_configurations, #build_settings, #common_resolved_build_setting, #copy_files_build_phases, #dependencies, #dependency_for_target, #deployment_target, #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
#<=>, #==, #ascii_plist_annotation, #display_name, #inspect, isa, #nested_object_for_hash, #pretty_print, #remove_from_project, #sort_recursively, #to_hash
Instance Attribute Details
#product_install_path ⇒ String
Returns the install path of the product.
453 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 453 attribute :product_install_path, String |
#product_reference ⇒ PBXFileReference
Returns the reference to the product file.
444 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 444 has_one :product_reference, PBXFileReference |
#product_type ⇒ String
Returns the build product type identifier.
440 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 440 attribute :product_type, String |
Instance Method Details
#add_file_references(file_references, compiler_flags = {}) ⇒ Array<PBXBuildFile>
Adds source files to the target.
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 526 def add_file_references(file_references, compiler_flags = {}) file_references.map do |file| extension = File.extname(file.path).downcase header_extensions = Constants::HEADER_FILES_EXTENSIONS is_header_phase = header_extensions.include?(extension) phase = is_header_phase ? headers_build_phase : source_build_phase unless build_file = phase.build_file(file) build_file = project.new(PBXBuildFile) build_file.file_ref = file phase.files << build_file end if compiler_flags && !compiler_flags.empty? && !is_header_phase (build_file.settings ||= {}).merge!('COMPILER_FLAGS' => compiler_flags) do |_, old, new| [old, new].compact.join(' ') end end yield build_file if block_given? build_file end end |
#add_on_demand_resources(on_demand_resource_tag_files) ⇒ void
This method returns an undefined value.
Adds on demand resources to the resources build phase of the target.
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 574 def add_on_demand_resources(on_demand_resource_tag_files) on_demand_resource_tag_files.each do |tag, file_refs| file_refs.each do |file_ref| if resources_build_phase.include?(file_ref) existing_build_file = resources_build_phase.build_file(file_ref) existing_build_file.settings ||= {} existing_build_file.settings['ASSET_TAGS'] ||= [] existing_build_file.settings['ASSET_TAGS'] << tag existing_build_file.settings['ASSET_TAGS'].uniq! next end build_file = resources_build_phase.add_file_reference(file_ref, true) build_file.settings = (build_file.settings ||= {}).merge('ASSET_TAGS' => [tag]) end end end |
#add_resources(resource_file_references) ⇒ void
This method returns an undefined value.
Adds resource files to the resources build phase of the target.
558 559 560 561 562 563 564 565 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 558 def add_resources(resource_file_references) resource_file_references.each do |file| next if resources_build_phase.include?(file) build_file = project.new(PBXBuildFile) build_file.file_ref = file resources_build_phase.files << build_file end end |
#build_phases ⇒ ObjectList<AbstractBuildPhase>
Apparently only PBXCopyFilesBuildPhase and PBXShellScriptBuildPhase can appear multiple times in a target.
Returns the build phases of the target.
462 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 462 has_many :build_phases, AbstractBuildPhase |
#build_rules ⇒ PBXBuildRule
Returns the build rules of this target.
436 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 436 has_many :build_rules, PBXBuildRule |
#excluded_keys_for_serialization_when_empty ⇒ Array<String>
Returns array of keys to exclude from serialization when the value is empty.
711 712 713 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 711 def excluded_keys_for_serialization_when_empty %w(packageProductDependencies fileSystemSynchronizedGroups) end |
#extension_target_type? ⇒ Boolean
Returns Whether the target is an extension.
493 494 495 496 497 498 499 500 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 493 def extension_target_type? case symbol_type when :app_extension, :watch_extension, :watch2_extension, :tv_extension, :messages_extension true else false end end |
#file_system_synchronized_groups ⇒ ObjectList<PBXFileSystemSynchronizedRootGroup>
Returns the file system synchronized groups containing files to include to build this target.
467 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 467 has_many :file_system_synchronized_groups, PBXFileSystemSynchronizedRootGroup |
#frameworks_build_phase ⇒ PBXFrameworksBuildPhase
A target should have only one frameworks build phase.
Finds or creates the frameworks build phase of the target.
636 637 638 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 636 def frameworks_build_phase find_or_create_build_phase_by_class(PBXFrameworksBuildPhase) end |
#headers_build_phase ⇒ PBXHeadersBuildPhase
A target should have only one headers build phase.
Finds or creates the headers build phase of the target.
616 617 618 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 616 def headers_build_phase find_or_create_build_phase_by_class(PBXHeadersBuildPhase) end |
#launchable_target_type? ⇒ Boolean
Returns Whether the target is launchable.
504 505 506 507 508 509 510 511 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 504 def launchable_target_type? case symbol_type when :application, :command_line_tool true else false end end |
#package_product_dependencies ⇒ ObjectList<XCSwiftPackageProductDependency>
Returns the Swift package products necessary to build this target.
449 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 449 has_many :package_product_dependencies, XCSwiftPackageProductDependency |
#remove_on_demand_resources(on_demand_resource_tag_files) ⇒ void
This method returns an undefined value.
Remove on demand resources from the resources build phase of the target.
598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 598 def remove_on_demand_resources(on_demand_resource_tag_files) on_demand_resource_tag_files.each do |tag, file_refs| file_refs.each do |file_ref| build_file = resources_build_phase.build_file(file_ref) next if build_file.nil? = build_file.settings['ASSET_TAGS'] .delete(tag) resources_build_phase.remove_file_reference(file_ref) if .empty? end end end |
#resources_build_phase ⇒ PBXResourcesBuildPhase
A target should have only one resources build phase.
Finds or creates the resources build phase of the target.
646 647 648 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 646 def resources_build_phase find_or_create_build_phase_by_class(PBXResourcesBuildPhase) end |
#sort(_options = nil) ⇒ Object
Sorts the to many attributes of the object according to the display name.
Build phases are not sorted as they order is relevant.
680 681 682 683 684 685 686 687 688 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 680 def sort( = 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 |
#source_build_phase ⇒ PBXSourcesBuildPhase
A target should have only one source build phase.
Finds or creates the source build phase of the target.
626 627 628 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 626 def source_build_phase find_or_create_build_phase_by_class(PBXSourcesBuildPhase) end |
#symbol_type ⇒ Symbol
Returns The type of the target expressed as a symbol.
476 477 478 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 476 def symbol_type Constants::PRODUCT_TYPE_UTI.key(product_type) end |
#test_target_type? ⇒ Boolean
Returns Whether the target is a test target.
482 483 484 485 486 487 488 489 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 482 def test_target_type? case symbol_type when :octest_bundle, :unit_test_bundle, :ui_test_bundle true else false end end |
#to_ascii_plist ⇒ Object
700 701 702 703 704 705 706 707 708 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 700 def to_ascii_plist plist = super excluded_keys_for_serialization_when_empty.each do |key| if !plist.value[key].nil? && plist.value[key].empty? plist.value.delete(key) end end plist end |
#to_hash_as(method = :to_hash) ⇒ Object
690 691 692 693 694 695 696 697 698 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 690 def to_hash_as(method = :to_hash) hash_as = super excluded_keys_for_serialization_when_empty.each do |key| if !hash_as[key].nil? && hash_as[key].empty? hash_as.delete(key) end end hash_as end |