Class: Pod::Installer::Xcode::PodsProjectGenerator::PodTargetInstaller

Inherits:
TargetInstaller
  • Object
show all
Defined in:
lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb

Overview

Creates the target for the Pods libraries in the Pods project and the relative support files.

Instance Attribute Summary collapse

Attributes inherited from TargetInstaller

#project, #sandbox

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TargetInstallerHelper

create_info_plist_file_with_sandbox, create_prefix_header, update_changed_file

Constructor Details

#initialize(sandbox, project, target, umbrella_header_paths = nil) ⇒ PodTargetInstaller

Initialize a new instance

Parameters:

  • sandbox (Sandbox)

    @see TargetInstaller#sandbox

  • project (Pod::Project)

    @see TargetInstaller#project

  • target (PodTarget)

    @see TargetInstaller#target

  • umbrella_header_paths (Array<Pathname>) (defaults to: nil)

    @see #umbrella_header_paths



30
31
32
33
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 30

def initialize(sandbox, project, target, umbrella_header_paths = nil)
  super(sandbox, project, target)
  @umbrella_header_paths = umbrella_header_paths
end

Instance Attribute Details

#targetPodTarget (readonly)

Returns @see TargetInstaller#target.

Returns:

  • (PodTarget)

    @see TargetInstaller#target



21
22
23
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 21

def target
  @target
end

#umbrella_header_pathsArray<Pathname> (readonly)

Returns Array of umbrella header paths in the headers directory.

Returns:

  • (Array<Pathname>)

    Array of umbrella header paths in the headers directory



17
18
19
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 17

def umbrella_header_paths
  @umbrella_header_paths
end

Class Method Details

.bcsymbolmap_paths(target) ⇒ Array<String>

Returns the bcsymbolmap paths for the given target.

Parameters:

  • target (PodTarget)

    the target to be installed

Returns:

  • (Array<String>)

    the bcsymbolmap paths for the given target



1228
1229
1230
1231
1232
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 1228

def bcsymbolmap_paths(target)
  target.framework_paths.values.flatten.reject do |fmwk_path|
    fmwk_path.bcsymbolmap_paths.nil?
  end.flat_map(&:bcsymbolmap_paths).uniq
end

.dsym_paths(target) ⇒ Array<String>

Returns the dSYM paths for the given target.

Parameters:

  • target (PodTarget)

    the target to be installed

Returns:

  • (Array<String>)

    the dSYM paths for the given target



1214
1215
1216
1217
1218
1219
1220
1221
1222
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 1214

def dsym_paths(target)
  dsym_paths = target.framework_paths.values.flatten.reject { |fmwk_path| fmwk_path.dsym_path.nil? }.map(&:dsym_path)
  dsym_paths.concat(target.xcframeworks.values.flatten.flat_map { |xcframework| xcframework_dsyms(xcframework.path) })
  dsym_paths.map do |dsym_path|
    dsym_pathname = Pathname(dsym_path)
    dsym_path = "${PODS_ROOT}/#{dsym_pathname.relative_path_from(target.sandbox.root)}" unless dsym_pathname.relative?
    dsym_path
  end
end

.xcframework_dsyms(xcframework_path) ⇒ Array<Pathname>

Returns all found .dSYM paths.

Parameters:

  • xcframework_path (Pathname)

    the base path of the .xcframework bundle

Returns:

  • (Array<Pathname>)

    all found .dSYM paths



1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 1239

def xcframework_dsyms(xcframework_path)
  basename = File.basename(xcframework_path, '.xcframework')
  dsym_basename = basename + '.dSYMs'
  path = xcframework_path.dirname + dsym_basename
  if File.directory?(path)
    Dir.glob(path + '*.dSYM')
  else
    []
  end
end

Instance Method Details

#install!TargetInstallationResult

Creates the target in the Pods project and the relative support files.

Returns:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 39

