gcc-to-clang-analyzer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce0c6a77b8d3895ec3f3f3859d73b4ead1785c99
4
+ data.tar.gz: 3383e3a4f4021151a28db15a8d456caa72568e48
5
+ SHA512:
6
+ metadata.gz: 060339665629fd1ed745db13548101a8dc8b60be78b7e935b03237eb3a3f3db97a897c154a4e328993d610d164121aedb525bd13833b3b1bfda6d9a8d78560f8
7
+ data.tar.gz: 268992b3f4e2a1e484dce241f947383f2eb89776417ff56fafb51dbb45294a8a9d74f457a5dc76acef442c22bc5967f63218ae4435bde8113fe8595da36dcee8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ gcc-to-clang-analyzer
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gcc-to-clang-analyzer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Christian Köstlin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Gcc::To::Clang::Analyzer
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gcc-to-clang-analyzer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gcc-to-clang-analyzer
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/gcc-to-clang-analyzer/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
data/bin/g++ ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gcc_to_clang_analyzer/prepare_compiler_commandline'
4
+ require 'gcc_to_clang_analyzer/rewrite_plist_file'
5
+ require 'logger'
6
+ logger = Logger.new(STDOUT)
7
+ logger.level = Logger::WARN
8
+ logger.debug("original #{ARGV.join(' ')}")
9
+
10
+ command_line, output = PrepareCompilerCommandline.transform(ARGV)
11
+
12
+ cl = command_line.join(' ')
13
+ logger.info("executing '#{cl}'")
14
+
15
+ res = system(cl)
16
+ if res
17
+ workspace_path = File.absolute_path('..')
18
+ prefix = File.absolute_path('.').gsub(workspace_path+'/', '')
19
+ tmp_output = output + ".tmp"
20
+ File.open(tmp_output, 'w') do |io|
21
+ io << RewritePlistFile.with_prefix(prefix, output)
22
+ end
23
+ File.delete(output)
24
+ File.rename(tmp_output, output)
25
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gcc_to_clang_analyzer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gcc-to-clang-analyzer'
8
+ spec.version = GccToClangAnalyzer::VERSION
9
+ spec.authors = ['Christian Köstlin']
10
+ spec.email = ['christian.koestlin@esrlabs.com']
11
+ spec.summary = %q{Maps g++ calls to clang --analyze calls.}
12
+ spec.description = %q{It then rewirtes the plist files to put the project name before the sourcefiles.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_runtime_dependency 'plist'
25
+ end
@@ -0,0 +1,2 @@
1
+ module GccToClangAnalyzer
2
+ end
@@ -0,0 +1,42 @@
1
+ class PrepareCompilerCommandline
2
+ def self.transform(args)
3
+ if args.find_index('-c')
4
+ return self.prepare_for_compile(args)
5
+ else
6
+ args[0] = 'true'
7
+ return [args, '']
8
+ end
9
+ end
10
+ def self.prepare_for_compile(args)
11
+ new_commandline = []
12
+ out = ''
13
+
14
+ args.shift
15
+ new_commandline << 'clang'
16
+ new_commandline << '--analyze'
17
+
18
+ while args.length > 0
19
+ arg = args.shift
20
+ case arg
21
+ when /-D.*/
22
+ new_commandline << arg
23
+ when /-I.*/
24
+ new_commandline << arg
25
+ when '-c'
26
+ when '-MF'
27
+ args.shift
28
+ when '-MMD'
29
+ when /-W.*/
30
+ when '-o'
31
+ new_commandline << arg
32
+ out = "#{args.shift}.plist"
33
+ new_commandline << out
34
+ else
35
+ new_commandline << arg
36
+ end
37
+ end
38
+
39
+ return [new_commandline, out]
40
+ end
41
+
42
+ end
@@ -0,0 +1,10 @@
1
+ require 'plist'
2
+
3
+ class RewritePlistFile
4
+ def self.with_prefix(prefix, original)
5
+ v = Plist::parse_xml(original)
6
+ files = v['files']
7
+ v['files'] = files.map{|i|File.join(prefix, i)}
8
+ v.to_plist()
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module GccToClangAnalyzer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'gcc_to_clang_analyzer/prepare_compiler_commandline'
2
+ describe PrepareCompilerCommandline do
3
+
4
+ it 'should remove the program name and replace it with clang --analyze when a -c is given' do
5
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', 1, 2])
6
+ cl[0...2].should eq(['clang', '--analyze'])
7
+ end
8
+
9
+ it 'should remove the program name and replace it with true when no -c is given' do
10
+ cl, out = PrepareCompilerCommandline.transform(['g++', 1, 2])
11
+ cl.first.should eq('true')
12
+ end
13
+
14
+ it 'should keep -D flags' do
15
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-Dflag', '-Dflag2=2'])
16
+ cl.should eq(['clang', '--analyze', '-Dflag', '-Dflag2=2'])
17
+ end
18
+
19
+ it 'should keep -I flags' do
20
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-I/usr/include', '-I/usr/include2'])
21
+ cl.should eq(['clang', '--analyze', '-I/usr/include', '-I/usr/include2'])
22
+ end
23
+
24
+ it 'should remove -c' do
25
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c'])
26
+ cl.should eq(['clang', '--analyze'])
27
+ end
28
+
29
+ it 'should remove -MF with a parameter' do
30
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-MF', 'anotherarg'])
31
+ cl.should eq(['clang', '--analyze'])
32
+ end
33
+
34
+ it 'should remove -MMD' do
35
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-MMD'])
36
+ cl.should eq(['clang', '--analyze'])
37
+ end
38
+
39
+ it 'should remove -Wwith values' do
40
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-Wall'])
41
+ cl.should eq(['clang', '--analyze'])
42
+ end
43
+
44
+ it 'should output to the normal output appended with .plist' do
45
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-o', 'test.o'])
46
+ cl.should eq(['clang', '--analyze', '-o', 'test.o.plist'])
47
+ out.should eq('test.o.plist')
48
+ end
49
+
50
+ it 'should let unknown flags pass' do
51
+ cl, out = PrepareCompilerCommandline.transform(['g++', '-c', '-unknown'])
52
+ cl.should eq(['clang', '--analyze', '-unknown'])
53
+ end
54
+
55
+ end
@@ -0,0 +1,42 @@
1
+ require 'gcc_to_clang_analyzer/rewrite_plist_file'
2
+
3
+ describe RewritePlistFile do
4
+ it 'should replace the files array with a prefixed version' do
5
+ original_plist = <<-eos
6
+ <?xml version="1.0" encoding="UTF-8"?>
7
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
8
+ <plist version="1.0">
9
+ <dict>
10
+ <key>clang_version</key>
11
+ <string>clang version 3.4 (trunk 182989)</string>
12
+ <key>files</key>
13
+ <array>
14
+ <string>src/eeprommanager/main1.cpp</string>
15
+ <string>src/eeprommanager/main2.cpp</string>
16
+ </array>
17
+ </dict>
18
+ </plist>
19
+ eos
20
+
21
+ should_be_plist = <<-eos
22
+ <?xml version="1.0" encoding="UTF-8"?>
23
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
24
+ <plist version="1.0">
25
+ <dict>
26
+ <key>clang_version</key>
27
+ <string>clang version 3.4 (trunk 182989)</string>
28
+ <key>files</key>
29
+ <array>
30
+ <string>test/src/eeprommanager/main1.cpp</string>
31
+ <string>test/src/eeprommanager/main2.cpp</string>
32
+ </array>
33
+ </dict>
34
+ </plist>
35
+ eos
36
+
37
+
38
+
39
+ new_plist = RewritePlistFile.with_prefix('test', original_plist)
40
+ new_plist.should eq(should_be_plist)
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gcc-to-clang-analyzer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christian Köstlin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: plist
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: It then rewirtes the plist files to put the project name before the sourcefiles.
70
+ email:
71
+ - christian.koestlin@esrlabs.com
72
+ executables:
73
+ - g++
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/g++
85
+ - gcc-to-clang-analyzer.gemspec
86
+ - lib/gcc_to_clang_analyzer/analyzer.rb
87
+ - lib/gcc_to_clang_analyzer/prepare_compiler_commandline.rb
88
+ - lib/gcc_to_clang_analyzer/rewrite_plist_file.rb
89
+ - lib/gcc_to_clang_analyzer/version.rb
90
+ - spec/prepare_compiler_commandline_spec.rb
91
+ - spec/rewrite_plist_file_spec.rb
92
+ homepage: ''
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.2
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Maps g++ calls to clang --analyze calls.
116
+ test_files:
117
+ - spec/prepare_compiler_commandline_spec.rb
118
+ - spec/rewrite_plist_file_spec.rb