Class Installer
In: setup.rb
Parent: Object

Methods

Included Modules

FileOperations HookScriptAPI

Classes and Modules

Class Installer::Shebang

Constants

FILETYPES = %w( bin lib ext data conf man )
JUNK_FILES = %w( core RCSLOG tags TAGS .make.state .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb *~ *.old *.bak *.BAK *.orig *.rej _$* *$ *.org *.in .* )   picked up many entries from cvs-1.11.1/src/ignore.c
GLOB2REGEX = { '.' => '\.', '$' => '\$', '#' => '\#', '*' => '.*'
TESTDIR = 'test'   TASK test

Public Class methods

[Source]

# File setup.rb, line 1165
  def initialize(config, srcroot, objroot)
    @config = config
    @srcdir = File.expand_path(srcroot)
    @objdir = File.expand_path(objroot)
    @currdir = '.'
  end

Public Instance methods

clean_dir_bin(rel)

Alias for noop

clean_dir_conf(rel)

Alias for noop

clean_dir_data(rel)

Alias for noop

[Source]

# File setup.rb, line 1486
  def clean_dir_ext(rel)
    return unless extdir?(curr_srcdir())
    make 'clean' if File.file?('Makefile')
  end
clean_dir_lib(rel)

Alias for noop

clean_dir_man(rel)

Alias for noop

config_dir_bin(rel)

Alias for noop

config_dir_conf(rel)

Alias for noop

config_dir_data(rel)

Alias for noop

[Source]

# File setup.rb, line 1229
  def config_dir_ext(rel)
    extconf if extdir?(curr_srcdir())
  end
config_dir_lib(rel)

Alias for noop

config_dir_man(rel)

Alias for noop

distclean_dir_bin(rel)

Alias for noop

distclean_dir_conf(rel)

Alias for noop

distclean_dir_data(rel)

Alias for noop

[Source]

# File setup.rb, line 1504
  def distclean_dir_ext(rel)
    return unless extdir?(curr_srcdir())
    make 'distclean' if File.file?('Makefile')
  end
distclean_dir_lib(rel)

Alias for noop

distclean_dir_man(rel)

Alias for noop

[Source]

# File setup.rb, line 1540
  def dive_into(rel)
    return unless File.dir?("#{@srcdir}/#{rel}")

    dir = File.basename(rel)
    Dir.mkdir dir unless File.dir?(dir)
    prevdir = Dir.pwd
    Dir.chdir dir
    $stderr.puts '---> ' + rel if verbose?
    @currdir = rel
    yield
    Dir.chdir prevdir
    $stderr.puts '<--- ' + rel if verbose?
    @currdir = File.dirname(rel)
  end

TASK clean

[Source]

# File setup.rb, line 1474
  def exec_clean
    exec_task_traverse 'clean'
    rm_f @config.savefile
    rm_f 'InstalledFiles'
  end

TASK config

[Source]

# File setup.rb, line 1222
  def exec_config
    exec_task_traverse 'config'
  end

TASK distclean

[Source]

# File setup.rb, line 1495
  def exec_distclean
    exec_task_traverse 'distclean'
    rm_f @config.savefile
    rm_f 'InstalledFiles'
  end

TASK install

[Source]

# File setup.rb, line 1340
  def exec_install
    rm_f 'InstalledFiles'
    exec_task_traverse 'install'
  end

TASK setup

[Source]

# File setup.rb, line 1245
  def exec_setup
    exec_task_traverse 'setup'
  end

Traversing

[Source]

# File setup.rb, line 1517
  def exec_task_traverse(task)
    run_hook "pre-#{task}"
    FILETYPES.each do |type|
      if type == 'ext' and config('without-ext') == 'yes'
        $stderr.puts 'skipping ext/* by user option' if verbose?
        next
      end
      traverse task, type, "#{task}_dir_#{type}"
    end
    run_hook "post-#{task}"
  end

[Source]

# File setup.rb, line 1454
  def exec_test
    unless File.directory?('test')
      $stderr.puts 'no test in this package' if verbose?
      return
    end
    $stderr.puts 'Running tests...' if verbose?
    begin
      require 'test/unit'
    rescue LoadError
      setup_rb_error 'test/unit cannot loaded.  You need Ruby 1.8 or later to invoke this task.'
    end
    runner = Test::Unit::AutoRunner.new(true)
    runner.to_run << TESTDIR
    runner.run
  end

[Source]

# File setup.rb, line 1415
  def existfiles
    glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
  end

[Source]

# File setup.rb, line 1237
  def extconf
    ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
  end

[Source]

# File setup.rb, line 1430
  def glob_reject(pats, ents)
    re = globs2re(pats)
    ents.reject {|ent| re =~ ent }
  end

[Source]

# File setup.rb, line 1425
  def glob_select(pat, ents)
    re = globs2re([pat])
    ents.select {|ent| re =~ ent }
  end

[Source]

# File setup.rb, line 1442
  def globs2re(pats)
    /\A(?:#{
      pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|')
    })\z/
  end

[Source]

# File setup.rb, line 1419
  def hookfiles
    %w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt|
      %w( config setup install clean ).map {|t| sprintf(fmt, t) }
    }.flatten
  end

[Source]

# File setup.rb, line 1172
  def inspect
    "#<#{self.class} #{File.basename(@srcdir)}>"
  end

[Source]

