class Setup::Configuration

Stores platform information and general install settings.

Constants

META_CONFIG_FILE

Custom configuration file.

RBCONFIG

Ruby System Configuration

Attributes

reset[RW]

def initialize_configfile

begin
   File.foreach(CONFIG_FILE) do |line|
     k, v = *line.split(/=/, 2)
     k.gsub!('-','_')
     __send__("#{k}=",v.strip) #self[k] = v.strip
   end
 rescue Errno::ENOENT
   raise Error, $!.message + "\n#{File.basename($0)} config first"
 end

end

Public Class Methods

new(values={}) { |self| ... } click to toggle source

New ConfigTable

# File lib/setup/configuration.rb, line 112
def initialize(values={})
  initialize_metaconfig
  initialize_defaults
  initialize_environment
  initialize_configfile unless values[:reset]

  values.each{ |k,v| __send__("#{k}=", v) }
  yield(self) if block_given?
end
option(name, *args) click to toggle source

TODO: better methods for path type

# File lib/setup/configuration.rb, line 32
def self.option(name, *args) #type, description)
  options << [name.to_s, *args] #type, description]
  attr_accessor(name)
end
options() click to toggle source
# File lib/setup/configuration.rb, line 25
def self.options
  @@options ||= []
end

Public Instance Methods

base_bindir() click to toggle source

Base bin directory

# File lib/setup/configuration.rb, line 198
def base_bindir
  @base_bindir ||= subprefix('bindir')
end
base_datadir() click to toggle source
# File lib/setup/configuration.rb, line 208
def base_datadir
  @base_datadir ||= subprefix('datadir')
end
base_docdir() click to toggle source

NOTE: This removed the trailing $(PACKAGE).

# File lib/setup/configuration.rb, line 218
def base_docdir
  @base_docdir || File.dirname(subprefix('docdir'))
end
base_libdir() click to toggle source

Base libdir

# File lib/setup/configuration.rb, line 203
def base_libdir
  @base_libdir ||= subprefix('libdir')
end
base_localstatedir() click to toggle source

Base directory for local state data

# File lib/setup/configuration.rb, line 238
def base_localstatedir
  @base_localstatedir ||= subprefix('localstatedir')
end
base_mandir() click to toggle source
# File lib/setup/configuration.rb, line 213
def base_mandir
  @base_mandir ||= subprefix('mandir')
end
base_rubyarchdir() click to toggle source
# File lib/setup/configuration.rb, line 228
def base_rubyarchdir
  @base_rubyarchdir ||= subprefix('archdir')
end
base_rubylibdir() click to toggle source
# File lib/setup/configuration.rb, line 223
def base_rubylibdir
  @rubylibdir ||= subprefix('rubylibdir')
end
base_sysconfdir() click to toggle source

Base directory for system configuration files

# File lib/setup/configuration.rb, line 233
def base_sysconfdir
  @base_sysconfdir ||= subprefix('sysconfdir')
end
bindir() click to toggle source

Directory for commands

# File lib/setup/configuration.rb, line 365
def bindir
  @bindir || File.join(prefix, base_bindir)
end
bindir=(path) click to toggle source

Set directory for commands

# File lib/setup/configuration.rb, line 370
def bindir=(path)
  @bindir = pathname(path)
end
compile?() click to toggle source

Compile native extensions?

# File lib/setup/configuration.rb, line 554
def compile?
  !no_ext
end
datadir() click to toggle source

Directory for shared data

# File lib/setup/configuration.rb, line 385
def datadir
  @datadir || File.join(prefix, base_datadir)
end
datadir=(path) click to toggle source

Set directory for shared data

# File lib/setup/configuration.rb, line 390
def datadir=(path)
  @datadir = pathname(path)
end
doc?() click to toggle source

Install doc directory?

# File lib/setup/configuration.rb, line 569
def doc?
  !no_doc
end
docdir() click to toggle source

Directory for documentation

# File lib/setup/configuration.rb, line 405
def docdir
  @docdir || File.join(prefix, base_docdir)
end
docdir=(path) click to toggle source

Set directory for documentation

# File lib/setup/configuration.rb, line 410
def docdir=(path)
  @docdir = pathname(path)
end
exist?() click to toggle source

Does the configuration file exist?

# File lib/setup/configuration.rb, line 611
def exist?
  File.exist?(CONFIG_FILE)
end
extconfopt() click to toggle source
# File lib/setup/configuration.rb, line 484
def extconfopt
  @extconfopt ||= ''
end
extconfopt=(string) click to toggle source
# File lib/setup/configuration.rb, line 489
def extconfopt=(string)
  @extconfopt = string
