Module: Pod::Generator::XCConfig::XCConfigHelper

Defined in:
lib/cocoapods/generator/xcconfig/xcconfig_helper.rb

Overview

Stores the shared logic of the classes of the XCConfig module.

Class Method Summary collapse

Class Method Details

.add_code_signing_settings(target, xcconfig) ⇒ Object

Add the code signing settings for generated targets to ensure that frameworks are correctly signed to be integrated and re-signed when building the application and embedding the framework

Parameters:

  • target (Target)

    The target.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



135
136
137
138
139
140
141
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 135

def self.add_code_signing_settings(target, xcconfig)
  build_settings = {}
  if target.platform.to_sym == :osx
    build_settings['CODE_SIGN_IDENTITY'] = ''
  end
  xcconfig.merge!(build_settings)
end

.add_developers_frameworks_if_needed(xcconfig, platform) ⇒ void

This method returns an undefined value.

Adds the search paths of the developer frameworks to the specification if needed. This is done because the ‘SenTestingKit` requires them and adding them to each specification which requires it is repetitive and error prone.

Parameters:

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 187

def self.add_developers_frameworks_if_needed(xcconfig, platform)
  matched_frameworks = xcconfig.frameworks & %w(XCTest SenTestingKit)
  unless matched_frameworks.empty?
    search_paths = xcconfig.attributes['FRAMEWORK_SEARCH_PATHS'] ||= ''
    search_paths_to_add = []
    search_paths_to_add << '$(inherited)'
    if platform == :ios || platform == :watchos
      search_paths_to_add << '"$(SDKROOT)/Developer/Library/Frameworks"'
    else
      search_paths_to_add << '"$(DEVELOPER_LIBRARY_DIR)/Frameworks"'
    end
    frameworks_path = '"$(PLATFORM_DIR)/Developer/Library/Frameworks"'
    search_paths_to_add << frameworks_path
    search_paths_to_add.each do |search_path|
      unless search_paths.include?(search_path)
        search_paths << ' ' unless search_paths.empty?
        search_paths << search_path
      end
    end
    search_paths
  end
end

.add_framework_build_settings(framework_path, xcconfig, sandbox_root) ⇒ Object

Configures the given Xcconfig with the build settings for the given framework path.

Parameters:

  • framework_path (Pathname)

    The path of the framework.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.

  • sandbox_root (Pathname)

    The path retrieved from Sandbox#root.



93
94
95
96
97
98
99
100
101
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 93

def self.add_framework_build_settings(framework_path, xcconfig, sandbox_root)
  name = File.basename(framework_path, '.framework')
  dirname = '$(PODS_ROOT)/' + framework_path.dirname.relative_path_from(sandbox_root).to_s
  build_settings = {
    'OTHER_LDFLAGS' => "-framework #{name}",
    'FRAMEWORK_SEARCH_PATHS' => quote([dirname]),
  }
  xcconfig.merge!(build_settings)
end

.add_language_specific_settings(target, xcconfig) ⇒ Object

Checks if the given target requires language specific settings and configures the given Xcconfig.

Parameters:

  • target (Target)

    The target.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



168
169
170
171
172
173
174
175
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 168

def self.add_language_specific_settings(target, xcconfig)
  if target.uses_swift?
    build_settings = {
      'OTHER_SWIFT_FLAGS' => '$(inherited) ' + quote(%w(-D COCOAPODS)),
    }
    xcconfig.merge!(build_settings)
  end
end

.add_library_build_settings(library_path, xcconfig, sandbox_root) ⇒ Object

Configures the given Xcconfig with the build settings for the given library path.

Parameters:

  • library_path (Pathname)

    The path of the library.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.

  • sandbox_root (Pathname)

    The path retrieved from Sandbox#root.



115
116
117
118
119
120
121
122
123
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 115

def self.add_library_build_settings(library_path, xcconfig, sandbox_root)
  name = File.basename(library_path, '.a').sub(/\Alib/, '')
  dirname = '$(PODS_ROOT)/' + library_path.dirname.relative_path_from(sandbox_root).to_s
  build_settings = {
    'OTHER_LDFLAGS' => "-l#{name}",
    'LIBRARY_SEARCH_PATHS' => quote([dirname]),
  }
  xcconfig.merge!(build_settings)
end

.add_settings_for_file_accessors_of_target(target, xcconfig) ⇒ Object

Configures the given Xcconfig

Parameters:

  • target (PodTarget)

    The pod target, which holds the list of Spec::FileAccessor.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 52

def self.add_settings_for_file_accessors_of_target(target, xcconfig)
  target.file_accessors.each do |file_accessor|
    XCConfigHelper.add_spec_build_settings_to_xcconfig(file_accessor.spec_consumer, xcconfig)
    file_accessor.vendored_frameworks.each do |vendored_framework|
      XCConfigHelper.add_framework_build_settings(vendored_framework, xcconfig, target.sandbox.root)
    end
    file_accessor.vendored_libraries.each do |vendored_library|
      XCConfigHelper.add_library_build_settings(vendored_library, xcconfig, target.sandbox.root)
    end
  end
end

.add_spec_build_settings_to_xcconfig(consumer, xcconfig) ⇒ Object

Configures the given Xcconfig according to the build settings of the given Specification.

Parameters:

  • consumer (Specification::Consumer)

    The consumer of the specification.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



73
74
75
76
77
78
79
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 73

def self.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
  xcconfig.merge!(consumer.pod_target_xcconfig)
  xcconfig.libraries.merge(consumer.libraries)
  xcconfig.frameworks.merge(consumer.frameworks)
  xcconfig.weak_frameworks.merge(consumer.weak_frameworks)
  add_developers_frameworks_if_needed(xcconfig, consumer.platform_name)
end

.add_target_specific_settings(target, xcconfig) ⇒ Object

Checks if the given target requires specific settings and configures the given Xcconfig.

Parameters:

  • target (Target)

    The target.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



152
153
154
155
156
157
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 152

def self.add_target_specific_settings(target, xcconfig)
  if target.requires_frameworks?
    add_code_signing_settings(target, xcconfig)
  end
  add_language_specific_settings(target, xcconfig)
end

.default_ld_flags(target, includes_static_libraries = false) ⇒ String

Return the default linker flags

Parameters:

  • target (Target)

    the target, which is used to check if the ARC compatibility flag is required.

Returns:

  • (String)

    the default linker flags. ‘-ObjC` is always included while `-fobjc-arc` is included only if requested in the Podfile.



34
35
36
37
38
39
40
41
42
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 34

def self.default_ld_flags(target, includes_static_libraries = false)
  ld_flags = ''
  ld_flags << '-ObjC' if includes_static_libraries
  if target.podfile.set_arc_compatibility_flag? &&
      target.spec_consumers.any?(&:requires_arc?)
    ld_flags << ' -fobjc-arc'
  end
  ld_flags.strip
end

.quote(strings, prefix = nil) ⇒ String

Converts an array of strings to a single string where the each string is surrounded by double quotes and separated by a space. Used to represent strings in a xcconfig file.

Parameters:

  • strings (Array<String>)

    a list of strings.

  • prefix (String) (defaults to: nil)

    optional prefix, such as a flag or option.

Returns:

  • (String)

    the resulting string.



19
20
21
22
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 19

def self.quote(strings, prefix = nil)
  prefix = "#{prefix} " if prefix
  strings.sort.map { |s| %W(          #{prefix}"#{s}"          ) }.join(' ')
end