Class: Options

Inherits:
Object
  • Object
show all
Defined in:
ext/options.rb

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



2
3
4
5
6
7
8
# File 'ext/options.rb', line 2

def initialize
  @options = {}
  @pending_options = []
  @ignored_options = []

  configure
end

Instance Method Details

#cmake_optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ext/options.rb', line 30

def cmake_options
  return @cmake_options if @cmake_options

  output = nil
  Dir.chdir __dir__ do
    output = `cmake -S sources -B build -L`
  end
  started = false
  @cmake_options = output.lines.filter_map {|line|
    if line.chomp == "-- Cache values"
      started = true
      next
    end
    next unless started
    option, value = line.chomp.split("=", 2)
    name, type = option.split(":", 2)
    [name, type, value]
  }
end

#extra_optionsObject



55
56
57
58
# File 'ext/options.rb', line 55

def extra_options
  @options.keys + @pending_options + @ignored_options -
    cmake_options.collect {|name, type, value| name}
end

#helpObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'ext/options.rb', line 10

def help
  @options
    .collect_concat {|name, (type, value)|
      option = option_name(name)
      if type == :bool
        ["--enable-#{option}", "--disable-#{option}"]
      else
        "--#{option}=#{type.upcase}"
      end
    }
    .join($/)
end

#missing_optionsObject



50
51
52
53
# File 'ext/options.rb', line 50

def missing_options
  cmake_options.collect {|name, type, value| name} -
    @options.keys - @pending_options - @ignored_options
end

#to_sObject



23
24
25
26
27
28
# File 'ext/options.rb', line 23

def to_s
  @options
    .reject {|name, (type, value)| value.nil?}
    .collect {|name, (type, value)| "-D #{name}=#{value == true ? "ON" : value == false ? "OFF" : value.shellescape}"}
    .join(" ")
end