Class: Installer

Inherits:
Object show all
Includes:
FileOperations, HookScriptAPI
Defined in:
lib/roebe/setup/setup.rb

Defined Under Namespace

Classes: Shebang

Constant Summary collapse

FILETYPES =
%w( bin lib ext data conf man )
GLOB2REGEX =

TASK install

{
  '.' => '\.',
  '$' => '\$',
  '#' => '\#',
  '*' => '.*'
}
JUNK_FILES =

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

%w( 
  core RCSLOG tags TAGS .make.state
  .nse_depinfo #* .#* cvslog.* ,* .del-* *.olb
  *~ *.old *.bak *.BAK *.orig *.rej _$* *$

  *.org *.in .*
)
TESTDIR =

TASK test

'test'

Constants included from FileOperations

FileOperations::DIR_REJECT

Instance Method Summary collapse

Methods included from HookScriptAPI

#curr_objdir, #curr_srcdir, #get_config, #set_config, #srcdirectories, #srcdirectory?, #srcentries, #srcexist?, #srcfile, #srcfile?, #srcfiles

Methods included from FileOperations

#command, #diff?, #directories_of, #extdir?, #files_of, #force_remove_file, #install, #make, #mkdir_p, #move_file, #remove_file, #remove_tree, #remove_tree0, #rm_f, #rm_rf, #ruby

Constructor Details

#initialize(config, srcroot, objroot) ⇒ Installer

Returns a new instance of Installer.



1230
1231
1232
1233
1234
1235
# File 'lib/roebe/setup/setup.rb', line 1230

def initialize(config, srcroot, objroot)
  @config = config
  @srcdir = File.expand_path(srcroot)
  @objdir = File.expand_path(objroot)
  @currdir = '.'
end

Instance Method Details

#clean_dir_ext(rel) ⇒ Object



1561
1562
1563
1564
# File 'lib/roebe/setup/setup.rb', line 1561

def clean_dir_ext(rel)
  return unless extdir?(curr_srcdir())
  make 'clean' if File.file?('Makefile')
end

#config_dir_ext(rel) ⇒ Object



1294
1295
1296
# File 'lib/roebe/setup/setup.rb', line 1294

def config_dir_ext(rel)
  extconf if extdir?(curr_srcdir())
end

#distclean_dir_ext(rel) ⇒ Object



1579
1580
1581
1582
# File 'lib/roebe/setup/setup.rb', line 1579

def distclean_dir_ext(rel)
  return unless extdir?(curr_srcdir())
  make 'distclean' if File.file?('Makefile')
end

#dive_into(rel) ⇒ Object



1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
# File 'lib/roebe/setup/setup.rb', line 1620

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_cleanObject

TASK clean



1549
1550
1551
1552
1553
# File 'lib/roebe/setup/setup.rb', line 1549

def exec_clean
  exec_task_traverse 'clean'
  rm_f @config.savefile
  rm_f 'InstalledFiles'
end

#exec_configObject

TASK config



1287
1288
1289
# File 'lib/roebe/setup/setup.rb', line 1287

def exec_config
  exec_task_traverse 'config'
end

#exec_distcleanObject

TASK distclean



1570
1571
1572
1573
1574
# File 'lib/roebe/setup/setup.rb', line 1570

def exec_distclean
  exec_task_traverse 'distclean'
  rm_f @config.savefile
  rm_f 'InstalledFiles'
end

#exec_installObject



1412
1413
1414
1415
# File 'lib/roebe/setup/setup.rb', line 1412

def exec_install
  rm_f 'InstalledFiles'
  exec_task_traverse 'install'
end

#exec_setupObject

TASK setup



1310
1311
1312
# File 'lib/roebe/setup/setup.rb', line 1310

def exec_setup
  exec_task_traverse 'setup'
end

#exec_task_traverse(task) ⇒ Object

Traversing



1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
# File 'lib/roebe/setup/setup.rb', line 1592

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_testObject



1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
# File 'lib/roebe/setup/setup.rb', line 1529

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

#existfilesObject



1490
1491
1492
# File 'lib/roebe/setup/setup.rb', line 1490

def existfiles
  glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
end

#extconfObject



1302
1303
1304
# File 'lib/roebe/setup/setup.rb', line 1302

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

#glob_reject(pats, ents) ⇒ Object

#

glob_reject

#


1508
1509
1510
1511
1512
1513
1514
1515
# File 'lib/roebe/setup/setup.rb', line 1508

def glob_reject(pats, ents)
  re = globs2re(pats)
  begin
    ents.reject {|ent| re =~ ent }
  rescue ArgumentError => error
    pp error
  end
end

#glob_select(pat, ents) ⇒ Object



1500
1501
1502
1503
# File 'lib/roebe/setup/setup.rb', line 1500

def glob_select(pat, ents)
  re = globs2re([pat])
  ents.select {|ent| re =~ ent }
end

#globs2re(pats) ⇒ Object



1517
1518
1519
1520
1521
# File 'lib/roebe/setup/setup.rb', line 1517

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

