Class: Installer

Inherits:
Object
  • Object
show all
Includes:
FileOperations, HookScriptAPI
Defined in:
lib/priority-queue/setup.rb

Constant Summary collapse

FILETYPES =
%w( bin lib ext data conf man )
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 .*
)
GLOB2REGEX =
{
  '.' => '\.',
  '$' => '\$',
  '#' => '\#',
  '*' => '.*'
}
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.



1165
1166
1167
1168
1169
1170
# File 'lib/priority-queue/setup.rb', line 1165

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

Instance Method Details

#adjust_shebang(path) ⇒ Object



1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File 'lib/priority-queue/setup.rb', line 1260

def adjust_shebang(path)
  return if no_harm?
  tmpfile = File.basename(path) + '.tmp'
  begin
    File.open(path, 'rb') {|r|
      first = r.gets
      return unless File.basename(first.sub(/\A\#!/, '').split[0].to_s) == 'ruby'
      $stderr.puts "adjusting shebang: #{File.basename(path)}" if verbose?
      File.open(tmpfile, 'wb') {|w|
        w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))
        w.write r.read
      }
    }
    move_file tmpfile, File.basename(path)
  ensure
    File.unlink tmpfile if File.exist?(tmpfile)
  end
end

#clean_dir_bin(rel) ⇒ Object



1435
1436
# File 'lib/priority-queue/setup.rb', line 1435

def clean_dir_bin(rel)
end

#clean_dir_conf(rel) ⇒ Object



1449
1450
# File 'lib/priority-queue/setup.rb', line 1449

def clean_dir_conf(rel)
end

#clean_dir_data(rel) ⇒ Object



1446
1447
# File 'lib/priority-queue/setup.rb', line 1446

def clean_dir_data(rel)
end

#clean_dir_ext(rel) ⇒ Object



1441
1442
1443
1444
# File 'lib/priority-queue/setup.rb', line 1441

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

#clean_dir_lib(rel) ⇒ Object



1438
1439
# File 'lib/priority-queue/setup.rb', line 1438

def clean_dir_lib(rel)
end

#config_dir_bin(rel) ⇒ Object



1223
1224
# File 'lib/priority-queue/setup.rb', line 1223

def config_dir_bin(rel)
end

#config_dir_conf(rel) ⇒ Object



1243
1244
# File 'lib/priority-queue/setup.rb', line 1243

def config_dir_conf(rel)
end

#config_dir_data(rel) ⇒ Object



1240
1241
# File 'lib/priority-queue/setup.rb', line 1240

def config_dir_data(rel)
end

#config_dir_ext(rel) ⇒ Object



1232
1233
1234
# File 'lib/priority-queue/setup.rb', line 1232

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

#config_dir_lib(rel) ⇒ Object



1226
1227
# File 'lib/priority-queue/setup.rb', line 1226

def config_dir_lib(rel)
end

#config_dir_man(rel) ⇒ Object



1229
1230
# File 'lib/priority-queue/setup.rb', line 1229

def config_dir_man(rel)
end

#distclean_dir_bin(rel) ⇒ Object



1462
1463
# File 'lib/priority-queue/setup.rb', line 1462

def distclean_dir_bin(rel)
end

#distclean_dir_conf(rel) ⇒ Object



1476
1477
# File 'lib/priority-queue/setup.rb', line 1476

def distclean_dir_conf(rel)
end

#distclean_dir_data(rel) ⇒ Object



1473
1474
# File 'lib/priority-queue/setup.rb', line 1473

def distclean_dir_data(rel)
end

#distclean_dir_ext(rel) ⇒ Object



1468
1469
1470
1471
# File 'lib/priority-queue/setup.rb', line 1468

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

#distclean_dir_lib(rel) ⇒ Object



1465
1466
# File 'lib/priority-queue/setup.rb', line 1465

def distclean_dir_lib(rel)
end

#dive_into(rel) ⇒ Object



1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
# File 'lib/priority-queue/setup.rb', line 1506

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



1429
1430
1431
1432
1433
# File 'lib/priority-queue/setup.rb', line 1429

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

#exec_configObject

TASK config



1219
1220
1221
# File 'lib/priority-queue/setup.rb', line 1219

def exec_config
  exec_task_traverse 'config'
end

#exec_distcleanObject

TASK distclean



1456
1457
1458
1459
1460
# File 'lib/priority-queue/setup.rb', line 1456

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

#exec_installObject

TASK install



1299
1300
1301
1302
# File 'lib/priority-queue/setup.rb', line 1299

def exec_install
  rm_f 'InstalledFiles'
  exec_task_traverse 'install'
end

#exec_setupObject

TASK setup



1250
1251
1252
# File 'lib/priority-queue/setup.rb', line 1250

def exec_setup
  exec_task_traverse 'setup'
end

#exec_task_traverse(task) ⇒ Object

lib



1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
# File 'lib/priority-queue/setup.rb', line 1483

def exec_task_traverse(task)
  run_hook "pre-#{task}"
  FILETYPES.each do |type|
    if config('without-ext') == 'yes' and type == 'ext'
      $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



1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'lib/priority-queue/setup.rb', line 1413

