Class: Pod::Generator::XCConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/generator/xcconfig.rb

Overview

Generates an xcconfig file for each target of the Pods project. The configuration file should be used by the user target as well.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, spec_consumers, relative_pods_root) ⇒ XCConfig

Returns a new instance of XCConfig.

Parameters:

  • sandbox (Sandbox)

    @see sandbox

  • pods (Array<LocalPod>)

    @see pods

  • relative_pods_root (String)

    @see relative_pods_root



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

def initialize(sandbox, spec_consumers, relative_pods_root)
  @sandbox = sandbox
  @spec_consumers = spec_consumers
  @relative_pods_root = relative_pods_root
end

Instance Attribute Details

#relative_pods_rootString (readonly)

Returns the relative path of the Pods root respect the user project that should be integrated by this library.

Returns:

  • (String)

    the relative path of the Pods root respect the user project that should be integrated by this library.



21
22
23
# File 'lib/cocoapods/generator/xcconfig.rb', line 21

def relative_pods_root
  @relative_pods_root
end

#sandboxSandbox (readonly)

Returns the sandbox where the Pods project is installed.

Returns:

  • (Sandbox)

    the sandbox where the Pods project is installed.



11
12
13
# File 'lib/cocoapods/generator/xcconfig.rb', line 11

def sandbox
  @sandbox
end

#set_arc_compatibility_flagBool

Returns whether the Podfile specifies to add the ‘-fobjc-arc` flag for compatibility.

Returns:

  • (Bool)

    whether the Podfile specifies to add the ‘-fobjc-arc` flag for compatibility.



36
37
38
# File 'lib/cocoapods/generator/xcconfig.rb', line 36

def set_arc_compatibility_flag
  @set_arc_compatibility_flag
end

#spec_consumersArray<Specification::Consumer> (readonly)

Returns the consumers for the specifications of the library which needs the xcconfig.

Returns:

  • (Array<Specification::Consumer>)

    the consumers for the specifications of the library which needs the xcconfig.



16
17
18
# File 'lib/cocoapods/generator/xcconfig.rb', line 16

def spec_consumers
  @spec_consumers
end

#xcconfigXcodeproj::Config (readonly)

Returns The generated xcconfig.

Returns:

  • (Xcodeproj::Config)

    The generated xcconfig.



73
74
75
# File 'lib/cocoapods/generator/xcconfig.rb', line 73

def xcconfig
  @xcconfig
end

Class Method Details

.pods_project_settingsHash

Returns The settings of the xcconfig that the Pods project needs to override.

Returns:

  • (Hash)

    The settings of the xcconfig that the Pods project needs to override.



78
79
80
81
# File 'lib/cocoapods/generator/xcconfig.rb', line 78

def self.pods_project_settings
  { 'PODS_ROOT' => '${SRCROOT}',
    'PODS_HEADERS_SEARCH_PATHS' => '${PODS_BUILD_HEADERS_SEARCH_PATHS}' }
end

Instance Method Details

#generateXcodeproj::Config

Note:

The value ‘PODS_HEADERS_SEARCH_PATHS` is used to store the headers so xcconfig can reference the variable.

Generates the xcconfig for the library.

Returns:

  • (Xcodeproj::Config)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cocoapods/generator/xcconfig.rb', line 47

def generate
  ld_flags = '-ObjC'
  if  set_arc_compatibility_flag && spec_consumers.any? { |consumer| consumer.requires_arc }
    ld_flags << ' -fobjc-arc'
  end

  @xcconfig = Xcodeproj::Config.new({
    'ALWAYS_SEARCH_USER_PATHS'         => 'YES',
    'OTHER_LDFLAGS'                    => ld_flags,
    'HEADER_SEARCH_PATHS'              => '${PODS_HEADERS_SEARCH_PATHS}',
    'PODS_ROOT'                        => relative_pods_root,
    'PODS_HEADERS_SEARCH_PATHS'        => '${PODS_PUBLIC_HEADERS_SEARCH_PATHS}',
    'PODS_BUILD_HEADERS_SEARCH_PATHS'  => quote(sandbox.build_headers.search_paths),
    'PODS_PUBLIC_HEADERS_SEARCH_PATHS' => quote(sandbox.public_headers.search_paths),
    'GCC_PREPROCESSOR_DEFINITIONS'     => '$(inherited) COCOAPODS=1'
  })

  spec_consumers.each do |consumer|
    add_spec_build_settings_to_xcconfig(consumer, @xcconfig)
  end

  @xcconfig
end

#save_as(path) ⇒ void

This method returns an undefined value.

Generates and saves the xcconfig to the given path.

Parameters:

  • path (Pathname)

    the path where the prefix header should be stored.



90
91
92
# File 'lib/cocoapods/generator/xcconfig.rb', line 90

def save_as(path)
  path.open('w') { |file| file.write(generate) }
end