Class: Pod::AggregateTarget

Inherits:
Target
  • Object
show all
Defined in:
lib/cocoapods/target/aggregate_target.rb

Overview

Stores the information relative to the target used to cluster the targets of the single Pods. The client targets will then depend on this one.

Constant Summary collapse

EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES =

Product types where the product's frameworks must be embedded in a host target

[:app_extension, :framework, :static_library, :messages_extension, :watch_extension, :xpc_service].freeze

Constants inherited from Target

Target::DEFAULT_VERSION

Instance Attribute Summary collapse

Attributes inherited from Target

#archs, #host_requires_frameworks, #native_target, #sandbox, #user_build_configurations

Support files collapse

Instance Method Summary collapse

Methods inherited from Target

#bridge_support_path, #dummy_source_path, #framework_name, #info_plist_path, #inspect, #module_map_path, #name, #product_basename, #product_name, #product_type, #requires_frameworks?, #static_framework?, #static_library_name, #support_files_dir, #umbrella_header_path, #version, #xcconfig_path

Constructor Details

#initialize(target_definition, sandbox) ⇒ AggregateTarget

Initialize a new instance

Parameters:

  • target_definition (TargetDefinition)

    @see target_definition

  • sandbox (Sandbox)

    @see sandbox



19
20
21
22
23
24
25
26
27
28
# File 'lib/cocoapods/target/aggregate_target.rb', line 19

def initialize(target_definition, sandbox)
  raise "Can't initialize an AggregateTarget with an abstract TargetDefinition" if target_definition.abstract?
  super()
  @target_definition = target_definition
  @sandbox = sandbox
  @pod_targets = []
  @search_paths_aggregate_targets = []
  @file_accessors = []
  @xcconfigs = {}
end

Instance Attribute Details

#client_rootPathname

Returns the folder where the client is stored used for computing the relative paths. If integrating it should be the folder where the user project is stored, otherwise it should be the installation root.

Returns:

  • (Pathname)

    the folder where the client is stored used for computing the relative paths. If integrating it should be the folder where the user project is stored, otherwise it should be the installation root.



89
90
91
# File 'lib/cocoapods/target/aggregate_target.rb', line 89

def client_root
  @client_root
end

#pod_targetsArray<PodTarget>

Returns The dependencies for this target.

Returns:

  • (Array<PodTarget>)

    The dependencies for this target.



138
139
140
# File 'lib/cocoapods/target/aggregate_target.rb', line 138

def pod_targets
  @pod_targets
end

#search_paths_aggregate_targetsArray<AggregateTarget> (readonly)

Returns The aggregate targets whose pods this target must be able to import, but will not directly link against.

Returns:

  • (Array<AggregateTarget>)

    The aggregate targets whose pods this target must be able to import, but will not directly link against.



143
144
145
# File 'lib/cocoapods/target/aggregate_target.rb', line 143

def search_paths_aggregate_targets
  @search_paths_aggregate_targets
end

#target_definitionTargetDefinition (readonly)

Returns the target definition of the Podfile that generated this target.

Returns:

  • (TargetDefinition)

    the target definition of the Podfile that generated this target.



8
9
10
# File 'lib/cocoapods/target/aggregate_target.rb', line 8

def target_definition
  @target_definition
end

#user_projectXcodeproj::Project

Returns the user project that this target will integrate as identified by the analyzer.

Returns:

  • (Xcodeproj::Project)

    the user project that this target will integrate as identified by the analyzer.



94
95
96
# File 'lib/cocoapods/target/aggregate_target.rb', line 94

def user_project
  @user_project
end

#user_target_uuidsArray<String>

Note:

The target instances are not stored to prevent editing different instances.

Returns the list of the UUIDs of the user targets that will be integrated by this target as identified by the analyzer.

Returns:

  • (Array<String>)

    the list of the UUIDs of the user targets that will be integrated by this target as identified by the analyzer.



109
110
111
# File 'lib/cocoapods/target/aggregate_target.rb', line 109

def user_target_uuids
  @user_target_uuids
end

