Class: CocoapodsMangle::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods_mangle/config.rb

Overview

Manages xcconfig files for configuring mangling.

Constant Summary collapse

MANGLING_DEFINES_XCCONFIG_KEY =
'MANGLING_DEFINES'
MANGLED_SPECS_CHECKSUM_XCCONFIG_KEY =
'MANGLED_SPECS_CHECKSUM'

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Config

Returns a new instance of Config.

Parameters:



13
14
15
# File 'lib/cocoapods_mangle/config.rb', line 13

def initialize(context)
  @context = context
end

Instance Method Details

#needs_update?Truthy

Does the mangling xcconfig need to be updated?

Returns:

  • (Truthy)

    Does the xcconfig need to be updated?



42
43
44
45
46
47
48
# File 'lib/cocoapods_mangle/config.rb', line 42

def needs_update?
  return true unless File.exist?(@context.xcconfig_path)
  xcconfig_hash = Xcodeproj::Config.new(File.new(@context.xcconfig_path)).to_hash
  needs_update = xcconfig_hash[MANGLED_SPECS_CHECKSUM_XCCONFIG_KEY] != @context.specs_checksum
  Pod::UI.message '- Mangling config already up to date' unless needs_update
  needs_update
end

#update_mangling!Object

Update the mangling xcconfig file with new mangling defines



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cocoapods_mangle/config.rb', line 18

def update_mangling!
  Pod::UI.message '- Updating mangling xcconfig' do
    builder = Builder.new(@context.pods_project_path, @context.pod_target_labels)
    builder.build!

    defines = Defines.mangling_defines(@context.mangle_prefix, builder.binaries_to_mangle)

    contents = "      // This config file is automatically generated any time Podfile.lock changes\n      // Changes should be committed to git along with Podfile.lock\n\n      \#{MANGLING_DEFINES_XCCONFIG_KEY} = \#{defines.join(' ')}\n\n      // This checksum is used to ensure mangling is up to date\n      \#{MANGLED_SPECS_CHECKSUM_XCCONFIG_KEY} = \#{@context.specs_checksum}\n    MANGLE_XCCONFIG\n\n    Pod::UI.message \"- Writing '\#{File.basename(@context.xcconfig_path)}'\"\n    File.open(@context.xcconfig_path, 'w') { |xcconfig| xcconfig.write(contents) }\n  end\nend\n"

#update_pod_xcconfig_for_mangling!(pod_xcconfig_path) ⇒ Object

Update a mangling config to use the mangling defines

Parameters:

  • pod_xcconfig_path (String)

    Path to the pod xcconfig to update



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/cocoapods_mangle/config.rb', line 63

def update_pod_xcconfig_for_mangling!(pod_xcconfig_path)
  mangle_xcconfig_include = "#include \"#{@context.xcconfig_path}\"\n"

  gcc_preprocessor_defs = File.readlines(pod_xcconfig_path).select { |line| line =~ /GCC_PREPROCESSOR_DEFINITIONS/ }.first
  gcc_preprocessor_defs.strip!

  xcconfig_contents = File.read(pod_xcconfig_path)
  # import the mangling config
  new_xcconfig_contents = mangle_xcconfig_include + xcconfig_contents
  # update GCC_PREPROCESSOR_DEFINITIONS to include mangling
  new_xcconfig_contents.sub!(gcc_preprocessor_defs, gcc_preprocessor_defs + " $(#{MANGLING_DEFINES_XCCONFIG_KEY})")
  File.open(pod_xcconfig_path, 'w') { |pod_xcconfig| pod_xcconfig.write(new_xcconfig_contents) }
end

#update_pod_xcconfigs_for_mangling!Object

Update all pod xcconfigs to use the mangling defines



51
52
53
54
55
56
57
58
# File 'lib/cocoapods_mangle/config.rb', line 51

def update_pod_xcconfigs_for_mangling!
  Pod::UI.message '- Updating Pod xcconfig files' do
    @context.pod_xcconfig_paths.each do |pod_xcconfig_path|
      Pod::UI.message "- Updating '#{File.basename(pod_xcconfig_path)}'"
      update_pod_xcconfig_for_mangling!(pod_xcconfig_path)
    end
  end
end