lib/autobuild/pkgconfig.rb in autobuild-1.17.0 vs lib/autobuild/pkgconfig.rb in autobuild-1.18.0

- old
+ new

@@ -1,43 +1,55 @@ # Access to information from pkg-config(1) class PkgConfig class NotFound < RuntimeError attr_reader :name - def initialize(name); @name = name end - def to_s; "#{name} is not available to pkg-config" end + + def initialize(name) + @name = name + end + + def to_s + "#{name} is not available to pkg-config" + end end - + # The module name attr_reader :name # The module version attr_reader :version # Create a PkgConfig object for the package +name+ # Raises PkgConfig::NotFound if the module does not exist def initialize(name) - if !system("pkg-config --exists #{name}") - raise NotFound.new(name) + unless system("pkg-config --exists #{name}") + raise NotFound.new(name), "pkg-config package '#{name}' not found" end - + @name = name @version = `pkg-config --modversion #{name}`.chomp.strip @actions = Hash.new @variables = Hash.new end - ACTIONS = %w{cflags cflags-only-I cflags-only-other - libs libs-only-L libs-only-l libs-only-other static} + ACTIONS = %w[cflags cflags-only-I cflags-only-other + libs libs-only-L libs-only-l libs-only-other static].freeze ACTIONS.each do |action| - define_method(action.gsub(/-/, '_')) do + define_method(action.tr('-', '_')) do @actions[action] ||= `pkg-config --#{action} #{name}`.chomp.strip end end + def respond_to_missing?(varname, _include_all) + varname =~ /^\w+$/ + end + def method_missing(varname, *args, &proc) if args.empty? - @variables[varname] ||= `pkg-config --variable=#{varname} #{name}`.chomp.strip - else - super(varname, *args, &proc) + unless (value = @variables[varname]) + value = `pkg-config --variable=#{varname} #{name}`.chomp.strip + @variables[varname] = value + end + return value end + super end end -