Class: Bake::Options

Inherits:
Parser show all
Defined in:
lib/bake/options/options.rb

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) ⇒ Options

Returns a new instance of Options.



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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
# File 'lib/bake/options/options.rb', line 40

def initialize(argv)
  super(argv)

  @caseSensitivityCheck = Bake::Utils::OS.windows?
  @skipBuildingLine = false
  @debug_threads = false
  @dry = false
  @filelist = nil
  @qac = false
  @projectPaths = false
  @wparse = false
  @dot = false
  @dotFilename = nil
  @prebuild = false
  @printTime = false
  @buildDirDelimiter = "/"
  @conversion_info = false
  @envToolchain = false
  @analyze = false
  @eclipseOrder = false
  @showConfigs = false
  @consoleOutput_fullnames = false
  @prepro = false
  @stopOnFirstError = false
  @verbose = 1
  @vars = {}
  @build_config = ""
  @main_dir = nil
  @project = nil
  @filename = nil
  @cc2j_filename = nil
  @json = false
  @clean = false
  @clobber = false
  @docu = false
  @debug = false
  @rebuild = false
  @nocache = false
  @show_includes = false
  @show_includes_and_defines = false
  @linkOnly = false
  @compileOnly = false
  @no_autodir = false
  @threads = 8
  @roots = []
  @socket = 0
  @include_filter = []
  @include_filter_args = {}
  @exclude_filter = []
  @main_project_name = ""
  @adapt = []
  @syncedOutput = false
  @profiling = false
  @diabCaseCheck = false
  @defines = []
  @fileCmd = false
  @dotAndCompile = false
  @show_roots = false
  @dev_features = []
  @dotShowProjOnly = false

  add_option(["-b",                   ""                     ], lambda { |x| set_build_config(x)                     })
  add_option(["-m"                                           ], lambda { |x| @main_dir = x                           })
  add_option(["-p"                                           ], lambda { |x| @project = x                            })
  add_option(["-f"                                           ], lambda { |x| @filename = x.gsub(/[\\]/,'/')          })
  add_option(["-c"                                           ], lambda {     @clean = true                           })
  add_option(["-a"                                           ], lambda { |x| Bake.formatter.setColorScheme(x.to_sym) })
  add_option(["-w"                                           ], lambda { |x| set_root(x)                             })
  add_option(["-r"                                           ], lambda {     @stopOnFirstError = true                })
  add_option(["-O"                                           ], lambda {     @syncedOutput = true                    })
  add_option(["--rebuild"                                    ], lambda {     @rebuild = true                         })
  add_option(["--profiling"                                  ], lambda {     @profiling = true                         })
  add_option(["--prepro"                                     ], lambda {     @prepro = true                          })
  add_option(["--link-only",          "--link_only"          ], lambda {     @linkOnly = true;                       })
  add_option(["--compile-only",       "--compile_only"       ], lambda {     @compileOnly = true;                    })
  add_option(["--no-autodir",         "--no_autodir"         ], lambda {     @no_autodir = true                      })

  add_option(["--create"                                     ], lambda { |x| Bake::Create.proj(x)                    })
  add_option(["--conversion-info",    "--conversion_info"    ], lambda {     @conversion_info = true; @syncedOutput = true })
  add_option(["--file-list",          "--file_list"          ], lambda {     @filelist = Set.new                     })
  add_option(["--filter-paths"                               ], lambda {     @projectPaths = true                    })
  add_option(["--qac"                                        ], lambda {     @qac = true                             })
  add_option(["-Z"                                           ], lambda { |x| @dev_features <<  x                     })

  add_option(["--generate-doc",       "--docu"               ], lambda {     @docu = true                            })

  add_option(["--adapt"                                      ], lambda { |x| set_adapt(x)                            })

  add_option(["-v"                                           ], lambda { |x, dummy1, dummy2| set_verbose(x)          })

  add_option(["--debug"                                      ], lambda {     @debug = true                           })
  add_option(["--debug-threads"                              ], lambda {     @debug_threads = true                   })
  add_option(["--set"                                        ], lambda { |x| set_set(x)                              })
  add_option(["-nb"                                          ], lambda {     @skipBuildingLine = true                })
  add_option(["--no-case-check"                              ], lambda {     @caseSensitivityCheck = false           })
  add_option(["--file-cmd"                                   ], lambda {     @fileCmd = true                         })
  add_option(["--clobber"                                    ], lambda {     @clobber = true; @clean = true          })
  add_option(["--ignore-cache",       "--ignore_cache"       ], lambda {     @nocache = true                         })
  add_option(["-j",                   "--threads"            ], lambda { |x, dummy1, dummy2| set_threads(x)          })
  add_option(["--socket"                                     ], lambda { |x| @socket = String === x ? x.to_i : x     })
  add_option(["--toolchain-info",     "--toolchain_info"     ], lambda { |x| ToolchainInfo.showToolchain(x)          })
  add_option(["--toolchain-names",    "--toolchain_names"    ], lambda {     ToolchainInfo.showToolchainList         })
  add_option(["--dot",                                       ], lambda { |x,dummy| @dot = true; @dotFilename = x; @dotAndCompile = false        })
  add_option(["--dotc",                                      ], lambda { |x,dummy| @dot = true; @dotFilename = x; @dotAndCompile = true         })
  add_option(["--dot-project-level",                         ], lambda { @dot = true; @dotShowProjOnly = true        })
  add_option(["--do",                 "--include_filter"     ], lambda { |x| set_filter(x)                           })
  add_option(["--omit",               "--exclude_filter"     ], lambda { |x| @exclude_filter << x                    })
  add_option(["--abs-paths",          "--show_abs_paths"     ], lambda {     @consoleOutput_fullnames = true         })
  add_option(["--prebuild"                                   ], lambda {     @prebuild = true                        })
  add_option(["--Wparse"                                     ], lambda {     @wparse = true                          })

  add_option(["-h",                   "--help"               ], lambda {     Bake::Usage.show                        })
  add_option(["--time",                                      ], lambda {     @printTime = true                       })

  add_option(["--incs-and-defs",      "--show_incs_and_defs" ], lambda {     @show_includes_and_defines = true       })
  add_option(["--incs-and-defs=bake",                        ], lambda {     @show_includes_and_defines = true       })
  add_option(["--incs-and-defs=json"                         ], lambda { @show_includes_and_defines=true; @json=true })
  add_option(["--license",            "--show_license"       ], lambda {     License.show                            })
  add_option(["--doc",                "--show_doc"           ], lambda {     Doc.show                                })
  add_option(["--install-doc",        "--install_doc"        ], lambda {     Doc.install                             })

  add_option(["-D"                                           ], lambda { |x| @defines << x                           })

  add_option(["--dry"                                        ], lambda {     @dry = true                             })

  add_option(["--crc32"                                      ], lambda { |x| CRC32.printAndExit(x)                   })

  add_option(["--diab-case-check"                            ], lambda {  @diabCaseCheck = true; @compileOnly = true })

  add_option(["--version"                                    ], lambda {     Bake::Usage.version                     })
  add_option(["--list",               "--show_configs"       ], lambda {     @showConfigs = true                     })
  add_option(["--compilation-db"                             ], lambda { |x,dummy| @cc2j_filename = (x ? x : "compile_commands.json" )})
  add_option(["--build_",                                    ], lambda {     @buildDirDelimiter = "_"                })

  # deprecated and not replaced by new command

  add_option(["--show_include_paths"                         ], lambda {     @show_includes = true                   })
    
  add_option(["--roots"                                      ], lambda {     @show_roots = true                      })

