mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/tk/lib/tkextlib/pkg_checker.rb: improve the check process
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3a43b8429f
commit
73472b4b7b
1 changed files with 64 additions and 9 deletions
|
@ -10,15 +10,58 @@ TkRoot.new.withdraw # hide root window
|
||||||
|
|
||||||
name = File.basename(__FILE__)
|
name = File.basename(__FILE__)
|
||||||
|
|
||||||
|
add_path = false
|
||||||
|
verbose = false
|
||||||
|
|
||||||
|
def help_msg
|
||||||
|
print "Usage: #{$0} [-l] [-v] [-h] [--] [dir]\n"
|
||||||
|
print "\tIf dir is omitted, check the directry that this command exists.\n"
|
||||||
|
print "\tAvailable options are \n"
|
||||||
|
print "\t -l : Add dir to $LOAD_PATH\n"
|
||||||
|
print "\t (If dir == '<parent>/tkextlib', add <parent> also.)\n"
|
||||||
|
print "\t -v : Verbose mode (show reason of fail)\n"
|
||||||
|
print "\t -h : Show this message\n"
|
||||||
|
print "\t -- : End of options\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
while(ARGV[0] && ARGV[0][0] == ?-)
|
||||||
|
case ARGV[0]
|
||||||
|
when '--'
|
||||||
|
ARGV.shift
|
||||||
|
break;
|
||||||
|
when '-l'
|
||||||
|
ARGV.shift
|
||||||
|
add_path = true
|
||||||
|
when '-v'
|
||||||
|
ARGV.shift
|
||||||
|
verbose = true
|
||||||
|
when '-h'
|
||||||
|
help_msg
|
||||||
|
exit(0)
|
||||||
|
else
|
||||||
|
print "Argument Error!! : unknown option '#{ARGV[0]}'\n"
|
||||||
|
help_msg
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if ARGV[0]
|
if ARGV[0]
|
||||||
dir = File.expand_path(ARGV[0])
|
dir = File.expand_path(ARGV[0])
|
||||||
else
|
else
|
||||||
dir = File.dirname(File.expand_path(__FILE__))
|
dir = File.dirname(File.expand_path(__FILE__))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if add_path
|
||||||
|
$LOAD_PATH.unshift(dir)
|
||||||
|
if File.basename(dir) == 'tkextlib'
|
||||||
|
$LOAD_PATH.unshift(File.dirname(dir))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
print "\nRuby/Tk extension library checker\n"
|
print "\nRuby/Tk extension library checker\n"
|
||||||
print "( Note:: This check is very simple one. Shown status may be wrong. )\n"
|
print "( Note:: This check is very simple one. Shown status may be wrong. )\n"
|
||||||
print "\n check directory :: #{dir}\n"
|
print "\n check directory :: #{dir}"
|
||||||
|
print "\n $LOAD_PATH :: #{$LOAD_PATH.inspect}\n"
|
||||||
|
|
||||||
def get_pkg_list(file)
|
def get_pkg_list(file)
|
||||||
pkg_list = []
|
pkg_list = []
|
||||||
|
@ -36,12 +79,16 @@ def get_pkg_list(file)
|
||||||
pkg = [$2, :script]
|
pkg = [$2, :script]
|
||||||
pkg_list << pkg unless pkg_list.member?(pkg)
|
pkg_list << pkg unless pkg_list.member?(pkg)
|
||||||
end
|
end
|
||||||
|
if l =~ /^(?:[^#]+\s|\s*)(?:|;\s*)require\s*\(?\s*(["'])((\w|\/|:)+)\1/
|
||||||
|
pkg = [$2, :require_ruby_lib]
|
||||||
|
pkg_list << pkg unless pkg_list.member?(pkg)
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_list
|
pkg_list
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_pkg(file)
|
def check_pkg(file, verbose=false)
|
||||||
pkg_list = get_pkg_list(file)
|
pkg_list = get_pkg_list(file)
|
||||||
|
|
||||||
error_list = []
|
error_list = []
|
||||||
|
@ -67,9 +114,16 @@ def check_pkg(file)
|
||||||
success_list[name] = :script
|
success_list[name] = :script
|
||||||
error_list.delete_if{|n, t| n == name}
|
error_list.delete_if{|n, t| n == name}
|
||||||
|
|
||||||
|
when :require_ruby_lib
|
||||||
|
require name
|
||||||
|
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
if verbose
|
||||||
|
error_list << [name, type, e.message]
|
||||||
|
else
|
||||||
|
error_list << [name, type]
|
||||||
end
|
end
|
||||||
rescue
|
|
||||||
error_list << [name, type]
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,14 +140,14 @@ def check_pkg(file)
|
||||||
[success_list, error_list]
|
[success_list, error_list]
|
||||||
end
|
end
|
||||||
|
|
||||||
def subdir_check(dir)
|
def subdir_check(dir, verbose=false)
|
||||||
Dir.foreach(dir){|f|
|
Dir.foreach(dir){|f|
|
||||||
next if f == '.' || f == '..'
|
next if f == '.' || f == '..'
|
||||||
if File.directory?(f)
|
if File.directory?(f)
|
||||||
subdir_check(File.join(dir, f))
|
subdir_check(File.join(dir, f))
|
||||||
elsif File.extname(f) == '.rb'
|
elsif File.extname(f) == '.rb'
|
||||||
path = File.join(dir, f)
|
path = File.join(dir, f)
|
||||||
suc, err = check_pkg(path)
|
suc, err = check_pkg(path, verbose)
|
||||||
if err.empty?
|
if err.empty?
|
||||||
print 'Ready : ', path, ' : require->', suc.inspect, "\n"
|
print 'Ready : ', path, ' : require->', suc.inspect, "\n"
|
||||||
else
|
else
|
||||||
|
@ -108,16 +162,17 @@ Dir.chdir(dir)
|
||||||
|
|
||||||
(Dir['*.rb'] - ['setup.rb', name]).each{|f|
|
(Dir['*.rb'] - ['setup.rb', name]).each{|f|
|
||||||
subdir = File.basename(f, '.*')
|
subdir = File.basename(f, '.*')
|
||||||
|
=begin
|
||||||
begin
|
begin
|
||||||
# read 'setup.rb' as if the library has standard structure
|
# read 'setup.rb' as if the library has standard structure
|
||||||
require File.join(subdir, 'setup.rb')
|
require File.join(subdir, 'setup.rb')
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
# ignore error
|
# ignore error
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
print "\n"
|
print "\n"
|
||||||
|
|
||||||
suc, err = check_pkg(f)
|
suc, err = check_pkg(f, verbose)
|
||||||
if err.empty?
|
if err.empty?
|
||||||
print 'Ready : ', f, ' : require->', suc.inspect, "\n"
|
print 'Ready : ', f, ' : require->', suc.inspect, "\n"
|
||||||
else
|
else
|
||||||
|
@ -125,5 +180,5 @@ Dir.chdir(dir)
|
||||||
' FAIL->', err.inspect, "\n"
|
' FAIL->', err.inspect, "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
subdir_check(subdir) if File.directory?(subdir)
|
subdir_check(subdir, verbose) if File.directory?(subdir)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue