class Installer

Constants

FILETYPES
GLOB2REGEX
JUNK_FILES

picked up many entries from cvs-1.11.1/src/ignore.c

TESTDIR

TASK test

Public Class Methods

new(config, srcroot, objroot) click to toggle source
# File pkg/statsample-1.4.0/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
clean_dir_ext(rel) click to toggle source
# File pkg/statsample-1.4.0/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
config_dir_ext(rel) click to toggle source
# File pkg/statsample-1.4.0/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
distclean_dir_ext(rel) click to toggle source
# File pkg/statsample-1.4.0/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
dive_into(rel) { || ... } click to toggle source
# File pkg/statsample-1.4.0/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
exec_clean() click to toggle source

TASK clean

# File pkg/statsample-1.4.0/setup.rb, line 1474
def exec_clean
  exec_task_traverse 'clean'
  rm_f @config.savefile
  rm_f 'InstalledFiles'
end
exec_config() click to toggle source

TASK config

# File pkg/statsample-1.4.0/setup.rb, line 1222
def exec_config
  exec_task_traverse 'config'
end
exec_distclean() click to toggle source

TASK distclean

# File pkg/statsample-1.4.0/setup.rb, line 1495
def exec_distclean
  exec_task_traverse 'distclean'
  rm_f @config.savefile
  rm_f 'InstalledFiles'
end
exec_install() click to toggle source

TASK install

# File pkg/statsample-1.4.0/setup.rb, line 1340
def exec_install
  rm_f 'InstalledFiles'
  exec_task_traverse 'install'
end
exec_setup() click to toggle source

TASK setup

# File pkg/statsample-1.4.0/setup.rb, line 1245
def exec_setup
  exec_task_traverse 'setup'
end
exec_task_traverse(task) click to toggle source

Traversing

# File pkg/statsample-1.4.0/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
exec_test() click to toggle source
# File pkg/statsample-1.4.0/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
existfiles() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1415
def existfiles
  glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
end
extconf() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1237
def extconf
  ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
end
glob_reject(pats, ents) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1430
def glob_reject(pats, ents)
  re = globs2re(pats)
  ents.reject {|ent| re =~ ent }
end
glob_select(pat, ents) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1425
def glob_select(pat, ents)
  re = globs2re([pat])
  ents.select {|ent| re =~ ent }
end
globs2re(pats) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1442
def globs2re(pats)
  /\A(?:#{
    pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|')
  })\z/
end
hookfiles() click to toggle source
# File pkg/statsample-1.4.0/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
inspect() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1172
def inspect
  "#<#{self.class} #{File.basename(@srcdir)}>"
end
install_dir_bin(rel) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1345
def install_dir_bin(rel)
  install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
end
install_dir_conf(rel) click to toggle source
# File pkg/statsample-1.4.0/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
install_dir_data(rel) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1360
def install_dir_data(rel)
  install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644
end
install_dir_ext(rel) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1353
def install_dir_ext(rel)
  return unless extdir?(curr_srcdir())
  install_files rubyextentions('.'),
                "#{config('sodir')}/#{File.dirname(rel)}",
                0555
end
install_dir_lib(rel) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1349
def install_dir_lib(rel)
  install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
end
install_dir_man(rel) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1370
def install_dir_man(rel)
  install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
end
install_files(list, dest, mode) click to toggle source
# File pkg/statsample-1.4.0/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
libfiles() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1381
def libfiles
  glob_reject(%w(*.y *.output), targetfiles())
end
mapdir(ents) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1397
def mapdir(ents)
  ents.map {|ent|
    if File.exist?(ent)
    then ent                         # objdir
    else "#{curr_srcdir()}/#{ent}"   # srcdir
    end
  }
end
new_shebang(old) click to toggle source
# File pkg/statsample-1.4.0/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
no_harm?() click to toggle source

module FileOperations requires this

# File pkg/statsample-1.4.0/setup.rb, line 1205
def no_harm?
  @config.no_harm?
end
noop(rel) click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1176
def noop(rel)
end
Also aliased as: config_dir_bin, config_dir_lib, config_dir_data, config_dir_conf, config_dir_man, setup_dir_lib, setup_dir_data, setup_dir_conf, setup_dir_man, clean_dir_bin, clean_dir_lib, clean_dir_data, clean_dir_conf, clean_dir_man, distclean_dir_bin, distclean_dir_lib, distclean_dir_data, distclean_dir_conf, distclean_dir_man, config_dir_bin, config_dir_lib, config_dir_data, config_dir_conf, config_dir_man, setup_dir_lib, setup_dir_data, setup_dir_conf, setup_dir_man, clean_dir_bin, clean_dir_lib, clean_dir_data, clean_dir_conf, clean_dir_man, distclean_dir_bin, distclean_dir_lib, distclean_dir_data, distclean_dir_conf, distclean_dir_man
objdir_root() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1187
def objdir_root
  @objdir
end
open_atomic_writer(path, &block) click to toggle source
# File pkg/statsample-1.4.0/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
relpath() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1191
def relpath
  @currdir
end
rubyextentions(dir) click to toggle source
# File pkg/statsample-1.4.0/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
run_hook(id) click to toggle source
# File pkg/statsample-1.4.0/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
setup_dir_bin(rel) click to toggle source
# File pkg/statsample-1.4.0/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
setup_dir_ext(rel) click to toggle source
# File pkg/statsample-1.4.0/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
srcdir_root() click to toggle source

Hook Script API base methods

# File pkg/statsample-1.4.0/setup.rb, line 1183
def srcdir_root
  @srcdir
end
targetfiles() click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1393
def targetfiles
  mapdir(existfiles() - hookfiles())
end
traverse(task, rel, mid) click to toggle source
# File pkg/statsample-1.4.0/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
update_shebang_line(path) click to toggle source
# File pkg/statsample-1.4.0/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
verbose?() click to toggle source

module FileOperations requires this

# File pkg/statsample-1.4.0/setup.rb, line 1200
def verbose?
  @config.verbose?
end
verbose_off() { || ... } click to toggle source
# File pkg/statsample-1.4.0/setup.rb, line 1209
def verbose_off
  begin
    save, @config.verbose = @config.verbose?, false
    yield
  ensure
    @config.verbose = save
  end
end