mkmf: deal with environment variables in MakeMakefile#xpopen
This commit is contained in:
parent
1c3d6d6cc9
commit
21a29844a3
Notes:
git
2021-11-26 22:32:46 +09:00
38
lib/mkmf.rb
38
lib/mkmf.rb
@ -386,30 +386,56 @@ MESSAGE
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def xsystem command, opts = nil
|
def expand_command(commands, envs = libpath_env)
|
||||||
varpat = /\$\((\w+)\)|\$\{(\w+)\}/
|
varpat = /\$\((\w+)\)|\$\{(\w+)\}/
|
||||||
|
vars = nil
|
||||||
|
expand = proc do |command|
|
||||||
|
case command
|
||||||
|
when Array
|
||||||
|
command.map(&expand)
|
||||||
|
when String
|
||||||
if varpat =~ command
|
if varpat =~ command
|
||||||
vars = Hash.new {|h, k| h[k] = ENV[k]}
|
vars ||= Hash.new {|h, k| h[k] = ENV[k]}
|
||||||
command = command.dup
|
command = command.dup
|
||||||
nil while command.gsub!(varpat) {vars[$1||$2]}
|
nil while command.gsub!(varpat) {vars[$1||$2]}
|
||||||
end
|
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
|
Logging::open do
|
||||||
puts command.quote
|
puts [env_quote(env), command.quote].join(' ')
|
||||||
if opts and opts[:werror]
|
if opts and opts[:werror]
|
||||||
result = nil
|
result = nil
|
||||||
Logging.postpone do |log|
|
Logging.postpone do |log|
|
||||||
output = IO.popen(libpath_env, command, &:read)
|
output = IO.popen(env, command, &:read)
|
||||||
result = ($?.success? and File.zero?(log.path))
|
result = ($?.success? and File.zero?(log.path))
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
else
|
else
|
||||||
system(libpath_env, command)
|
system(env, *command)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def xpopen command, *mode, &block
|
def xpopen command, *mode, &block
|
||||||
|
env, commands = expand_command(command)
|
||||||
|
command = [env_quote(env), command].join(' ')
|
||||||
Logging::open do
|
Logging::open do
|
||||||
case mode[0]
|
case mode[0]
|
||||||
when nil, Hash, /^r/
|
when nil, Hash, /^r/
|
||||||
@ -417,7 +443,7 @@ MESSAGE
|
|||||||
else
|
else
|
||||||
puts "| #{command}"
|
puts "| #{command}"
|
||||||
end
|
end
|
||||||
IO.popen(libpath_env, command, *mode, &block)
|
IO.popen(env, commands, *mode, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user