Skip to content

Commit 6cef28d

Browse files
committed
Add support for continuous line
GitHub: Fix ruby-gnome/ruby-gnome#1686 It's used by Poppler 25.09.0. Reported by Vincent Garrigues. Thanks!!!
1 parent 282c67e commit 6cef28d

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

lib/pkg-config.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,20 +637,26 @@ def parse_pc
637637
@variables = {}
638638
@declarations = {}
639639
File.open(pc_path) do |input|
640+
current_line = +""
640641
input.each_line do |line|
641642
if line.dup.force_encoding("UTF-8").valid_encoding?
642643
line.force_encoding("UTF-8")
643644
end
644645
line = line.gsub(/#.*/, "").strip
645-
next if line.empty?
646-
case line
646+
if line.end_with?("\\")
647+
current_line += line[0..-2]
648+
next
649+
end
650+
current_line += line
651+
case current_line
647652
when /^(#{IDENTIFIER_RE})\s*=\s*/
648653
match = Regexp.last_match
649654
@variables[match[1]] = match.post_match.strip
650655
when /^(#{IDENTIFIER_RE})\s*:\s*/
651656
match = Regexp.last_match
652657
@declarations[match[1]] = match.post_match.strip
653658
end
659+
current_line = +""
654660
end
655661
end
656662
end

test/test-pkg-config.rb

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require "mkmf"
2+
require "tempfile"
3+
24
require "pkg-config"
35

46
class PkgConfigTest < Test::Unit::TestCase
@@ -227,6 +229,56 @@ def configure_args(args)
227229
$configure_args = original_configure_args
228230
end
229231

232+
sub_test_case("#parse_pc") do
233+
def parse_pc(content)
234+
Tempfile.create(["pkg-config", ".pc"]) do |file|
235+
file.puts(content)
236+
file.close
237+
package_config = PackageConfig.new(file.path)
238+
package_config.__send__(:parse_pc)
239+
[
240+
package_config.instance_variable_get(:@variables),
241+
package_config.instance_variable_get(:@declarations),
242+
]
243+
end
244+
end
245+
246+
def test_continuous_line
247+
assert_equal([
248+
{
249+
"prefix" => "/usr/local",
250+
"libdir" => "/usr/local/lib",
251+
"includedir" => "/usr/local/include",
252+
},
253+
{
254+
"Name" => "my-package",
255+
"Description" => "This is my package",
256+
"Version" => "1.0.0",
257+
"Requires" => "glib-2.0 >= 2.72 gobject-2.0 >= 2.72",
258+
"Requires.private" => "gio-2.0 >= 2.72 " +
259+
" cairo",
260+
"Libs" => "-L${libdir} -lmy-package",
261+
"Cflags" => "-I${includedir}/my-package",
262+
},
263+
],
264+
parse_pc(<<-PC))
265+
prefix=/usr/local
266+
libdir=/usr/local/lib
267+
includedir=/usr/local/include
268+
269+
Name: my-package
270+
Description: This is my package
271+
Version: 1.0.0
272+
Requires: glib-2.0 >= 2.72 gobject-2.0 >= 2.72
273+
Requires.private: gio-2.0 >= 2.72 \
274+
cairo
275+
276+
Libs: -L${libdir} -lmy-package
277+
Cflags: -I${includedir}/my-package
278+
PC
279+
end
280+
end
281+
230282
sub_test_case("#parse_requires") do
231283
def parse_requires(requires)
232284
@glib.__send__(:parse_requires, requires)

0 commit comments

Comments
 (0)