Class ToplevelInstaller
In: setup.rb
Parent: Object

Methods

Constants

Version = '3.4.1'
Copyright = 'Copyright (c) 2000-2005 Minero Aoki'
TASKS = [ [ 'all', 'do config, setup, then install' ], [ 'config', 'saves your configurations' ], [ 'show', 'shows current configuration' ], [ 'setup', 'compiles ruby extentions and others' ], [ 'install', 'installs files' ], [ 'test', 'run all tests in test/' ], [ 'clean', "does `make clean' for each extention" ], [ 'distclean',"does `make distclean' for each extention" ]

Public Class methods

[Source]

# File setup.rb, line 767
  def ToplevelInstaller.invoke
    config = ConfigTable.new(load_rbconfig())
    config.load_standard_entries
    config.load_multipackage_entries if multipackage?
    config.fixup
    klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller)
    klass.new(File.dirname($0), config).invoke
  end

[Source]

# File setup.rb, line 780
  def ToplevelInstaller.load_rbconfig
    if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
      ARGV.delete(arg)
      load File.expand_path(arg.split(/=/, 2)[1])
      $".push 'rbconfig.rb'
    else
      require 'rbconfig'
    end
    ::Config::CONFIG
  end

[Source]

# File setup.rb, line 776
  def ToplevelInstaller.multipackage?
    File.dir?(File.dirname($0) + '/packages')
  end

[Source]

# File setup.rb, line 791
  def initialize(ardir_root, config)
    @ardir = File.expand_path(ardir_root)
    @config = config
    # cache
    @valid_task_re = nil
  end

Public Instance methods

[Source]

# File setup.rb, line 798
  def config(key)
    @config[key]
  end

[Source]

# File setup.rb, line 1013
  def exec_clean
    @installer.exec_clean
  end

Task Handlers

[Source]

# File setup.rb, line 990
  def exec_config
    @installer.exec_config
    @config.save   # must be final
  end

[Source]

# File setup.rb, line 1017
  def exec_distclean
    @installer.exec_distclean
  end

[Source]

# File setup.rb, line 999
  def exec_install
    @installer.exec_install
  end

[Source]

# File setup.rb, line 995
  def exec_setup
    @installer.exec_setup
  end

[Source]

# File setup.rb, line 1007
  def exec_show
    @config.each do |i|
      printf "%-20s %s\n", i.name, i.value if i.value?
    end
  end

[Source]

# File setup.rb, line 1003
  def exec_test
    @installer.exec_test
  end

[Source]

# File setup.rb, line 834
  def init_installers
    @installer = Installer.new(@config, @ardir, File.expand_path('.'))
  end

[Source]

# File setup.rb, line 802
  def inspect
    "#<#{self.class} #{__id__()}>"
  end

[Source]

# File setup.rb, line 806
  def invoke
    run_metaconfigs
    case task = parsearg_global()
    when nil, 'all'
      parsearg_config
      init_installers
      exec_config
      exec_setup
      exec_install
    else
      case task
      when 'config', 'test'
        ;
      when 'clean', 'distclean'
        @config.load_savefile if File.exist?(@config.savefile)
      else
        @config.load_savefile
      end
      __send__ "parsearg_#{task}"
      init_installers
      __send__ "exec_#{task}"
    end
  end

[Source]

# File setup.rb, line 846
  def objdir_root
    '.'
  end
parsearg_clean()

[Source]

# File setup.rb, line 905
  def parsearg_config
    evalopt = []
    set = []
    @config.config_opt = []
    while i = ARGV.shift
      if /\A--?\z/ =~ i
        @config.config_opt = ARGV.dup
        break
      end
      name, value = *@config.parse_opt(i)
      if @config.value_config?(name)
        @config[name] = value
      else
        evalopt.push [name, value]
      end
      set.push name
    end
    evalopt.each do |name, value|
      @config.lookup(name).evaluate value, @config
    end
    # Check if configuration is valid
    set.each do |n|
      @config[n] if @config.value_config?(n)
    end
  end
parsearg_distclean()

Option Parsing

[Source]

# File setup.rb, line 858
  def parsearg_global
    while arg = ARGV.shift
      case arg
      when /\A\w+\z/
        setup_rb_error "invalid task: #{arg}" unless valid_task?(arg)
        return arg
      when '-q', '--quiet'
        @config.verbose = false
      when '--verbose'
        @config.verbose = true
      when '--help'
        print_usage $stdout
        exit 0
      when '--version'
        puts "#{File.basename($0)} version #{Version}"
        exit 0
      when '--copyright'
        puts Copyright
        exit 0
      else
        setup_rb_error "unknown global option '#{arg}'"
      end
    end
    nil
  end

[Source]

# File setup.rb, line 931
  def parsearg_install
    @config.no_harm = false
    @config.install_prefix = ''
    while a = ARGV.shift
      case a
      when '--no-harm'
        @config.no_harm = true
      when /\A--prefix=/
        path = a.split(/=/, 2)[1]
        path = File.expand_path(path) unless path[0,1] == '/'
        @config.install_prefix = path
      else
        setup_rb_error "install: unknown option #{a}"
      end
    end
  end

[Source]

# File setup.rb, line 892
  def parsearg_no_options
    unless ARGV.empty?
      task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1)
      setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"
    end
  end
parsearg_setup()
parsearg_show()
parsearg_test()

[Source]

# File setup.rb, line 948
  def print_usage(out)
    out.puts 'Typical Installation Procedure:'
    out.puts "  $ ruby #{File.basename $0} config"
    out.puts "  $ ruby #{File.basename $0} setup"
    out.puts "  # ruby #{File.basename $0} install (may require root privilege)"
    out.puts
    out.puts 'Detailed Usage:'
    out.puts "  ruby #{File.basename $0} <global option>"
    out.puts "  ruby #{File.basename $0} [<global options>] <task> [<task options>]"

    fmt = "  %-24s %s\n"
    out.puts
    out.puts 'Global options:'
    out.printf fmt, '-q,--quiet',   'suppress message outputs'
    out.printf fmt, '   --verbose', 'output messages verbosely'
    out.printf fmt, '   --help',    'print this message'
    out.printf fmt, '   --version', 'print version and quit'
    out.printf fmt, '   --copyright',  'print copyright and quit'
    out.puts
    out.puts 'Tasks:'
    TASKS.each do |name, desc|
      out.printf fmt, name, desc
    end

    fmt = "  %-24s %s [%s]\n"
    out.puts
    out.puts 'Options for CONFIG or ALL:'
    @config.each do |item|
      out.printf fmt, item.help_opt, item.description, item.help_default
    end
    out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
    out.puts
    out.puts 'Options for INSTALL:'
    out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
    out.printf fmt, '--prefix=path',  'install path prefix', ''
    out.puts
  end

[Source]

# File setup.rb, line 850
  def relpath
    '.'
  end

[Source]

# File setup.rb, line 830
  def run_metaconfigs
    @config.load_script "#{@ardir}/metaconfig"
  end

Hook Script API bases

[Source]

# File setup.rb, line 842
  def srcdir_root
    @ardir
  end

[Source]

# File setup.rb, line 884
  def valid_task?(t)
    valid_task_re() =~ t
  end

[Source]

# File setup.rb, line 888
  def valid_task_re
    @valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/
  end

[Validate]