Skip to content

Commit c438e36

Browse files
authored
Merge pull request #929 from maierru/fix/shared_tmp_inside_docker
fix unlink error
2 parents 517b658 + 9552253 commit c438e36

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/ffi/tools/const_generator.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ def const(name, format = nil, cast = '', ruby_name = nil, converter = nil,
105105
# @return [nil]
106106
# @raise if a constant is missing and +:required+ was set to +true+ (see {#initialize})
107107
def calculate(options = {})
108-
binary = File.join Dir.tmpdir, "rb_const_gen_bin_#{Process.pid}"
108+
binary_path = nil
109109

110110
Tempfile.open("#{@prefix}.const_generator") do |f|
111+
binary_path = f.path + ".bin"
111112
@includes.each do |inc|
112113
f.puts "#include <#{inc}>"
113114
end
@@ -125,16 +126,16 @@ def calculate(options = {})
125126
f.flush
126127

127128
cc = ENV['CC'] || 'gcc'
128-
output = `#{cc} #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary} 2>&1`
129+
output = `#{cc} #{options[:cppflags]} -D_DARWIN_USE_64_BIT_INODE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -x c -Wall -Werror #{f.path} -o #{binary_path} 2>&1`
129130

130131
unless $?.success? then
131132
output = output.split("\n").map { |l| "\t#{l}" }.join "\n"
132133
raise "Compilation error generating constants #{@prefix}:\n#{output}"
133134
end
134135
end
135136

136-
output = `#{binary}`
137-
File.unlink(binary + (FFI::Platform.windows? ? ".exe" : ""))
137+
output = `#{binary_path}`
138+
File.unlink(binary_path + (FFI::Platform.windows? ? ".exe" : ""))
138139
output.each_line do |line|
139140
line =~ /^(\S+)\s(.*)$/
140141
const = @constants[$1]

0 commit comments

Comments
 (0)