10
10
11
11
name = File . basename ( __FILE__ )
12
12
13
+ add_path = false
14
+ verbose = false
15
+
16
+ def help_msg
17
+ print "Usage: #{ $0} [-l] [-v] [-h] [--] [dir]\n "
18
+ print "\t If dir is omitted, check the directry that this command exists.\n "
19
+ print "\t Available 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
+
13
48
if ARGV [ 0 ]
14
49
dir = File . expand_path ( ARGV [ 0 ] )
15
50
else
16
51
dir = File . dirname ( File . expand_path ( __FILE__ ) )
17
52
end
18
53
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
+
19
61
print "\n Ruby/Tk extension library checker\n "
20
62
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 "
22
65
23
66
def get_pkg_list ( file )
24
67
pkg_list = [ ]
@@ -36,12 +79,16 @@ def get_pkg_list(file)
36
79
pkg = [ $2, :script ]
37
80
pkg_list << pkg unless pkg_list . member? ( pkg )
38
81
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
39
86
}
40
87
41
88
pkg_list
42
89
end
43
90
44
- def check_pkg ( file )
91
+ def check_pkg ( file , verbose = false )
45
92
pkg_list = get_pkg_list ( file )
46
93
47
94
error_list = [ ]
@@ -67,9 +114,16 @@ def check_pkg(file)
67
114
success_list [ name ] = :script
68
115
error_list . delete_if { |n , t | n == name }
69
116
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 ]
70
126
end
71
- rescue
72
- error_list << [ name , type ]
73
127
end
74
128
}
75
129
@@ -86,14 +140,14 @@ def check_pkg(file)
86
140
[ success_list , error_list ]
87
141
end
88
142
89
- def subdir_check ( dir )
143
+ def subdir_check ( dir , verbose = false )
90
144
Dir . foreach ( dir ) { |f |
91
145
next if f == '.' || f == '..'
92
146
if File . directory? ( f )
93
147
subdir_check ( File . join ( dir , f ) )
94
148
elsif File . extname ( f ) == '.rb'
95
149
path = File . join ( dir , f )
96
- suc , err = check_pkg ( path )
150
+ suc , err = check_pkg ( path , verbose )
97
151
if err . empty?
98
152
print 'Ready : ' , path , ' : require->' , suc . inspect , "\n "
99
153
else
@@ -108,22 +162,23 @@ def subdir_check(dir)
108
162
109
163
( Dir [ '*.rb' ] - [ 'setup.rb' , name ] ) . each { |f |
110
164
subdir = File . basename ( f , '.*' )
165
+ =begin
111
166
begin
112
167
# read 'setup.rb' as if the library has standard structure
113
168
require File.join(subdir, 'setup.rb')
114
169
rescue LoadError
115
170
# ignore error
116
171
end
117
-
172
+ =end
118
173
print "\n "
119
174
120
- suc , err = check_pkg ( f )
175
+ suc , err = check_pkg ( f , verbose )
121
176
if err . empty?
122
177
print 'Ready : ' , f , ' : require->' , suc . inspect , "\n "
123
178
else
124
179
print '*LACK : ' , f , ' : require->' , suc . inspect ,
125
180
' FAIL->' , err . inspect , "\n "
126
181
end
127
182
128
- subdir_check ( subdir ) if File . directory? ( subdir )
183
+ subdir_check ( subdir , verbose ) if File . directory? ( subdir )
129
184
}
0 commit comments