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, resolve_against_xcconfig: false) ⇒ 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.
- #deployment_target=(deployment_target) ⇒ Object
-
#platform_name ⇒ Symbol
The name of the platform of the target.
-
#resolved_build_setting(key, resolve_against_xcconfig = false) ⇒ 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 frameworks 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 shell script build phases of the target.
System frameworks collapse
-
#add_system_framework(names) ⇒ Array<PBXFileReference>
(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 dylib libraries to the project if needed and adds them to the Frameworks build phases.
-
#add_system_library_tbd(names) ⇒ void
(also: #add_system_libraries_tbd)
Adds a file reference for one or more system tbd 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
#<=>, #==, #ascii_plist_annotation, #display_name, #inspect, isa, #nested_object_for_hash, #remove_from_project, #sort, #sort_recursively, #to_ascii_plist, #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.
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 185 def add_build_configuration(name, type) if existing = build_configuration_list[name] existing else build_configuration = project.new(XCBuildConfiguration) build_configuration.name = name product_type = self.product_type if respond_to?(:product_type) 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.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 242 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 received target that belongs to a project that 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) ⇒ Array<PBXFileReference> 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.
Adds a file reference for one or more system framework to the project if needed and adds them to the Frameworks build phases.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 333 def add_system_framework(names) Array(names).map 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 :visionos group = project.frameworks_group['visionOS'] || project.frameworks_group.new_group('visionOS') path_sdk_name = 'XROS' path_sdk_version = sdk_version || Constants::LAST_KNOWN_VISIONOS_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 dylib libraries to the project if needed and adds them to the Frameworks build phases.
378 379 380 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 378 def add_system_library(names) add_system_library_extension(names, 'dylib') end |
#add_system_library_tbd(names) ⇒ void Also known as: add_system_libraries_tbd
This method returns an undefined value.
Adds a file reference for one or more system tbd libraries to the project if needed and adds them to the Frameworks build phases.
404 405 406 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 404 def add_system_library_tbd(names) add_system_library_extension(names, 'tbd') end |
#build_configurations ⇒ ObjectList<XCBuildConfiguration>
Returns the build configurations of the target.
164 165 166 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 164 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.
205 206 207 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 205 def build_settings(build_configuration_name) build_configuration_list.build_settings(build_configuration_name) end |
#common_resolved_build_setting(key, resolve_against_xcconfig: false) ⇒ 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.
90 91 92 93 94 95 96 97 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 90 def common_resolved_build_setting(key, resolve_against_xcconfig: false) values = resolved_build_setting(key, resolve_against_xcconfig).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.
221 222 223 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 221 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.
272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 272 def dependency_for_target(target) dependencies.find do |dep| if dep.target_proxy.remote? subproject_reference = project.reference_for_path(target.project.path) uuid = subproject_reference.uuid if subproject_reference dep.target_proxy.remote_global_id_string == target.uuid && dep.target_proxy.container_portal == uuid else dep.target.uuid == target.uuid end end end |
#deployment_target ⇒ String
Returns the deployment target of the target according to its platform.
146 147 148 149 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 146 def deployment_target return unless setting = DEPLOYMENT_TARGET_SETTING_BY_PLATFORM_NAME[platform_name] common_resolved_build_setting(setting) end |
#deployment_target=(deployment_target) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 154 def deployment_target=(deployment_target) return unless setting = DEPLOYMENT_TARGET_SETTING_BY_PLATFORM_NAME[platform_name] build_configurations.each do |config| config.build_settings[setting] = deployment_target end end |
#frameworks_build_phases ⇒ PBXFrameworksBuildPhase
Returns the frameworks build phases of the target.
214 215 216 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 214 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.
291 292 293 294 295 296 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 291 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.
304 305 306 307 308 309 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 304 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.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 107 def platform_name return unless sdk if sdk.include? 'iphoneos' :ios elsif sdk.include? 'macosx' :osx elsif sdk.include? 'appletvos' :tvos elsif sdk.include? 'xros' :visionos elsif sdk.include? 'watchos' :watchos end end |
#pretty_print ⇒ Hash{String => Hash}
Returns A hash suitable to display the object to the user.
417 418 419 420 421 422 423 424 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 417 def pretty_print { display_name => { 'Build Phases' => build_phases.map(&:pretty_print), 'Build Configurations' => build_configurations.map(&:pretty_print), }, } end |
#resolved_build_setting(key, resolve_against_xcconfig = false) ⇒ 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
the default values for the platform.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 54 def resolved_build_setting(key, resolve_against_xcconfig = false) target_settings = build_configuration_list.get_setting(key, resolve_against_xcconfig, self) project_settings = project.build_configuration_list.get_setting(key, resolve_against_xcconfig) target_settings.merge(project_settings) do |_key, target_val, proj_val| target_includes_inherited = Constants::INHERITED_KEYWORDS.any? { |keyword| target_val.include?(keyword) } if target_val if target_includes_inherited && proj_val if target_val.is_a? String target_val.gsub(Regexp.union(Constants::INHERITED_KEYWORDS), proj_val) else target_val.flat_map { |value| Constants::INHERITED_KEYWORDS.include?(value) ? proj_val : value } end else target_val || proj_val end end end |
#sdk ⇒ String
Returns the SDK that the target should use.
101 102 103 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 101 def sdk common_resolved_build_setting('SDKROOT') end |
#sdk_version ⇒ String
Returns the version of the SDK.
124 125 126 127 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 124 def sdk_version return unless sdk sdk.scan(/[0-9.]+/).first end |
#shell_script_build_phases ⇒ Array<PBXShellScriptBuildPhase>
Returns the shell script build phases of the target.
228 229 230 |
# File 'lib/xcodeproj/project/object/native_target.rb', line 228 def shell_script_build_phases build_phases.grep(PBXShellScriptBuildPhase) end |