#xcconfigsHash<String, Xcodeproj::Config> (readonly)

Note:

The configurations are generated by the TargetInstaller and used by UserProjectIntegrator to check for any overridden values.

Returns Map from configuration name to configuration file for the target

Returns:

  • (Hash<String, Xcodeproj::Config>)

    Map from configuration name to configuration file for the target



134
135
136
# File 'lib/cocoapods/target/aggregate_target.rb', line 134

def xcconfigs
  @xcconfigs
end

Instance Method Details

#acknowledgements_basepathPathname

Note:

The acknowledgements generators add the extension according to the file type.

Returns The absolute path of acknowledgements file.

Returns:

  • (Pathname)

    The absolute path of acknowledgements file.



237
238
239
# File 'lib/cocoapods/target/aggregate_target.rb', line 237

def acknowledgements_basepath
  support_files_dir + "#{label}-acknowledgements"
end

#bridge_support_filePathname

Returns the path of the bridge support file relative to the sandbox or `nil` if bridge support is disabled.

Returns:

  • (Pathname)

    the path of the bridge support file relative to the sandbox or `nil` if bridge support is disabled.



224
225
226
# File 'lib/cocoapods/target/aggregate_target.rb', line 224

def bridge_support_file
  bridge_support_path.relative_path_from(sandbox.root) if podfile.generate_bridge_support?
end

#check_manifest_lock_script_output_file_pathString

Returns The output file path fo the check manifest lock script.

Returns:

  • (String)

    The output file path fo the check manifest lock script.



255
256
257
# File 'lib/cocoapods/target/aggregate_target.rb', line 255

def check_manifest_lock_script_output_file_path
  "$(DERIVED_FILE_DIR)/#{label}-checkManifestLockResult.txt"
end

#copy_resources_script_pathPathname

Returns The absolute path of the copy resources script.

Returns:

  • (Pathname)

    The absolute path of the copy resources script.



243
244
245
# File 'lib/cocoapods/target/aggregate_target.rb', line 243

def copy_resources_script_path
  support_files_dir + "#{label}-resources.sh"
end

#copy_resources_script_relative_pathString

Returns The path of the copy resources script relative to the root of the user project.

Returns:

  • (String)

    The path of the copy resources script relative to the root of the user project.



287
288
289
# File 'lib/cocoapods/target/aggregate_target.rb', line 287

def copy_resources_script_relative_path
  "${SRCROOT}/#{relative_to_srcroot(copy_resources_script_path)}"
end

#embed_frameworks_script_pathPathname

Returns The absolute path of the embed frameworks script.

Returns:

  • (Pathname)

    The absolute path of the embed frameworks script.



249
250
251
# File 'lib/cocoapods/target/aggregate_target.rb', line 249

def embed_frameworks_script_path
  support_files_dir + "#{label}-frameworks.sh"
end

#embed_frameworks_script_relative_pathString

Returns The path of the embed frameworks relative to the root of the user project.

Returns:

  • (String)

    The path of the embed frameworks relative to the root of the user project.



294
295
296
# File 'lib/cocoapods/target/aggregate_target.rb', line 294

def embed_frameworks_script_relative_path
  "${SRCROOT}/#{relative_to_srcroot(embed_frameworks_script_path)}"
end

#framework_paths_by_configHash{String => Array<Hash{Symbol => [String]}>}

Returns The vendored dynamic artifacts and framework target input and output paths grouped by config

Returns:

  • (Hash{String => Array<Hash{Symbol => [String]}>})

    The vendored dynamic artifacts and framework target input and output paths grouped by config



195
196
197
198
199
200
201
202
203
204
# File 'lib/cocoapods/target/aggregate_target.rb', line 195

def framework_paths_by_config
  @framework_paths_by_config ||= begin
    framework_paths_by_config = {}
    user_build_configurations.keys.each do |config|
      relevant_pod_targets = pod_targets_for_build_configuration(config)
      framework_paths_by_config[config] = relevant_pod_targets.flat_map { |pt| pt.framework_paths(false) }
    end
    framework_paths_by_config
  end
end

