[前][次][番号順一覧][スレッド一覧]

ruby-changes:69953

From: Nobuyoshi <ko1@a...>
Date: Fri, 26 Nov 2021 22:32:43 +0900 (JST)
Subject: [ruby-changes:69953] 21a29844a3 (master): mkmf: deal with environment variables in MakeMakefile#xpopen

https://git.ruby-lang.org/ruby.git/commit/?id=21a29844a3

From 21a29844a34589506e88a2473c62f84e417a61bc Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 26 Nov 2021 20:53:52 +0900
Subject: mkmf: deal with environment variables in MakeMakefile#xpopen

---
 lib/mkmf.rb | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index f4ad2070a08..6cc455424e7 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -386,30 +386,56 @@ MESSAGE https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L386
     end
   end
 
-  def xsystem command, opts = nil
+  def expand_command(commands, envs = libpath_env)
     varpat = /\$\((\w+)\)|\$\{(\w+)\}/
-    if varpat =~ command
-      vars = Hash.new {|h, k| h[k] = ENV[k]}
-      command = command.dup
-      nil while command.gsub!(varpat) {vars[$1||$2]}
+    vars = nil
+    expand = proc do |command|
+      case command
+      when Array
+        command.map(&expand)
+      when String
+        if varpat =~ command
+          vars ||= Hash.new {|h, k| h[k] = ENV[k]}
+          command = command.dup
+          nil while command.gsub!(varpat) {vars[$1||$2]}
+        end
+        command
+      else
+        command
+      end
+    end
+    if Array === commands
+      env, *commands = commands if Hash === commands.first
+      envs.merge!(env) if env
     end
+    return envs, expand[commands]
+  end
+
+  def env_quote(envs)
+    envs.map {|e, v| "#{e}=#{v.quote}"}
+  end
+
+  def xsystem command, opts = nil
+    env, command = expand_command(command)
     Logging::open do
-      puts command.quote
+      puts [env_quote(env), command.quote].join(' ')
       if opts and opts[:werror]
         result = nil
         Logging.postpone do |log|
-          output = IO.popen(libpath_env, command, &:read)
+          output = IO.popen(env, command, &:read)
           result = ($?.success? and File.zero?(log.path))
           output
         end
         result
       else
-        system(libpath_env, command)
+        system(env, *command)
       end
     end
   end
 
   def xpopen command, *mode, &block
+    env, commands = expand_command(command)
+    command = [env_quote(env), command].join(' ')
     Logging::open do
       case mode[0]
       when nil, Hash, /^r/
@@ -417,7 +443,7 @@ MESSAGE https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L443
       else
         puts "| #{command}"
       end
-      IO.popen(libpath_env, command, *mode, &block)
+      IO.popen(env, commands, *mode, &block)
     end
   end
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]