end

Instance Attribute Details

#adaptObject (readonly)

String List



24
25
26
# File 'lib/bake/options/options.rb', line 24

def adapt
  @adapt
end

#analyzeObject

Returns the value of attribute analyze.



22
23
24
# File 'lib/bake/options/options.rb', line 22

def analyze
  @analyze
end

#build_configObject

Returns the value of attribute build_config.



22
23
24
# File 'lib/bake/options/options.rb', line 22

def build_config
  @build_config
end

#buildDirDelimiterObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def buildDirDelimiter
  @buildDirDelimiter
end

#caseSensitivityCheckObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def caseSensitivityCheck
  @caseSensitivityCheck
end

#cc2j_filenameObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def cc2j_filename
  @cc2j_filename
end

#cleanObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def clean
  @clean
end

#clobberObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def clobber
  @clobber
end

#compileOnlyObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def compileOnly
  @compileOnly
end

#consoleOutput_fullnamesObject (readonly)

Returns the value of attribute consoleOutput_fullnames.



32
33
34
# File 'lib/bake/options/options.rb', line 32

def consoleOutput_fullnames
  @consoleOutput_fullnames
end

#conversion_infoObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def conversion_info
  @conversion_info
end

#debugObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def debug
  @debug
end

#debug_threadsObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def debug_threads
  @debug_threads
