Class: Neutron::PkgConf
- Inherits:
-
Object
- Object
- Neutron::PkgConf
- Defined in:
- lib/neutron/pkgconf.rb
Defined Under Namespace
Classes: InvalidPkgConfError
Instance Attribute Summary collapse
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
Instance Method Summary collapse
- #+(target) ⇒ Object
-
#initialize(packages) ⇒ PkgConf
constructor
A new instance of PkgConf.
- #to_cc(**opts) ⇒ Object
- #to_valac ⇒ Object
Constructor Details
#initialize(packages) ⇒ PkgConf
Returns a new instance of PkgConf.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/neutron/pkgconf.rb', line 8 def initialize(packages) @packages = packages @packages.freeze found = [] checked = Neutron::PkgStatus.get_checked begin (packages-checked).each do |package| _, code = *Neutron.execute("pkg-config --exists #{package}") if code == 0 found << package else raise Neutron::PkgStatus::PkgNotFoundError, "Cannot find #{package}!" end end rescue Neutron::PkgStatus::PkgNotFoundError self.taint raise ensure Neutron::PkgStatus.add_found(found) end freeze end |
Instance Attribute Details
#packages ⇒ Object (readonly)
Returns the value of attribute packages.
6 7 8 |
# File 'lib/neutron/pkgconf.rb', line 6 def packages @packages end |
Instance Method Details
#+(target) ⇒ Object
31 32 33 34 35 |
# File 'lib/neutron/pkgconf.rb', line 31 def +(target) raise InvalidPkgConfError, 'Current pkg-conf is invalid!' if tainted? raise InvalidPkgConfError, 'Target pkg-conf is invalid!' if target.tainted? Neutron::PkgConf.new((@packages+target.packages).uniq) end |
#to_cc(**opts) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/neutron/pkgconf.rb', line 37 def to_cc(**opts) raise InvalidPkgConfError if tainted? o = { libs: true, cflags: true }.merge(opts) Neutron.execute("pkg-config #{"--libs" if o[:libs]} #{"--cflags" if o[:cflags]} #{@packages.join(' ')}")[0].strip end |
#to_valac ⇒ Object
46 47 48 49 |
# File 'lib/neutron/pkgconf.rb', line 46 def to_valac raise InvalidPkgConfError if tainted? @packages.map{|p|"--pkg #{p}"}.join(' ') end |