diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-11-26 20:53:52 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-11-26 22:32:26 +0900 |
commit | 21a29844a34589506e88a2473c62f84e417a61bc (patch) | |
tree | c2f882d284a7326f1b1210740f20ac59eaac5a32 /lib/mkmf.rb | |
parent | 1c3d6d6cc905dc9f0a84eb2a3bf885cccbcd6225 (diff) |
mkmf: deal with environment variables in MakeMakefile#xpopen
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5182
Diffstat (limited to 'lib/mkmf.rb')
-rw-r--r-- | lib/mkmf.rb | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb index f4ad2070a0..6cc455424e 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -386,30 +386,56 @@ MESSAGE 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 else puts "| #{command}" end - IO.popen(libpath_env, command, *mode, &block) + IO.popen(env, commands, *mode, &block) end end |