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_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.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 101

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
      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 the build settings for the given framework path.

Parameters:

  • framework_path (Pathanme)

    The path of the framework.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



62
63
64
65
66
67
68
69
70
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 62

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_library_build_settings(library_path, xcconfig, sandbox_root) ⇒ Object

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

Parameters:

  • framework_path (Pathanme)

    The path of the framework.

  • xcconfig (Xcodeproj::Config)

    The xcconfig to edit.



81
82
83
84
85
86
87
88
89
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 81

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_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.



45
46
47
48
49
50
51
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 45

def self.add_spec_build_settings_to_xcconfig(consumer, xcconfig)
  xcconfig.merge!(consumer.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

.default_ld_flags(target) ⇒ String

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

Returns:

  • (String)

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



27
28
29
30
31
32
33
34
# File 'lib/cocoapods/generator/xcconfig/xcconfig_helper.rb', line 27

def self.default_ld_flags(target)
  ld_flags = '-ObjC'
  if target.target_definition.podfile.set_arc_compatibility_flag? &&
    target.spec_consumers.any?(&:requires_arc?)
    ld_flags << ' -fobjc-arc'
  end
  ld_flags
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.

  • optional (String)

    prefix, such as a flag or option.

Returns:

  • (String)

    the resulting string.



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

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