From 3e2f3b2f578b214f31fc4592075eab23c82e3ddc Mon Sep 17 00:00:00 2001 From: inglorion Date: Sun, 21 Nov 2010 13:07:31 +0100 Subject: [PATCH] Updated NasmELFGenerator to raise an exception if running the assembler fails. --- lib/voodoo/generators/nasm_elf_generator.rb | 51 +++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/voodoo/generators/nasm_elf_generator.rb b/lib/voodoo/generators/nasm_elf_generator.rb index ae30e61..02e802c 100644 --- a/lib/voodoo/generators/nasm_elf_generator.rb +++ b/lib/voodoo/generators/nasm_elf_generator.rb @@ -31,29 +31,38 @@ module Voodoo end Tempfile.open(base + '.asm') do |nasmfile| - Tempfile.open(base + '.o') do |elffile| - elffile.close - # Write NASM code to nsamfile - @nasmgenerator.write nasmfile - nasmfile.close - # Find out the name of the nasm executable - if ENV.has_key? 'NASM' - nasm = ENV['NASM'] - elsif ENV.has_key? 'YASM' - nasm = ENV['YASM'] - else - nasm = Voodoo::Config.nasm_command + begin + Tempfile.open(base + '.o') do |elffile| + begin + elffile.close + # Write NASM code to nsamfile + @nasmgenerator.write nasmfile + nasmfile.close + # Find out the name of the nasm executable + if ENV.has_key? 'NASM' + nasm = ENV['NASM'] + elsif ENV.has_key? 'YASM' + nasm = ENV['YASM'] + else + nasm = Voodoo::Config.nasm_command + end + # Invoke nasm on nasmfile + command = "#{nasm} #{@nasm_extra_args}" + + " -o #{shell_encode elffile.path}" + + " #{shell_encode nasmfile.path}" + if system(command) + write_file_to_io elffile.path, io + else + raise "Command (#{command}) failed " + + " with status #{$?.exitstatus}" + end + ensure + elffile.unlink + end end - # Invoke nasm on nasmfile - command = "#{nasm} #{@nasm_extra_args}" + - " -o #{shell_encode elffile.path}" + - " #{shell_encode nasmfile.path}" - if system(command) - write_file_to_io elffile.path, io - end - elffile.unlink + ensure + nasmfile.unlink end - nasmfile.unlink end end end -- 2.11.4.GIT