end

#definesObject (readonly)

Returns the value of attribute defines.



35
36
37
# File 'lib/bake/options/options.rb', line 35

def defines
  @defines
end

#dev_featuresObject (readonly)

Returns the value of attribute dev_features.



36
37
38
# File 'lib/bake/options/options.rb', line 36

def dev_features
  @dev_features
end

#diabCaseCheckObject (readonly)

Returns the value of attribute diabCaseCheck.



34
35
36
# File 'lib/bake/options/options.rb', line 34

def diabCaseCheck
  @diabCaseCheck
end

#docuObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def docu
  @docu
end

#dotObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def dot
  @dot
end

#dotAndCompileObject (readonly)

Returns the value of attribute dotAndCompile.



27
28
29
# File 'lib/bake/options/options.rb', line 27

def dotAndCompile
  @dotAndCompile
end

#dotFilenameObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def dotFilename
  @dotFilename
end

#dotShowProjOnlyObject (readonly)

Returns the value of attribute dotShowProjOnly.



37
38
39
# File 'lib/bake/options/options.rb', line 37

def dotShowProjOnly
  @dotShowProjOnly
end

#dryObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def dry
  @dry
end

#eclipseOrderObject

Returns the value of attribute eclipseOrder.



22
23
24
# File 'lib/bake/options/options.rb', line 22

def eclipseOrder
  @eclipseOrder
end

#envToolchainObject

Returns the value of attribute envToolchain.



22
23
24
# File 'lib/bake/options/options.rb', line 22

def envToolchain
  @envToolchain
end

#exclude_filterObject (readonly)

String List



24
25
26
# File 'lib/bake/options/options.rb', line 24

def exclude_filter
  @exclude_filter
end

#fileCmdObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def fileCmd
  @fileCmd
end

#filelistObject (readonly)

set



31
32
33
# File 'lib/bake/options/options.rb', line 31

def filelist
  @filelist
end

#filenameObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def filename
  @filename
end

#include_filterObject (readonly)

String List



24
25
26
# File 'lib/bake/options/options.rb', line 24

def include_filter
  @include_filter
end

#include_filter_argsObject (readonly)

map



29
30
31
# File 'lib/bake/options/options.rb', line 29

def include_filter_args
  @include_filter_args
end

#jsonObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def json
  @json
end

#linkOnlyObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def linkOnly
  @linkOnly
end

#main_dirObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def main_dir
  @main_dir
end

#main_project_nameObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def main_project_name
  @main_project_name
end

#no_autodirObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def no_autodir
  @no_autodir
end

#nocacheObject

Returns the value of attribute nocache.



22
23
24
# File 'lib/bake/options/options.rb', line 22

def nocache
  @nocache
end

#prebuildObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def prebuild
  @prebuild
