Bug 8734 – Compiler must verify exe path is writable before attempting compilation
Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-28T18:30:00Z
Last change time
2015-06-09T05:15:07Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2012-09-28T18:30:07Z
Windows example:
test1.d:
module test;
import std.stdio;
import std.process;
void main()
{
system("echo > test.exe");
auto file = File("test.exe", "r");
system("dmd test2.d -oftest.exe");
}
test2.d:
module test2;
import std.string;
string mixMe()
{
string res;
foreach (i; 0 .. 3_000)
res ~= xformat("int i_%s;", i);
return res;
}
mixin(mixMe());
void main()
{
}
$ rdmd test1.d
OPTLINK (R) for Win32 Release 8.00.12
Copyright (C) Digital Mars 1989-2010 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
OPTLINK : Error 3: Cannot Create File test.exe
--- errorlevel 1
test2.d demonstrates a module that takes a longer while to compile. test1.d creates a phony test.exe, then opens it in read-mode to lock it. Then it attempts to compile test2.d and write over test.exe.
DMD will first compile test2.d and only then attempt to write to test.exe and fail. This can be a considerate waste of time, the compiler should check if the output location is writable *before* attempting to compile.
Comment #1 by bugzilla — 2012-09-28T19:21:24Z
I'm not seeing why this is an issue. Does this come up a lot for you?
Comment #2 by andrej.mitrovich — 2012-09-28T19:29:10Z
(In reply to comment #1)
> I'm not seeing why this is an issue. Does this come up a lot for you?
It takes about half a minute to build one of my projects but I forgot to close down the previously compiled application when doing so, so I've had to recompile again.
This could be integrated into a build system, or even RDMD, but I thought it would be nice to put the check directly into DMD.
If you believe the check would slow things down then I guess we can live without the feature. It could be implemented as a simple system() call, e.g. pseudocode:
if (system("echo > main.exe") == -1) // error, couldn't overwrite file
{ }
Comment #3 by bugzilla — 2012-09-28T23:29:56Z
I think it would slow things down in general.
Comment #4 by andrej.mitrovich — 2012-09-29T08:54:30Z
(In reply to comment #3)
> I think it would slow things down in general.
Ok I'm closing it. Anyway here's a win32 batch workaround:
@echo off
set "exePath=test.exe"
echo x > %exePath% || goto :ERROR
goto :EOF
:ERROR
echo Can't write to "%exePath%".