def install!
  UI.message "- Installing target `#{target.name}` #{target.platform}" do
    create_support_files_dir
    library_file_accessors = target.file_accessors.select { |fa| fa.spec.library_specification? }
    test_file_accessors = target.file_accessors.select { |fa| fa.spec.test_specification? }
    app_file_accessors = target.file_accessors.select { |fa| fa.spec.app_specification? }

    native_target = if target.should_build?
                      add_target
                    else
                      # For targets that should not be built (e.g. pre-built vendored frameworks etc), we add a placeholder
                      # PBXAggregateTarget that will be used to wire up dependencies later.
                      add_placeholder_target
                    end

    resource_bundle_targets = add_resources_bundle_targets(library_file_accessors).values.flatten

    test_native_targets = add_test_targets
    test_app_host_targets = add_test_app_host_targets
    test_resource_bundle_targets = add_resources_bundle_targets(test_file_accessors)

    app_native_targets = add_app_targets
    app_resource_bundle_targets = add_resources_bundle_targets(app_file_accessors)

    add_files_to_build_phases(native_target, test_native_targets, app_native_targets)
    targets_to_validate = test_native_targets + app_native_targets.values
    targets_to_validate << native_target if target.should_build?
    validate_targets_contain_sources(targets_to_validate)
    validate_xcframeworks if target.should_build?

    create_copy_xcframeworks_script unless target.xcframeworks.values.all?(&:empty?)

    create_xcconfig_file(native_target, resource_bundle_targets)
    create_test_xcconfig_files(test_native_targets, test_resource_bundle_targets)
    create_app_xcconfig_files(app_native_targets, app_resource_bundle_targets)

    if target.should_build? && target.defines_module? && !skip_modulemap?(target.library_specs)
      create_module_map(native_target) do |generator|
        generator.headers.concat module_map_additional_headers
      end
      create_umbrella_header(native_target) do |generator|
        generator.imports += library_file_accessors.flat_map do |file_accessor|
          header_dir = if !target.build_as_framework? && dir = file_accessor.spec_consumer.header_dir
                         Pathname.new(dir)
                       end

          file_accessor.public_headers.map do |public_header|
            public_header = if header_mappings_dir(file_accessor)
                              public_header.relative_path_from(header_mappings_dir(file_accessor))
                            else
                              public_header.basename
                            end
            if header_dir
              public_header = header_dir.join(public_header)
            end
            public_header
          end
        end
      end
    end

    if target.should_build? && target.build_as_framework?
      unless skip_info_plist?(native_target)
        create_info_plist_file(target.info_plist_path, native_target, target.version, target.platform,
                               :additional_entries => target.info_plist_entries)
      end
      create_build_phase_to_symlink_header_folders(native_target)
    end

    if target.should_build? && target.build_as_library? && target.uses_swift?
      add_swift_library_compatibility_header_phase(native_target)
    end

    project_directory = project.path.dirname

    if target.should_build? && !skip_pch?(target.library_specs)
      path = target.prefix_header_path
      create_prefix_header(path, library_file_accessors, target.platform, native_target, project_directory)
      add_file_to_support_group(path)
    end
    unless skip_pch?(target.test_specs)
      target.test_specs.each do |test_spec|
        path = target.prefix_header_path_for_spec(test_spec)
        test_spec_consumer = test_spec.consumer(target.platform)
        test_native_target = test_native_target_from_spec(test_spec_consumer.spec, test_native_targets)
        create_prefix_header(path, test_file_accessors, target.platform, test_native_target, project_directory)
        add_file_to_support_group(path)
      end
    end
    unless skip_pch?(target.app_specs)
      target.app_specs.each do |app_spec|
        path = target.prefix_header_path_for_spec(app_spec)
        app_spec_consumer = app_spec.consumer(target.platform)
        app_native_target = app_native_targets[app_spec_consumer.spec]
        create_prefix_header(path, app_file_accessors, target.platform, app_native_target, project_directory)
        add_file_to_support_group(path)
      end
    end
    create_dummy_source(native_target) if target.should_build?
    create_copy_dsyms_script
    clean_support_files_temp_dir
    TargetInstallationResult.new(target, native_target, resource_bundle_targets,
                                 test_native_targets, test_resource_bundle_targets, test_app_host_targets,
                                 app_native_targets, app_resource_bundle_targets)
  end
end