Class: Installer
Defined Under Namespace
Classes: Shebang
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 =
'test'
FileOperations::DIR_REJECT
Instance Method Summary
collapse
-
#clean_dir_ext(rel) ⇒ Object
-
#config_dir_ext(rel) ⇒ Object
-
#distclean_dir_ext(rel) ⇒ Object
-
#dive_into(rel) ⇒ Object
-
#exec_clean ⇒ Object
-
#exec_config ⇒ Object
-
#exec_distclean ⇒ Object
-
#exec_install ⇒ Object
-
#exec_setup ⇒ Object
-
#exec_task_traverse(task) ⇒ Object
-
#exec_test ⇒ Object
-
#existfiles ⇒ Object
-
#extconf ⇒ Object
-
#glob_reject(pats, ents) ⇒ Object
-
#glob_select(pat, ents) ⇒ Object
-
#globs2re(pats) ⇒ Object
-
#hookfiles ⇒ Object
-
#initialize(config, srcroot, objroot) ⇒ Installer
constructor
A new instance of Installer.
-
#inspect ⇒ Object
-
#install_dir_bin(rel) ⇒ Object
-
#install_dir_conf(rel) ⇒ Object
-
#install_dir_data(rel) ⇒ Object
-
#install_dir_ext(rel) ⇒ Object
-
#install_dir_lib(rel) ⇒ Object
-
#install_dir_man(rel) ⇒ Object
-
#install_files(list, dest, mode) ⇒ Object
-
#libfiles ⇒ Object
-
#mapdir(ents) ⇒ Object
-
#new_shebang(old) ⇒ Object
-
#no_harm? ⇒ Boolean
module FileOperations requires this.
-
#noop(rel) ⇒ Object
(also: #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 ⇒ Object
-
#open_atomic_writer(path, &block) ⇒ Object
-
#relpath ⇒ Object
-
#rubyextentions(dir) ⇒ Object
-
#run_hook(id) ⇒ Object
-
#setup_dir_bin(rel) ⇒ Object
-
#setup_dir_ext(rel) ⇒ Object
-
#srcdir_root ⇒ Object
Hook Script API base methods.
-
#targetfiles ⇒ Object
-
#traverse(task, rel, mid) ⇒ Object
-
#update_shebang_line(path) ⇒ Object
-
#verbose? ⇒ Boolean
module FileOperations requires this.
-
#verbose_off ⇒ Object
#curr_objdir, #curr_srcdir, #get_config, #set_config, #srcdirectories, #srcdirectory?, #srcentries, #srcexist?, #srcfile, #srcfile?, #srcfiles
#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.
1166
1167
1168
1169
1170
1171
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1166
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
1487
1488
1489
1490
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1487
def clean_dir_ext(rel)
return unless extdir?(curr_srcdir())
make 'clean' if File.file?('Makefile')
end
|
#config_dir_ext(rel) ⇒ Object
1230
1231
1232
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1230
def config_dir_ext(rel)
extconf if extdir?(curr_srcdir())
end
|
#distclean_dir_ext(rel) ⇒ Object
1505
1506
1507
1508
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1505
def distclean_dir_ext(rel)
return unless extdir?(curr_srcdir())
make 'distclean' if File.file?('Makefile')
end
|
#dive_into(rel) ⇒ Object
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1541
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 ⇒ Object
1475
1476
1477
1478
1479
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1475
def exec_clean
exec_task_traverse 'clean'
rm_f @config.savefile
rm_f 'InstalledFiles'
end
|
#exec_config ⇒ Object
1223
1224
1225
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1223
def exec_config
exec_task_traverse 'config'
end
|
#exec_distclean ⇒ Object
1496
1497
1498
1499
1500
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1496
def exec_distclean
exec_task_traverse 'distclean'
rm_f @config.savefile
rm_f 'InstalledFiles'
end
|
#exec_install ⇒ Object
1341
1342
1343
1344
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1341
def exec_install
rm_f 'InstalledFiles'
exec_task_traverse 'install'
end
|
#exec_setup ⇒ Object
1246
1247
1248
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1246
def exec_setup
exec_task_traverse 'setup'
end
|
#exec_task_traverse(task) ⇒ Object
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1518
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 ⇒ Object
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1455
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 ⇒ Object
1416
1417
1418
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1416
def existfiles
glob_reject(JUNK_FILES, (files_of(curr_srcdir()) | files_of('.')))
end
|
#extconf ⇒ Object
1238
1239
1240
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1238
def extconf
ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
end
|
#glob_reject(pats, ents) ⇒ Object
1431
1432
1433
1434
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1431
def glob_reject(pats, ents)
re = globs2re(pats)
ents.reject {|ent| re =~ ent }
end
|
#glob_select(pat, ents) ⇒ Object
1426
1427
1428
1429
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1426
def glob_select(pat, ents)
re = globs2re([pat])
ents.select {|ent| re =~ ent }
end
|
#globs2re(pats) ⇒ Object
1443
1444
1445
1446
1447
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1443
def globs2re(pats)
/\A(?:#{
pats.map {|pat| pat.gsub(/[\.\$\#\*]/) {|ch| GLOB2REGEX[ch] } }.join('|')
})\z/
end
|
#hookfiles ⇒ Object
1420
1421
1422
1423
1424
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1420
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 ⇒ Object
1173
1174
1175
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1173
def inspect
"#<#{self.class} #{File.basename(@srcdir)}>"
end
|
#install_dir_bin(rel) ⇒ Object
1346
1347
1348
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1346
def install_dir_bin(rel)
install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
end
|
#install_dir_conf(rel) ⇒ Object
1365
1366
1367
1368
1369
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1365
def install_dir_conf(rel)
install_files targetfiles(), "#{config('sysconfdir')}/#{rel}", 0644
end
|
#install_dir_data(rel) ⇒ Object
1361
1362
1363
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1361
def install_dir_data(rel)
install_files targetfiles(), "#{config('datadir')}/#{rel}", 0644
end
|
#install_dir_ext(rel) ⇒ Object
1354
1355
1356
1357
1358
1359
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1354
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
1350
1351
1352
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1350
def install_dir_lib(rel)
install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
end
|
#install_dir_man(rel) ⇒ Object
1371
1372
1373
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1371
def install_dir_man(rel)
install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
end
|
#install_files(list, dest, mode) ⇒ Object
1375
1376
1377
1378
1379
1380
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1375
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 ⇒ Object
1382
1383
1384
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1382
def libfiles
glob_reject(%w(*.y *.output), targetfiles())
end
|
#mapdir(ents) ⇒ Object
1398
1399
1400
1401
1402
1403
1404
1405
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1398
def mapdir(ents)
ents.map {|ent|
if File.exist?(ent)
then ent else "#{curr_srcdir()}/#{ent}" end
}
end
|
#new_shebang(old) ⇒ Object
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1288
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
1206
1207
1208
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1206
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
1177
1178
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1177
def noop(rel)
end
|
#objdir_root ⇒ Object
1188
1189
1190
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1188
def objdir_root
@objdir
end
|
#open_atomic_writer(path, &block) ⇒ Object
1299
1300
1301
1302
1303
1304
1305
1306
1307
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1299
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 ⇒ Object
1192
1193
1194
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1192
def relpath
@currdir
end
|
#rubyextentions(dir) ⇒ Object
1386
1387
1388
1389
1390
1391
1392
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1386
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
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1556
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
1250
1251
1252
1253
1254
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1250
def setup_dir_bin(rel)
files_of(curr_srcdir()).each do |fname|
update_shebang_line "#{curr_srcdir()}/#{fname}"
end
end
|
#setup_dir_ext(rel) ⇒ Object
1258
1259
1260
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1258
def setup_dir_ext(rel)
make if extdir?(curr_srcdir())
end
|
#srcdir_root ⇒ Object
Hook Script API base methods
1184
1185
1186
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1184
def srcdir_root
@srcdir
end
|
#targetfiles ⇒ Object
1394
1395
1396
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1394
def targetfiles
mapdir(existfiles() - hookfiles())
end
|
#traverse(task, rel, mid) ⇒ Object
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1530
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) ⇒ Object
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1266
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 output.puts new.to_s
output.print f.read
}
}
end
|
#verbose? ⇒ Boolean
module FileOperations requires this
1201
1202
1203
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1201
def verbose?
@config.verbose?
end
|
#verbose_off ⇒ Object
1210
1211
1212
1213
1214
1215
1216
1217
|
# File 'lib/vendor/xmpp4r/setup.rb', line 1210
def verbose_off
begin
save, @config.verbose = @config.verbose?, false
yield
ensure
@config.verbose = save
end
end
|