#hookfilesObject



1494
1495
1496
1497
1498
# File 'lib/roebe/setup/setup.rb', line 1494

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

#inspectObject



1237
1238
1239
# File 'lib/roebe/setup/setup.rb', line 1237

def inspect
  "#<#{self.class} #{File.basename(@srcdir)}>"
end

#install_dir_bin(rel) ⇒ Object

#

install_dir_bin

#


1420
1421
1422
# File 'lib/roebe/setup/setup.rb', line 1420

def install_dir_bin(rel)
  install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
end

#install_dir_conf(rel) ⇒ Object



1439
1440
1441
1442
1443
# File 'lib/roebe/setup/setup.rb', line 1439

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) ⇒ Object



1435
1436
1437
# File 'lib/roebe/setup/setup.rb', line 1435

def install_dir_data(rel)
  install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644
end

#install_dir_ext(rel) ⇒ Object



1428
1429
1430
1431
1432
1433
# File 'lib/roebe/setup/setup.rb', line 1428

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

#install_dir_lib(rel) ⇒ Object



1424
1425
1426
# File 'lib/roebe/setup/setup.rb', line 1424

def install_dir_lib(rel)
  install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
end

#install_dir_man(rel) ⇒ Object



1445
1446
1447
# File 'lib/roebe/setup/setup.rb', line 1445

def install_dir_man(rel)
  install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
end

#install_files(list, dest, mode) ⇒ Object



1449
1450
1451
1452
1453
1454
# File 'lib/roebe/setup/setup.rb', line 1449

def install_files(list, dest, mode)
  mkdir_p dest, @config.install_prefix
  list.each { |fname|
    install fname, dest, mode, @config.install_prefix
  }
end

#libfilesObject



1456
1457
1458
# File 'lib/roebe/setup/setup.rb', line 1456

def libfiles
  glob_reject(%w(*.y *.output), targetfiles())
end

#mapdir(ents) ⇒ Object



1472
1473
1474
1475
1476
1477
1478
1479
# File 'lib/roebe/setup/setup.rb', line 1472

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

#new_shebang(old) ⇒ Object



1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
# File 'lib/roebe/setup/setup.rb', line 1352

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?Boolean

module FileOperations requires this

Returns:

  • (Boolean)


1270
1271
1272
# File 'lib/roebe/setup/setup.rb', line 1270

def no_harm?
  @config.no_harm?
end

#noop(rel) ⇒ Object Also known 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



1241
1242
# File 'lib/roebe/setup/setup.rb', line 1241

def noop(rel)
end

#objdir_rootObject



1252
1253
1254
# File 'lib/roebe/setup/setup.rb', line 1252

def objdir_root
  @objdir
end

#open_atomic_writer(path, &block) ⇒ Object



1363
1364
1365
1366
1367
1368
1369
1370
1371
# File 'lib/roebe/setup/setup.rb', line 1363

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

#relpathObject



1256
1257
1258
# File 'lib/roebe/setup/setup.rb', line 1256

def relpath
  @currdir
end

#rubyextentions(dir) ⇒ Object



1460
1461
1462
1463
1464
1465
1466
# File 'lib/roebe/setup/setup.rb', line 1460

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) ⇒ Object



1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
# File 'lib/roebe/setup/setup.rb', line 1635

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) ⇒ Object



1314
1315
1316
1317
1318
# File 'lib/roebe/setup/setup.rb', line 1314

def setup_dir_bin(rel)
  # files_of(curr_srcdir()).each do |fname|
  #   update_shebang_line "#{curr_srcdir()}/#{fname}"
  # end # The above line was modifed by shevy Sep 2014.
end

#setup_dir_ext(rel) ⇒ Object



1322
1323
1324
# File 'lib/roebe/setup/setup.rb', line 1322

def setup_dir_ext(rel)
  make if extdir?(curr_srcdir())
end

#srcdir_rootObject

Hook Script API base methods



1248
1249
1250
# File 'lib/roebe/setup/setup.rb', line 1248

def srcdir_root
  @srcdir
end

#targetfilesObject



1468
1469
1470
# File 'lib/roebe/setup/setup.rb', line 1468

def targetfiles
  mapdir(existfiles() - hookfiles())
end

#traverse(task, rel, mid) ⇒ Object

#

traverse

This method can fail when it comes to Encoding-related issues.

#


1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
# File 'lib/roebe/setup/setup.rb', line 1609

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

#update_shebang_line(path) ⇒ Object



1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
# File 'lib/roebe/setup/setup.rb', line 1330

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?Boolean

module FileOperations requires this

Returns:

  • (Boolean)


1265
1266
1267
# File 'lib/roebe/setup/setup.rb', line 1265

def verbose?
  @config.verbose?
end

#verbose_offObject



1274
1275
1276
1277
1278
1279
1280
1281
# File 'lib/roebe/setup/setup.rb', line 1274

def verbose_off
  begin
    save, @config.verbose = @config.verbose?, false
    yield
  ensure
    @config.verbose = save
  end
end