def exec_test
  unless File.directory?('test')
    $stderr.puts 'no test in this package' if verbose?
    return
  end
  $stderr.puts 'Running tests...' if verbose?
  require 'test/unit'
  runner = Test::Unit::AutoRunner.new(true)
  runner.to_run << TESTDIR
  runner.run
end

#existfilesObject



1374
1375
1376
# File 'lib/priority-queue/setup.rb', line 1374

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

#extconfObject



1236
1237
1238
# File 'lib/priority-queue/setup.rb', line 1236

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

#glob_reject(pats, ents) ⇒ Object



1389
1390
1391
1392
# File 'lib/priority-queue/setup.rb', line 1389

def glob_reject(pats, ents)
  re = globs2re(pats)
  ents.reject {|ent| re =~ ent }
end

#glob_select(pat, ents) ⇒ Object



1384
1385
1386
1387
# File 'lib/priority-queue/setup.rb', line 1384

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

#globs2re(pats) ⇒ Object



1401
1402
1403
1404
1405
# File 'lib/priority-queue/setup.rb', line 1401

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

#hookfilesObject



1378
1379
1380
1381
1382
# File 'lib/priority-queue/setup.rb', line 1378

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



1172
1173
1174
# File 'lib/priority-queue/setup.rb', line 1172

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

#install_dir_bin(rel) ⇒ Object



1304
1305
1306
# File 'lib/priority-queue/setup.rb', line 1304

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

#install_dir_conf(rel) ⇒ Object



1323
1324
1325
1326
1327
# File 'lib/priority-queue/setup.rb', line 1323

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



1319
1320
1321
# File 'lib/priority-queue/setup.rb', line 1319

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

#install_dir_ext(rel) ⇒ Object



1312
1313
1314
1315
1316
1317
# File 'lib/priority-queue/setup.rb', line 1312

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



1308
1309
1310
# File 'lib/priority-queue/setup.rb', line 1308

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

#install_dir_man(rel) ⇒ Object



1329
1330
1331
# File 'lib/priority-queue/setup.rb', line 1329

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

#install_files(list, dest, mode) ⇒ Object



1333
1334
1335
1336
1337
1338
# File 'lib/priority-queue/setup.rb', line 1333

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

#mapdir(ents) ⇒ Object



1356
1357
1358
1359
1360
1361
1362
1363
# File 'lib/priority-queue/setup.rb', line 1356

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

#no_harm?Boolean

module FileOperations requires this

Returns:

  • (Boolean)


1202
1203
1204
# File 'lib/priority-queue/setup.rb', line 1202

def no_harm?
  @config.no_harm?
end

#objdir_rootObject



1184
1185
1186
# File 'lib/priority-queue/setup.rb', line 1184

def objdir_root
  @objdir
end

#relpathObject



1188
1189
1190
# File 'lib/priority-queue/setup.rb', line 1188

def relpath
  @currdir
end

#rubyextentions(dir) ⇒ Object



1344
1345
1346
1347
1348
1349
1350
# File 'lib/priority-queue/setup.rb', line 1344

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

#rubyscriptsObject



1340
1341
1342
# File 'lib/priority-queue/setup.rb', line 1340

def rubyscripts
  glob_select(@config.libsrc_pattern, targetfiles())
end

#run_hook(id) ⇒ Object



1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
# File 'lib/priority-queue/setup.rb', line 1521

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



1254
1255
1256
1257
1258
# File 'lib/priority-queue/setup.rb', line 1254

def setup_dir_bin(rel)
  files_of(curr_srcdir()).each do |fname|
    adjust_shebang "#{curr_srcdir()}/#{fname}"
  end
end

#setup_dir_conf(rel) ⇒ Object



1292
1293
# File 'lib/priority-queue/setup.rb', line 1292

def setup_dir_conf(rel)
end

#setup_dir_data(rel) ⇒ Object



1289
1290
# File 'lib/priority-queue/setup.rb', line 1289

def setup_dir_data(rel)
end

#setup_dir_ext(rel) ⇒ Object



1285
1286
1287
# File 'lib/priority-queue/setup.rb', line 1285

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

#setup_dir_lib(rel) ⇒ Object



1279
1280
# File 'lib/priority-queue/setup.rb', line 1279

def setup_dir_lib(rel)
end

#setup_dir_man(rel) ⇒ Object



1282
1283
# File 'lib/priority-queue/setup.rb', line 1282

def setup_dir_man(rel)
end

#srcdir_rootObject

Hook Script API base methods



1180
1181
1182
# File 'lib/priority-queue/setup.rb', line 1180

def srcdir_root
  @srcdir
end

#targetfilesObject



1352
1353
1354
# File 'lib/priority-queue/setup.rb', line 1352

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

#traverse(task, rel, mid) ⇒ Object



1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
# File 'lib/priority-queue/setup.rb', line 1495

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

#verbose?Boolean

module FileOperations requires this

Returns:

  • (Boolean)


1197
1198
1199
# File 'lib/priority-queue/setup.rb', line 1197

def verbose?
  @config.verbose?
end

#verbose_offObject



1206
1207
1208
1209
1210
1211
1212
1213
# File 'lib/priority-queue/setup.rb', line 1206

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