class Pod::Installer::Xcode::PodsProjectGenerator::PodTargetInstaller

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

Constants

ENABLE_OBJECT_USE_OBJC_FROM

Attributes

umbrella_header_paths[R]

@return [Array<Pathname>] Array of umbrella header paths in the headers directory

Public Class Methods

new(sandbox, project, target, umbrella_header_paths = nil) click to toggle source

Initialize a new instance

@param [Sandbox] sandbox @see TargetInstaller#sandbox @param [Pod::Project] project @see TargetInstaller#project @param [Target] target @see TargetInstaller#target @param [Array<Pathname>] umbrella_header_paths @see umbrella_header_paths

Calls superclass method
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 20
def initialize(sandbox, project, target, umbrella_header_paths = nil)
  super(sandbox, project, target)
  @umbrella_header_paths = umbrella_header_paths
end

Public Instance Methods

install!() click to toggle source

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

@return [TargetInstallationResult] the result of the installation of this target.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 29
def install!
  UI.message "- Installing target `#{target.name}` #{target.platform}" do
    create_support_files_dir
    test_file_accessors, file_accessors = target.file_accessors.partition { |fa| fa.spec.test_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(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(file_accessors).values.flatten

    test_native_targets = add_test_targets
    test_resource_bundle_targets = add_resources_bundle_targets(test_file_accessors)

    add_files_to_build_phases(native_target, test_native_targets)

    create_xcconfig_file(native_target, resource_bundle_targets)
    create_test_xcconfig_files(test_native_targets, test_resource_bundle_targets.values.flatten)

    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 += file_accessors.flat_map do |file_accessor|
          header_dir = if !target.requires_frameworks? && 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
                              public_header.relative_path_from(header_mappings_dir)
                            else
                              public_header.basename
                            end
            if header_dir
              public_header = header_dir.join(public_header)
            end
            public_header
          end
        end
      end
    end

    if target.requires_frameworks?
      unless skip_info_plist?(native_target)
        create_info_plist_file(target.info_plist_path, native_target, target.version, target.platform)
      end
      create_build_phase_to_symlink_header_folders(native_target)
    elsif target.uses_swift?
      add_swift_static_library_compatibility_header_phase(native_target)
    end

    unless skip_pch?(target.non_test_specs)
      path = target.prefix_header_path
      create_prefix_header(path, file_accessors, target.platform, [native_target])
    end
    unless skip_pch?(target.test_specs)
      target.supported_test_types.each do |test_type|
        path = target.prefix_header_path_for_test_type(test_type)
        create_prefix_header(path, test_file_accessors, target.platform, test_native_targets)
      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)
  end
end

Private Instance Methods

add_files_to_build_phases(native_target, test_native_targets) click to toggle source

Adds the build files of the pods to the target and adds a reference to the frameworks of the Pods.

@note The Frameworks are used only for presentation purposes as the

xcconfig is the authoritative source about their information.

@note Core Data model directories (.xcdatamodeld) defined in the `resources`

property are currently added to the `Copy Resources` build phase like
all other resources. The Xcode UI adds these to the `Compile Sources`
build phase, but they will compile correctly either way.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 213
def add_files_to_build_phases(native_target, test_native_targets)
  target.file_accessors.each do |file_accessor|
    consumer = file_accessor.spec_consumer

    native_target = if !consumer.spec.test_specification?
                      native_target
                    else
                      test_native_target_from_spec_consumer(consumer, test_native_targets)
                    end

    headers = file_accessor.headers
    public_headers = file_accessor.public_headers.map(&:realpath)
    private_headers = file_accessor.private_headers.map(&:realpath)
    other_source_files = file_accessor.other_source_files

    {
      true => file_accessor.arc_source_files,
      false => file_accessor.non_arc_source_files,
    }.each do |arc, files|
      next if files.empty?
      files = files - headers - other_source_files
      flags = compiler_flags_for_consumer(consumer, arc)
      regular_file_refs = project_file_references_array(files, 'source')
      native_target.add_file_references(regular_file_refs, flags)
    end

    header_file_refs = project_file_references_array(headers, 'header')
    native_target.add_file_references(header_file_refs) do |build_file|
      add_header(build_file, public_headers, private_headers, native_target)
    end

    other_file_refs = project_file_references_array(other_source_files, 'other source')
    native_target.add_file_references(other_file_refs, nil)

    next unless target.requires_frameworks?

    filter_resource_file_references(file_accessor.resources.flatten) do |resource_phase_refs, compile_phase_refs|
      native_target.add_file_references(compile_phase_refs, nil)
      native_target.add_resources(resource_phase_refs)
    end
  end
end
add_header(build_file, public_headers, private_headers, native_target) click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 661
def add_header(build_file, public_headers, private_headers, native_target)
  file_ref = build_file.file_ref
  acl = if !target.requires_frameworks? # Headers are already rooted at ${PODS_ROOT}/Headers/P*/[pod]/...
          'Project'
        elsif public_headers.include?(file_ref.real_path)
          'Public'
        elsif private_headers.include?(file_ref.real_path)
          'Private'
        else
          'Project'
        end

  if target.requires_frameworks? && header_mappings_dir && acl != 'Project'
    relative_path = file_ref.real_path.relative_path_from(header_mappings_dir)
    sub_dir = relative_path.dirname
    copy_phase_name = "Copy #{sub_dir} #{acl} Headers"
    copy_phase = native_target.copy_files_build_phases.find { |bp| bp.name == copy_phase_name } ||
      native_target.new_copy_files_build_phase(copy_phase_name)
    copy_phase.symbol_dst_subfolder_spec = :products_directory
    copy_phase.dst_path = "$(#{acl.upcase}_HEADERS_FOLDER_PATH)/#{sub_dir}"
    copy_phase.add_file_reference(file_ref, true)
  else
    build_file.settings ||= {}
    build_file.settings['ATTRIBUTES'] = [acl]
  end
end
add_placeholder_target() click to toggle source

Adds a placeholder native target for the library to the Pods project with the appropriate build configurations.

@return [PBXAggregateTarget] the native target that was added.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 717
def add_placeholder_target
  native_target = project.new_aggregate_target(target.label)
  native_target.deployment_target = deployment_target
  target.user_build_configurations.each do |bc_name, type|
    native_target.add_build_configuration(bc_name, type)
  end
  native_target.build_configurations.each do |configuration|
    configuration.build_settings['ARCHS'] = target.archs
  end
  native_target
end
add_resources_bundle_targets(file_accessors) click to toggle source

Adds the resources of the Pods to the Pods project.

@note The source files are grouped by Pod and in turn by subspec

(recursively) in the resources group.

@param [Array<Sandbox::FileAccessor>] file_accessors

the file accessors list to generate resource bundles for.

@return [Array<PBXNativeTarget] the resource bundle native targets created.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 319
def add_resources_bundle_targets(file_accessors)
  file_accessors.each_with_object({}) do |file_accessor, hash|
    hash[file_accessor.spec.name] = file_accessor.resource_bundles.map do |bundle_name, paths|
      label = target.resources_bundle_target_label(bundle_name)
      resource_bundle_target = project.new_resources_bundle(label, file_accessor.spec_consumer.platform_name)
      resource_bundle_target.product_reference.tap do |bundle_product|
        bundle_file_name = "#{bundle_name}.bundle"
        bundle_product.name = bundle_file_name
      end

      filter_resource_file_references(paths) do |resource_phase_refs, compile_phase_refs|
        # Resource bundles are only meant to have resources, so install everything
        # into the resources phase. See note in filter_resource_file_references.
        resource_bundle_target.add_resources(resource_phase_refs + compile_phase_refs)
      end

      target.user_build_configurations.each do |bc_name, type|
        resource_bundle_target.add_build_configuration(bc_name, type)
      end
      resource_bundle_target.deployment_target = deployment_target

      # Create Info.plist file for bundle
      path = target.info_plist_path
      path.dirname.mkdir unless path.dirname.exist?
      info_plist_path = path.dirname + "ResourceBundle-#{bundle_name}-#{path.basename}"
      create_info_plist_file(info_plist_path, resource_bundle_target, target.version, target.platform, :bndl)

      resource_bundle_target.build_configurations.each do |c|
        c.build_settings['PRODUCT_NAME'] = bundle_name
        # Do not set the CONFIGURATION_BUILD_DIR for resource bundles that are only meant for test targets.
        # This is because the test target itself also does not set this configuration build dir and it expects
        # all bundles to be copied from the default path.
        unless file_accessor.spec.test_specification?
          c.build_settings['CONFIGURATION_BUILD_DIR'] = target.configuration_build_dir('$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)')
        end

        # Set the correct device family for this bundle, based on the platform
        device_family_by_platform = {
          :ios => '1,2',
          :tvos => '3',
          :watchos => '1,2' # The device family for watchOS is 4, but Xcode creates watchkit-compatible bundles as 1,2
        }

        if (family = device_family_by_platform[target.platform.name])
          c.build_settings['TARGETED_DEVICE_FAMILY'] = family
        end
      end

      resource_bundle_target
    end
  end
end
add_swift_static_library_compatibility_header_phase(native_target) click to toggle source

Adds a shell script phase, intended only for static library targets that contain swift, to copy the ObjC compatibility header (the -Swift.h file that the swift compiler generates) to the built products directory. Additionally, the script phase copies the module map, appending a `.Swift` submodule that references the (moved) compatibility header. Since the module map has been moved, the umbrella header is also copied, so that it is sitting next to the module map. This is necessary for a successful archive build.

@param [PBXNativeTarget] native_target

the native target to add the Swift static library script phase into.

@return [Void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 740
          def add_swift_static_library_compatibility_header_phase(native_target)
            if custom_module_map
              raise Informative, 'Using Swift static libraries with custom module maps does not yet work.' \
                                 "Please build #{pod_target.label} as a framework or remove the custom module map for the time being."
            end

            build_phase = native_target.new_shell_script_build_phase('Copy generated compatibility header')

            relative_module_map_path = target.module_map_path.relative_path_from(target.sandbox.root)
            relative_umbrella_header_path = target.umbrella_header_path.relative_path_from(target.sandbox.root)

            build_phase.shell_script = <<-SH.strip_heredoc
              COMPATIBILITY_HEADER_PATH="${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}-Swift.h"
              MODULE_MAP_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap"

              ditto "${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h" "${COMPATIBILITY_HEADER_PATH}"
              ditto "${PODS_ROOT}/#{relative_module_map_path}" "${MODULE_MAP_PATH}"
              ditto "${PODS_ROOT}/#{relative_umbrella_header_path}" "${BUILT_PRODUCTS_DIR}"
              printf "\\n\\nmodule ${PRODUCT_MODULE_NAME}.Swift {\\n  header \\"${COMPATIBILITY_HEADER_PATH}\\"\\n  requires objc\\n}\\n" >> "${MODULE_MAP_PATH}"
            SH
            build_phase.input_paths = %W(
              ${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h
              ${PODS_ROOT}/#{relative_module_map_path}
              ${PODS_ROOT}/#{relative_umbrella_header_path}
            )
            build_phase.output_paths = %W(
              ${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap
              ${BUILT_PRODUCTS_DIR}/#{relative_umbrella_header_path.basename}
              ${BUILT_PRODUCTS_DIR}/Swift\ Compatibility\ Header/${PRODUCT_MODULE_NAME}-Swift.h
            )
          end
add_test_targets() click to toggle source

Adds the test targets for the library to the Pods project with the appropriate build configurations.

@return [Array<PBXNativeTarget>] the test native targets created.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 261
def add_test_targets
  target.supported_test_types.map do |test_type|
    product_type = target.product_type_for_test_type(test_type)
    name = target.test_target_label(test_type)
    platform_name = target.platform.name
    language = target.uses_swift_for_test_type?(test_type) ? :swift : :objc
    test_native_target = project.new_target(product_type, name, platform_name, deployment_target, nil, language)
    test_native_target.product_reference.name = name

    target.user_build_configurations.each do |bc_name, type|
      test_native_target.add_build_configuration(bc_name, type)
    end

    test_native_target.build_configurations.each do |configuration|
      configuration.build_settings.merge!(custom_build_settings)
      # target_installer will automatically add an empty `OTHER_LDFLAGS`. For test
      # targets those are set via a test xcconfig file instead.
      configuration.build_settings.delete('OTHER_LDFLAGS')
      # target_installer will automatically set the product name to the module name if the target
      # requires frameworks. For tests we always use the test target name as the product name
      # irrelevant to whether we use frameworks or not.
      configuration.build_settings['PRODUCT_NAME'] = name
      # Use xcode default product module name, which is $(PRODUCT_NAME:c99extidentifier)
      # this gives us always valid name that is distinct from the parent spec module name
      # which allow tests to use either import or @testable import to access the parent framework
      configuration.build_settings.delete('PRODUCT_MODULE_NAME')
      # We must codesign iOS XCTest bundles that contain binary frameworks to allow them to be launchable in the simulator
      unless target.platform == :osx
        configuration.build_settings['CODE_SIGNING_REQUIRED'] = 'YES'
        configuration.build_settings['CODE_SIGNING_ALLOWED'] = 'YES'
      end
      # For macOS we do not code sign the XCTest bundle because we do not code sign the frameworks either.
      configuration.build_settings['CODE_SIGN_IDENTITY'] = '' if target.platform == :osx
    end

    # Test native targets also need frameworks and resources to be copied over to their xctest bundle.
    create_test_target_embed_frameworks_script(test_type)
    create_test_target_copy_resources_script(test_type)

    # Generate vanila Info.plist for test target similar to the one xcode gererates for new test target.
    # This creates valid test bundle accessible at the runtime, allowing tests to load bundle resources
    # defined in podspec.
    create_info_plist_file(target.info_plist_path_for_test_type(test_type), test_native_target, '1.0', target.platform, :bndl)

    test_native_target
  end
end
app_host_info_plist_path_for_test_type(name, test_type) click to toggle source

@param [Symbol] test_type

The test type this Info.plist path is for.

@return [Pathname] The absolute path of the Info.plist to use for an app host.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 702
def app_host_info_plist_path_for_test_type(name, test_type)
  project.path.dirname.+("#{name}/#{target.app_host_label(test_type)}-Info.plist")
end
apply_xcconfig_file_ref_to_resource_bundle_targets(resource_bundle_targets, xcconfig_file_ref) click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 592
def apply_xcconfig_file_ref_to_resource_bundle_targets(resource_bundle_targets, xcconfig_file_ref)
  resource_bundle_targets.each do |rsrc_target|
    rsrc_target.build_configurations.each do |rsrc_bc|
      rsrc_bc.base_configuration_reference = xcconfig_file_ref
    end
  end
end
compiler_flags_for_consumer(consumer, arc) click to toggle source

Returns the compiler flags for the source files of the given specification.

The following behavior is regarding the `OS_OBJECT_USE_OBJC` flag. When set to `0`, it will allow code to use `dispatch_release()` on >= iOS 6.0 and OS X 10.8.

  • New libraries that do not require ARC don’t need to care about this issue at all.

  • New libraries that do require ARC and have a deployment target of >= iOS 6.0 or OS X 10.8:

    These no longer use `dispatch_release()` and should not have the `OS_OBJECT_USE_OBJC` flag set to `0`.

    Note: this means that these libraries have to specify the

    deployment target in order to function well.
  • New libraries that do require ARC, but have a deployment target of < iOS 6.0 or OS X 10.8:

    These contain `dispatch_release()` calls and as such need the `OS_OBJECT_USE_OBJC` flag set to `1`.

    Note: libraries that do not specify a platform version are

    assumed to have a deployment target of < iOS 6.0 or OS X 10.8.
For more information, see: http://opensource.apple.com/source/libdispatch/libdispatch-228.18/os/object.h

@param [Specification::Consumer] consumer

The consumer for the specification for which the compiler flags
are needed.

@return [String] The compiler flags.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 575
def compiler_flags_for_consumer(consumer, arc)
  flags = consumer.compiler_flags.dup
  if !arc
    flags << '-fno-objc-arc'
  else
    platform_name = consumer.platform_name
    spec_deployment_target = consumer.spec.deployment_target(platform_name)
    if spec_deployment_target.nil? || Version.new(spec_deployment_target) < ENABLE_OBJECT_USE_OBJC_FROM[platform_name]
      flags << '-DOS_OBJECT_USE_OBJC=0'
    end
  end
  if target.inhibit_warnings?
    flags << '-w -Xanalyzer -analyzer-disable-all-checks'
  end
  flags * ' '
end
create_module_map(native_target) click to toggle source
Calls superclass method
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 600
def create_module_map(native_target)
  return super(native_target) unless custom_module_map

  path = target.module_map_path_to_write
  UI.message "- Copying module map file to #{UI.path(path)}" do
    contents = custom_module_map.read
    unless target.requires_frameworks?
      contents.gsub!(/^(\s*)framework\s+(module[^{}]+){/, '\1\2{')
    end
    generator = Generator::Constant.new(contents)
    update_changed_file(generator, path)
    add_file_to_support_group(path)

    linked_path = target.module_map_path
    if path != linked_path
      linked_path.dirname.mkpath
      FileUtils.ln_sf(path, linked_path)
    end

    relative_path = target.module_map_path.relative_path_from(sandbox.root).to_s
    native_target.build_configurations.each do |c|
      c.build_settings['MODULEMAP_FILE'] = relative_path.to_s
    end
  end
end
create_prefix_header(path, file_accessors, platform, native_targets) click to toggle source

Creates a prefix header file which imports `UIKit` or `Cocoa` according to the platform of the target. This file also include any prefix header content reported by the specification of the pods.

@param [Pathname] path

the path to generate the prefix header for.

@param [Array<Sandbox::FileAccessor>] file_accessors

the file accessors to use for this prefix header that point to a path of a prefix header.

@param [Platform] platform

the platform to use for this prefix header.

@param [Array<PBXNativeTarget>] native_targets

the native targets on which the prefix header should be configured for.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 520
def create_prefix_header(path, file_accessors, platform, native_targets)
  generator = Generator::PrefixHeader.new(file_accessors, platform)
  update_changed_file(generator, path)
  add_file_to_support_group(path)

  native_targets.each do |native_target|
    native_target.build_configurations.each do |c|
      relative_path = path.relative_path_from(project.path.dirname)
      c.build_settings['GCC_PREFIX_HEADER'] = relative_path.to_s
    end
  end
end
create_test_target_copy_resources_script(test_type) click to toggle source

Creates a script that copies the resources to the bundle of the test target.

@param [Symbol] test_type

The test type to create the script for.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 432
def create_test_target_copy_resources_script(test_type)
  path = target.copy_resources_script_path_for_test_type(test_type)
  pod_targets = target.all_dependent_targets
  resource_paths_by_config = target.user_build_configurations.keys.each_with_object({}) do |config, resources_by_config|
    resources_by_config[config] = pod_targets.flat_map do |pod_target|
      spec_paths_to_include = pod_target == target ? pod_target.specs.map(&:name) : pod_target.non_test_specs.map(&:name)
      pod_target.resource_paths.values_at(*spec_paths_to_include).flatten.compact
    end
  end
  generator = Generator::CopyResourcesScript.new(resource_paths_by_config, target.platform)
  update_changed_file(generator, path)
  add_file_to_support_group(path)
end
create_test_target_embed_frameworks_script(test_type) click to toggle source

Creates a script that embeds the frameworks to the bundle of the test target.

@param [Symbol] test_type

The test type to create the script for.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 453
def create_test_target_embed_frameworks_script(test_type)
  path = target.embed_frameworks_script_path_for_test_type(test_type)
  pod_targets = target.all_dependent_targets
  framework_paths_by_config = target.user_build_configurations.keys.each_with_object({}) do |config, paths_by_config|
    paths_by_config[config] = pod_targets.flat_map do |pod_target|
      spec_paths_to_include = pod_target == target ? pod_target.specs.map(&:name) : pod_target.non_test_specs.map(&:name)
      pod_target.framework_paths.values_at(*spec_paths_to_include).flatten.compact.uniq
    end
  end
  generator = Generator::EmbedFrameworksScript.new(framework_paths_by_config)
  update_changed_file(generator, path)
  add_file_to_support_group(path)
end
create_test_xcconfig_files(test_native_targets, test_resource_bundle_targets) click to toggle source

Generates the contents of the xcconfig file used for each test target type and saves it to disk.

@param [Array<PBXNativeTarget>] test_native_targets

the test native target to link the xcconfig file into.

@param [Array<PBXNativeTarget>] test_resource_bundle_targets

the additional test resource bundle targets to link the xcconfig file into.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 405
def create_test_xcconfig_files(test_native_targets, test_resource_bundle_targets)
  target.test_specs.each do |test_spec|
    spec_consumer = test_spec.consumer(target.platform)
    test_type = spec_consumer.test_type
    path = target.xcconfig_path(test_type.to_s)
    update_changed_file(Target::BuildSettings::PodTargetSettings.new(target, test_spec), path)
    xcconfig_file_ref = add_file_to_support_group(path)

    test_native_targets.each do |test_target|
      test_target.build_configurations.each do |test_target_bc|
        test_target_swift_debug_hack(test_target_bc)
        test_target_bc.base_configuration_reference = xcconfig_file_ref
      end
    end

    # also apply the private config to resource bundle test targets.
    apply_xcconfig_file_ref_to_resource_bundle_targets(test_resource_bundle_targets, xcconfig_file_ref)
  end
end
create_umbrella_header(native_target) click to toggle source
Calls superclass method
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 637
def create_umbrella_header(native_target)
  return super(native_target) unless custom_module_map
end
create_xcconfig_file(native_target, resource_bundle_targets) click to toggle source

Generates the contents of the xcconfig file and saves it to disk.

@param [PBXNativeTarget] native_target

the native target to link the xcconfig file into.

@param [Array<PBXNativeTarget>] resource_bundle_targets

the additional resource bundle targets to link the xcconfig file into.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 382
def create_xcconfig_file(native_target, resource_bundle_targets)
  path = target.xcconfig_path
  update_changed_file(target.build_settings, path)
  xcconfig_file_ref = add_file_to_support_group(path)

  native_target.build_configurations.each do |c|
    c.base_configuration_reference = xcconfig_file_ref
  end

  # also apply the private config to resource bundle targets.
  apply_xcconfig_file_ref_to_resource_bundle_targets(resource_bundle_targets, xcconfig_file_ref)
end
custom_build_settings() click to toggle source

Remove the default headers folder path settings for static library pod targets.

@return [Hash{String => String}]

Calls superclass method
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 133
def custom_build_settings
  settings = super
  unless target.requires_frameworks?
    settings['PRIVATE_HEADERS_FOLDER_PATH'] = ''
    settings['PUBLIC_HEADERS_FOLDER_PATH'] = ''
  end

  settings['PRODUCT_NAME'] = target.product_basename
  settings['PRODUCT_MODULE_NAME'] = target.product_module_name

  settings['CODE_SIGN_IDENTITY[sdk=appletvos*]'] = ''
  settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = ''
  settings['CODE_SIGN_IDENTITY[sdk=watchos*]'] = ''

  settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = '$(inherited) '

  if target.swift_version
    settings['SWIFT_VERSION'] = target.swift_version
  end

  settings
end
custom_module_map() click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 641
def custom_module_map
  @custom_module_map ||= target.file_accessors.first.module_map
end
filter_resource_file_references(resource_file_references) { |resources_phase_refs, compile_phase_refs| ... } click to toggle source

Filters the given resource file references discarding empty paths which are added by their parent directory. This will also include references to the parent [PBXVariantGroup] for all resources underneath it.

@param [Array<Pathname>] resource_file_references

The array of all resource file references to filter.

@yield_param [Array<PBXFileReference>} The filtered resource file references to be installed

in the copy resources phase.

@yield_param [Array<PBXFileReference>} The filtered resource file references to be installed

in the compile sources phase.

@note Core Data model directories (.xcdatamodeld) used to be added to the

`Copy Resources` build phase like all other resources, since they would
compile correctly in either the resources or compile phase. In recent
versions of xcode, there's an exception for data models that generate
headers. These need to be added to the compile sources phase of a real
target for the headers to be built in time for code in the target to
use them. These kinds of models generally break when added to resource
bundles.
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 178
def filter_resource_file_references(resource_file_references)
  file_references = resource_file_references.map do |resource_file_reference|
    ref = project.reference_for_path(resource_file_reference)

    # Some nested files are not directly present in the Xcode project, such as the contents
    # of an .xcdatamodeld directory. These files are implicitly included by including their
    # parent directory.
    next if ref.nil?

    # For variant groups, the variant group itself is added, not its members.
    next ref.parent if ref.parent.is_a?(Xcodeproj::Project::Object::PBXVariantGroup)

    ref
  end.compact.uniq
  compile_phase_matcher = lambda { |ref| !(ref.path =~ /.*\.xcdatamodeld/i).nil? }
  resources_phase_refs = file_references.reject(&compile_phase_matcher)
  compile_phase_refs = file_references.select(&compile_phase_matcher)
  yield resources_phase_refs, compile_phase_refs
end
header_mappings_dir() click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 653
def header_mappings_dir
  return @header_mappings_dir if defined?(@header_mappings_dir)
  file_accessor = target.file_accessors.first
  @header_mappings_dir = if dir = file_accessor.spec_consumer.header_mappings_dir
                           file_accessor.path_list.root + dir
                         end
end
module_map_additional_headers() click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 626
def module_map_additional_headers
  return [] unless umbrella_header_paths

  other_paths = umbrella_header_paths - [target.umbrella_header_path]
  other_paths.map do |module_map_path|
    # exclude other targets umbrella headers, to avoid
    # incomplete umbrella warnings
    Generator::ModuleMap::Header.new(module_map_path.basename, nil, nil, nil, true)
  end
end
project_file_references_array(files, file_type) click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 645
def project_file_references_array(files, file_type)
  files.map do |sf|
    project.reference_for_path(sf).tap do |ref|
      raise Informative, "Unable to find #{file_type} ref for #{sf} for target #{target.name}." unless ref
    end
  end
end
skip_info_plist?(native_target) click to toggle source

True if info.plist generation should be skipped

@param [PXNativeTarget] native_target

@return [Boolean] Whether the target should build an Info.plist file

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 122
def skip_info_plist?(native_target)
  return true if target.static_framework?
  existing_setting = native_target.resolved_build_setting('INFOPLIST_FILE', true).values.compact
  !existing_setting.empty?
end
skip_pch?(specs) click to toggle source

@param [Array<Specification>] specs

the specs to check against whether `.pch` generation should be skipped or not.

@return [Boolean] Whether the target should build a pch file.

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 112
def skip_pch?(specs)
  specs.any? { |spec| spec.prefix_header_file.is_a?(FalseClass) }
end
support_files_group() click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 688
def support_files_group
  pod_name = target.pod_name
  dir = target.support_files_dir
  project.pod_support_files_group(pod_name, dir)
end
test_native_target_from_spec_consumer(spec_consumer, test_native_targets) click to toggle source
# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 706
def test_native_target_from_spec_consumer(spec_consumer, test_native_targets)
  test_native_targets.find do |native_target|
    native_target.symbol_type == target.product_type_for_test_type(spec_consumer.test_type)
  end
end
test_target_swift_debug_hack(test_target_bc) click to toggle source

Manually add `libswiftSwiftOnoneSupport.dylib` as it seems there is an issue with tests that do not include it for Debug configurations. Possibly related to Swift module optimization.

@return [void]

# File lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb, line 472
def test_target_swift_debug_hack(test_target_bc)
  return unless test_target_bc.debug?
  return unless target.all_dependent_targets.any?(&:uses_swift?)
  ldflags = test_target_bc.build_settings['OTHER_LDFLAGS'] ||= '$(inherited)'
  ldflags << ' -lswiftSwiftOnoneSupport'
end