end

#preproObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def prepro
  @prepro
end

#printTimeObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def printTime
  @printTime
end

#profilingObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def profiling
  @profiling
end

#projectObject (readonly)

String



23
24
25
# File 'lib/bake/options/options.rb', line 23

def project
  @project
end

#projectPathsObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def projectPaths
  @projectPaths
end

#qacObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def qac
  @qac
end

#rebuildObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def rebuild
  @rebuild
end

#rootsObject (readonly)

Root array



33
34
35
# File 'lib/bake/options/options.rb', line 33

def roots
  @roots
end

#show_includesObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def show_includes
  @show_includes
end

#show_includes_and_definesObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def show_includes_and_defines
  @show_includes_and_defines
end

#show_rootsObject (readonly)

Returns the value of attribute show_roots.



27
28
29
# File 'lib/bake/options/options.rb', line 27

def show_roots
  @show_roots
end

#showConfigsObject

Returns the value of attribute showConfigs.



22
23
24
# File 'lib/bake/options/options.rb', line 22

def showConfigs
  @showConfigs
end

#skipBuildingLineObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def skipBuildingLine
  @skipBuildingLine
end

#socketObject (readonly)

Fixnum



28
29
30
# File 'lib/bake/options/options.rb', line 28

def socket
  @socket
end

#stopOnFirstErrorObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def stopOnFirstError
  @stopOnFirstError
end

#syncedOutputObject (readonly)

Boolean



25
26
27
# File 'lib/bake/options/options.rb', line 25

def syncedOutput
  @syncedOutput
end

#threadsObject (readonly)

Fixnum



28
29
30
# File 'lib/bake/options/options.rb', line 28

def threads
  @threads
end

#varsObject (readonly)

map



29
30
31
# File 'lib/bake/options/options.rb', line 29

def vars
  @vars
end

#verboseObject (readonly)

Returns the value of attribute verbose.



30
31
32
# File 'lib/bake/options/options.rb', line 30

def verbose
  @verbose
end

#wparseObject (readonly)

Boolean



26
27
28
# File 'lib/bake/options/options.rb', line 26

def wparse
  @wparse
end

Instance Method Details

#check_valid_dir(dir) ⇒ Object



297
298
299
300
301
302
303
304
305
306
# File 'lib/bake/options/options.rb', line 297

