Skip to content

Commit 421a9d0

Browse files
author
nagai
committed
* ext/tk/lib/tkextlib/pkg_checker.rb: improve the check process
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 1784fd2 commit 421a9d0

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

ext/tk/lib/tkextlib/pkg_checker.rb

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,58 @@
1010

1111
name = File.basename(__FILE__)
1212

13+
add_path = false
14+
verbose = false
15+
16+
def help_msg
17+
print "Usage: #{$0} [-l] [-v] [-h] [--] [dir]\n"
18+
print "\tIf dir is omitted, check the directry that this command exists.\n"
19+
print "\tAvailable options are \n"
20+
print "\t -l : Add dir to $LOAD_PATH\n"
21+
print "\t (If dir == '<parent>/tkextlib', add <parent> also.)\n"
22+
print "\t -v : Verbose mode (show reason of fail)\n"
23+
print "\t -h : Show this message\n"
24+
print "\t -- : End of options\n"
25+
end
26+
27+
while(ARGV[0] && ARGV[0][0] == ?-)
28+
case ARGV[0]
29+
when '--'
30+
ARGV.shift
31+
break;
32+
when '-l'
33+
ARGV.shift
34+
add_path = true
35+
when '-v'
36+
ARGV.shift
37+
verbose = true
38+
when '-h'
39+
help_msg
40+
exit(0)
41+
else
42+
print "Argument Error!! : unknown option '#{ARGV[0]}'\n"
43+
help_msg
44+
exit(1)
45+
end
46+
end
47+
1348
if ARGV[0]
1449
dir = File.expand_path(ARGV[0])
1550
else
1651
dir = File.dirname(File.expand_path(__FILE__))
1752
end
1853

54+
if add_path
55+
$LOAD_PATH.unshift(dir)
56+
if File.basename(dir) == 'tkextlib'
57+
$LOAD_PATH.unshift(File.dirname(dir))
58+
end
59+
end
60+
1961
print "\nRuby/Tk extension library checker\n"
2062
print "( Note:: This check is very simple one. Shown status may be wrong. )\n"
21-
print "\n check directory :: #{dir}\n"
63+
print "\n check directory :: #{dir}"
64+
print "\n $LOAD_PATH :: #{$LOAD_PATH.inspect}\n"
2265

2366
def get_pkg_list(file)
2467
pkg_list = []
@@ -36,12 +79,16 @@ def get_pkg_list(file)
3679
pkg = [$2, :script]
3780
pkg_list << pkg unless pkg_list.member?(pkg)
3881
end
82+
if l =~ /^(?:[^#]+\s|\s*)(?:|;\s*)require\s*\(?\s*(["'])((\w|\/|:)+)\1/
83+
pkg = [$2, :require_ruby_lib]
84+
pkg_list << pkg unless pkg_list.member?(pkg)
85+
end
3986
}
4087

4188
pkg_list
4289
end
4390

44-
def check_pkg(file)
91+
def check_pkg(file, verbose=false)
4592
pkg_list = get_pkg_list(file)
4693

4794
error_list = []
@@ -67,9 +114,16 @@ def check_pkg(file)
67114
success_list[name] = :script
68115
error_list.delete_if{|n, t| n == name}
69116

117+
when :require_ruby_lib
118+
require name
119+
120+
end
121+
rescue => e
122+
if verbose
123+
error_list << [name, type, e.message]
124+
else
125+
error_list << [name, type]
70126
end
71-
rescue
72-
error_list << [name, type]
73127
end
74128
}
75129

@@ -86,14 +140,14 @@ def check_pkg(file)
86140
[success_list, error_list]
87141
end
88142

89-
def subdir_check(dir)
143+
def subdir_check(dir, verbose=false)
90144
Dir.foreach(dir){|f|
91145
next if f == '.' || f == '..'
92146
if File.directory?(f)
93147
subdir_check(File.join(dir, f))
94148
elsif File.extname(f) == '.rb'
95149
path = File.join(dir, f)
96-
suc, err = check_pkg(path)
150+
suc, err = check_pkg(path, verbose)
97151
if err.empty?
98152
print 'Ready : ', path, ' : require->', suc.inspect, "\n"
99153
else
@@ -108,22 +162,23 @@ def subdir_check(dir)
108162

109163
(Dir['*.rb'] - ['setup.rb', name]).each{|f|
110164
subdir = File.basename(f, '.*')
165+
=begin
111166
begin
112167
# read 'setup.rb' as if the library has standard structure
113168
require File.join(subdir, 'setup.rb')
114169
rescue LoadError
115170
# ignore error
116171
end
117-
172+
=end
118173
print "\n"
119174

120-
suc, err = check_pkg(f)
175+
suc, err = check_pkg(f, verbose)
121176
if err.empty?
122177
print 'Ready : ', f, ' : require->', suc.inspect, "\n"
123178
else
124179
print '*LACK : ', f, ' : require->', suc.inspect,
125180
' FAIL->', err.inspect, "\n"
126181
end
127182

128-
subdir_check(subdir) if File.directory?(subdir)
183+
subdir_check(subdir, verbose) if File.directory?(subdir)
129184
}

0 commit comments

Comments
 (0)