ruby-changes:74152
From: nagachika <ko1@a...>
Date: Fri, 21 Oct 2022 14:02:39 +0900 (JST)
Subject: [ruby-changes:74152] d07fc4c455 (ruby_3_1): merge revision(s) b90e56e6243f4e6567991bfd2375e1f58b1414a0:
https://git.ruby-lang.org/ruby.git/commit/?id=d07fc4c455 From d07fc4c4553bbacddeafc0108b21f2aec074b5ba Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Fri, 21 Oct 2022 12:40:06 +0900 Subject: merge revision(s) b90e56e6243f4e6567991bfd2375e1f58b1414a0: mkmf: pkg_config accepts multiple options --- lib/mkmf.rb | 48 +++++++++++++++++++++++--------------------- test/mkmf/test_pkg_config.rb | 7 +++++++ 2 files changed, 32 insertions(+), 23 deletions(-) --- lib/mkmf.rb | 48 +++++++++++++++++++++++--------------------- test/mkmf/test_pkg_config.rb | 7 +++++++ version.h | 2 +- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 6f9b8fd670..013a117670 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -1841,26 +1841,26 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L1841 $config_dirs[target] = [idir, ldir] end - # Returns compile/link information about an installed library in a - # tuple of <code>[cflags, ldflags, libs]</code>, by using the - # command found first in the following commands: + # Returns compile/link information about an installed library in a tuple of <code>[cflags, + # ldflags, libs]</code>, by using the command found first in the following commands: # # 1. If <code>--with-{pkg}-config={command}</code> is given via - # command line option: <code>{command} {option}</code> + # command line option: <code>{command} {options}</code> # - # 2. <code>{pkg}-config {option}</code> + # 2. <code>{pkg}-config {options}</code> # - # 3. <code>pkg-config {option} {pkg}</code> + # 3. <code>pkg-config {options} {pkg}</code> # - # Where {option} is, for instance, <code>--cflags</code>. + # Where +options+ is the option name without dashes, for instance <code>"cflags"</code> for the + # <code>--cflags</code> flag. # - # The values obtained are appended to +$INCFLAGS+, +$CFLAGS+, +$LDFLAGS+ and - # +$libs+. + # The values obtained are appended to <code>$INCFLAGS</code>, <code>$CFLAGS</code>, + # <code>$LDFLAGS</code> and <code>$libs</code>. # - # If an <code>option</code> argument is given, the config command is - # invoked with the option and a stripped output string is returned - # without modifying any of the global values mentioned above. - def pkg_config(pkg, option=nil) + # If one or more <code>options</code> argument is given, the config command is + # invoked with the options and a stripped output string is returned without + # modifying any of the global values mentioned above. + def pkg_config(pkg, *options) _, ldir = dir_config(pkg) if ldir pkg_config_path = "#{ldir}/pkgconfig" @@ -1877,10 +1877,11 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L1877 xsystem([*envs, $PKGCONFIG, "--exists", pkg]) # default to pkg-config command pkgconfig = $PKGCONFIG - get = proc {|opt| - opt = xpopen([*envs, $PKGCONFIG, "--#{opt}", pkg], err:[:child, :out], &:read) - Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}} - opt.strip if $?.success? + get = proc {|opts| + opts = Array(opts).map { |o| "--#{o}" } + opts = xpopen([*envs, $PKGCONFIG, *opts, pkg], err:[:child, :out], &:read) + Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}} + opts.strip if $?.success? } elsif find_executable0(pkgconfig = "#{pkg}-config") # default to package specific config command, as a last resort. @@ -1888,15 +1889,16 @@ SRC https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L1889 pkgconfig = nil end if pkgconfig - get ||= proc {|opt| - opt = xpopen([*envs, pkgconfig, "--#{opt}"], err:[:child, :out], &:read) - Logging.open {puts opt.each_line.map{|s|"=> #{s.inspect}"}} - opt.strip if $?.success? + get ||= proc {|opts| + opts = Array(opts).map { |o| "--#{o}" } + opts = xpopen([*envs, pkgconfig, *opts], err:[:child, :out], &:read) + Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}} + opts.strip if $?.success? } end orig_ldflags = $LDFLAGS - if get and option - get[option] + if get and !options.empty? + get[options] elsif get and try_ldflags(ldflags = get['libs']) if incflags = get['cflags-only-I'] $INCFLAGS << " " << incflags diff --git a/test/mkmf/test_pkg_config.rb b/test/mkmf/test_pkg_config.rb index 42aad65cf3..1f4f48db12 100644 --- a/test/mkmf/test_pkg_config.rb +++ b/test/mkmf/test_pkg_config.rb @@ -57,5 +57,12 @@ class TestMkmf https://github.com/ruby/ruby/blob/trunk/test/mkmf/test_pkg_config.rb#L57 actual = pkg_config("test1", "cflags").shellsplit.sort assert_equal(expected, actual, MKMFLOG) end + + def test_pkgconfig_with_multiple_options + pend("skipping because pkg-config is not installed") unless PKG_CONFIG + expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort + actual = pkg_config("test1", "libs", "static").shellsplit.sort + assert_equal(expected, actual, MKMFLOG) + end end end diff --git a/version.h b/version.h index 17a0072e26..8d6bb6c43d 100644 --- a/version.h +++ b/version.h @@ -11,7 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L11 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 3 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 122 +#define RUBY_PATCHLEVEL 123 #define RUBY_RELEASE_YEAR 2022 #define RUBY_RELEASE_MONTH 10 -- cgit v1.2.3 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/