Module: Symbols

Defined in:
lib/cocoapods-packager/mangle.rb,
lib/cocoapods-packager/symbols.rb

Class Method Summary collapse

Class Method Details

.alias_symbol(sym, pod_name) ⇒ Object



26
27
28
29
# File 'lib/cocoapods-packager/mangle.rb', line 26

def alias_symbol(sym, pod_name)
  pod_name = pod_name.tr('-', '_')
  sym + "=Pod#{pod_name}_" + sym
end

.classes_from_symbols(syms) ⇒ Object



21
22
23
24
25
# File 'lib/cocoapods-packager/symbols.rb', line 21

def classes_from_symbols(syms)
  classes = syms.select { |klass| klass[/OBJC_CLASS_\$_/] }
  classes = classes.uniq
  classes.map! { |klass| klass.gsub(/^.*\$_/, '') }
end

.constants_from_symbols(syms) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cocoapods-packager/symbols.rb', line 27

def constants_from_symbols(syms)
  consts = syms.select { |const| const[/ S /] }
  consts = consts.select { |const| const !~ /OBJC|\.eh/ }
  consts = consts.uniq
  consts = consts.map! { |const| const.gsub(/^.* _/, '') }

  other_consts = syms.select { |const| const[/ T /] }
  other_consts = other_consts.uniq
  other_consts = other_consts.map! { |const| const.gsub(/^.* _/, '') }

  consts + other_consts
end

.mangle_for_pod_dependencies(pod_name, sandbox_root) ⇒ Object

performs symbol aliasing

for each dependency: - determine symbols for classes and global constants - alias each symbol to Pod#pod_name_#symbol - put defines into ‘GCC_PREPROCESSOR_DEFINITIONS` for passing to Xcode



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cocoapods-packager/mangle.rb', line 10

def mangle_for_pod_dependencies(pod_name, sandbox_root)
  pod_libs = Dir.glob("#{sandbox_root}/build/lib*.a").select do |file|
    file !~ /lib#{pod_name}.a$/
  end

  dummy_alias = alias_symbol "PodsDummy_#{pod_name}", pod_name
  all_syms = [dummy_alias]

  pod_libs.each do |pod_lib|
    syms = Symbols.symbols_from_library(pod_lib)
    all_syms += syms.map! { |sym| alias_symbol sym, pod_name }
  end

  "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) #{all_syms.uniq.join(' ')}'"
end

.symbols_from_library(library) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cocoapods-packager/symbols.rb', line 2

def symbols_from_library(library)
  syms = `nm -defined-only -extern-only #{library}`.split("\n")
  result = classes_from_symbols(syms)
  result += constants_from_symbols(syms)

  result.select do |e|
    case e
    when 'llvm.cmdline', 'llvm.embedded.module', '__clang_at_available_requires_core_foundation_framework'
      false
    else
      true
    end
  end
end