#labelString

Returns the label for the target.

Returns:

  • (String)

    the label for the target.



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

def label
  target_definition.label.to_s
end

#library?Boolean

Returns True if the user_target refers to a library (framework, static or dynamic lib).

Returns:

  • (Boolean)

    True if the user_target refers to a library (framework, static or dynamic lib).

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
# File 'lib/cocoapods/target/aggregate_target.rb', line 33

def library?
  # Without a user_project, we can't say for sure
  # that this is a library
  return false if user_project.nil?
  symbol_types = user_targets.map(&:symbol_type).uniq
  raise ArgumentError, "Expected single kind of user_target for #{name}. Found #{symbol_types.join(', ')}." unless symbol_types.count == 1
  [:framework, :dynamic_library, :static_library].include? symbol_types.first
end

#platformPlatform

Returns the platform for this target.

Returns:

  • (Platform)

    the platform for this target.



74
75
76
# File 'lib/cocoapods/target/aggregate_target.rb', line 74

def platform
  @platform ||= target_definition.platform
end

#pod_targets_for_build_configuration(build_configuration) ⇒ Array<PodTarget>

Returns the pod targets for the given build configuration.

Parameters:

  • build_configuration (String)

    The build configuration for which the the pod targets should be returned.

Returns:

  • (Array<PodTarget>)

    the pod targets for the given build configuration.



151
152
153
154
155
156
# File 'lib/cocoapods/target/aggregate_target.rb', line 151

def pod_targets_for_build_configuration(build_configuration)
  @pod_targets_for_build_configuration ||= {}
  @pod_targets_for_build_configuration[build_configuration] ||= pod_targets.select do |pod_target|
    pod_target.include_in_build_config?(target_definition, build_configuration)
  end
end


158
159
160
# File 'lib/cocoapods/target/aggregate_target.rb', line 158

def pod_targets_to_link
  @pod_targets_to_link ||= pod_targets.to_set - search_paths_aggregate_targets.flat_map(&:pod_targets)
end

#podfilePodfile

Returns The podfile which declares the dependency

Returns:

  • (Podfile)

    The podfile which declares the dependency



80
81
82
# File 'lib/cocoapods/target/aggregate_target.rb', line 80

def podfile
  target_definition.podfile
end

#podfile_dir_relative_pathString

Returns The path of the Podfile directory relative to the root of the user project.

Returns:

  • (String)

    The path of the Podfile directory relative to the root of the user project.



269
270
271
272
273
274
# File 'lib/cocoapods/target/aggregate_target.rb', line 269

def podfile_dir_relative_path
  podfile_path = target_definition.podfile.defined_in_file
  return "${SRCROOT}/#{podfile_path.relative_path_from(client_root).dirname}" unless podfile_path.nil?
  # Fallback to the standard path if the Podfile is not represented by a file.
  '${PODS_ROOT}/..'
end

#product_module_nameString

Returns the name to use for the source code module constructed for this target, and which will be used to import the module in implementation source files.

Returns:

  • (String)

    the name to use for the source code module constructed for this target, and which will be used to import the module in implementation source files.



68
69
70
# File 'lib/cocoapods/target/aggregate_target.rb', line 68

def product_module_name
  c99ext_identifier(label)
end

#relative_pods_rootString

Returns The xcconfig path of the root from the `$(SRCROOT)` variable of the user's project.

Returns:

  • (String)

    The xcconfig path of the root from the `$(SRCROOT)` variable of the user's project.



262
263
264
# File 'lib/cocoapods/target/aggregate_target.rb', line 262

def relative_pods_root
  "${SRCROOT}/#{sandbox.root.relative_path_from(client_root)}"
end

#requires_host_target?Boolean

Returns True if the user_target's pods are for an extension and must be embedded in a host, target, otherwise false.

Returns:

  • (Boolean)

    True if the user_target's pods are for an extension and must be embedded in a host, target, otherwise false.

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cocoapods/target/aggregate_target.rb', line 46

