Thread overview
[Issue 8734] New: Compiler must verify exe path is writable before attempting compilation
Sep 29, 2012
Andrej Mitrovic
Sep 29, 2012
Walter Bright
Sep 29, 2012
Andrej Mitrovic
Sep 29, 2012
Walter Bright
Sep 29, 2012
Andrej Mitrovic
September 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8734

           Summary: Compiler must verify exe path is writable before
                    attempting compilation
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-09-28 18:30:07 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8734


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2012-09-28 19:21:24 PDT ---
I'm not seeing why this is an issue. Does this come up a lot for you?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8734



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-09-28 19:29:10 PDT ---
(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
{ }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8734



--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-09-28 23:29:56 PDT ---
I think it would slow things down in general.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8734


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-09-29 08:54:30 PDT ---
(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%".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------