def check_valid_dir(dir)
 if not File.exists?(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



335
336
337
338
339
340
# File 'lib/bake/options/options.rb', line 335

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

#parse_optionsObject



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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/bake/options/options.rb', line 181

def parse_options()
  parse_internal(false)

  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

  def_roots = Root.calc_roots_bake(@main_dir)
  @roots += def_roots

  if @roots.empty?
    @roots = []
    @roots = Root.calc_def_roots(@main_dir)
  end

  @roots = Root.uniq(@roots)
  
  if @show_roots
    puts @roots.map {|r| r.dir }
    ExitHelper.exit(0)
  end

  @adapt.uniq!

  if @project
    ar = @project.split(",")
    if ar.length > 2
      Bake.formatter.printError("Error: only one comma allowed for -p")
      ExitHelper.exit(1)
    end
    ar[0] = File::basename(Dir.pwd) if ar[0] == "."
    @project = ar.join(",")
  end

  if @conversion_info
    if @rebuild
      Bake.formatter.printError("Error: --conversion-info and --rebuild not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @clean
      Bake.formatter.printError("Error: --conversion-info and -c not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @prepro
      Bake.formatter.printError("Error: --conversion-info and --prepro not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @linkOnly
      Bake.formatter.printError("Error: --conversion-info and --linkOnly not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @compileOnly
      Bake.formatter.printError("Error: --conversion-info and --compileOnly not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @docu
      Bake.formatter.printError("Error: --conversion-info and --docu not allowed at the same time")
      ExitHelper.exit(1)
    end
  end

  if @linkOnly
    if @rebuild
      Bake.formatter.printError("Error: --link-only and --rebuild not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @clean
      Bake.formatter.printError("Error: --link-only and -c not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @prepro
      Bake.formatter.printError("Error: --link-only and --prepro not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @filename
      Bake.formatter.printError("Error: --link-only and --filename not allowed at the same time")
      ExitHelper.exit(1)
    end
  end

  if @compileOnly
    if @linkOnly
      Bake.formatter.printError("Error: --compile-only and --link-only not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @filename
      Bake.formatter.printError("Error: --compile-only and --filename not allowed at the same time")
      ExitHelper.exit(1)
    end
  end

  if @prepro
    if @rebuild
      Bake.formatter.printError("Error: --prepro and --rebuild not allowed at the same time")
      ExitHelper.exit(1)
    end
    if @clean
      Bake.formatter.printError("Error: --prepro and -c not allowed at the same time")
      ExitHelper.exit(1)
    end
  end

  if @caseSensitivityCheck == false && @diabCaseCheck == true
    Bake.formatter.printError("Error: --no-case-check and --diab-case-check not allowed at the same time")
    ExitHelper.exit(1)
  end

  @filename = "." if @compileOnly

end

#set_adapt(name) ⇒ Object



329
330
331
332
333
# File 'lib/bake/options/options.rb', line 329

def set_adapt(name)
  name.split(",").each do |n|
    @adapt << n if not @adapt.include?n
  end
end

#set_build_config(config) ⇒ Object



308
309
310
311
312
313
314
# File 'lib/bake/options/options.rb', line 308

def set_build_config(config)
  if not @build_config.empty?
    Bake.formatter.printError("Error: Cannot set build config '#{config}', because build config is already set to '#{@build_config}'")
    ExitHelper.exit(1)
  end
  @build_config = config
end

#set_filter(f) ⇒ Object



369
370
371
372
373
# File 'lib/bake/options/options.rb', line 369

def set_filter(f)
  splitted = f.split("=", 2)
  @include_filter << splitted[0]
  @include_filter_args[splitted[0]] = splitted[1] if splitted.length == 2
end

#set_main_dir(dir) ⇒ Object



316
317
318
319
320
# File 'lib/bake/options/options.rb', line 316

def set_main_dir(dir)
  check_valid_dir(dir)
  @main_dir = File.expand_path(dir.gsub(/[\\]/,'/'))
  @main_project_name = File::basename(@main_dir)
end

#set_root(dir) ⇒ Object



322
323
324
325
326
327
# File 'lib/bake/options/options.rb', line 322

def set_root(dir)
  root = Root.extract_depth(dir)
  check_valid_dir(root.dir)
  root.dir  = File.expand_path(root.dir.gsub(/[\\]/,'/'))
  @roots << root
end

#set_set(str) ⇒ Object



360
361
362
363
364
365
366
367
# File 'lib/bake/options/options.rb', line 360

def set_set(str)
  ar = str.split("=")
  if not str.include?"=" or ar[0].length == 0
    Bake.formatter.printError("Error: --set must be followed by key=value")
    ExitHelper.exit(1)
  end
  @vars[ar[0]] = ar[1..-1].join("=")
end

#set_threads(num) ⇒ Object



342
343
344
345
346
347
348
349
# File 'lib/bake/options/options.rb', line 342

def set_threads(num)
  checkNum(num)
  @threads = String === num ? num.to_i : num
  if @threads <= 0
    Bake.formatter.printError("Error: number of threads must be > 0")
    ExitHelper.exit(1)
  end
end

#set_verbose(num) ⇒ Object



351
352
353
354
355
356
357
358
# File 'lib/bake/options/options.rb', line 351

def set_verbose(num)
  checkNum(num)
  @verbose = String === num ? num.to_i : num
  if @verbose < 0 || verbose > 3
    Bake.formatter.printError("Error: verbose must be between 0 and 3")
    ExitHelper.exit(1)
  end
end