utilrb 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.travis.yml +4 -2
 - data/lib/utilrb/kernel/arity.rb +11 -6
 - data/lib/utilrb/kernel/load_dsl_file.rb +2 -2
 - data/lib/utilrb/logger/forward.rb +10 -0
 - data/lib/utilrb/logger/hierarchy.rb +28 -5
 - data/lib/utilrb/logger/root.rb +12 -12
 - data/lib/utilrb/marshal.rb +3 -0
 - data/lib/utilrb/marshal/load_with_missing_constants.rb +18 -21
 - data/lib/utilrb/pkgconfig.rb +171 -76
 - data/lib/utilrb/test.rb +4 -4
 - data/lib/utilrb/timepoints.rb +7 -0
 - data/lib/utilrb/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: dfc6c628c67691e4051455e910ea27774e48d1f8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 3985cf51ce618e65f82a503ec1d3708a76986c0d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7c0826bbdc14832b30ee1f08585b04f8ae203bcaca23eebf9b2a8441e2c63599a12e8d9a774c673b01652530f0aff811162dc21840cc3aed36d5950878a70243
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 7a2e844418cc195a2515bb2575f684ed4d264c481a2ed19713e688c7ada8802d06c85feca9b30009e1579b012f87920d444a366487dc1ccb0d0915e19636d95b
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/lib/utilrb/kernel/arity.rb
    CHANGED
    
    | 
         @@ -1,15 +1,20 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Kernel
         
     | 
| 
       2 
2 
     | 
    
         
             
                # Raises if +object+ can accept calls with exactly +arity+ arguments. 
         
     | 
| 
       3 
3 
     | 
    
         
             
                # object should respond to #arity
         
     | 
| 
       4 
     | 
    
         
            -
                def check_arity(object, arity)
         
     | 
| 
       5 
     | 
    
         
            -
                    if  
     | 
| 
       6 
     | 
    
         
            -
                        if  
     | 
| 
       7 
     | 
    
         
            -
                             
     | 
| 
      
 4 
     | 
    
         
            +
                def check_arity(object, arity, strict: nil)
         
     | 
| 
      
 5 
     | 
    
         
            +
                    if strict.nil?
         
     | 
| 
      
 6 
     | 
    
         
            +
                        if object.respond_to?(:lambda?)
         
     | 
| 
      
 7 
     | 
    
         
            +
                            strict = object.lambda?
         
     | 
| 
      
 8 
     | 
    
         
            +
                        else strict = true
         
     | 
| 
       8 
9 
     | 
    
         
             
                        end
         
     | 
| 
       9 
10 
     | 
    
         
             
                    end
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                     
     | 
| 
       12 
     | 
    
         
            -
                         
     | 
| 
      
 12 
     | 
    
         
            +
                    if strict
         
     | 
| 
      
 13 
     | 
    
         
            +
                        if object.arity >= 0 && object.arity != arity
         
     | 
| 
      
 14 
     | 
    
         
            +
                            raise ArgumentError, "#{object} requests #{object.arity} arguments, but #{arity} was requested"
         
     | 
| 
      
 15 
     | 
    
         
            +
                        elsif -object.arity-1 > arity
         
     | 
| 
      
 16 
     | 
    
         
            +
                            raise ArgumentError, "#{object} requests at least #{object.arity} arguments, but #{arity} was requested"
         
     | 
| 
      
 17 
     | 
    
         
            +
                        end
         
     | 
| 
       13 
18 
     | 
    
         
             
                    end
         
     | 
| 
       14 
19 
     | 
    
         
             
                end
         
     | 
| 
       15 
20 
     | 
    
         
             
            end
         
     | 
| 
         @@ -116,13 +116,13 @@ module Kernel 
     | 
|
| 
       116 
116 
     | 
    
         
             
                # The caller of this method should call it at the end of its definition
         
     | 
| 
       117 
117 
     | 
    
         
             
                # file, or the translation method may not be robust at all
         
     | 
| 
       118 
118 
     | 
    
         
             
                def eval_dsl_file(file, proxied_object, context, full_backtrace, *exceptions, &block)
         
     | 
| 
      
 119 
     | 
    
         
            +
                    file = File.expand_path(file)
         
     | 
| 
       119 
120 
     | 
    
         
             
                    if !File.readable?(file)
         
     | 
| 
       120 
121 
     | 
    
         
             
                        raise ArgumentError, "#{file} does not exist"
         
     | 
| 
       121 
122 
     | 
    
         
             
                    end
         
     | 
| 
       122 
