1
0
mirror of https://github.com/pfusik/xasm.git synced 2024-06-07 11:29:32 +00:00

Remove the object file on error.

Close #4.
This commit is contained in:
Piotr Fusik 2019-10-14 10:56:46 +02:00
parent 384643ab84
commit a0bfe1366d

View File

@ -19,6 +19,7 @@
import std.algorithm; import std.algorithm;
import std.array; import std.array;
import std.conv; import std.conv;
import std.file;
import std.math; import std.math;
import std.path; import std.path;
import std.stdio; import std.stdio;
@ -40,7 +41,7 @@ string sourceFilename = null;
bool[26] options; bool[26] options;
string[26] optionParameters; string[26] optionParameters;
string[] commandLineDefinitions = null; string[] commandLineDefinitions = null;
string makeTarget; string objectFilename = null;
string[] makeSources = null; string[] makeSources = null;
int exitCode = 0; int exitCode = 0;
@ -1084,7 +1085,7 @@ File openOutputFile(char letter, string defaultExt) {
if (filename is null) if (filename is null)
filename = sourceFilename.setExtension(defaultExt); filename = sourceFilename.setExtension(defaultExt);
if (letter == 'o') if (letter == 'o')
makeTarget = makeEscape(filename); objectFilename = filename;
try { try {
return File(filename, "wb"); return File(filename, "wb");
} catch (Exception e) { } catch (Exception e) {
@ -2963,6 +2964,10 @@ int main(string[] args) {
} catch (AssemblyError e) { } catch (AssemblyError e) {
warning(e.msg, true); warning(e.msg, true);
exitCode = 2; exitCode = 2;
if (objectStream.isOpen) {
objectStream.close();
remove(objectFilename);
}
} }
listingStream.close(); listingStream.close();
objectStream.close(); objectStream.close();
@ -2973,7 +2978,7 @@ int main(string[] args) {
writefln("%d bytes written to the object file", objectBytes); writefln("%d bytes written to the object file", objectBytes);
} }
if (getOption('m')) { if (getOption('m')) {
writef("%s:", makeTarget); writef("%s:", makeEscape(objectFilename));
foreach (filename; makeSources) foreach (filename; makeSources)
writef(" %s", makeEscape(filename)); writef(" %s", makeEscape(filename));
write("\n\txasm"); write("\n\txasm");