end
initialize_configfile() click to toggle source

Load configuration.

# File lib/setup/configuration.rb, line 153
def initialize_configfile
  if exist?
    erb = ERB.new(File.read(CONFIG_FILE))
    txt = erb.result(binding)
    dat = YAML.load(txt)
    dat.each do |k, v|
      next if 'type' == k
      next if 'installdirs' == k
      k = k.gsub('-','_')
      __send__("#{k}=", v)
    end
    # do these last
    if dat['type']
      self.type = dat['type']
    end
    if dat['installdirs']
      self.installdirs = dat['installdirs']
    end
  #else
  #  raise Error, $!.message + "\n#{File.basename($0)} config first"
  end
end
initialize_defaults() click to toggle source

By default installation is to site locations, tests will not be run, ri documentation will not be generated, but the doc/ directory will be installed.

# File lib/setup/configuration.rb, line 133
def initialize_defaults
  self.type    = 'site'
  self.no_ri   = true
  self.no_test = true
  self.no_doc  = true
  self.no_ext  = false
  #@rbdir = siterubyver      #'$siterubyver'
  #@sodir = siterubyverarch  #'$siterubyverarch'
end
initialize_environment() click to toggle source

Get configuration from environment.

# File lib/setup/configuration.rb, line 144
def initialize_environment
  options.each do |name, *args|
    if value = ENV["RUBYSETUP_#{name.to_s.upcase}"]
      __send__("#{name}=", value)
    end
  end
end
initialize_metaconfig() click to toggle source
# File lib/setup/configuration.rb, line 123
def initialize_metaconfig
  if File.exist?(META_CONFIG_FILE)
    script = File.read(META_CONFIG_FILE)
    (class << self; self; end).class_eval(script)
  end
end
installdirs()

Alias for ‘#type`.

Alias for: type
installdirs=(val)

Alias for ‘#type=`.

Alias for: type=
libdir() click to toggle source

Directory for libraries

# File lib/setup/configuration.rb, line 375
def libdir
  @libdir || File.join(prefix, base_libdir)
end
libdir=(path) click to toggle source

Set directory for libraries

# File lib/setup/configuration.rb, line 380
def libdir=(path)
  @libdir = pathname(path)
end
libruby() click to toggle source

Directory for ruby libraries

# File lib/setup/configuration.rb, line 299
def libruby
  @libruby ||= RBCONFIG['prefix'] + "/lib/ruby"
end
libruby=(path) click to toggle source

Set directory for ruby libraries

# File lib/setup/configuration.rb, line 304
def libruby=(path)
  path = pathname(path)
  @librubyver = librubyver.sub(libruby, path)
  @librubyverarch = librubyverarch.sub(libruby, path)
  @libruby = path
end
librubyver() click to toggle source

Directory for standard ruby libraries

# File lib/setup/configuration.rb, line 312
def librubyver
  @librubyver ||= RBCONFIG['rubylibdir']
end
librubyver=(path) click to toggle source

Set directory for standard ruby libraries

# File lib/setup/configuration.rb, line 317
def librubyver=(path)
  @librubyver = pathname(path)
end
librubyverarch() click to toggle source

Directory for standard ruby extensions

# File lib/setup/configuration.rb, line 322
def librubyverarch
  @librubyverarch ||= RBCONFIG['archdir']
end
librubyverarch=(path) click to toggle source

Set directory for standard ruby extensions

# File lib/setup/configuration.rb, line 327
def librubyverarch=(path)
  @librubyverarch = pathname(path)
end
localstatedir() click to toggle source

Directory for local state data TODO: Can this be prefixed?

# File lib/setup/configuration.rb, line 437
def localstatedir
  @localstatedir ||= base_localstatedir
end
localstatedir=(path) click to toggle source

Set directory for local state data

# File lib/setup/configuration.rb, line 442
def localstatedir=(path)
  @localstatedir = pathname(path)
end
makeprog() click to toggle source

TODO: Does this handle ‘nmake’ on windows?

