D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8734 - Compiler must verify exe path is writable before attempting compilation
Summary: Compiler must verify exe path is writable before attempting compilation
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-28 18:30 UTC by Andrej Mitrovic
Modified: 2015-06-09 05:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-09-28 18:30:07 UTC
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 Walter Bright 2012-09-28 19:21:24 UTC
I'm not seeing why this is an issue. Does this come up a lot for you?
Comment 2 Andrej Mitrovic 2012-09-28 19:29:10 UTC
(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 Walter Bright 2012-09-28 23:29:56 UTC
I think it would slow things down in general.
Comment 4 Andrej Mitrovic 2012-09-29 08:54:30 UTC
(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%".