Sha256: f09029fbabafeec1e1bbc2b71a2ff6cfd4e0ef018a3c9fef9e3cda241cefb9d6

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

module Symbols
  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 += variables_from_symbols(syms)

    result.reject { |e| e == 'llvm.cmdline' || e == 'llvm.embedded.module' }
  end

  module_function :symbols_from_library

  private

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

  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

  def variables_from_symbols(syms)
    variables = syms.select { |variable| variable[/ D /] }
    variables = variables.select { |variable| variable !~ /l_OBJC|\.eh/ }
    variables = variables.uniq
    variables.map! { |variable| variable.gsub(/^.* _/, '') }
  end

  module_function :classes_from_symbols
  module_function :constants_from_symbols
  module_function :variables_from_symbols
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ty-cocoapods-packager-1.5.13 lib/cocoapods-packager/symbols.rb
ty-cocoapods-packager-1.5.12 lib/cocoapods-packager/symbols.rb
ty-cocoapods-packager-1.5.11 lib/cocoapods-packager/symbols.rb
ty-cocoapods-packager-1.5.10 lib/cocoapods-packager/symbols.rb
ty-cocoapods-packager-1.5.9 lib/cocoapods-packager/symbols.rb
ty-cocoapods-packager-1.5.7 lib/cocoapods-packager/symbols.rb