Class: ObjcDependenciesGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/objc/objc_dependencies_generator.rb

Instance Method Summary collapse

Instance Method Details

#dwarfdump_tag_pointers_in_file(filename) ⇒ Object



60
61
62
63
64
# File 'lib/objc/objc_dependencies_generator.rb', line 60

def dwarfdump_tag_pointers_in_file(filename)
  IO.popen("dwarfdump \"#{filename.strip}\" | grep -A1 TAG_pointer_type") { |fd|
    fd.each { |line| yield line }
  }
end

#generate_dependencies(object_files_dir, include_dwarf_info) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/objc/objc_dependencies_generator.rb', line 3

def generate_dependencies(object_files_dir, include_dwarf_info)

  #Searching all the .o files and showing its information through nm call
  symbol_names_in_files_in_dir(object_files_dir) do |line|
    # See of output here
    # https://gist.github.com/PaulTaykalo/8d2618ea9741ea772004

    # Capturing filename as a source and class name as the dest
    match = /[^\w]*([^\.\/]+)\.o.*_OBJC_CLASS_\$_(.*)/.match(line)
    next unless match

    source, dest = match[1, 2]

    yield source, dest
  end

  return unless include_dwarf_info

  object_files_in_dir(object_files_dir) do |filename|

    source = /.*\/(.+)\.o/.match(filename)[1]
    yield source, nil

    # Full output example https://gist.github.com/PaulTaykalo/62cd5d545301c8355cb5
    # With grep output example https://gist.github.com/PaulTaykalo/9d5ecbce8a30a412cdbe
    dwarfdump_tag_pointers_in_file(filename) do |tag_pointer_line|

      # Finding the name in types
      # AT_type( {0x00000456} ( objc_object ) )
      tag_pointer_for_class = /.*?AT_type\(\s\{.*?\}.*\(\s((function|const)\s)?([A-Z][^\)]+?)\*?\s\).*/.match(tag_pointer_line)
      next unless tag_pointer_for_class

      dest = tag_pointer_for_class[3]

      yield source, dest
    end
  end
end

#object_files_in_dir(object_files_dirs) ⇒ Object



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

def object_files_in_dir(object_files_dirs)
  dirs = Array(object_files_dirs)
  dirs.each do |dir|
    IO.popen("find \"#{dir}\" -name \"*.o\"") { |f|
      f.each { |line| yield line }
    }
  end  
end

#symbol_names_in_files_in_dir(object_files_dirs) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/objc/objc_dependencies_generator.rb', line 42

def symbol_names_in_files_in_dir(object_files_dirs)
  dirs = Array(object_files_dirs)
  dirs.each do |dir|
    IO.popen("find \"#{dir}\" -name \"*.o\" -exec /usr/bin/nm -o {} \\;") { |f|
      f.each { |line| yield line }
    }
  end  
end