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, #parse_internal

Constructor Details

#initialize(argv) ⇒ Options

Returns a new instance of Options.



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
122
123
124
125
# File 'lib/bake/options/options.rb', line 30

def initialize(argv)
  super(argv)

  @conversion_info = false
  @envToolchain = false
  @analyze = false
  @eclipseOrder = false
  @showConfigs = false
  @consoleOutput_fullnames = false
  @consoleOutput_visualStudio = false           
  @prepro = false
  @stopOnFirstError = false
  @verbose = 1
  @vars = {}
  @build_config = ""
  @main_dir = nil
  @project = nil      
  @filename = nil
  @cc2j_filename = nil
  @clean = false
  @clobber = false
  @lint = false
  @docu = false
  @debug = false
  @rebuild = false
  @nocache = false
  @show_includes = false
  @show_includes_and_defines = false
  @linkOnly = false
  @no_autodir = false
  @threads = 8
  @lint_min = 0
  @lint_max = -1
  @roots = []
  @socket = 0
  @include_filter = []
  @exclude_filter = []
  @def_roots = []
  @main_project_name = ""
  
  add_option(["-b",                   ""                     ], lambda { |x| set_build_config(x)                     })
  add_option(["-m"                                           ], lambda { |x| set_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(["--rebuild"                                    ], lambda {     @rebuild = true                         })
  add_option(["--prepro"                                     ], lambda {     @prepro = true                          })
  add_option(["--link-only",          "--link_only"          ], lambda {     @linkOnly = true;                       })
  add_option(["--no-autodir",         "--no_autodir"         ], lambda {     @no_autodir = true                      })
  add_option(["--lint"                                       ], lambda {     @lint = true                            })
  add_option(["--lint-min",           "--lint_min"           ], lambda { |x| @lint_min = String === x ? x.to_i : x   })
  add_option(["--lint-max",           "--lint_max"           ], lambda { |x| @lint_max = String === x ? x.to_i : x   })
                                                                                                                     
  add_option(["--create"                                     ], lambda { |x| Bake::Create.proj(x)                    })     
  add_option(["--conversion-info",    "--conversion_info"    ], lambda { @conversion_info = true                     }) 
                                                                                                                     
  add_option(["--generate-doc",       "--docu"               ], lambda {     @docu = true                            })
                                                                                                                     
  add_option(["-v0"                                          ], lambda {     @verbose = 0                            })
  add_option(["-v1"                                          ], lambda {     @verbose = 1                            })
  add_option(["-v2"                                          ], lambda {     @verbose = 2                            })
  add_option(["-v3"                                          ], lambda {     @verbose = 3                            })
    
  add_option(["--debug"                                      ], lambda {     @debug = true                           })
  add_option(["--set"                                        ], lambda { |x| set_set(x)                              })
    
  add_option(["--clobber"                                    ], lambda {     @clobber = true; @clean = true          })
  add_option(["--ignore-cache",       "--ignore_cache"       ], lambda {     @nocache = true                         })
  add_option(["--threads"                                    ], lambda { |x| 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(["--do",                 "--include_filter"     ], lambda { |x| @include_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(["-h",                   "--help"               ], lambda {     Bake::Usage.show                        })

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

  add_option(["--version"                                    ], lambda {     ExitHelper.exit(0)                      })
  add_option(["--list",               "--show_configs"       ], lambda {     @showConfigs = true                     })
  add_option(["--writeCC2J"                                  ], lambda { |x| @cc2j_filename = x.gsub(/[\\]/,'/')     })

  # hidden
  add_option(["--visualStudio"                               ], lambda {     @consoleOutput_visualStudio = true      })
        
  # deprecated and not replaced by new command
  add_option(["--show_include_paths"                         ], lambda {     @show_includes = true                   })

end

Instance Attribute Details

#analyzeObject

Returns the value of attribute analyze.



20
21
22
# File 'lib/bake/options/options.rb', line 20

def analyze
  @analyze
end

#build_configObject

Returns the value of attribute build_config.



20
21
22
# File 'lib/bake/options/options.rb', line 20

def build_config
  @build_config
end

#cc2j_filenameObject (readonly)

String



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

def cc2j_filename
  @cc2j_filename
end

#cleanObject (readonly)

Boolean



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

def clean
  @clean
end

#clobberObject (readonly)

Boolean



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

def clobber
  @clobber
end

#consoleOutput_fullnamesObject (readonly)

Returns the value of attribute consoleOutput_fullnames.



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

def consoleOutput_fullnames
  @consoleOutput_fullnames
end

#consoleOutput_visualStudioObject (readonly)

Returns the value of attribute consoleOutput_visualStudio.



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

def consoleOutput_visualStudio
  @consoleOutput_visualStudio
end

#conversion_infoObject (readonly)

Boolean



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

def conversion_info
  @conversion_info
end

#debugObject (readonly)

Boolean



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

def debug
  @debug
end

#docuObject (readonly)

Boolean



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

def docu
  @docu
end

#eclipseOrderObject

Returns the value of attribute eclipseOrder.



20
21
22
# File 'lib/bake/options/options.rb', line 20

def eclipseOrder
  @eclipseOrder
end

#envToolchainObject

Returns the value of attribute envToolchain.



20
21
22
# File 'lib/bake/options/options.rb', line 20

def envToolchain
  @envToolchain
end

#exclude_filterObject (readonly)

String List



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

def exclude_filter
  @exclude_filter
end

#filenameObject (readonly)

String



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

def filename
  @filename
end

#include_filterObject (readonly)

String List



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

def include_filter
  @include_filter
end

#linkOnlyObject (readonly)

Boolean



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

def linkOnly
  @linkOnly
end

#lintObject (readonly)

Boolean



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

def lint
  @lint
end

#lint_maxObject (readonly)

Fixnum



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

def lint_max
  @lint_max
end

#lint_minObject (readonly)

Fixnum



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

def lint_min
  @lint_min
end

#main_dirObject (readonly)

String



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

def main_dir
  @main_dir
end

#main_project_nameObject (readonly)

String



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

def main_project_name
  @main_project_name
end

#no_autodirObject (readonly)

Boolean



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

def no_autodir
  @no_autodir
end

#nocacheObject

Returns the value of attribute nocache.



20
21
22
# File 'lib/bake/options/options.rb', line 20

def nocache
  @nocache
end

#preproObject (readonly)

Boolean



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

def prepro
  @prepro
end

#projectObject (readonly)

String



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

def project
  @project
end

#rebuildObject (readonly)

Boolean



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

def rebuild
  @rebuild
end

#rootsObject (readonly)

String List



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

def roots
  @roots
end

#show_includesObject (readonly)

Boolean



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

def show_includes
  @show_includes
end

#show_includes_and_definesObject (readonly)

Boolean



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

def show_includes_and_defines
  @show_includes_and_defines
end

#socketObject (readonly)

Fixnum



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

def socket
  @socket
end

#stopOnFirstErrorObject (readonly)

Boolean



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

def stopOnFirstError
  @stopOnFirstError
end

#threadsObject (readonly)

Fixnum



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

def threads
  @threads
end

#varsObject (readonly)

map



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

def vars
  @vars
end

#verboseObject (readonly)

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

Instance Method Details

#check_valid_dir(dir) ⇒ Object



204
205
206
207
208
209
210
211
212
213
# File 'lib/bake/options/options.rb', line 204

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

#parse_optionsObject



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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/bake/options/options.rb', line 127

def parse_options()
  parse_internal()
  set_main_dir(Dir.pwd) if @main_dir.nil?
  @roots = @def_roots if @roots.length == 0
  
  if @project
    if @project.split(',').length > 2
      Bake.formatter.printError("Error: only one comma allowed for -p")
      ExitHelper.exit(1)
    end
  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 @lint
      Bake.formatter.printError("Error: --conversion-info and --lint 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
    if not @project
      Bake.formatter.printError("Error: --conversion-info must be used with -p")
      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
  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 @lint and @docu
    Bake.formatter.printError("Error: --lint and --docu not allowed at the same time")
    ExitHelper.exit(1)
  end

  ConfigNames.show if @showConfigs
end

#set_build_config(config) ⇒ Object



215
216
217
218
219
220
221
# File 'lib/bake/options/options.rb', line 215

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_main_dir(dir) ⇒ Object



223
224
225
226
227
228
# File 'lib/bake/options/options.rb', line 223

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

#set_root(dir) ⇒ Object



230
231
232
233
234
# File 'lib/bake/options/options.rb', line 230

def set_root(dir)
  check_valid_dir(dir)
  r = File.expand_path(dir.gsub(/[\\]/,'/'))
  @roots << r if not @roots.include?r
end

#set_set(str) ⇒ Object



244
245
246
247
248
249
250
251
# File 'lib/bake/options/options.rb', line 244

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



236
237
238
239
240
241
242
# File 'lib/bake/options/options.rb', line 236

def set_threads(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