Class: Bake::BakeqacOptions
- Defined in:
- lib/bakeqac/options/options.rb
Constant Summary collapse
- RCF_DEFAULT =
"config/rcf/mcpp-*-en_US.rcf".freeze()
Instance Attribute Summary collapse
-
#acf ⇒ Object
readonly
String.
-
#c11 ⇒ Object
readonly
Boolean.
-
#c14 ⇒ Object
readonly
Boolean.
-
#cct ⇒ Object
readonly
Array.
-
#cct_append ⇒ Object
readonly
String.
-
#cct_patch ⇒ Object
readonly
Boolean.
-
#mcpp_home ⇒ Object
readonly
String.
-
#qac_home ⇒ Object
readonly
String.
-
#qacdata ⇒ Object
String.
-
#qacdoc ⇒ Object
readonly
Boolean.
-
#qacfilefilter ⇒ Object
readonly
Boolean.
-
#qacmsgfilter ⇒ Object
readonly
Boolean.
-
#qacnoformat ⇒ Object
readonly
Boolean.
-
#qacretry ⇒ Object
readonly
int.
-
#qacstep ⇒ Object
readonly
String.
-
#qacunittest ⇒ Object
readonly
Boolean.
-
#qacverbose ⇒ Object
readonly
Boolean.
-
#rcf ⇒ Object
readonly
String.
Instance Method Summary collapse
- #check_valid_dir(dir) ⇒ Object
- #checkNum(num) ⇒ Object
- #incrementQacdata ⇒ Object
-
#initialize(argv) ⇒ BakeqacOptions
constructor
A new instance of BakeqacOptions.
- #parse_options(bakeOptions) ⇒ Object
- #searchCctFile(dir) ⇒ Object
- #set_main_dir(dir) ⇒ Object
- #setDefault(x) ⇒ Object
- #usage ⇒ Object
Methods inherited from Parser
#add_option, #get_block, #num_parameter?, #parse_internal, #valid?
Constructor Details
#initialize(argv) ⇒ BakeqacOptions
Returns a new instance of BakeqacOptions.
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 |
# File 'lib/bakeqac/options/options.rb', line 17 def initialize(argv) super(argv) @cct_patch = false @cct_append = nil @main_dir = nil @cVersion = "" @c11 = false @acf = nil @rcf = nil @cct = [] @default = nil @qacdata = nil @qacverbose = false @qacstep = nil @qacmsgfilter = true @qacfilefilter = true @qacnoformat = false @qacunittest = false @qacretry = 0 @qacdoc = false @qacdataOrg = nil @qacdataCounter = 0 add_option(["-b", "" ], lambda { |x| setDefault(x) }) add_option(["-a" ], lambda { |x| Bake.formatter.setColorScheme(x.to_sym) }) add_option(["-m" ], lambda { |x| set_main_dir(x) }) add_option(["--c++11" ], lambda { @cVersion = "-c++11" }) add_option(["--c++14" ], lambda { @cVersion = "-c++14" }) add_option(["--cct" ], lambda { |x| @cct << x.gsub(/\\/,"/") }) add_option(["--rcf" ], lambda { |x| @rcf = x.gsub(/\\/,"/") }) add_option(["--acf" ], lambda { |x| @acf = x.gsub(/\\/,"/") }) add_option(["--qaccctpatch" ], lambda { @cct_patch = true }) add_option(["--qacdata" ], lambda { |x| @qacdata = x.gsub(/\\/,"/") }) add_option(["--qacstep" ], lambda { |x| @qacstep = x }) add_option(["--qacnofilter" ], lambda { @qacfilefilter = false; @qacmsgfilter = false }) # backward compatibility add_option(["--qacnofilefilter" ], lambda { @qacfilefilter = false }) add_option(["--qacnomsgfilter" ], lambda { @qacmsgfilter = false }) add_option(["--qacretry" ], lambda { |x| @qacretry = x.to_i }) add_option(["--qacnoformat", "--qacrawformat"], lambda { @qacnoformat = true }) add_option(["--qacunittest" ], lambda { @qacunittest = true }) add_option(["--qacdoc" ], lambda { @qacdoc = true }) add_option(["--qacverbose" ], lambda { @qacverbose = true }) add_option(["-h", "--help" ], lambda { usage; ExitHelper.exit(0) }) add_option(["--version" ], lambda { Bake::Version.printBakeqacVersion; ExitHelper.exit(0) }) end |
Instance Attribute Details
#acf ⇒ Object (readonly)
String
9 10 11 |
# File 'lib/bakeqac/options/options.rb', line 9 def acf @acf end |
#c11 ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def c11 @c11 end |
#c14 ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def c14 @c14 end |
#cct ⇒ Object (readonly)
Array
11 12 13 |
# File 'lib/bakeqac/options/options.rb', line 11 def cct @cct end |
#cct_append ⇒ Object (readonly)
String
9 10 11 |
# File 'lib/bakeqac/options/options.rb', line 9 def cct_append @cct_append end |
#cct_patch ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def cct_patch @cct_patch end |
#mcpp_home ⇒ Object (readonly)
String
9 10 11 |
# File 'lib/bakeqac/options/options.rb', line 9 def mcpp_home @mcpp_home end |
#qac_home ⇒ Object (readonly)
String
9 10 11 |
# File 'lib/bakeqac/options/options.rb', line 9 def qac_home @qac_home end |
#qacdata ⇒ Object
String
13 14 15 |
# File 'lib/bakeqac/options/options.rb', line 13 def qacdata @qacdata end |
#qacdoc ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def qacdoc @qacdoc end |
#qacfilefilter ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def qacfilefilter @qacfilefilter end |
#qacmsgfilter ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def qacmsgfilter @qacmsgfilter end |
#qacnoformat ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def qacnoformat @qacnoformat end |
#qacretry ⇒ Object (readonly)
int
12 13 14 |
# File 'lib/bakeqac/options/options.rb', line 12 def qacretry @qacretry end |
#qacstep ⇒ Object (readonly)
String
9 10 11 |
# File 'lib/bakeqac/options/options.rb', line 9 def qacstep @qacstep end |
#qacunittest ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def qacunittest @qacunittest end |
#qacverbose ⇒ Object (readonly)
Boolean
10 11 12 |
# File 'lib/bakeqac/options/options.rb', line 10 def qacverbose @qacverbose end |
#rcf ⇒ Object (readonly)
String
9 10 11 |
# File 'lib/bakeqac/options/options.rb', line 9 def rcf @rcf end |
Instance Method Details
#check_valid_dir(dir) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/bakeqac/options/options.rb', line 105 def check_valid_dir(dir) if not File.exist?(dir) Bake.formatter.printError("Error: Directory #{dir} does not exist") ExitHelper.exit(1) end if not File.directory?(dir) Bake.formatter.printError("Error: #{dir} is not a directory") ExitHelper.exit(1) end end |
#checkNum(num) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/bakeqac/options/options.rb', line 90 def checkNum(num) if String === num && !/\A\d+\z/.match(num) Bake.formatter.printError("Error: #{num} is not a positive number") ExitHelper.exit(1) end end |
#incrementQacdata ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/bakeqac/options/options.rb', line 131 def incrementQacdata() if @qacdataCounter > 0 FileUtils::rm_rf(@qacdata) end @qacdataCounter = @qacdataCounter + 1 @qacdata = @qacdataOrg + "/run" + @qacdataCounter.to_s end |
#parse_options(bakeOptions) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/bakeqac/options/options.rb', line 139 def (bakeOptions) parse_internal(true, bakeOptions) searchDir = @main_dir.nil? ? Dir.pwd : @main_dir dir = Bake.findDirOfFileToRoot(searchDir,"Project.meta") if dir set_main_dir(dir) else Bake.formatter.printError("Error: Project.meta not found in #{searchDir} or upwards") ExitHelper.exit(1) end @qacdata = "#{@main_dir}/.qacdata" if @qacdata.nil? @qacdataOrg = @qacdata @qacdataCounter = 0 incrementQacdata() if !ENV["QAC_HOME"] || ENV["QAC_HOME"].empty? Bake.formatter.printError("Error: specify the environment variable QAC_HOME.") ExitHelper.exit(1) end @qac_home = ENV["QAC_HOME"].gsub(/\\/,"/") @qac_home = @qac_home[0, @qac_home.length-1] if @qac_home.end_with?"/" if !File.directory?(@qac_home) Bake.formatter.printError("Error: QAC_HOME points to invalid directory.") ExitHelper.exit(1) end # find mcpp install folder # prio 1: explicit env var if ENV["MCPP_HOME"] && !ENV["MCPP_HOME"].empty? @mcpp_home = ENV["MCPP_HOME"].gsub(/\\/,"/") @mcpp_home = @mcpp_home[0, @mcpp_home.length-1] if @mcpp_home.end_with?"/" if !File.directory?(@mcpp_home) Bake.formatter.printError("Error: MCPP_HOME points to invalid directory: #{@mcpp_home}") ExitHelper.exit(1) end # prio 2: with qac_home elsif !(mcps = Dir.glob(@qac_home+"/#{RCF_DEFAULT}")).empty? @mcpp_home = @qac_home # prio 3: next to qac_home elsif !(mcps = Dir.glob(File.dirname(@qac_home)+"/mcpp-*/")).empty? @mcpp_home = mcps.sort.last[0..-2] else Bake.formatter.printError("Error: cannot find MCPP home folder. Specify MCPP_HOME.") ExitHelper.exit(1) end if !@qacstep.nil? @qacstep.split(/[,|]/).each do |s| if not ["admin", "analyze", "view", "report", "mdr"].include?s Bake.formatter.printError("Error: incorrect qacstep name.") ExitHelper.exit(1) end end end if @cct.empty? gccVersion = Bake::Toolchain::getGccVersion if gccVersion.length < 2 Bake.formatter.printError("Error: could not determine GCC version.") ExitHelper.exit(1) end plStr = nil gccPlatform = Bake::Toolchain::getGccPlatform if gccPlatform.include?"mingw" plStr = "w64-mingw32" elsif gccPlatform.include?"cygwin" plStr = "pc-cygwin" elsif gccPlatform.include?"linux" plStr = "generic-linux" end if plStr.nil? # fallback if RUBY_PLATFORM =~ /mingw/ plStr = "w64-mingw32" elsif RUBY_PLATFORM =~ /cygwin/ plStr = "pc-cygwin" else plStr = "generic-linux" end end while (@cct.empty? or gccVersion[0]>=4) @cct = [@qac_home + "/config/cct/GNU_GCC-g++_#{gccVersion[0]}.#{gccVersion[1]}-i686-#{plStr}-C++#{@cVersion}.cct"] break if File.exist?@cct[0] @cct = [@qac_home + "/config/cct/GNU_GCC-g++_#{gccVersion[0]}.#{gccVersion[1]}-x86_64-#{plStr}-C++#{@cVersion}.cct"] break if File.exist?@cct[0] if gccVersion[1]>0 gccVersion[1] -= 1 else gccVersion[0] -= 1 gccVersion[1] = 20 end end end cctInDir = searchCctFile(@main_dir) @cct_append = cctInDir.gsub(/[\\]/,'/') if cctInDir if @acf.nil? @acf = @qac_home + "/config/acf/default.acf" end if @rcf.nil? rcfs = Dir.glob(@mcpp_home+"/#{RCF_DEFAULT}") if rcfs.empty? Bake.formatter.printError("Error: rcf file not found: #{@mcpp_home+"/#{RCF_DEFAULT}"}") ExitHelper.exit(1) end @rcf = rcfs.sort.last end @cct.each do |cct| if !File.exist?(cct) Bake.formatter.printError("Error: cct file not found: #{cct}") ExitHelper.exit(1) end end if !File.exist?(@acf) Bake.formatter.printError("Error: acf file not found: #{@acf}") ExitHelper.exit(1) end if !File.exist?(@rcf) Bake.formatter.printError("Error: rcf file not found: #{@rcf}") ExitHelper.exit(1) end end |
#searchCctFile(dir) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/bakeqac/options/options.rb', line 121 def searchCctFile(dir) cctFile = dir+"/qac.cct" return cctFile if File.exist?(cctFile) parent = File.dirname(dir) return searchCctFile(parent) if parent != dir return nil end |
#set_main_dir(dir) ⇒ Object
116 117 118 119 |
# File 'lib/bakeqac/options/options.rb', line 116 def set_main_dir(dir) check_valid_dir(dir) @main_dir = File.(dir.gsub(/[\\]/,'/')) end |
#setDefault(x) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/bakeqac/options/options.rb', line 97 def setDefault(x) if (@default) Bake.formatter.printError("Error: '#{x}' not allowed, '#{@default}' already set.") ExitHelper.exit(1) end @default = x end |
#usage ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bakeqac/options/options.rb', line 65 def usage puts "\nUsage: bakeqac [options]" puts " --c++11 Use C++11 rules, available for GCC 4.7 and higher." puts " --c++14 Use C++14 rules, available for GCC 4.9 and higher." puts " --cct <file> Set a specific compiler compatibility template, can be defined multiple times." puts " If not specified, $(QAC_HOME)/config/cct/<platform>.ctt will be used and additionally" puts " a file named qac.cct will be searched up to root and also used if found." puts " --rcf <file> Set a specific rule config file. If not specified, $(MCPP_HOME)/#{RCF_DEFAULT} will be used." puts " --acf <file> Set a specific analysis config file, otherwise $(QAC_HOME)/config/acf/default.acf will be used." puts " --qaccctpatch If specified, some adaptions to cct are made. Might improve the result - no guarantee." puts " --qacdata <dir> QAC writes data into this folder. Default is <working directory>/.qacdata." puts " --qacstep <steps> Can be admin,analyze,view,report,mdr (separated by \",\" without spaces)." puts " Defines the steps to execute, see documentation. Default: admin,analyze,view" puts " --qacnofilefilter Some files will be filtered per default, like /test/." puts " --qacnomsgfilter Some messages will be filter per default filters to reduce noise." puts " --qacrawformat Raw QAC output (with incomplete MISRA rules!)." puts " --qacretry <seconds> If build or result step fail due to refused license, the step will be retried until timeout." puts " --qacdoc Print link to HTML help page for every warning if found." puts " --qacverbose Verbose output of bakeqac." puts " --version Print version." puts " -h, --help Print this help." puts "Note: all parameters from bake apply also here. Note, that --rebuild and --compile-only will be added to the internal bake call automatically." puts "Note: works only for GCC 4.1 and above" end |