forked from sjas/adlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadlint_cma
executable file
·121 lines (107 loc) · 3.49 KB
/
adlint_cma
1
2
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#! /usr/bin/env ruby
#
# Cross module analyzer.
#
# Author:: Yutaka Yanoh <mailto:[email protected]>
# Copyright:: Copyright (C) 2010-2014, OGIS-RI Co.,Ltd.
# License:: GPLv3+: GNU General Public License version 3 or later
#
# Owner:: Yutaka Yanoh <mailto:[email protected]>
#--
# ___ ____ __ ___ _________
# / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
# / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
# / __ |/ /_/ / /___/ / /| / / /
# /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2014, OGIS-RI Co.,Ltd.
#
# This file is part of AdLint.
#
# AdLint is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# AdLint. If not, see <http://www.gnu.org/licenses/>.
#
#++
$LOAD_PATH.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
require "adlint"
$stdout.set_encoding(Encoding.default_external)
$stderr.set_encoding(Encoding.default_external)
version = "AdLint cross module analyzer #{AdLint::VERSION}"
usage = <<EOS
Usage: adlint_cma [options] sma-metric-file...
Options:
-t FILE, --traits FILE Use FILE as traits file (mandatory)
-o DIR, --output-dir DIR Output result files to DIR
-v, --verbose Increase verbosity but suppress message output
--version Display version information
--copyright Display copyright information
--prefix Display prefix directory of AdLint
-h, --help Display this message
EOS
require "getoptlong"
getopt = GetoptLong.new(
["--traits", "-t", GetoptLong::REQUIRED_ARGUMENT],
["--output-dir", "-o", GetoptLong::REQUIRED_ARGUMENT],
["--verbose", "-v", GetoptLong::NO_ARGUMENT],
["--version", GetoptLong::NO_ARGUMENT],
["--copyright", GetoptLong::NO_ARGUMENT],
["--prefix", GetoptLong::NO_ARGUMENT],
["--help", "-h", GetoptLong::NO_ARGUMENT]
)
begin
traits_fpath = nil
output_dpath = nil
verbose = false
getopt.each_option do |opt_name, opt_val|
case opt_name
when "--traits"
traits_fpath = Pathname.new(opt_val)
when "--output-dir"
output_dpath = Pathname.new(opt_val)
when "--verbose"
verbose = true
when "--version"
puts version, AdLint::AUTHOR
exit 0
when "--copyright"
puts AdLint::COPYRIGHT
exit 0
when "--prefix"
puts AdLint::Config[:prefix]
exit 0
when "--help"
puts usage
exit 0
end
end
rescue
$stderr.puts usage
exit 1
end
input_fpaths = ARGV.map { |str| Pathname.new(str) }
if input_fpaths.empty?
$stderr.puts "#{File.basename(__FILE__)}: no input files"
$stderr.puts usage
exit 1
end
unless traits_fpath
$stderr.puts "#{File.basename(__FILE__)}: no traits file"
$stderr.puts usage
exit 1
end
begin
adlint = AdLint::AdLint.new(traits_fpath, output_dpath, verbose)
adlint.run_cma!(input_fpaths) or exit 5
rescue => ex
$stderr.puts ex.message, ex.backtrace
$stderr.puts
exit 2
end
exit 0