123 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                    loaded_file = file.gsub(/^#{Regexp.quote(Dir.pwd)}\//, '')
         
     | 
| 
       124 
124 
     | 
    
         
             
                    file_content = File.read(file)
         
     | 
| 
       125 
     | 
    
         
            -
                    eval_dsl_file_content( 
     | 
| 
      
 125 
     | 
    
         
            +
                    eval_dsl_file_content(file, file_content, proxied_object, context, full_backtrace, *exceptions, &block)
         
     | 
| 
       126 
126 
     | 
    
         
             
                end
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
       128 
128 
     | 
    
         
             
                # Same than eval_dsl_file, but will not load the same file twice
         
     | 
| 
         @@ -15,6 +15,16 @@ class Logger 
     | 
|
| 
       15 
15 
     | 
    
         
             
                        EOF
         
     | 
| 
       16 
16 
     | 
    
         
             
                    end
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
      
 18 
     | 
    
         
            +
                    # The logger level
         
     | 
| 
      
 19 
     | 
    
         
            +
                    def log_level
         
     | 
| 
      
 20 
     | 
    
         
            +
                        logger.level
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    # Sets the logger's level
         
     | 
| 
      
 24 
     | 
    
         
            +
                    def log_level=(level)
         
     | 
| 
      
 25 
     | 
    
         
            +
                        logger.level = level
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       18 
28 
     | 
    
         
             
                    # Forwarded to {Logger#silent}
         
     | 
| 
       19 
29 
     | 
    
         
             
                    def log_silent(&block)
         
     | 
| 
       20 
30 
     | 
    
         
             
                        logger.silent(&block)
         
     | 
| 
         @@ -2,6 +2,7 @@ require 'facets/module/spacename' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'facets/kernel/constant'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'utilrb/object/attribute'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'utilrb/logger/forward'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'weakref'
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            class Logger
         
     | 
| 
       7 
8 
     | 
    
         
             
                module HierarchyElement
         
     | 
| 
         @@ -23,13 +24,30 @@ class Logger 
     | 
|
| 
       23 
24 
     | 
    
         
             
                        self.logger = new_logger
         
     | 
| 
       24 
25 
     | 
    
         
             
                    end
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
      
 27 
     | 
    
         
            +
                    def register_log_child(child)
         
     | 
| 
      
 28 
     | 
    
         
            +
                        log_children << WeakRef.new(child)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    def each_log_child
         
     | 
| 
      
 32 
     | 
    
         
            +
                        return enum_for(__method__) if !block_given?
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                        log_children.delete_if do |ref|
         
     | 
| 
      
 35 
     | 
    
         
            +
                            begin
         
     | 
| 
      
 36 
     | 
    
         
            +
                                yield(ref.__getobj__)
         
     | 
| 
      
 37 
     | 
    
         
            +
                                false
         
     | 
| 
      
 38 
     | 
    
         
            +
                            rescue WeakRef::RefError
         
     | 
| 
      
 39 
     | 
    
         
            +
                                true
         
     | 
| 
      
 40 
     | 
    
         
            +
                            end
         
     | 
| 
      
 41 
     | 
    
         
            +
                        end
         
     | 
| 
      
 42 
     | 
    
         
            +
                    end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       26 
44 
     | 
    
         
             
                    # Allows to change the logger object at this level of the hierarchy
         
     | 
| 
       27 
45 
     | 
    
         
             
                    #
         
     | 
| 
       28 
46 
     | 
    
         
             
                    # This is usually not used directly: a new logger can be created with
         
     | 
| 
       29 
47 
     | 
    
         
             
                    # Hierarchy#make_own_logger and removed with Hierarchy#reset_own_logger
         
     | 
| 
       30 
48 
     | 
    
         
             
                    def logger=(new_logger)
         
     | 
| 
       31 
49 
     | 
    
         
             
                        @logger = new_logger
         
     | 
| 
       32 
     | 
    
         
            -
                         
     | 
| 
      
 50 
     | 
    
         
            +
                        each_log_child do |child|
         
     | 
| 
       33 
51 
     | 
    
         
             
                            child.reset_default_logger
         
     | 
| 
       34 
52 
     | 
    
         
             
                        end
         
     | 
| 
       35 
53 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -38,14 +56,14 @@ class Logger 
     | 
|
| 
       38 
56 
     | 
    
         
             
                    # logging methods will now access the parent's module logger.
         
     | 
| 
       39 
57 
     | 
    
         
             
                    def reset_own_logger
         
     | 
| 
       40 
58 
     | 
    
         
             
                        @logger = nil
         
     | 
| 
       41 
     | 
    
         
            -
                         
     | 
| 
      
 59 
     | 
    
         
            +
                        each_log_child do |child|
         
     | 
| 
       42 
60 
     | 
    
         
             
                            child.reset_default_logger
         
     | 
| 
       43 
61 
     | 
    
         
             
                        end
         
     | 
| 
       44 
62 
     | 
    
         
             
                    end
         
     | 
| 
       45 
63 
     | 
    
         | 
| 
       46 
64 
     | 
    
         
             
                    def reset_default_logger
         
     | 
| 
       47 
65 
     | 
    
         
             
                        @__utilrb_hierarchy__default_logger = nil
         
     | 
| 
       48 
     | 
    
         
            -
                         
     | 
| 
      
 66 
     | 
    
         
            +
                        each_log_child do |child|
         
     | 
| 
       49 
67 
     | 
    
         
             
                            child.reset_default_logger
         
     | 
| 
       50 
68 
     | 
    
         
             
                        end
         
     | 
| 
       51 
69 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -130,8 +148,13 @@ class Logger 
     | 
|
| 
       130 
148 
     | 
    
         
             
                                            break
         
     | 
| 
       131 
149 
     | 
    
         
             
                                        end
         
     | 
| 
       132 
150 
     | 
    
         
             
                                    end
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
       133 
152 
     | 
    
         
             
                                    if m.respond_to?(:superclass)
         
     | 
| 
       134 
153 
     | 
    
         
             
                                        m = m.superclass
         
     | 
| 
      
 154 
     | 
    
         
            +
                                        if m.respond_to?(:logger)
         
     | 
| 
      
 155 
     | 
    
         
            +
                                            parent_module = m
         
     | 
| 
      
 156 
     | 
    
         
            +
                                            break
         
     | 
| 
      
 157 
     | 
    
         
            +
                                        end
         
     | 
| 
       135 
158 
     | 
    
         
             
                                    else
         
     | 
| 
       136 
159 
     | 
    
         
             
                                        m = nil; break
         
     | 
| 
       137 
160 
     | 
    
         
             
                                    end
         
     | 
| 
         @@ -140,8 +163,8 @@ class Logger 
     | 
|
| 
       140 
163 
     | 
    
         
             
                                if !m
         
     | 
| 
       141 
164 
     | 
    
         
             
                                    raise NoParentLogger, "cannot find a logger for #{self}"
         
     | 
| 
       142 
165 
     | 
    
         
             
                                end
         
     | 
| 
       143 
     | 
    
         
            -
                                if parent_module.respond_to? : 
     | 
| 
       144 
     | 
    
         
            -
                                    parent_module. 
     | 
| 
      
 166 
     | 
    
         
            +
                                if parent_module.respond_to? :register_log_child
         
     | 
| 
      
 167 
     | 
    
         
            +
                                    parent_module.register_log_child(self)
         
     | 
| 
       145 
168 
     | 
    
         
             
                                end
         
     | 
| 
       146 
169 
     | 
    
         
             
                                parent_module.logger
         
     | 
| 
       147 
170 
     | 
    
         
             
                            else
         
     | 
    
        data/lib/utilrb/logger/root.rb
    CHANGED
    
    | 
         @@ -1,19 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'utilrb/logger/hierarchy'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       2 
3 
     | 
    
         
             
            class Logger
         
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
                LEVEL_TO_COLOR =
         
     | 
| 
       4 
5 
     | 
    
         
             
                    begin
         
     | 
| 
       5 
     | 
    
         
            -
                        require ' 
     | 
| 
       6 
     | 
    
         
            -
                         
     | 
| 
      
 6 
     | 
    
         
            +
                        require 'pastel'
         
     | 
| 
      
 7 
     | 
    
         
            +
                        colorizer = Pastel.new
         
     | 
| 
      
 8 
     | 
    
         
            +
                        { 'DEBUG' => ->(t) { t },
         
     | 
| 
      
 9 
     | 
    
         
            +
                          'INFO' =>  ->(t) { t },
         
     | 
| 
      
 10 
     | 
    
         
            +
                          'WARN' =>  colorizer.magenta.detach,
         
     | 
| 
      
 11 
     | 
    
         
            +
                          'ERROR' => colorizer.red.detach,
         
     | 
| 
      
 12 
     | 
    
         
            +
                          'FATAL' => colorizer.red.bold.detach }
         
     | 
| 
       7 
13 
     | 
    
         
             
                    rescue LoadError
         
     | 
| 
      
 14 
     | 
    
         
            +
                        Hash.new
         
     | 
| 
       8 
15 
     | 
    
         
             
                    end
         
     | 
| 
       9 
16 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
                LEVEL_TO_COLOR =
         
     | 
| 
       11 
     | 
    
         
            -
                    { 'DEBUG' => [],
         
     | 
| 
       12 
     | 
    
         
            -
                      'INFO' => [],
         
     | 
| 
       13 
     | 
    
         
            -
                      'WARN' => [:magenta],
         
     | 
| 
       14 
     | 
    
         
            -
                      'ERROR' => [:red],
         
     | 
| 
       15 
     | 
    
         
            -
                      'FATAL' => [:red, :bold] }
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
17 
     | 
    
         
             
                # Defines a logger on a module, allowing to use that module as a root in a
         
     | 
| 
       18 
18 
     | 
    
         
             
                # hierarchy (i.e. having submodules use the Logger::Hierarchy support)
         
     | 
| 
       19 
19 
     | 
    
         
             
                #
         
     | 
| 
         @@ -56,9 +56,9 @@ class Logger 
     | 
|
| 
       56 
56 
     | 
    
         
             
                    console = @console
         
     | 
| 
       57 
57 
     | 
    
         
             
                    formatter =
         
     | 
| 
       58 
58 
     | 
    
         
             
                        if block then lambda(&block)
         
     | 
| 
       59 
     | 
    
         
            -
                        elsif  
     | 
| 
      
 59 
     | 
    
         
            +
                        elsif !LEVEL_TO_COLOR.empty?
         
     | 
| 
       60 
60 
     | 
    
         
             
                            lambda do |severity, time, name, msg|
         
     | 
| 
       61 
     | 
    
         
            -
                                 
     | 
| 
      
 61 
     | 
    
         
            +
                                LEVEL_TO_COLOR[severity].call("#{name}[#{severity}]: #{msg}\n")
         
     | 
| 
       62 
62 
     | 
    
         
             
                            end
         
     | 
| 
       63 
63 
     | 
    
         
             
                        else lambda { |severity, time, name, msg| "#{name}[#{severity}]: #{msg}\n" }
         
     | 
| 
       64 
64 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -1,26 +1,32 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Marshal
         
     | 
| 
       2 
     | 
    
         
            -
                if defined? BasicObject
         
     | 
| 
       3 
     | 
    
         
            -
                    class BlackHole < BasicObject
         
     | 
| 
       4 
     | 
    
         
            -
                    end
         
     | 
| 
       5 
     | 
    
         
            -
                end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
2 
     | 
    
         
             
                class BlackHole
         
     | 
| 
       8 
3 
     | 
    
         
             
                    class << self
         
     | 
| 
       9 
     | 
    
         
            -
                        :name
         
     | 
| 
      
 4 
     | 
    
         
            +
                        attr_reader :name
         
     | 
| 
       10 
5 
     | 
    
         
             
                    end
         
     | 
| 
       11 
6 
     | 
    
         | 
| 
       12 
7 
     | 
    
         
             
                    def initialize(*args)
         
     | 
| 
       13 
8 
     | 
    
         
             
                    end
         
     | 
| 
       14 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
                    def hash
         
     | 
| 
      
 11 
     | 
    
         
            +
                        __id__
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                    def eql?(obj)
         
     | 
| 
      
 15 
     | 
    
         
            +
                        equal?(obj)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
       15 
18 
     | 
    
         
             
                    attr_reader :__content__
         
     | 
| 
       16 
19 
     | 
    
         
             
                    def method_missing(*args)
         
     | 
| 
      
 20 
     | 
    
         
            +
                        ::Kernel.puts args.inspect
         
     | 
| 
      
 21 
     | 
    
         
            +
                        ::Kernel.puts ::Kernel.caller
         
     | 
| 
       17 
22 
     | 
    
         
             
                    end
         
     | 
| 
       18 
23 
     | 
    
         
             
                    def self._load(*args)
         
     | 
| 
       19 
24 
     | 
    
         
             
                        hole = BlackHole.new
         
     | 
| 
       20 
25 
     | 
    
         
             
                        hole.instance_variable_set(:@__content__, args)
         
     | 
| 
       21 
26 
     | 
    
         
             
                    end
         
     | 
| 
       22 
27 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                    def self.method_missing(*args)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    def self.method_missing(*args, **options)
         
     | 
| 
      
 29 
     | 
    
         
            +
                        BlackHole.new
         
     | 
| 
       24 
30 
     | 
    
         
             
                    end
         
     | 
| 
       25 
31 
     | 
    
         
             
                end
         
     | 
| 
       26 
32 
     | 
    
         | 
| 
         @@ -32,20 +38,11 @@ module Marshal 
     | 
|
| 
       32 
38 
     | 
    
         
             
                    self.load(str_or_io)
         
     | 
| 
       33 
39 
     | 
    
         
             
                rescue Exception => e
         
     | 
| 
       34 
40 
     | 
    
         
             
                    case e.message
         
     | 
| 
       35 
     | 
    
         
            -
                    when /undefined class\/module ((?:\w 
     | 
| 
       36 
     | 
    
         
            -
                         
     | 
| 
       37 
     | 
    
         
            -
                         
     | 
| 
       38 
     | 
    
         
            -
                         
     | 
| 
       39 
     | 
    
         
            -
                         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                        if original_pos
         
     | 
| 
       42 
     | 
    
         
            -
                            str_or_io.seek(original_pos)
         
     | 
| 
       43 
     | 
    
         
            -
                        end
         
     | 
| 
       44 
     | 
    
         
            -
                        retry
         
     | 
| 
       45 
     | 
    
         
            -
                    when /undefined class\/module ((?:\w+::)+)(\w+)$/
         
     | 
| 
       46 
     | 
    
         
            -
                        mod, klass   = $1, $2
         
     | 
| 
       47 
     | 
    
         
            -
                        full_name = "#{mod}#{klass}"
         
     | 
| 
       48 
     | 
    
         
            -
                        mod = mod.split('::').inject(Object) { |m, n| m.const_get(n) }
         
     | 
| 
      
 41 
     | 
    
         
            +
                    when /undefined class\/module ((?:\w+)(?:::\w+)*)(?:::)?$/
         
     | 
| 
      
 42 
     | 
    
         
            +
                        full_name = $1
         
     | 
| 
      
 43 
     | 
    
         
            +
                        path = $1.split('::')
         
     | 
| 
      
 44 
     | 
    
         
            +
                        *path, klass = *path
         
     | 
| 
      
 45 
     | 
    
         
            +
                        mod = path.inject(Object) { |m, n| m.const_get(n) }
         
     | 
| 
       49 
46 
     | 
    
         | 
| 
       50 
47 
     | 
    
         
             
                        blackhole = Class.new(BlackHole) do
         
     | 
| 
       51 
48 
     | 
    
         
             
                            @name = full_name
         
     | 
    
        data/lib/utilrb/pkgconfig.rb
    CHANGED
    
    | 
         @@ -41,15 +41,6 @@ module Utilrb 
     | 
|
| 
       41 
41 
     | 
    
         
             
                    VAR_NAME_RX     = /\w+/
         
     | 
| 
       42 
42 
     | 
    
         
             
                    FIELD_NAME_RX   = /[\w\.\-]+/
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                    class << self
         
     | 
| 
       45 
     | 
    
         
            -
                        attr_reader :loaded_packages
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                        def clear_cache
         
     | 
| 
       48 
     | 
    
         
            -
                            loaded_packages.clear
         
     | 
| 
       49 
     | 
    
         
            -
                        end
         
     | 
| 
       50 
     | 
    
         
            -
                    end
         
     | 
| 
       51 
     | 
    
         
            -
                    @loaded_packages = Hash.new
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
44 
     | 
    
         
             
                    def self.load(path, preset_variables)
         
     | 
| 
       54 
45 
     | 
    
         
             
                        pkg_name = File.basename(path, ".pc")
         
     | 
| 
       55 
46 
     | 
    
         
             
                        pkg = Class.instance_method(:new).bind(PkgConfig).call(pkg_name)
         
     | 
| 
         @@ -57,28 +48,41 @@ module Utilrb 
     | 
|
| 
       57 
48 
     | 
    
         
             
                        pkg
         
     | 
| 
       58 
49 
     | 
    
         
             
                    end
         
     | 
| 
       59 
50 
     | 
    
         | 
| 
      
 51 
     | 
    
         
            +
                    def self.load_minimal(path, preset_variables)
         
     | 
| 
      
 52 
     | 
    
         
            +
                        pkg_name = File.basename(path, ".pc")
         
     | 
| 
      
 53 
     | 
    
         
            +
                        pkg = Class.instance_method(:new).bind(PkgConfig).call(pkg_name)
         
     | 
| 
      
 54 
     | 
    
         
            +
                        pkg.load_minimal(path, preset_variables)
         
     | 
| 
      
 55 
     | 
    
         
            +
                        pkg
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                    # @deprecated {PkgConfig} does not cache the packages anymore, so no
         
     | 
| 
      
 59 
     | 
    
         
            +
                    #   need to call this method
         
     | 
| 
      
 60 
     | 
    
         
            +
                    def self.clear_cache
         
     | 
| 
      
 61 
     | 
    
         
            +
                    end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
       60 
63 
     | 
    
         
             
                    # Returns the pkg-config object that matches the given name, and
         
     | 
| 
       61 
64 
     | 
    
         
             
                    # optionally a version string
         
     | 
| 
       62 
     | 
    
         
            -
                    def self.get(name, version_spec = nil, preset_variables = Hash.new)
         
     | 
| 
       63 
     | 
    
         
            -
                         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
                            end
         
     | 
| 
      
 65 
     | 
    
         
            +
                    def self.get(name, version_spec = nil, preset_variables = Hash.new, minimal: false, pkg_config_path: self.pkg_config_path)
         
     | 
| 
      
 66 
     | 
    
         
            +
                        paths = find_all_package_files(name, pkg_config_path: pkg_config_path)
         
     | 
| 
      
 67 
     | 
    
         
            +
                        if paths.empty?
         
     | 
| 
      
 68 
     | 
    
         
            +
                            raise NotFound.new(name), "cannot find the pkg-config specification for #{name}"
         
     | 
| 
      
 69 
     | 
    
         
            +
                        end
         
     | 
| 
       68 
70 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                             
     | 
| 
       71 
     | 
    
         
            -
                                candidates << PkgConfig.load(p, preset_variables)
         
     | 
| 
       72 
     | 
    
         
            -
                            end
         
     | 
| 
       73 
     | 
    
         
            -
                            loaded_packages[name] = candidates
         
     | 
| 
      
 71 
     | 
    
         
            +
                        candidates = paths.map do |p|
         
     | 
| 
      
 72 
     | 
    
         
            +
                            PkgConfig.load_minimal(p, preset_variables)
         
     | 
| 
       74 
73 
     | 
    
         
             
                        end
         
     | 
| 
       75 
74 
     | 
    
         | 
| 
       76 
75 
     | 
    
         
             
                        # Now try to find a matching spec
         
     | 
| 
       77 
     | 
    
         
            -
                        if  
     | 
| 
       78 
     | 
    
         
            -
                             
     | 
| 
      
 76 
     | 
    
         
            +
                        if match = find_matching_version(candidates, version_spec)
         
     | 
| 
      
 77 
     | 
    
         
            +
                            match
         
     | 
| 
       79 
78 
     | 
    
         
             
                        else
         
     | 
| 
       80 
79 
     | 
    
         
             
                            raise NotFound, "found #{candidates.size} packages for #{name}, but none match the version specification #{version_spec}"
         
     | 
| 
       81 
80 
     | 
    
         
             
                        end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                        if !minimal
         
     | 
| 
      
 83 
     | 
    
         
            +
                            match.load_fields
         
     | 
| 
      
 84 
     | 
    
         
            +
                        end
         
     | 
| 
      
 85 
     | 
    
         
            +
                        match
         
     | 
| 
       82 
86 
     | 
    
         
             
                    end
         
     | 
| 
       83 
87 
     | 
    
         | 
| 
       84 
88 
     | 
    
         
             
                    # Finds the provided package and optional version and returns its
         
     | 
| 
         @@ -140,7 +144,6 @@ module Utilrb 
     | 
|
| 
       140 
144 
     | 
    
         
             
                    end
         
     | 
| 
       141 
145 
     | 
    
         | 
| 
       142 
146 
     | 
    
         | 
| 
       143 
     | 
    
         
            -
                    attr_reader :file
         
     | 
| 
       144 
147 
     | 
    
         
             
                    attr_reader :path
         
     | 
| 
       145 
148 
     | 
    
         | 
| 
       146 
149 
     | 
    
         
             
            	# The module name
         
     | 
| 
         @@ -151,10 +154,17 @@ module Utilrb 
     | 
|
| 
       151 
154 
     | 
    
         
             
                    # The module version, as an array of integers
         
     | 
| 
       152 
155 
     | 
    
         
             
                    attr_reader :version
         
     | 
| 
       153 
156 
     | 
    
         | 
| 
      
 157 
     | 
    
         
            +
                    attr_reader :raw_fields
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
       154 
159 
     | 
    
         
             
                    # Information extracted from the file
         
     | 
| 
       155 
160 
     | 
    
         
             
                    attr_reader :variables
         
     | 
| 
       156 
161 
     | 
    
         
             
                    attr_reader :fields
         
     | 
| 
       157 
162 
     | 
    
         | 
| 
      
 163 
     | 
    
         
            +
                    # The list of packages that are Require:'d by this package
         
     | 
| 
      
 164 
     | 
    
         
            +
                    #
         
     | 
| 
      
 165 
     | 
    
         
            +
                    # @return [Array<PkgConfig>]
         
     | 
| 
      
 166 
     | 
    
         
            +
                    attr_reader :requires
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
       158 
168 
     | 
    
         
             
            	# Create a PkgConfig object for the package +name+
         
     | 
| 
       159 
169 
     | 
    
         
             
            	# Raises PkgConfig::NotFound if the module does not exist
         
     | 
| 
       160 
170 
     | 
    
         
             
            	def initialize(name)
         
     | 
| 
         @@ -169,7 +179,7 @@ module Utilrb 
     | 
|
| 
       169 
179 
     | 
    
         
             
                    # +current+ is a string that describes what we are expanding. It is used
         
     | 
| 
       170 
180 
     | 
    
         
             
                    # to detect recursion in expansion of variables, and to give meaningful
         
     | 
| 
       171 
181 
     | 
    
         
             
                    # errors to the user
         
     | 
| 
       172 
     | 
    
         
            -
                    def  
     | 
| 
      
 182 
     | 
    
         
            +
                    def perform_substitution(value, variables, current)
         
     | 
| 
       173 
183 
     | 
    
         
             
                        value = value.gsub(/\$\{(\w+)\}/) do |rx|
         
     | 
| 
       174 
184 
     | 
    
         
             
                            expand_name = $1
         
     | 
| 
       175 
185 
     | 
    
         
             
                            if expand_name == current
         
     | 
| 
         @@ -211,16 +221,23 @@ module Utilrb 
     | 
|
| 
       211 
221 
     | 
    
         | 
| 
       212 
222 
     | 
    
         
             
                    SHELL_VARS = %w{Cflags Libs Libs.private}
         
     | 
| 
       213 
223 
     | 
    
         | 
| 
       214 
     | 
    
         
            -
                    #  
     | 
| 
       215 
     | 
    
         
            -
                     
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
       219 
     | 
    
         
            -
                         
     | 
| 
       220 
     | 
    
         
            -
                         
     | 
| 
      
 224 
     | 
    
         
            +
                    # @api private
         
     | 
| 
      
 225 
     | 
    
         
            +
                    #
         
     | 
| 
      
 226 
     | 
    
         
            +
                    # Normalize a field name to be lowercase with only the first letter
         
     | 
| 
      
 227 
     | 
    
         
            +
                    # capitalized
         
     | 
| 
      
 228 
     | 
    
         
            +
                    def normalize_field_name(name)
         
     | 
| 
      
 229 
     | 
    
         
            +
                        name = name.downcase
         
     | 
| 
      
 230 
     | 
    
         
            +
                        name[0, 1] = name[0, 1].upcase
         
     | 
| 
      
 231 
     | 
    
         
            +
                        name
         
     | 
| 
      
 232 
     | 
    
         
            +
                    end
         
     | 
| 
       221 
233 
     | 
    
         | 
| 
      
 234 
     | 
    
         
            +
                    # Parse a pkg-config field and extracts the raw definition of variables
         
     | 
| 
      
 235 
     | 
    
         
            +
                    # and fields
         
     | 
| 
      
 236 
     | 
    
         
            +
                    #
         
     | 
| 
      
 237 
     | 
    
         
            +
                    # @return [(Hash,Hash)] the set of variables and the set of fields
         
     | 
| 
      
 238 
     | 
    
         
            +
                    def parse(path)
         
     | 
| 
       222 
239 
     | 
    
         
             
                        running_line = nil
         
     | 
| 
       223 
     | 
    
         
            -
                         
     | 
| 
      
 240 
     | 
    
         
            +
                        file = File.readlines(path).map do |line|
         
     | 
| 
       224 
241 
     | 
    
         
             
                            line = line.gsub(/\s*#.*$/, '')
         
     | 
| 
       225 
242 
     | 
    
         
             
                            line = line.strip
         
     | 
| 
       226 
243 
     | 
    
         
             
                            next if line.empty?
         
     | 
| 
         @@ -240,54 +257,90 @@ module Utilrb 
     | 
|
| 
       240 
257 
     | 
    
         
             
                        end.compact
         
     | 
| 
       241 
258 
     | 
    
         | 
| 
       242 
259 
     | 
    
         | 
| 
      
 260 
     | 
    
         
            +
                        raw_variables, raw_fields = Hash.new, Hash.new
         
     | 
| 
       243 
261 
     | 
    
         
             
                        file.each do |line|
         
     | 
| 
       244 
262 
     | 
    
         
             
                            case line
         
     | 
| 
       245 
263 
     | 
    
         
             
                            when /^(#{VAR_NAME_RX})\s*=(.*)/
         
     | 
| 
       246 
264 
     | 
    
         
             
                                raw_variables[$1] = $2.strip
         
     | 
| 
       247 
265 
     | 
    
         
             
                            when /^(#{FIELD_NAME_RX}):\s*(.*)/
         
     | 
| 
       248 
     | 
    
         
            -
                                 
     | 
| 
      
 266 
     | 
    
         
            +
                                field_name = normalize_field_name($1)
         
     | 
| 
      
 267 
     | 
    
         
            +
                                raw_fields[field_name] = $2.strip
         
     | 
| 
       249 
268 
     | 
    
         
             
                            else
         
     | 
| 
       250 
269 
     | 
    
         
             
                                raise NotImplementedError, "#{path}: cannot parse pkg-config line #{line.inspect}"
         
     | 
| 
       251 
270 
     | 
    
         
             
                            end
         
     | 
| 
       252 
271 
     | 
    
         
             
                        end
         
     | 
| 
      
 272 
     | 
    
         
            +
                        return raw_variables, raw_fields
         
     | 
| 
      
 273 
     | 
    
         
            +
                    end
         
     | 
| 
      
 274 
     | 
    
         
            +
                    
         
     | 
| 
      
 275 
     | 
    
         
            +
                    def expand_variables(raw_variables)
         
     | 
| 
      
 276 
     | 
    
         
            +
                        raw_variables = raw_variables.dup
         
     | 
| 
       253 
277 
     | 
    
         | 
| 
      
 278 
     | 
    
         
            +
                        variables = Hash.new
         
     | 
| 
       254 
279 
     | 
    
         
             
                        # Resolve the variables
         
     | 
| 
       255 
280 
     | 
    
         
             
                        while variables.size != raw_variables.size
         
     | 
| 
       256 
281 
     | 
    
         
             
                            raw_variables.each do |name, value|
         
     | 
| 
       257 
     | 
    
         
            -
                                value =  
     | 
| 
      
 282 
     | 
    
         
            +
                                value = perform_substitution(value, raw_variables, name)
         
     | 
| 
       258 
283 
     | 
    
         
             
                                raw_variables[name] = value
         
     | 
| 
       259 
284 
     | 
    
         
             
                                if value !~ /\$\{#{VAR_NAME_RX}\}/
         
     | 
| 
       260 
285 
     | 
    
         
             
                                    variables[name] = value
         
     | 
| 
       261 
286 
     | 
    
         
             
                                end
         
     | 
| 
       262 
287 
     | 
    
         
             
                            end
         
     | 
| 
       263 
288 
     | 
    
         
             
                        end
         
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
             
     | 
| 
       266 
     | 
    
         
            -
             
     | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
       268 
     | 
    
         
            -
             
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
       270 
     | 
    
         
            -
             
     | 
| 
       271 
     | 
    
         
            -
             
     | 
| 
       272 
     | 
    
         
            -
             
     | 
| 
       273 
     | 
    
         
            -
             
     | 
| 
       274 
     | 
    
         
            -
             
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
                                         
     | 
| 
       277 
     | 
    
         
            -
             
     | 
| 
       278 
     | 
    
         
            -
                                         
     | 
| 
       279 
     | 
    
         
            -
                                    end 
     | 
| 
       280 
     | 
    
         
            -
                                end
         
     | 
| 
       281 
     | 
    
         
            -
                                fields[name] = resolved
         
     | 
| 
       282 
     | 
    
         
            -
                            else
         
     | 
| 
       283 
     | 
    
         
            -
                                fields[name] = expand_variables(value, variables, name)
         
     | 
| 
      
 289 
     | 
    
         
            +
                        variables
         
     | 
| 
      
 290 
     | 
    
         
            +
                    end
         
     | 
| 
      
 291 
     | 
    
         
            +
                    
         
     | 
| 
      
 292 
     | 
    
         
            +
                    def expand_field(name, field)
         
     | 
| 
      
 293 
     | 
    
         
            +
                        if SHELL_VARS.include?(name) 
         
     | 
| 
      
 294 
     | 
    
         
            +
                            value = Shellwords.shellsplit(field)
         
     | 
| 
      
 295 
     | 
    
         
            +
                            resolved = Array.new
         
     | 
| 
      
 296 
     | 
    
         
            +
                            while !value.empty?
         
     | 
| 
      
 297 
     | 
    
         
            +
                                value = value.flat_map do |v|
         
     | 
| 
      
 298 
     | 
    
         
            +
                                    expanded = perform_substitution(v, variables, name)
         
     | 
| 
      
 299 
     | 
    
         
            +
                                    if expanded == v
         
     | 
| 
      
 300 
     | 
    
         
            +
                                        resolved << v
         
     | 
| 
      
 301 
     | 
    
         
            +
                                        nil
         
     | 
| 
      
 302 
     | 
    
         
            +
                                    else
         
     | 
| 
      
 303 
     | 
    
         
            +
                                        Shellwords.shellsplit(expanded)
         
     | 
| 
      
 304 
     | 
    
         
            +
                                    end
         
     | 
| 
      
 305 
     | 
    
         
            +
                                end.compact
         
     | 
| 
       284 
306 
     | 
    
         
             
                            end
         
     | 
| 
      
 307 
     | 
    
         
            +
                            resolved
         
     | 
| 
      
 308 
     | 
    
         
            +
                        else
         
     | 
| 
      
 309 
     | 
    
         
            +
                            perform_substitution(field, variables, name)
         
     | 
| 
      
 310 
     | 
    
         
            +
                        end
         
     | 
| 
      
 311 
     | 
    
         
            +
                    end
         
     | 
| 
      
 312 
     | 
    
         
            +
             
     | 
| 
      
 313 
     | 
    
         
            +
                    def load_variables(path, preset_variables = Hash.new)
         
     | 
| 
      
 314 
     | 
    
         
            +
                        raw_variables, raw_fields = parse(path)
         
     | 
| 
      
 315 
     | 
    
         
            +
                        raw_variables = preset_variables.merge(raw_variables)
         
     | 
| 
      
 316 
     | 
    
         
            +
                        expand_variables(raw_variables)
         
     | 
| 
      
 317 
     | 
    
         
            +
                    end
         
     | 
| 
      
 318 
     | 
    
         
            +
                    
         
     | 
| 
      
 319 
     | 
    
         
            +
                    def load_minimal(path, preset_variables = Hash.new)
         
     | 
| 
      
 320 
     | 
    
         
            +
                        raw_variables, raw_fields = parse(path)
         
     | 
| 
      
 321 
     | 
    
         
            +
                        raw_variables = preset_variables.merge(raw_variables)
         
     | 
| 
      
 322 
     | 
    
         
            +
             
     | 
| 
      
 323 
     | 
    
         
            +
                        @variables = expand_variables(raw_variables)
         
     | 
| 
      
 324 
     | 
    
         
            +
                        if raw_fields['Version']
         
     | 
| 
      
 325 
     | 
    
         
            +
                            @raw_version = expand_field('Version', raw_fields['Version'])
         
     | 
| 
      
 326 
     | 
    
         
            +
                        else
         
     | 
| 
      
 327 
     | 
    
         
            +
                            @raw_version = ''
         
     | 
| 
      
 328 
     | 
    
         
            +
                        end
         
     | 
| 
      
 329 
     | 
    
         
            +
                        @version = raw_version.split('.').map { |v| Integer(v) if v =~ /^\d+$/ }.compact
         
     | 
| 
      
 330 
     | 
    
         
            +
             
     | 
| 
      
 331 
     | 
    
         
            +
                        # To be used in the call to #load
         
     | 
| 
      
 332 
     | 
    
         
            +
                        @raw_fields = raw_fields
         
     | 
| 
      
 333 
     | 
    
         
            +
                        @path = path
         
     | 
| 
      
 334 
     | 
    
         
            +
                    end
         
     | 
| 
       285 
335 
     | 
    
         | 
| 
      
 336 
     | 
    
         
            +
                    def load_fields
         
     | 
| 
      
 337 
     | 
    
         
            +
                        fields = Hash.new
         
     | 
| 
      
 338 
     | 
    
         
            +
                        @raw_fields.each do |name, value|
         
     | 
| 
      
 339 
     | 
    
         
            +
                            fields[name] = expand_field(name, value)
         
     | 
| 
       286 
340 
     | 
    
         
             
                        end
         
     | 
| 
      
 341 
     | 
    
         
            +
                        @fields = fields
         
     | 
| 
       287 
342 
     | 
    
         | 
| 
       288 
343 
     | 
    
         
             
                        # Initialize the main flags
         
     | 
| 
       289 
     | 
    
         
            -
                        @raw_version = (fields['Version'] || '')
         
     | 
| 
       290 
     | 
    
         
            -
                        @version = raw_version.split('.').map { |v| Integer(v) if v =~ /^\d+$/ }.compact
         
     | 
| 
       291 
344 
     | 
    
         
             
                        @description = (fields['Description'] || '')
         
     | 
| 
       292 
345 
     | 
    
         | 
| 
       293 
346 
     | 
    
         
             
                        # Get the requires/conflicts
         
     | 
| 
         @@ -326,6 +379,14 @@ module Utilrb 
     | 
|
| 
       326 
379 
     | 
    
         
             
                        end
         
     | 
| 
       327 
380 
     | 
    
         
             
                    end
         
     | 
| 
       328 
381 
     | 
    
         | 
| 
      
 382 
     | 
    
         
            +
                    # Loads the information contained in +path+
         
     | 
| 
      
 383 
     | 
    
         
            +
                    def load(path, preset_variables = Hash.new)
         
     | 
| 
      
 384 
     | 
    
         
            +
                        if !@raw_fields
         
     | 
| 
      
 385 
     | 
    
         
            +
                            load_minimal(path, preset_variables)
         
     | 
| 
      
 386 
     | 
    
         
            +
                        end
         
     | 
| 
      
 387 
     | 
    
         
            +
                        load_fields
         
     | 
| 
      
 388 
     | 
    
         
            +
                    end
         
     | 
| 
      
 389 
     | 
    
         
            +
             
     | 
| 
       329 
390 
     | 
    
         
             
            	def self.define_pkgconfig_action(action) # :nodoc:
         
     | 
| 
       330 
391 
     | 
    
         
             
                        class_eval <<-EOD, __FILE__, __LINE__+1
         
     | 
| 
       331 
392 
     | 
    
         
             
                        def pkgconfig_#{action.gsub(/-/, '_')}(static = false)
         
     | 
| 
         @@ -346,7 +407,7 @@ module Utilrb 
     | 
|
| 
       346 
407 
     | 
    
         
             
                    # Returns the list of include directories listed in the Cflags: section
         
     | 
| 
       347 
408 
     | 
    
         
             
                    # of the pkgconfig file
         
     | 
| 
       348 
409 
     | 
    
         
             
                    def include_dirs
         
     | 
| 
       349 
     | 
    
         
            -
                        result =  
     | 
| 
      
 410 
     | 
    
         
            +
                        result = raw_cflags_only_I.map { |v| v[2..-1] }
         
     | 
| 
       350 
411 
     | 
    
         
             
                        if result.any?(&:empty?)
         
     | 
| 
       351 
412 
     | 
    
         
             
                            raise Invalid.new(name), "empty include directory (-I without argument) found in pkg-config package #{name}"
         
     | 
| 
       352 
413 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -356,7 +417,7 @@ module Utilrb 
     | 
|
| 
       356 
417 
     | 
    
         
             
                    # Returns the list of library directories listed in the Libs: section
         
     | 
| 
       357 
418 
     | 
    
         
             
                    # of the pkgconfig file
         
     | 
| 
       358 
419 
     | 
    
         
             
                    def library_dirs
         
     | 
| 
       359 
     | 
    
         
            -
                        result =  
     | 
| 
      
 420 
     | 
    
         
            +
                        result = raw_libs_only_L.map { |v| v[2..-1] }
         
     | 
| 
       360 
421 
     | 
    
         
             
                        if result.any?(&:empty?)
         
     | 
| 
       361 
422 
     | 
    
         
             
                            raise Invalid.new(name), "empty link directory (-L without argument) found in pkg-config package #{name}"
         
     | 
| 
       362 
423 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -371,18 +432,27 @@ module Utilrb 
     | 
|
| 
       371 
432 
     | 
    
         
             
                        @cflags
         
     | 
| 
       372 
433 
     | 
    
         
             
                    end
         
     | 
| 
       373 
434 
     | 
    
         | 
| 
      
 435 
     | 
    
         
            +
                    def raw_cflags_only_I
         
     | 
| 
      
 436 
     | 
    
         
            +
                        @cflags.grep(/^-I/)
         
     | 
| 
      
 437 
     | 
    
         
            +
                    end
         
     | 
| 
      
 438 
     | 
    
         
            +
             
     | 
| 
      
 439 
     | 
    
         
            +
                    def raw_cflags_only_other
         
     | 
| 
      
 440 
     | 
    
         
            +
                        @cflags.find_all { |s| s !~ /^-I/ }
         
     | 
| 
      
 441 
     | 
    
         
            +
                    end
         
     | 
| 
      
 442 
     | 
    
         
            +
             
     | 
| 
       374 
443 
     | 
    
         
             
                    def cflags
         
     | 
| 
       375 
     | 
    
         
            -
                         
     | 
| 
      
 444 
     | 
    
         
            +
                        raw_cflags.join(" ")
         
     | 
| 
       376 
445 
     | 
    
         
             
                    end
         
     | 
| 
       377 
446 
     | 
    
         | 
| 
       378 
447 
     | 
    
         
             
                    def cflags_only_I
         
     | 
| 
       379 
     | 
    
         
            -
                         
     | 
| 
      
 448 
     | 
    
         
            +
                        raw_cflags_only_I.join(" ")
         
     | 
| 
       380 
449 
     | 
    
         
             
                    end
         
     | 
| 
       381 
450 
     | 
    
         | 
| 
       382 
451 
     | 
    
         
             
                    def cflags_only_other
         
     | 
| 
       383 
     | 
    
         
            -
                         
     | 
| 
      
 452 
     | 
    
         
            +
                        raw_cflags_only_other.join(" ")
         
     | 
| 
       384 
453 
     | 
    
         
             
                    end
         
     | 
| 
       385 
454 
     | 
    
         | 
| 
      
 455 
     | 
    
         
            +
             
     | 
| 
       386 
456 
     | 
    
         
             
                    def raw_ldflags
         
     | 
| 
       387 
457 
     | 
    
         
             
                        @ldflags
         
     | 
| 
       388 
458 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -391,20 +461,38 @@ module Utilrb 
     | 
|
| 
       391 
461 
     | 
    
         
             
                        @ldflags_with_requires
         
     | 
| 
       392 
462 
     | 
    
         
             
                    end
         
     | 
| 
       393 
463 
     | 
    
         | 
| 
      
 464 
     | 
    
         
            +
             
     | 
| 
      
 465 
     | 
    
         
            +
                    def raw_libs(static = false)
         
     | 
| 
      
 466 
     | 
    
         
            +
                        @ldflags_with_requires[static]
         
     | 
| 
      
 467 
     | 
    
         
            +
                    end
         
     | 
| 
      
 468 
     | 
    
         
            +
             
     | 
| 
      
 469 
     | 
    
         
            +
                    def raw_libs_only_L(static = false)
         
     | 
| 
      
 470 
     | 
    
         
            +
                        @ldflags_with_requires[static].grep(/^-L/)
         
     | 
| 
      
 471 
     | 
    
         
            +
                    end
         
     | 
| 
      
 472 
     | 
    
         
            +
             
     | 
| 
      
 473 
     | 
    
         
            +
                    def raw_libs_only_l(static = false)
         
     | 
| 
      
 474 
     | 
    
         
            +
                        @ldflags_with_requires[static].grep(/^-l/)
         
     | 
| 
      
 475 
     | 
    
         
            +
                    end
         
     | 
| 
      
 476 
     | 
    
         
            +
             
     | 
| 
      
 477 
     | 
    
         
            +
                    def raw_libs_only_other(static = false)
         
     | 
| 
      
 478 
     | 
    
         
            +
                        @ldflags_with_requires[static].find_all { |s| s !~ /^-[lL]/ }
         
     | 
| 
      
 479 
     | 
    
         
            +
                    end
         
     | 
| 
      
 480 
     | 
    
         
            +
             
     | 
| 
      
 481 
     | 
    
         
            +
             
     | 
| 
       394 
482 
     | 
    
         
             
                    def libs(static = false)
         
     | 
| 
       395 
     | 
    
         
            -
                         
     | 
| 
      
 483 
     | 
    
         
            +
                        raw_libs(static).join(" ")
         
     | 
| 
       396 
484 
     | 
    
         
             
                    end
         
     | 
| 
       397 
485 
     | 
    
         | 
| 
       398 
486 
     | 
    
         
             
                    def libs_only_L(static = false)
         
     | 
| 
       399 
     | 
    
         
            -
                         
     | 
| 
      
 487 
     | 
    
         
            +
                        raw_libs_only_L(static).join(" ")
         
     | 
| 
       400 
488 
     | 
    
         
             
                    end
         
     | 
| 
       401 
489 
     | 
    
         | 
| 
       402 
490 
     | 
    
         
             
                    def libs_only_l(static = false)
         
     | 
| 
       403 
     | 
    
         
            -
                         
     | 
| 
      
 491 
     | 
    
         
            +
                        raw_libs_only_l(static).join(" ")
         
     | 
| 
       404 
492 
     | 
    
         
             
                    end
         
     | 
| 
       405 
493 
     | 
    
         | 
| 
       406 
494 
     | 
    
         
             
                    def libs_only_other(static = false)
         
     | 
| 
       407 
     | 
    
         
            -
                         
     | 
| 
      
 495 
     | 
    
         
            +
                        raw_libs_only_other(static).join(" ")
         
     | 
| 
       408 
496 
     | 
    
         
             
                    end
         
     | 
| 
       409 
497 
     | 
    
         | 
| 
       410 
498 
     | 
    
         
             
            	def method_missing(varname, *args, &proc) # :nodoc:
         
     | 
| 
         @@ -415,17 +503,22 @@ module Utilrb 
     | 
|
| 
       415 
503 
     | 
    
         
             
            	    end
         
     | 
| 
       416 
504 
     | 
    
         
             
            	end
         
     | 
| 
       417 
505 
     | 
    
         | 
| 
       418 
     | 
    
         
            -
                    def self. 
     | 
| 
       419 
     | 
    
         
            -
                         
     | 
| 
       420 
     | 
    
         
            -
             
     | 
| 
      
 506 
     | 
    
         
            +
                    def self.pkg_config_path
         
     | 
| 
      
 507 
     | 
    
         
            +
                        ENV['PKG_CONFIG_PATH']
         
     | 
| 
      
 508 
     | 
    
         
            +
                    end
         
     | 
| 
      
 509 
     | 
    
         
            +
             
     | 
| 
      
 510 
     | 
    
         
            +
                    def self.each_pkgconfig_directory(pkg_config_path: self.pkg_config_path, &block)
         
     | 
| 
      
 511 
     | 
    
         
            +
                        return enum_for(__method__) if !block_given?
         
     | 
| 
      
 512 
     | 
    
         
            +
                        if pkg_config_path
         
     | 
| 
      
 513 
     | 
    
         
            +
                            pkg_config_path.split(':').each(&block)
         
     | 
| 
       421 
514 
     | 
    
         
             
                        end
         
     | 
| 
       422 
515 
     | 
    
         
             
                        default_search_path.each(&block)
         
     | 
| 
       423 
516 
     | 
    
         
             
                    end
         
     | 
| 
       424 
517 
     | 
    
         | 
| 
       425 
518 
     | 
    
         
             
                    # Returns true if there is a package with this name
         
     | 
| 
       426 
     | 
    
         
            -
                    def self.find_all_package_files(name)
         
     | 
| 
      
 519 
     | 
    
         
            +
                    def self.find_all_package_files(name, pkg_config_path: self.pkg_config_path)
         
     | 
| 
       427 
520 
     | 
    
         
             
                        result = []
         
     | 
| 
       428 
     | 
    
         
            -
                        each_pkgconfig_directory do |dir|
         
     | 
| 
      
 521 
     | 
    
         
            +
                        each_pkgconfig_directory(pkg_config_path: pkg_config_path) do |dir|
         
     | 
| 
       429 
522 
     | 
    
         
             
                            path = File.join(dir, "#{name}.pc")
         
     | 
| 
       430 
523 
     | 
    
         
             
                            if File.exist?(path)
         
     | 
| 
       431 
524 
     | 
    
         
             
                                result << path
         
     | 
| 
         @@ -434,9 +527,9 @@ module Utilrb 
     | 
|
| 
       434 
527 
     | 
    
         
             
                        result
         
     | 
| 
       435 
528 
     | 
    
         
             
                    end
         
     | 
| 
       436 
529 
     | 
    
         | 
| 
       437 
     | 
    
         
            -
                    def self.available_package_names
         
     | 
| 
      
 530 
     | 
    
         
            +
                    def self.available_package_names(pkg_config_path: self.pkg_config_path)
         
     | 
| 
       438 
531 
     | 
    
         
             
                        result = []
         
     | 
| 
       439 
     | 
    
         
            -
                        each_pkgconfig_directory do |dir|
         
     | 
| 
      
 532 
     | 
    
         
            +
                        each_pkgconfig_directory(pkg_config_path: pkg_config_path) do |dir|
         
     | 
| 
       440 
533 
     | 
    
         
             
                            Dir.glob(File.join(dir, "*.pc")) do |path|
         
     | 
| 
       441 
534 
     | 
    
         
             
                                result << File.basename(path, ".pc")
         
     | 
| 
       442 
535 
     | 
    
         
             
                            end
         
     | 
| 
         @@ -445,15 +538,17 @@ module Utilrb 
     | 
|
| 
       445 
538 
     | 
    
         
             
                    end
         
     | 
| 
       446 
539 
     | 
    
         | 
| 
       447 
540 
     | 
    
         
             
                    # Returns true if there is a package with this name
         
     | 
| 
       448 
     | 
    
         
            -
                    def self.has_package?(name)
         
     | 
| 
       449 
     | 
    
         
            -
                        !find_all_package_files(name).empty?
         
     | 
| 
      
 541 
     | 
    
         
            +
                    def self.has_package?(name, pkg_config_path: self.pkg_config_path)
         
     | 
| 
      
 542 
     | 
    
         
            +
                        !find_all_package_files(name, pkg_config_path: pkg_config_path).empty?
         
     | 
| 
       450 
543 
     | 
    
         
             
                    end
         
     | 
| 
       451 
544 
     | 
    
         | 
| 
       452 
545 
     | 
    
         
             
                    # Yields the package names of available packages. If +regex+ is given,
         
     | 
| 
       453 
546 
     | 
    
         
             
                    # lists only the names that match the regular expression.
         
     | 
| 
       454 
     | 
    
         
            -
                    def self.each_package(regex = nil)
         
     | 
| 
      
 547 
     | 
    
         
            +
                    def self.each_package(regex = nil, pkg_config_path: self.pkg_config_path)
         
     | 
| 
      
 548 
     | 
    
         
            +
                        return enum_for(__method__) if !block_given?
         
     | 
| 
      
 549 
     | 
    
         
            +
             
     | 
| 
       455 
550 
     | 
    
         
             
                        seen = Set.new
         
     | 
| 
       456 
     | 
    
         
            -
                        each_pkgconfig_directory do |dir|
         
     | 
| 
      
 551 
     | 
    
         
            +
                        each_pkgconfig_directory(pkg_config_path: pkg_config_path) do |dir|
         
     | 
| 
       457 
552 
     | 
    
         
             
                            Dir.glob(File.join(dir, '*.pc')) do |file|
         
     | 
| 
       458 
553 
     | 
    
         
             
                                pkg_name = File.basename(file, ".pc")
         
     | 
| 
       459 
554 
     | 
    
         
             
                                next if seen.include?(pkg_name)
         
     | 
    
        data/lib/utilrb/test.rb
    CHANGED
    
    | 
         @@ -4,10 +4,10 @@ if ENV['TEST_ENABLE_COVERAGE'] != '0' 
     | 
|
| 
       4 
4 
     | 
    
         
             
                begin
         
     | 
| 
       5 
5 
     | 
    
         
             
                    require 'simplecov'
         
     | 
| 
       6 
6 
     | 
    
         
             
                    require 'coveralls'
         
     | 
| 
       7 
     | 
    
         
            -
                    SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter 
     | 
| 
       8 
     | 
    
         
            -
                        SimpleCov::Formatter::HTMLFormatter,
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                     
     | 
| 
      
 7 
     | 
    
         
            +
                    SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
         
     | 
| 
      
 8 
     | 
    
         
            +
                        [SimpleCov::Formatter::HTMLFormatter,
         
     | 
| 
      
 9 
     | 
    
         
            +
                         Coveralls::SimpleCov::Formatter]
         
     | 
| 
      
 10 
     | 
    
         
            +
                    )
         
     | 
| 
       11 
11 
     | 
    
         
             
                    SimpleCov.start do
         
     | 
| 
       12 
12 
     | 
    
         
             
                        add_filter "/test/"
         
     | 
| 
       13 
13 
     | 
    
         
             
                    end
         
     | 
    
        data/lib/utilrb/timepoints.rb
    CHANGED
    
    | 
         @@ -15,8 +15,15 @@ module Utilrb 
     | 
|
| 
       15 
15 
     | 
    
         
             
                    end
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
                    def format_timepoints
         
     | 
| 
      
 18 
     | 
    
         
            +
                        start_points = Hash.new
         
     | 
| 
       18 
19 
     | 
    
         
             
                        result = []
         
     | 
| 
       19 
20 
     | 
    
         
             
                        @timepoints.inject(@timepoints.first.first) do |last_t, (t, name)|
         
     | 
| 
      
 21 
     | 
    
         
            +
                            if name.last == 'start'
         
     | 
| 
      
 22 
     | 
    
         
            +
                                start_points[name[0..-2]] = t
         
     | 
| 
      
 23 
     | 
    
         
            +
                            elsif name.last == 'done'
         
     | 
| 
      
 24 
     | 
    
         
            +
                                total = t - start_points.delete(name[0..-2])
         
     | 
| 
      
 25 
     | 
    
         
            +
                                name = name + ["total=%.3f" % total]
         
     | 
| 
      
 26 
     | 
    
         
            +
                            end
         
     | 
| 
       20 
27 
     | 
    
         
             
                            result << name + [t - last_t]
         
     | 
| 
       21 
28 
     | 
    
         
             
                            t
         
     | 
| 
       22 
29 
     | 
    
         
             
                        end
         
     | 
    
        data/lib/utilrb/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: utilrb
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 3.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Sylvain Joyeux
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-03-28 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: facets
         
     | 
| 
         @@ -152,6 +152,7 @@ files: 
     | 
|
| 
       152 
152 
     | 
    
         
             
            - lib/utilrb/logger/log_pp.rb
         
     | 
| 
       153 
153 
     | 
    
         
             
            - lib/utilrb/logger/root.rb
         
     | 
| 
       154 
154 
     | 
    
         
             
            - lib/utilrb/logger/silent.rb
         
     | 
| 
      
 155 
     | 
    
         
            +
            - lib/utilrb/marshal.rb
         
     | 
| 
       155 
156 
     | 
    
         
             
            - lib/utilrb/marshal/load_with_missing_constants.rb
         
     | 
| 
       156 
157 
     | 
    
         
             
            - lib/utilrb/module.rb
         
     | 
| 
       157 
158 
     | 
    
         
             
            - lib/utilrb/module/ancestor_p.rb
         
     |