def requires_host_target?
  # If we don't have a user_project, then we can't
  # glean any info about how this target is going to
  # be integrated, so return false since we can't know
  # for sure that this target refers to an extension
  # target that would require a host target
  return false if user_project.nil?
  symbol_types = user_targets.map(&:symbol_type).uniq
  raise ArgumentError, "Expected single kind of user_target for #{name}. Found #{symbol_types.join(', ')}." unless symbol_types.count == 1
  EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES.include?(symbol_types[0])
end

#resource_paths_by_configHash{String => Array<String>}

Returns Uniqued Resources grouped by config

Returns:

  • (Hash{String => Array<String>})

    Uniqued Resources grouped by config



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/cocoapods/target/aggregate_target.rb', line 208

def resource_paths_by_config
  @resource_paths_by_config ||= begin
    relevant_pod_targets = pod_targets.reject do |pod_target|
      pod_target.should_build? && pod_target.requires_frameworks? && !pod_target.static_framework?
    end
    user_build_configurations.keys.each_with_object({}) do |config, resources_by_config|
      resources_by_config[config] = (relevant_pod_targets & pod_targets_for_build_configuration(config)).flat_map do |pod_target|
        (pod_target.resource_paths(false) + [bridge_support_file].compact).uniq
      end
    end
  end
end

#spec_consumersArray<Specification::Consumer>

Returns The consumers of the Pod.

Returns:

  • (Array<Specification::Consumer>)

    The consumers of the Pod.



182
183
184
# File 'lib/cocoapods/target/aggregate_target.rb', line 182

def spec_consumers
  specs.map { |spec| spec.consumer(platform) }
end

#specsArray<Specification>

Returns The specifications used by this aggregate target.

Returns:

  • (Array<Specification>)

    The specifications used by this aggregate target.



164
165
166
# File 'lib/cocoapods/target/aggregate_target.rb', line 164

def specs
  pod_targets.flat_map(&:specs)
end

#specs_by_build_configurationHash{Symbol => Array<Specification>}

Returns The pod targets for each build configuration.

Returns:

  • (Hash{Symbol => Array<Specification>})

    The pod targets for each build configuration.



171
172
173
174
175
176
177
178
# File 'lib/cocoapods/target/aggregate_target.rb', line 171

def specs_by_build_configuration
  result = {}
  user_build_configurations.keys.each do |build_configuration|
    result[build_configuration] = pod_targets_for_build_configuration(build_configuration).
      flat_map(&:specs)
  end
  result
end

#user_project_pathPathname

Returns the path of the user project that this target will integrate as identified by the analyzer.

Returns:

  • (Pathname)

    the path of the user project that this target will integrate as identified by the analyzer.



99
100
101
# File 'lib/cocoapods/target/aggregate_target.rb', line 99

def user_project_path
  user_project.path if user_project
end

#user_targetsArray<PBXNativeTarget>

List all user targets that will be integrated by this #target.

Returns:

  • (Array<PBXNativeTarget>)


115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cocoapods/target/aggregate_target.rb', line 115

def user_targets
  return [] unless user_project
  user_target_uuids.map do |uuid|
    native_target = user_project.objects_by_uuid[uuid]
    unless native_target
      raise Informative, '[Bug] Unable to find the target with ' \
        "the `#{uuid}` UUID for the `#{self}` integration library"
    end
    native_target
  end
end

#uses_swift?Boolean

Returns Whether the target uses Swift code

Returns:

  • (Boolean)

    Whether the target uses Swift code



188
189
190
# File 'lib/cocoapods/target/aggregate_target.rb', line 188

def uses_swift?
  pod_targets.any?(&:uses_swift?)
end

#xcconfig_relative_path(config_name) ⇒ String

Returns The path of the xcconfig file relative to the root of the user project.

Parameters:

  • config_name (String)

    The build configuration name to get the xcconfig for

Returns:

  • (String)

    The path of the xcconfig file relative to the root of the user project.



280
281
282
# File 'lib/cocoapods/target/aggregate_target.rb', line 280

def xcconfig_relative_path(config_name)
  relative_to_srcroot(xcconfig_path(config_name)).to_s
end