# File setup.rb, line 1345
  def install_dir_bin(rel)
    install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
  end

[Source]

# File setup.rb, line 1364
  def install_dir_conf(rel)
    # FIXME: should not remove current config files
    # (rename previous file to .old/.org)
    install_files targetfiles(), "#{config('sysconfdir')}/#{rel}", 0644
  end

[Source]

# File setup.rb, line 1360
  def install_dir_data(rel)
    install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644
  end

[Source]

# File setup.rb, line 1353
  def install_dir_ext(rel)
    return unless extdir?(curr_srcdir())
    install_files rubyextentions('.'),
                  "#{config('sodir')}/#{File.dirname(rel)}",
                  0555
  end

[Source]

# File setup.rb, line 1349
  def install_dir_lib(rel)
    install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
  end

[Source]

# File setup.rb, line 1370
  def install_dir_man(rel)
    install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
  end

[Source]

# File setup.rb, line 1374
  def install_files(list, dest, mode)
    mkdir_p dest, @config.install_prefix
    list.each do |fname|
      install fname, dest, mode, @config.install_prefix
    end
  end

[Source]

# File setup.rb, line 1381
  def libfiles
    glob_reject(%w(*.y *.output), targetfiles())
  end

[Source]

# File setup.rb, line 1397
  def mapdir(ents)
    ents.map {|ent|
      if File.exist?(ent)
      then ent                         # objdir
      else "#{curr_srcdir()}/#{ent}"   # srcdir
      end
    }
  end

[Source]

# File setup.rb, line 1287
  def new_shebang(old)
    if /\Aruby/ =~ File.basename(old.cmd)
      Shebang.new(config('rubypath'), old.args)
    elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
      Shebang.new(config('rubypath'), old.args[1..-1])
    else
      return old unless config('shebang') == 'all'
      Shebang.new(config('rubypath'))
    end
  end

module FileOperations requires this

[Source]

# File setup.rb, line 1205
  def no_harm?
    @config.no_harm?
  end

[Source]

# File setup.rb, line 1176
  def noop(rel)
  end

[Source]

# File setup.rb, line 1187
  def objdir_root
    @objdir
  end

[Source]

# File setup.rb, line 1298
  def open_atomic_writer(path, &block)
    tmpfile = File.basename(path) + '.tmp'
    begin
      File.open(tmpfile, 'wb', &block)
      File.rename tmpfile, File.basename(path)
    ensure
      File.unlink tmpfile if File.exist?(tmpfile)
    end
  end

[Source]

# File setup.rb, line 1191
  def relpath
    @currdir
  end

[Source]

# File setup.rb, line 1385
  def rubyextentions(dir)
    ents = glob_select("*.#{@config.dllext}", targetfiles())
    if ents.empty?
      setup_rb_error "no ruby extention exists: 'ruby #{$0} setup' first"
    end
    ents
  end

[Source]

# File setup.rb, line 1555
  def run_hook(id)
    path = [ "#{curr_srcdir()}/#{id}",
             "#{curr_srcdir()}/#{id}.rb" ].detect {|cand| File.file?(cand) }
    return unless path
    begin
      instance_eval File.read(path), path, 1
    rescue
      raise if $DEBUG
      setup_rb_error "hook #{path} failed:\n" + $!.message
    end
  end

[Source]

# File setup.rb, line 1249
  def setup_dir_bin(rel)
    files_of(curr_srcdir()).each do |fname|
      update_shebang_line "#{curr_srcdir()}/#{fname}"
    end
  end
setup_dir_conf(rel)

Alias for noop

setup_dir_data(rel)

Alias for noop

[Source]

# File setup.rb, line 1257
  def setup_dir_ext(rel)
    make if extdir?(curr_srcdir())
  end
setup_dir_lib(rel)

Alias for noop

setup_dir_man(rel)

Alias for noop

Hook Script API base methods

[Source]

# File setup.rb, line 1183
  def srcdir_root
    @srcdir
  end

[Source]

# File setup.rb, line 1393
  def targetfiles
    mapdir(existfiles() - hookfiles())
  end

[Source]

# File setup.rb, line 1529
  def traverse(task, rel, mid)
    dive_into(rel) {
      run_hook "pre-#{task}"
      __send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '')
      directories_of(curr_srcdir()).each do |d|
        traverse task, "#{rel}/#{d}", mid
      end
      run_hook "post-#{task}"
    }
  end

[Source]

# File setup.rb, line 1265
  def update_shebang_line(path)
    return if no_harm?
    return if config('shebang') == 'never'
    old = Shebang.load(path)
    if old
      $stderr.puts "warning: #{path}: Shebang line includes too many args.  It is not portable and your program may not work." if old.args.size > 1
      new = new_shebang(old)
      return if new.to_s == old.to_s
    else
      return unless config('shebang') == 'all'
      new = Shebang.new(config('rubypath'))
    end
    $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
    open_atomic_writer(path) {|output|
      File.open(path, 'rb') {|f|
        f.gets if old   # discard
        output.puts new.to_s
        output.print f.read
      }
    }
  end

module FileOperations requires this

[Source]

# File setup.rb, line 1200
  def verbose?
    @config.verbose?
  end

[Source]

# File setup.rb, line 1209
  def verbose_off
    begin
      save, @config.verbose = @config.verbose?, false
      yield
    ensure
      @config.verbose = save
    end
  end

[Validate]