Class: Xcodeproj::Project::Object::AbstractTarget
- Inherits:
-
AbstractObject
- Object
- AbstractObject
- Xcodeproj::Project::Object::AbstractTarget
- Defined in:
- lib/xcodeproj/project/object/native_target.rb
Direct Known Subclasses
Attributes collapse
-
#build_configuration_list ⇒ XCConfigurationList
The list of the build configurations of the target.
-
#comments ⇒ String
Comments associated with this target.
-
#name ⇒ String
The name of the Target.
-
#product_name ⇒ String
The name of the build product.
Attributes inherited from AbstractObject
Attributes collapse
-
#dependencies ⇒ ObjectList<PBXTargetDependency>
The targets necessary to build this target.
Helpers collapse
-
#add_build_configuration(name, type) ⇒ XCBuildConfiguration
Adds a new build configuration to the target and populates its with default settings according to the provided type if one doesn’t exists.
-
#build_configurations ⇒ ObjectList<XCBuildConfiguration>
The build configurations of the target.
-
#build_settings(build_configuration_name) ⇒ Hash
The build settings of the build configuration with the given name.
-
#common_resolved_build_setting(key) ⇒ String
Gets the value for the given build setting, properly inherited if need, if shared across the build configurations.
-
#deployment_target ⇒ String
The deployment target of the target according to its platform.
-
#platform_name ⇒ Symbol
The name of the platform of the target.
-
#resolved_build_setting(key) ⇒ Hash{String => String}
Gets the value for the given build setting in all the build configurations or the value inheriting the value from the project ones if needed.
-
#sdk ⇒ String
The SDK that the target should use.
-
#sdk_version ⇒ String
The version of the SDK.
Build Phases Helpers collapse
-
#add_dependency(target) ⇒ void
Adds a dependency on the given target.
-
#copy_files_build_phases ⇒ Array<PBXCopyFilesBuildPhase>
The copy files build phases of the target.
-
#dependency_for_target(target) ⇒ PBXTargetDependency
Checks whether this target has a dependency on the given target.
-
#frameworks_build_phases ⇒ PBXFrameworksBuildPhase
The copy files build phases of the target.
-
#new_copy_files_build_phase(name = nil) ⇒ PBXCopyFilesBuildPhase
Creates a new copy files build phase.
-
#new_shell_script_build_phase(name = nil) ⇒ PBXShellScriptBuildPhase
Creates a new shell script build phase.
-
#shell_script_build_phases ⇒ Array<PBXShellScriptBuildPhase>
The copy files build phases of the target.
System frameworks collapse
-
#add_system_framework(names) ⇒ void
(also: #add_system_frameworks)
Adds a file reference for one or more system framework to the project if needed and adds them to the Frameworks build phases.
-
#add_system_library(names) ⇒ void
(also: #add_system_libraries)
Adds a file reference for one or more system libraries to the project if needed and adds them to the Frameworks build phases.
AbstractObject Hooks collapse
-
#pretty_print ⇒ Hash{String => Hash}
A hash suitable to display the object to the user.
Methods inherited from AbstractObject
#<=>, #==, #display_name, #inspect, isa, #remove_from_project, #sort, #sort_recursively, #to_hash
Instance Attribute Details
#build_configuration_list ⇒ XCConfigurationList
Returns the list of the build configurations of the target. This list commonly include two configurations ‘Debug` and `Release`.
25 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 25 has_one :build_configuration_list, XCConfigurationList |
#comments ⇒ String
Returns Comments associated with this target.
This is apparently no longer used by Xcode.
19 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 19 attribute :comments, String |
#name ⇒ String
Returns The name of the Target.
9 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 9 attribute :name, String |
#product_name ⇒ String
Returns the name of the build product.
13 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 13 attribute :product_name, String |
Instance Method Details
#add_build_configuration(name, type) ⇒ XCBuildConfiguration
If a build configuration with the given name is already present no new build configuration is added.
Adds a new build configuration to the target and populates its with default settings according to the provided type if one doesn’t exists.
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 147 def add_build_configuration(name, type) if existing = build_configuration_list[name] existing else build_configuration = project.new(XCBuildConfiguration) build_configuration.name = name build_configuration.build_settings = ProjectHelper.common_build_settings(type, platform_name, deployment_target, product_type) build_configuration_list.build_configurations << build_configuration build_configuration end end |
#add_dependency(target) ⇒ void
This method returns an undefined value.
Adds a dependency on the given target.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 203 def add_dependency(target) unless dependency_for_target(target) container_proxy = project.new(Xcodeproj::Project::PBXContainerItemProxy) if target.project == project container_proxy.container_portal = project.root_object.uuid else subproject_reference = project.reference_for_path(target.project.path) raise ArgumentError, 'add_dependency got target that belongs to a project is not this project and is not a subproject of this project' unless subproject_reference container_proxy.container_portal = subproject_reference.uuid end container_proxy.proxy_type = Constants::PROXY_TYPES[:native_target] container_proxy.remote_global_id_string = target.uuid container_proxy.remote_info = target.name dependency = project.new(Xcodeproj::Project::PBXTargetDependency) dependency.name = target.name dependency.target = target if target.project == project dependency.target_proxy = container_proxy dependencies << dependency end end |
#add_system_framework(names) ⇒ void Also known as: add_system_frameworks
Xcode behaviour is following: if the target has the same SDK of the project it adds the reference relative to the SDK root otherwise the reference is added relative to the Developer directory. This can create confusion or duplication of the references of frameworks linked by iOS and OS X targets. For this reason the new Xcodeproj behaviour is to add the frameworks in a subgroup according to the platform.
This method returns an undefined value.
Adds a file reference for one or more system framework to the project if needed and adds them to the Frameworks build phases.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 291 def add_system_framework(names) Array(names).each do |name| case platform_name when :ios group = project.frameworks_group['iOS'] || project.frameworks_group.new_group('iOS') path_sdk_name = 'iPhoneOS' path_sdk_version = sdk_version || Constants::LAST_KNOWN_IOS_SDK when :osx group = project.frameworks_group['OS X'] || project.frameworks_group.new_group('OS X') path_sdk_name = 'MacOSX' path_sdk_version = sdk_version || Constants::LAST_KNOWN_OSX_SDK when :tvos group = project.frameworks_group['tvOS'] || project.frameworks_group.new_group('tvOS') path_sdk_name = 'AppleTVOS' path_sdk_version = sdk_version || Constants::LAST_KNOWN_TVOS_SDK when :watchos group = project.frameworks_group['watchOS'] || project.frameworks_group.new_group('watchOS') path_sdk_name = 'WatchOS' path_sdk_version = sdk_version || Constants::LAST_KNOWN_WATCHOS_SDK else raise 'Unknown platform for target' end path = "Platforms/#{path_sdk_name}.platform/Developer/SDKs/#{path_sdk_name}#{path_sdk_version}.sdk/System/Library/Frameworks/#{name}.framework" unless ref = group.find_file_by_path(path) ref = group.new_file(path, :developer_dir) end frameworks_build_phase.add_file_reference(ref, true) ref end end |
#add_system_library(names) ⇒ void Also known as: add_system_libraries
This method returns an undefined value.
Adds a file reference for one or more system libraries to the project if needed and adds them to the Frameworks build phases.
332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 332 def add_system_library(names) Array(names).each do |name| path = "usr/lib/lib#{name}.dylib" files = project.frameworks_group.files unless reference = files.find { |ref| ref.path == path } reference = project.frameworks_group.new_file(path, :sdk_root) end frameworks_build_phase.add_file_reference(reference, true) reference end end |
#build_configurations ⇒ ObjectList<XCBuildConfiguration>
Returns the build configurations of the target.
126 127 128 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 126 def build_configurations build_configuration_list.build_configurations end |
#build_settings(build_configuration_name) ⇒ Hash
Returns the build settings of the build configuration with the given name.
166 167 168 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 166 def build_settings(build_configuration_name) build_configuration_list.build_settings(build_configuration_name) end |
#common_resolved_build_setting(key) ⇒ String
As it is common not to have a setting with no value for custom build configurations nil keys are not considered to determine if the setting is unique. This is an heuristic which might not closely match Xcode behaviour.
Gets the value for the given build setting, properly inherited if need, if shared across the build configurations.
74 75 76 77 78 79 80 81 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 74 def common_resolved_build_setting(key) values = resolved_build_setting(key).values.compact.uniq if values.count <= 1 values.first else raise "[Xcodeproj] Consistency issue: build setting `#{key}` has multiple values: `#{resolved_build_setting(key)}`" end end |
#copy_files_build_phases ⇒ Array<PBXCopyFilesBuildPhase>
Returns the copy files build phases of the target.
182 183 184 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 182 def copy_files_build_phases build_phases.grep(PBXCopyFilesBuildPhase) end |
#dependencies ⇒ ObjectList<PBXTargetDependency>
Returns the targets necessary to build this target.
30 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 30 has_many :dependencies, PBXTargetDependency |
#dependency_for_target(target) ⇒ PBXTargetDependency
Checks whether this target has a dependency on the given target.
233 234 235 236 237 238 239 240 241 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 233 def dependency_for_target(target) dependencies.find do |dep| if dep.target_proxy.remote? dep.target_proxy.remote_global_id_string == target.uuid else dep.target == target end end end |
#deployment_target ⇒ String
Returns the deployment target of the target according to its platform.
114 115 116 117 118 119 120 121 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 114 def deployment_target case platform_name when :ios then common_resolved_build_setting('IPHONEOS_DEPLOYMENT_TARGET') when :osx then common_resolved_build_setting('MACOSX_DEPLOYMENT_TARGET') when :tvos then common_resolved_build_setting('TVOS_DEPLOYMENT_TARGET') when :watchos then common_resolved_build_setting('WATCHOS_DEPLOYMENT_TARGET') end end |
#frameworks_build_phases ⇒ PBXFrameworksBuildPhase
Returns the copy files build phases of the target.
175 176 177 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 175 def frameworks_build_phases build_phases.find { |bp| bp.class == PBXFrameworksBuildPhase } end |
#new_copy_files_build_phase(name = nil) ⇒ PBXCopyFilesBuildPhase
Creates a new copy files build phase.
250 251 252 253 254 255 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 250 def new_copy_files_build_phase(name = nil) phase = project.new(PBXCopyFilesBuildPhase) phase.name = name build_phases << phase phase end |
#new_shell_script_build_phase(name = nil) ⇒ PBXShellScriptBuildPhase
Creates a new shell script build phase.
263 264 265 266 267 268 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 263 def new_shell_script_build_phase(name = nil) phase = project.new(PBXShellScriptBuildPhase) phase.name = name build_phases << phase phase end |
#platform_name ⇒ Symbol
Returns the name of the platform of the target.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 91 def platform_name return unless sdk if sdk.include? 'iphoneos' :ios elsif sdk.include? 'macosx' :osx elsif sdk.include? 'appletvos' :tvos elsif sdk.include? 'watchos' :watchos end end |
#pretty_print ⇒ Hash{String => Hash}
Returns A hash suitable to display the object to the user.
353 354 355 356 357 358 359 360 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 353 def pretty_print { display_name => { 'Build Phases' => build_phases.map(&:pretty_print), 'Build Configurations' => build_configurations.map(&:pretty_print), }, } end |
#resolved_build_setting(key) ⇒ Hash{String => String}
Gets the value for the given build setting in all the build configurations or the value inheriting the value from the project ones if needed.
TODO: Full support for this would require to take into account
any associated xcconfig and the default values for the
platform.
51 52 53 54 55 56 57 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 51 def resolved_build_setting(key) target_settings = build_configuration_list.get_setting(key) project_settings = project.build_configuration_list.get_setting(key) target_settings.merge(project_settings) do |_key, target_val, proj_val| target_val || proj_val end end |
#sdk ⇒ String
Returns the SDK that the target should use.
85 86 87 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 85 def sdk common_resolved_build_setting('SDKROOT') end |
#sdk_version ⇒ String
Returns the version of the SDK.
106 107 108 109 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 106 def sdk_version return unless sdk sdk.scan(/[0-9.]+/).first end |
#shell_script_build_phases ⇒ Array<PBXShellScriptBuildPhase>
Returns the copy files build phases of the target.
189 190 191 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 189 def shell_script_build_phases build_phases.grep(PBXShellScriptBuildPhase) end |