linkmap_ios 0.1.0.pre.add.pre.obj.pre.detail

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9872bf32e4c04a1333405996812e0d7265fbf7f
4
+ data.tar.gz: 5c338823c5f290531175f7d664e2224742b91d71
5
+ SHA512:
6
+ metadata.gz: 9588cf725c5f1885906f628ccd6a9c8b5185325091f5a662375524fab7680877ae3de541fb395f0f6964649fa5e6245348884a95eef120b486b14178de1932fc
7
+ data.tar.gz: ad6a7e5fe6df9f4e113fe674267735214a35727ab86209398d3f2daa19f380c8e06cae673cffbe4e9055733c356bab8cdae6d8b45a59bd43f60a53cd94ca80eb
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .DS_Store
2
+
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.1.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in linkmap_ios.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jesse Luo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Linkmap for iOS
2
+ A ruby library to parse linkmap file generated by Xcode. Then ouput result with hash, json or report. Also have a command line tool.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'linkmap_ios'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install linkmap_ios
19
+
20
+ ## Usage
21
+ ```
22
+ linkmap_ios parse [LINKMAP FILE PATH]
23
+
24
+ Options:
25
+ -f, [--format=FORMAT]
26
+ # Possible values: hash, json, report
27
+ -o, [--output-path=OUTPUT_PATH]
28
+
29
+ Parse link map file and output. Will output Ruby Hash by default
30
+ ```
31
+ #### Note
32
+ Byte is the default unit in all kind of output.
33
+
34
+ ## Release Note
35
+ ### [0.1.0-add-obj-detail]2017-04-10
36
+
37
+ 1. add obj file size detail to hash and json report
38
+
39
+ ### [0.1.0] 2016-08-09
40
+ 1. Finish all base functions
41
+
42
+ ## TODO
43
+ 1. Add test specs
44
+ 2. Add sections analysis
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jesseluo/linkmap_ios.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "linkmap_ios"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/linkmap_ios ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "linkmap_ios"
5
+ require "csv"
6
+ require "thor"
7
+
8
+ module LinkmapIos
9
+ class CLI < Thor
10
+ desc "parse [LINKMAP FILE PATH]", "Parse link map file and output. Will output Ruby Hash by default"
11
+ # method_option :path, :type => :string, :required => true, :aliases => "-i"
12
+ method_option :format, :type => :string, :enum => %w{hash json report csv}, :aliases => "-f"
13
+ method_option :output_path, :type => :string, :aliases => "-o"
14
+ def parse(path)
15
+ puts "Start parsing. Link map file size is #{File.size(path)}"
16
+ start_time = Time.now
17
+
18
+ format = (options.format or 'hash')
19
+
20
+ if format.eql? 'csv'
21
+ output = LinkmapIos::LinkmapParser.new(path).hash
22
+ puts "Parse file done. Time used: #{Time.now - start_time}s"
23
+
24
+ CSV.open(options.output_path, "wb") do |csv|
25
+ csv << ['total size', output[:total]]
26
+ output[:detail].each do |lib|
27
+ csv << [lib[:library], lib[:size]]
28
+ end
29
+ end
30
+
31
+ return
32
+ end
33
+
34
+ output = LinkmapIos::LinkmapParser.new(path).send(format)
35
+
36
+ puts "Parse file done. Time used: #{Time.now - start_time}s"
37
+ start_time = Time.now
38
+
39
+ if options.output_path
40
+ File.write(options.output_path, output)
41
+ puts "Write file done. Time used: #{Time.now - start_time}s"
42
+ else
43
+ puts output
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ LinkmapIos::CLI.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module LinkmapIos
2
+ VERSION = "0.1.0-add-obj-detail"
3
+ end
@@ -0,0 +1,138 @@
1
+ require "linkmap_ios/version"
2
+ require "filesize"
3
+ require "json"
4
+
5
+ module LinkmapIos
6
+ Library = Struct.new(:name, :size, :objects)
7
+
8
+ class LinkmapParser
9
+ attr_reader :id_map
10
+ attr_reader :library_map
11
+
12
+ def initialize(file_path)
13
+ @file_path = file_path
14
+ @id_map = {}
15
+ @library_map = {}
16
+ end
17
+
18
+ def hash
19
+ # Cache
20
+ return @result_hash if @result_hash
21
+
22
+ parse
23
+
24
+ total_size = @library_map.values.map(&:size).inject(:+)
25
+ detail = @library_map.values.map do |lib|
26
+ {
27
+ :library => lib.name,
28
+ :size => lib.size,
29
+ :objects => lib.objects.map do |o|
30
+ {@id_map[o][:object].to_sym => @id_map[o][:size]}
31
+ end
32
+ }
33
+ end
34
+ # puts total_size
35
+ # puts detail
36
+
37
+ @result_hash = {:total => total_size, :detail => detail}
38
+ @result_hash
39
+ end
40
+
41
+ def json
42
+ JSON.pretty_generate(hash)
43
+ end
44
+
45
+ def report
46
+ result = hash
47
+
48
+ report = "# Total size\n"
49
+ report << "#{Filesize.from(result[:total].to_s + 'B').pretty}\n"
50
+ report << "\n# Library detail\n"
51
+ result[:detail].sort_by { |h| h[:size] }.reverse.each do |lib|
52
+ report << "#{lib[:library]} #{Filesize.from(lib[:size].to_s + 'B').pretty}\n"
53
+ end
54
+ report << "\n# Object detail\n"
55
+ @id_map.each_value do |id_info|
56
+ report << "#{id_info[:object]} #{Filesize.from(id_info[:size].to_s + 'B').pretty}\n"
57
+ end
58
+
59
+ report
60
+ end
61
+
62
+ private
63
+
64
+ def parse
65
+ File.foreach(@file_path).with_index do |line, line_num|
66
+ begin
67
+ # Deal with string like 
68
+ unless line.valid_encoding?
69
+ line = line.encode("UTF-16", :invalid => :replace, :replace => "?").encode('UTF-8')
70
+ # puts "#{line_num}: #{line}"
71
+ end
72
+
73
+ if line.include? "#"
74
+ if line.include? "# Object files:"
75
+ @subparser = :parse_object_files
76
+ elsif line.include? "# Sections:"
77
+ @subparser = :parse_sections
78
+ elsif line.include? "# Symbols:"
79
+ @subparser = :parse_symbols
80
+ end
81
+ else
82
+ send(@subparser, line)
83
+ end
84
+ rescue => e
85
+ puts "Exception on Link map file line #{line_num}. Content is"
86
+ puts line
87
+ raise e
88
+ end
89
+ end
90
+
91
+ # puts @id_map
92
+ # puts @library_map
93
+ end
94
+
95
+ def parse_object_files(text)
96
+ if text =~ /\[(.*)\].*\/(.*)\((.*)\)/
97
+ # Sample:
98
+ # [ 6] SomePath/Release-iphoneos/ReactiveCocoa/libReactiveCocoa.a(MKAnnotationView+RACSignalSupport.o)
99
+ # So $1 is id. $2 is library
100
+ id = $1.to_i
101
+ @id_map[id] = {:library => $2, :object => $3}
102
+
103
+ library = (@library_map[$2] or Library.new($2, 0, []))
104
+ library.objects << id
105
+ @library_map[$2] = library
106
+ elsif text =~ /\[(.*)\].*\/(.*)/
107
+ # Sample:
108
+ # System
109
+ # [100] /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.3.sdk/System/Library/Frameworks//UIKit.framework/UIKit.tbd
110
+ # Main
111
+ # [ 3] /SomePath/Release-iphoneos/CrashDemo.build/Objects-normal/arm64/AppDelegate.o
112
+ id = $1.to_i
113
+ lib = $2.end_with?('.tbd') ? 'System' : 'Main'
114
+ @id_map[id] = {:library => lib, :object => $2}
115
+
116
+ library = (@library_map[lib] or Library.new(lib, 0, []))
117
+ library.objects << id
118
+ @library_map[lib] = library
119
+ end
120
+ end
121
+
122
+ def parse_sections(text)
123
+ # Do nothing
124
+ end
125
+
126
+ def parse_symbols(text)
127
+ # Sample
128
+ # 0x1000055C8 0x0000003C [ 4] -[FirstViewController viewWillAppear:]
129
+ if text =~ /.*(0x.*)\s\[(.*\d)\].*/
130
+ id_info = @id_map[$2.to_i]
131
+ if id_info
132
+ id_info[:size] = (id_info[:size] or 0) + $1.to_i(16)
133
+ @library_map[id_info[:library]].size += $1.to_i(16)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'linkmap_ios/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "linkmap_ios"
8
+ spec.version = LinkmapIos::VERSION
9
+ spec.authors = ["Jesse Luo"]
10
+ spec.email = ["radishchrist@gmail.com"]
11
+
12
+ spec.summary = %q{A ruby library to parse linkmap file generated by Xcode}
13
+ spec.description = %q{A ruby library to parse linkmap file generated by Xcode.
14
+ Then ouput result with hash, json or report.
15
+ Also have a command line tool
16
+ }
17
+ spec.homepage = "https://github.com/jesseluo/linkmap_ios"
18
+ spec.license = "MIT"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ # if spec.respond_to?(:metadata)
23
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
24
+ # else
25
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
26
+ # end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "thor", "~> 0.19.1"
34
+ spec.add_dependency "filesize", "~> 0.1.1"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.12"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linkmap_ios
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.add.pre.obj.pre.detail
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Luo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: filesize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: "A ruby library to parse linkmap file generated by Xcode.\n Then
84
+ ouput result with hash, json or report.\n Also have a command
85
+ line tool\n "
86
+ email:
87
+ - radishchrist@gmail.com
88
+ executables:
89
+ - console
90
+ - linkmap_ios
91
+ - setup
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".gitignore"
96
+ - ".rspec"
97
+ - ".travis.yml"
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/linkmap_ios
104
+ - bin/setup
105
+ - lib/linkmap_ios.rb
106
+ - lib/linkmap_ios/version.rb
107
+ - linkmap_ios.gemspec
108
+ homepage: https://github.com/jesseluo/linkmap_ios
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">"
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.1
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.8
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A ruby library to parse linkmap file generated by Xcode
132
+ test_files: []