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, #target

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


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

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

Instance Attribute Details

#umbrella_header_pathsArray<Pathname> (readonly)


13
14
15
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 13

def umbrella_header_paths
  @umbrella_header_paths
end

Instance Method Details

#install!TargetInstallationResult

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


31
32
33
34
35
36
37
38
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
# File 'lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb', line 31

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? }

    unless target.should_build?
      # 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.
      native_target = add_placeholder_target
      resource_bundle_targets = add_resources_bundle_targets(library_file_accessors).values.flatten
      create_xcconfig_file(native_target, resource_bundle_targets)
      return TargetInstallationResult.new(target, native_target, resource_bundle_targets)
    end

    native_target = add_target
    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)
    validate_targets_contain_sources(test_native_targets + app_native_targets + [native_target])

    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.defines_module?
      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.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.build_as_library? && target.uses_swift?
      add_swift_library_compatibility_header_phase(native_target)
    end

    project_directory = project.path.dirname

    unless 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_target_from_spec(app_spec_consumer.spec, app_native_targets)
        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)
    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