@@ -191,11 +191,10 @@ def parse(env_or_cmd, *args)
191
191
192
192
parse_options ( options )
193
193
194
- if env and !env . empty?
195
- array = ( @options [ :env ] ||= [ ] )
196
-
194
+ @add_to_env = { }
195
+ if env
197
196
env . each_pair do |key , value |
198
- array << [ convert_env_key ( key ) , convert_env_value ( value ) ]
197
+ @add_to_env [ convert_env_key ( key ) ] = convert_env_value ( value )
199
198
end
200
199
end
201
200
end
@@ -373,14 +372,12 @@ def convert_env_value(value)
373
372
374
373
def spawn_setup ( alter_process )
375
374
env = @options . delete ( :unsetenv_others ) ? { } : ENV . to_hash
376
- @add_to_env = add_to_env = @options . delete ( :env )
377
- if add_to_env
378
- add_to_env . each do |key , value |
379
- if value
380
- env [ key ] = value
381
- else
382
- env . delete ( key )
383
- end
375
+
376
+ @add_to_env . each_pair do |key , value |
377
+ if value
378
+ env [ key ] = value
379
+ else
380
+ env . delete ( key )
384
381
end
385
382
end
386
383
@@ -502,10 +499,12 @@ def posix_spawnp(command, args, env_array, options)
502
499
end
503
500
end
504
501
505
- if chdir
502
+ use_helper = chdir || @add_to_env [ 'PATH' ]
503
+ if use_helper
506
504
# Go through spawn-helper to change the working dir and then execve()
507
505
spawn_helper = "#{ Truffle ::Boot . ruby_home } /lib/truffle/spawn-helper"
508
- args = [ spawn_helper , chdir , command , *args ]
506
+ cwd = chdir || Dir . pwd
507
+ args = [ spawn_helper , cwd , command , *args ]
509
508
command = spawn_helper
510
509
end
511
510
@@ -548,7 +547,7 @@ def exec
548
547
549
548
def log_command ( type )
550
549
if LOG_SUBPROCESS
551
- env = ( @add_to_env || { } ) . map { |k , v | "#{ k } =#{ v } " } . join ( ' ' )
550
+ env = @add_to_env . map { |k , v | "#{ k } =#{ v } " } . join ( ' ' )
552
551
Truffle ::Debug . log_info "#{ type } : #{ env } #{ ' ' unless env . empty? } #{ @argv . join ( ' ' ) } "
553
552
end
554
553
end
@@ -570,7 +569,8 @@ def resolve_in_path(command)
570
569
end
571
570
end
572
571
573
- ENV [ 'PATH' ] . split ( File ::PATH_SEPARATOR ) . each do |dir |
572
+ path = @add_to_env [ 'PATH' ] || ENV [ 'PATH' ]
573
+ path . split ( File ::PATH_SEPARATOR ) . each do |dir |
574
574
file = File . join ( dir , command )
575
575
if File . file? ( file ) && File . executable? ( file )
576
576
return file
0 commit comments