# File lib/setup/configuration.rb, line 468
def makeprog
  @makeprog ||= (
    if arg = RBCONFIG['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
      arg.sub(/'/, '').split(/=/, 2)[1]
    else
      'make'
    end
  )
end
makeprog=(command) click to toggle source
# File lib/setup/configuration.rb, line 479
def makeprog=(command)
  @makeprog = command
end
mandir() click to toggle source

Directory for man pages

# File lib/setup/configuration.rb, line 395
def mandir
  @mandir || File.join(prefix,  base_mandir)
end
mandir=(path) click to toggle source

Set directory for man pages

# File lib/setup/configuration.rb, line 400
def mandir=(path)
  @mandir = pathname(path)
end
no_doc() click to toggle source
# File lib/setup/configuration.rb, line 528
def no_doc
  @no_doc
end
no_doc=(val) click to toggle source
# File lib/setup/configuration.rb, line 533
def no_doc=(val)
  @no_doc = boolean(val)
end
no_ext() click to toggle source
# File lib/setup/configuration.rb, line 508
def no_ext
  @no_ext
end
no_ext=(val) click to toggle source
# File lib/setup/configuration.rb, line 513
def no_ext=(val)
  @no_ext = boolean(val)
end
no_ri() click to toggle source

@deprecated Will be remove in future version. Currently ignored.

# File lib/setup/configuration.rb, line 539
def no_ri
  @no_ri
end
no_ri=(val) click to toggle source

@deprecated Will be remove in future version. Currently ignored.

# File lib/setup/configuration.rb, line 544
def no_ri=(val)
  @no_ri = boolean(val)
end
no_test() click to toggle source
# File lib/setup/configuration.rb, line 518
def no_test
  @no_test
end
no_test=(val) click to toggle source
# File lib/setup/configuration.rb, line 523
def no_test=(val)
  @no_test = boolean(val)
end
options() click to toggle source
# File lib/setup/configuration.rb, line 104
def options
  #(class << self ; self ; end).options
  self.class.options
end
prefix() click to toggle source

Path prefix of target environment

# File lib/setup/configuration.rb, line 289
def prefix
  @prefix ||= RBCONFIG['prefix']
end
prefix=(path) click to toggle source

Set path prefix of target environment

# File lib/setup/configuration.rb, line 294
def prefix=(path)
  @prefix = pathname(path)
end
rbdir() click to toggle source

Directory for ruby scripts

# File lib/setup/configuration.rb, line 415
def rbdir
  @rbdir || File.join(prefix, base_rubylibdir)
end
rubypath() click to toggle source
# File lib/setup/configuration.rb, line 447
def rubypath
  #@rubypath ||= RBCONFIG['libexecdir']
  @rubypath ||= File.join(RBCONFIG['bindir'], RBCONFIG['ruby_install_name'] + RBCONFIG['EXEEXT'])
end
rubypath=(path) click to toggle source
# File lib/setup/configuration.rb, line 453
def rubypath=(path)
  @rubypath = pathname(path)
end
rubyprog() click to toggle source
# File lib/setup/configuration.rb, line 458
def rubyprog
  @rubyprog || rubypath
end
rubyprog=(command) click to toggle source
# File lib/setup/configuration.rb, line 463
def rubyprog=(command)
  @rubyprog = command
end
save_config() click to toggle source

Save configuration.

# File lib/setup/configuration.rb, line 596
def save_config
  out = to_yaml
  dir = File.dirname(CONFIG_FILE)
  unless File.exist?(dir)
    FileUtils.mkdir_p(dir)
  end
  if File.exist?(CONFIG_FILE)
    txt = File.read(CONFIG_FILE)
    return nil if txt == out
  end          
  File.open(CONFIG_FILE, 'w'){ |f| f << out }
  true
end
shebang() click to toggle source

Default is ruby.

# File lib/setup/configuration.rb, line 494
def shebang
  @shebang ||= 'ruby'
end
shebang=(val) click to toggle source

There are three options: all, ruby, never.

# File lib/setup/configuration.rb, line 499
def shebang=(val)
  if %w(all ruby never).include?(val)
    @shebang = val
  else
    raise Error, "bad config: use SHEBANG=(all|ruby|never) [#{val}]"
  end
end
siteruby() click to toggle source

Directory for version-independent aux ruby libraries

# File lib/setup/configuration.rb, line 332
def siteruby
  @siteruby ||= RBCONFIG['sitedir']
end
siteruby=(path) click to toggle source

Set directory for version-independent aux ruby libraries

# File lib/setup/configuration.rb, line 337
def siteruby=(path)
  path = pathname(path)
  @siterubyver = siterubyver.sub(siteruby, path)
  @siterubyverarch = siterubyverarch.sub(siteruby, path)
  @siteruby = path
end
siterubyver() click to toggle source

Directory for aux ruby libraries

# File lib/setup/configuration.rb, line 345
def siterubyver
  @siterubyver ||= RBCONFIG['sitelibdir']
end
siterubyver=(path) click to toggle source

Set directory for aux ruby libraries

# File lib/setup/configuration.rb, line 350
def siterubyver=(path)
  @siterubyver = pathname(path)
end
siterubyverarch() click to toggle source

Directory for aux ruby binary libraries

# File lib/setup/configuration.rb, line 355
def siterubyverarch
  @siterubyverarch ||= RBCONFIG['sitearchdir']
end
siterubyverarch=(path) click to toggle source

Set directory for aux arch ruby binaries

# File lib/setup/configuration.rb, line 360
def siterubyverarch=(path)
  @siterubyverarch = pathname(path)
end
sodir() click to toggle source

Directory for ruby extentions

# File lib/setup/configuration.rb, line 420
def sodir
  @sodir || File.join(prefix, base_rubyarchdir)
end
sysconfdir() click to toggle source

Directory for system configuration files TODO: Can this be prefixed?

# File lib/setup/configuration.rb, line 426
def sysconfdir
  @sysconfdir ||= base_sysconfdir
end
sysconfdir=(path) click to toggle source

Set directory for system configuration files

# File lib/setup/configuration.rb, line 431
def sysconfdir=(path)
  @sysconfdir = pathname(path)
end
test?() click to toggle source

Run unit tests?

# File lib/setup/configuration.rb, line 559
def test?
  !no_test
end
to_h() click to toggle source
# File lib/setup/configuration.rb, line 577
def to_h
  h = {}
  options.each do |name, *args|
    h[name.to_s] = __send__(name)
  end
  h
end
to_s() click to toggle source
# File lib/setup/configuration.rb, line 586
def to_s
  to_yaml.sub(/\A---\s*\n/,'')
end
to_yaml(*args) click to toggle source
# File lib/setup/configuration.rb, line 591
def to_yaml(*args)
  to_h.to_yaml(*args)
end
type() click to toggle source
# File lib/setup/configuration.rb, line 246
def type
  @type ||= 'site'
end
Also aliased as: installdirs
type=(val) click to toggle source
# File lib/setup/configuration.rb, line 251
def type=(val)
  @type = val
  case val.to_s
  when 'std', 'ruby'
    @rbdir = librubyver       #'$librubyver'
    @sodir = librubyverarch   #'$librubyverarch'
  when 'site'
    @rbdir = siterubyver      #'$siterubyver'
    @sodir = siterubyverarch  #'$siterubyverarch'
  when 'home'
    self.prefix = File.join(home, '.local')  # TODO: Use XDG
    @rbdir = nil #'$libdir/ruby'
    @sodir = nil #'$libdir/ruby'
  #when 'local'
  #  rbdir = subprefix(librubyver, '')
  #  sodir = subprefix(librubyverarch, '')
  #  self.prefix = '/usr/local' # FIXME: how?
  #  self.rbdir  = File.join(prefix, rbdir) #'$libdir/ruby'
  #  self.sodir  = File.join(prefix, sodir) #'$libdir/ruby'
  else
    raise Error, "bad config: use type=(std|site|home) [#{val}]"
  end
end
Also aliased as: installdirs=

Private Instance Methods

boolean(val, name=nil) click to toggle source

Boolean attribute. Can be assigned true, false, nil, or a string matching yes|true|y|t or no|false|n|f.

# File lib/setup/configuration.rb, line 645
def boolean(val, name=nil)
  case val
  when true, false, nil
    val
  else
    case val.to_s.downcase
    when 'y', 'yes', 't', 'true'
       true
    when 'n', 'no', 'f', 'false'
       false
    else
      raise Error, "bad config: use --#{name}=(yes|no) [\#{val}]"
    end
  end
end
home() click to toggle source
# File lib/setup/configuration.rb, line 670
def home
  ENV['HOME'] || raise(Error, 'HOME is not set.')
end
pathname(path) click to toggle source

def show

fmt = "%-20s %s\n"
OPTIONS.each do |name|
  value = self[name]
  reslv = __send__(name)
  case reslv
  when String
    reslv = "(none)" if reslv.empty?
  when false, nil
    reslv = "no"
  when true
    reslv = "yes"
  end
  printf fmt, name, reslv
end

end

# File lib/setup/configuration.rb, line 635
def pathname(path)
  path.gsub(%r<\\$([^/]+)>){ self[$1] }
end
subprefix(path, with='') click to toggle source
# File lib/setup/configuration.rb, line 662
def subprefix(path, with='')
  val = RBCONFIG[path]
  raise "Unknown path -- #{path}" if val.nil?
  prefix = Regexp.quote(RBCONFIG['prefix'])
  val.sub(/\A#{prefix}/, with)
end