Class: Neutron::PkgConf
- Inherits:
-
Object
show all
- Defined in:
- lib/neutron/pkgconf.rb
Defined Under Namespace
Classes: InvalidPkgConfError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
Returns the value of attribute packages.
6
7
8
|
# File 'lib/neutron/pkgconf.rb', line 6
def packages
@packages
end
|
Class Method Details
.gen_pc(filename, **opts) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/neutron/pkgconf.rb', line 51
def self.gen_pc(filename, **opts)
prefix = if ENV['PREFIX'] then ENV['PREFIX'] else '/usr' end
filename = File.expand_path(filename)
content = ''
content << "prefix=#{prefix}\n"
content << "exec_prefix=${prefix}\n"
content << "includedir=${prefix}/include\n"
content << "libdir=${exec_prefix}/lib\n"
content << "\n"
reqs = if opts[:requires] then opts[:requires].packages.join(' ') else '' end
preqs = if opts[:prequires] then opts[:prequires].packages.join(' ') else '' end
lname = opts[:name]
if m = /lib(.+)/.match(lname.downcase)
lname = m[1]
end
content << "Name: #{opts[:name] or 'Unnamed'}\n"
content << "Description: #{opts[:description] or 'No description'}\n"
content << "Version: #{opts[:version] or '0.1.0'}\n"
content << "Requires: #{reqs}\n"
content << "Requires.private: #{preqs}\n"
content << "Cflags: #{opts[:cflags] or "-I${includedir}/#{opts[:name].downcase or 'undefined'}"}\n"
content << "Libs: -L${libdir} -l#{lname or 'undefined'}\n"
content << "Libs.private: #{opts[:plibs] or ''}\n"
File.delete(filename) if File.exist?(filename)
File.write(filename, content)
puts "] Done generating pkg-config #{filename}"
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
|