Class: Bake::BakeqacOptions

Inherits:
Parser
  • Object
show all
Defined in:
lib/bakeqac/options/options.rb

Constant Summary collapse

RCF_DEFAULT =
"config/rcf/mcpp-*-en_US.rcf".freeze()

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#acfObject (readonly)

String



9
10
11
# File 'lib/bakeqac/options/options.rb', line 9

def acf
  @acf
end

#c11Object (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def c11
  @c11
end

#c14Object (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def c14
  @c14
end

#cctObject (readonly)

Array



11
12
13
# File 'lib/bakeqac/options/options.rb', line 11

def cct
  @cct
end

#cct_appendObject (readonly)

String



9
10
11
# File 'lib/bakeqac/options/options.rb', line 9

def cct_append
  @cct_append
end

#cct_patchObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def cct_patch
  @cct_patch
end

#mcpp_homeObject (readonly)

String



9
10
11
# File 'lib/bakeqac/options/options.rb', line 9

def mcpp_home
  @mcpp_home
end

#qac_homeObject (readonly)

String



9
10
11
# File 'lib/bakeqac/options/options.rb', line 9

def qac_home
  @qac_home
end

#qacdataObject

String



13
14
15
# File 'lib/bakeqac/options/options.rb', line 13

def qacdata
  @qacdata
end

#qacdocObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def qacdoc
  @qacdoc
end

#qacfilefilterObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def qacfilefilter
  @qacfilefilter
end

#qacmsgfilterObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def qacmsgfilter
  @qacmsgfilter
end

#qacnoformatObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def qacnoformat
  @qacnoformat
end

#qacretryObject (readonly)

int



12
13
14
# File 'lib/bakeqac/options/options.rb', line 12

def qacretry
  @qacretry
end

#qacstepObject (readonly)

String



9
10
11
# File 'lib/bakeqac/options/options.rb', line 9

def qacstep
  @qacstep
end

#qacunittestObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def qacunittest
  @qacunittest
end

#qacverboseObject (readonly)

Boolean



10
11
12
# File 'lib/bakeqac/options/options.rb', line 10

def qacverbose
  @qacverbose
end

#rcfObject (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

#incrementQacdataObject



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 parse_options(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.expand_path(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

#usageObject



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