utilrb 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Rakefile +2 -18
- data/lib/utilrb/common.rb +1 -1
- data/lib/utilrb/kernel/load_dsl_file.rb +1 -1
- data/lib/utilrb/logger/forward.rb +8 -0
- data/lib/utilrb/logger/hierarchy.rb +34 -3
- data/lib/utilrb/pkgconfig.rb +52 -4
- data/test/test_hash.rb +8 -0
- data/test/test_logger.rb +55 -0
- metadata +23 -21
data/.gemtest
ADDED
File without changes
|
data/Rakefile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require './lib/utilrb/common'
|
3
|
+
require './lib/utilrb/rake_common'
|
3
4
|
|
4
|
-
|
5
|
-
require 'hoe'
|
6
|
-
|
5
|
+
Utilrb::Rake.hoe do
|
7
6
|
hoe_spec = Hoe.spec 'utilrb' do
|
8
7
|
developer "Sylvain Joyeux", "sylvain.joyeux@m4x.org"
|
9
8
|
extra_deps <<
|
@@ -19,12 +18,6 @@ begin
|
|
19
18
|
hoe_spec.spec.extensions << 'ext/extconf.rb'
|
20
19
|
Rake.clear_tasks(/^default$/)
|
21
20
|
Rake.clear_tasks(/publish_docs/)
|
22
|
-
|
23
|
-
rescue Exception => e
|
24
|
-
if e.message !~ /\.rubyforge/
|
25
|
-
STDERR.puts "WARN: cannot load the Hoe gem, or Hoe fails. Publishing tasks are disabled"
|
26
|
-
STDERR.puts "WARN: error message is: #{e.message}"
|
27
|
-
end
|
28
21
|
end
|
29
22
|
|
30
23
|
task :default => :setup
|
@@ -39,15 +32,6 @@ task :setup do
|
|
39
32
|
FileUtils.ln_sf "../ext/utilrb_ext.so", "lib/utilrb_ext.so"
|
40
33
|
end
|
41
34
|
|
42
|
-
task 'publish_docs' => 'redocs' do
|
43
|
-
if !system('./update_github')
|
44
|
-
raise "cannot update the gh-pages branch for GitHub"
|
45
|
-
end
|
46
|
-
if !system('git', 'push', 'github', '+gh-pages')
|
47
|
-
raise "cannot push the documentation"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
35
|
task :clean do
|
52
36
|
puts "Cleaning extension in ext/"
|
53
37
|
FileUtils.rm_f "lib/utilrb_ext.so"
|
data/lib/utilrb/common.rb
CHANGED
@@ -14,6 +14,14 @@ class Logger
|
|
14
14
|
def #{level}(*args, &proc); logger.#{level}(*args, &proc) end
|
15
15
|
EOF
|
16
16
|
end
|
17
|
+
|
18
|
+
def log_nest(size, level = nil, &block)
|
19
|
+
logger.nest(size, level, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def log_pp(level, object, *first_line_format)
|
23
|
+
logger.log_pp(level, object, *first_line_format)
|
24
|
+
end
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'facets/module/spacename'
|
2
2
|
require 'facets/kernel/constant'
|
3
|
+
require 'utilrb/object/singleton_class'
|
4
|
+
require 'utilrb/logger/forward'
|
5
|
+
|
3
6
|
class Logger
|
4
7
|
# Define a hierarchy of loggers mapped to the module hierarchy.
|
8
|
+
#
|
5
9
|
# It defines the #logger accessor which either returns the logger
|
6
10
|
# attribute of the module, if one is defined, or its parent logger
|
7
11
|
# attribute.
|
@@ -21,23 +25,50 @@ class Logger
|
|
21
25
|
module Hierarchy
|
22
26
|
attr_writer :logger
|
23
27
|
|
28
|
+
def self.included(obj)
|
29
|
+
if obj.singleton_class.ancestors.include?(Logger::Forward)
|
30
|
+
obj.send(:include, Logger::Forward)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.extended(obj)
|
35
|
+
if obj.kind_of?(Module)
|
36
|
+
parent_module = constant(obj.spacename)
|
37
|
+
if (parent_module.singleton_class.ancestors.include?(Logger::Forward))
|
38
|
+
obj.send(:extend, Logger::Forward)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
24
43
|
def has_own_logger?
|
25
44
|
defined?(@logger) && @logger
|
26
45
|
end
|
27
46
|
|
28
|
-
def make_own_logger(new_level = nil)
|
47
|
+
def make_own_logger(new_progname = nil, new_level = nil)
|
29
48
|
if !has_own_logger?
|
30
49
|
@logger = self.logger.dup
|
31
50
|
end
|
51
|
+
if new_progname
|
52
|
+
@logger.progname = new_progname
|
53
|
+
end
|
32
54
|
if new_level
|
33
55
|
@logger.level = new_level
|
34
56
|
end
|
35
57
|
@logger
|
36
58
|
end
|
37
59
|
|
60
|
+
def reset_own_logger
|
61
|
+
@logger = nil
|
62
|
+
end
|
63
|
+
|
38
64
|
def logger
|
39
|
-
|
40
|
-
|
65
|
+
if defined?(@logger) && @logger
|
66
|
+
return @logger
|
67
|
+
elsif defined?(@default_logger) && @default_logger
|
68
|
+
return @default_logger
|
69
|
+
end
|
70
|
+
|
71
|
+
@default_logger ||=
|
41
72
|
if kind_of?(Module)
|
42
73
|
constant(self.spacename).logger
|
43
74
|
else
|
data/lib/utilrb/pkgconfig.rb
CHANGED
@@ -109,11 +109,23 @@ module Utilrb
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
# Exception raised when a request pkg-config file is not found
|
112
113
|
class NotFound < RuntimeError
|
114
|
+
# The name of the pkg-config package
|
113
115
|
attr_reader :name
|
116
|
+
|
114
117
|
def initialize(name); @name = name end
|
115
118
|
end
|
116
119
|
|
120
|
+
# Exception raised when invalid data is found in a pkg-config file
|
121
|
+
class Invalid < RuntimeError
|
122
|
+
# The name of the pkg-config package
|
123
|
+
attr_reader :name
|
124
|
+
|
125
|
+
def initialize(name); @name = name end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
117
129
|
attr_reader :file
|
118
130
|
attr_reader :path
|
119
131
|
|
@@ -192,10 +204,29 @@ module Utilrb
|
|
192
204
|
|
193
205
|
raw_variables = Hash.new
|
194
206
|
raw_fields = Hash.new
|
195
|
-
|
207
|
+
|
208
|
+
running_line = nil
|
209
|
+
@file = file.map do |line|
|
196
210
|
line.gsub! /\s*#.*$/, ''
|
211
|
+
line = line.strip
|
197
212
|
next if line.empty?
|
198
213
|
|
214
|
+
value = line.gsub(/\\$/, '')
|
215
|
+
if running_line
|
216
|
+
running_line << " " << value
|
217
|
+
end
|
218
|
+
|
219
|
+
if line =~ /\\$/
|
220
|
+
running_line ||= value
|
221
|
+
elsif running_line
|
222
|
+
running_line = nil
|
223
|
+
else
|
224
|
+
value
|
225
|
+
end
|
226
|
+
end.compact
|
227
|
+
|
228
|
+
|
229
|
+
file.each do |line|
|
199
230
|
case line
|
200
231
|
when /^(#{VAR_NAME_RX})\s*=(.*)/
|
201
232
|
raw_variables[$1] = $2.strip
|
@@ -292,13 +323,21 @@ module Utilrb
|
|
292
323
|
# Returns the list of include directories listed in the Cflags: section
|
293
324
|
# of the pkgconfig file
|
294
325
|
def include_dirs
|
295
|
-
Shellwords.shellsplit(cflags_only_I).map { |v| v[2..-1] }
|
326
|
+
result = Shellwords.shellsplit(cflags_only_I).map { |v| v[2..-1] }
|
327
|
+
if result.any?(&:empty?)
|
328
|
+
raise Invalid, "empty include directory (-I without argument) found in pkg-config package #{name}"
|
329
|
+
end
|
330
|
+
result
|
296
331
|
end
|
297
332
|
|
298
333
|
# Returns the list of library directories listed in the Libs: section
|
299
334
|
# of the pkgconfig file
|
300
335
|
def library_dirs
|
301
|
-
Shellwords.shellsplit(libs_only_L).map { |v| v[2..-1] }
|
336
|
+
result = Shellwords.shellsplit(libs_only_L).map { |v| v[2..-1] }
|
337
|
+
if result.any?(&:empty?)
|
338
|
+
raise Invalid, "empty link directory (-L without argument) found in pkg-config package #{name}"
|
339
|
+
end
|
340
|
+
result
|
302
341
|
end
|
303
342
|
|
304
343
|
ACTIONS = %w{cflags cflags-only-I cflags-only-other
|
@@ -374,6 +413,16 @@ module Utilrb
|
|
374
413
|
result
|
375
414
|
end
|
376
415
|
|
416
|
+
def self.available_package_names
|
417
|
+
result = []
|
418
|
+
each_pkgconfig_directory do |dir|
|
419
|
+
Dir.glob(File.join(dir, "*.pc")) do |path|
|
420
|
+
result << File.basename(path, ".pc")
|
421
|
+
end
|
422
|
+
end
|
423
|
+
result
|
424
|
+
end
|
425
|
+
|
377
426
|
# Returns true if there is a package with this name
|
378
427
|
def self.has_package?(name)
|
379
428
|
!find_all_package_files(name).empty?
|
@@ -385,7 +434,6 @@ module Utilrb
|
|
385
434
|
seen = Set.new
|
386
435
|
each_pkgconfig_directory do |dir|
|
387
436
|
Dir.glob(File.join(dir, '*.pc')) do |file|
|
388
|
-
puts file
|
389
437
|
pkg_name = File.basename(file, ".pc")
|
390
438
|
next if seen.include?(pkg_name)
|
391
439
|
next if regex && pkg_name !~ regex
|
data/test/test_hash.rb
CHANGED
@@ -26,5 +26,13 @@ class TC_Hash < Test::Unit::TestCase
|
|
26
26
|
values = $1.split(", ")
|
27
27
|
assert_equal(["1 => 2", "2 => 3", "3 => ..."].to_set, values.to_set)
|
28
28
|
end
|
29
|
+
|
30
|
+
def test_map_value
|
31
|
+
base = { 'a' => 1, 'b' => 2 }
|
32
|
+
result = base.map_value { |k, v| v += 1 }
|
33
|
+
|
34
|
+
assert_equal({ 'a' => 1, 'b' => 2 }, base)
|
35
|
+
assert_equal({ 'a' => 2, 'b' => 3 }, result)
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
data/test/test_logger.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_config'
|
2
|
+
require 'utilrb/logger'
|
3
|
+
|
4
|
+
class TC_Logger < Test::Unit::TestCase
|
5
|
+
module Root
|
6
|
+
extend Logger::Root('TC_Logger', Logger::INFO)
|
7
|
+
|
8
|
+
module Child
|
9
|
+
extend Logger::Hierarchy
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
Root::Child.reset_own_logger
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_logger_root
|
18
|
+
assert Root.respond_to?(:logger)
|
19
|
+
assert Root.logger
|
20
|
+
assert_equal Logger::INFO, Root.logger.level
|
21
|
+
assert_equal 'TC_Logger', Root.logger.progname
|
22
|
+
|
23
|
+
assert Root.respond_to?(:warn)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_logger_hierarchy
|
27
|
+
child = Root::Child
|
28
|
+
assert child.respond_to?(:logger)
|
29
|
+
assert child.logger
|
30
|
+
assert_same Root.logger, child.logger
|
31
|
+
assert child.respond_to?(:warn)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_logger_hierarch_make_own
|
35
|
+
child = Root::Child
|
36
|
+
assert_same Root.logger, child.logger
|
37
|
+
|
38
|
+
child.make_own_logger('child', Logger::DEBUG)
|
39
|
+
assert_not_same Root.logger, child.logger
|
40
|
+
assert_equal "child", child.logger.progname
|
41
|
+
assert_equal Logger::DEBUG, child.logger.level
|
42
|
+
assert_equal "TC_Logger", Root.logger.progname
|
43
|
+
assert_equal Logger::INFO, Root.logger.level
|
44
|
+
|
45
|
+
assert child.has_own_logger?
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_logger_hierarch_reset_own
|
49
|
+
child = Root::Child
|
50
|
+
child.make_own_logger('child', Logger::DEBUG)
|
51
|
+
assert_not_same Root.logger, child.logger
|
52
|
+
child.reset_own_logger
|
53
|
+
test_logger_hierarchy
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sylvain Joyeux
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-03 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: facets
|
@@ -69,14 +69,13 @@ dependencies:
|
|
69
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
70
|
none: false
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ~>
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
hash:
|
74
|
+
hash: 27
|
75
75
|
segments:
|
76
76
|
- 2
|
77
|
-
-
|
78
|
-
|
79
|
-
version: 2.8.0
|
77
|
+
- 12
|
78
|
+
version: "2.12"
|
80
79
|
type: :development
|
81
80
|
version_requirements: *id004
|
82
81
|
description: |-
|
@@ -198,6 +197,8 @@ files:
|
|
198
197
|
- test/test_time.rb
|
199
198
|
- test/test_unbound_method.rb
|
200
199
|
- test/test_weakref.rb
|
200
|
+
- test/test_logger.rb
|
201
|
+
- .gemtest
|
201
202
|
homepage: http://utilrb.rubyforge.org
|
202
203
|
licenses: []
|
203
204
|
|
@@ -228,26 +229,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
229
|
requirements: []
|
229
230
|
|
230
231
|
rubyforge_project: utilrb
|
231
|
-
rubygems_version: 1.
|
232
|
+
rubygems_version: 1.8.10
|
232
233
|
signing_key:
|
233
234
|
specification_version: 3
|
234
235
|
summary: Yet another Ruby toolkit
|
235
236
|
test_files:
|
237
|
+
- test/test_kernel.rb
|
236
238
|
- test/test_unbound_method.rb
|
237
239
|
- test/test_hash.rb
|
238
|
-
- test/test_misc.rb
|
239
240
|
- test/test_exception.rb
|
240
|
-
- test/test_kernel.rb
|
241
|
-
- test/test_gc.rb
|
242
|
-
- test/test_proc.rb
|
243
|
-
- test/test_time.rb
|
244
|
-
- test/test_pkgconfig.rb
|
245
|
-
- test/test_weakref.rb
|
246
|
-
- test/test_object.rb
|
247
|
-
- test/test_enumerable.rb
|
248
241
|
- test/test_config.rb
|
249
|
-
- test/
|
250
|
-
- test/
|
242
|
+
- test/test_time.rb
|
243
|
+
- test/test_logger.rb
|
251
244
|
- test/test_module.rb
|
252
245
|
- test/test_objectstats.rb
|
246
|
+
- test/test_enumerable.rb
|
247
|
+
- test/test_gc.rb
|
248
|
+
- test/test_misc.rb
|
249
|
+
- test/test_object.rb
|
250
|
+
- test/test_array.rb
|
251
|
+
- test/test_dir.rb
|
252
|
+
- test/test_weakref.rb
|
253
|
+
- test/test_proc.rb
|
253
254
|
- test/test_set.rb
|
255
|
+
- test/test_pkgconfig.rb
|