Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Deleting the static library before generating it?

<< < (3/4) > >>

oBFusCATed:
Because the delete command won't be executed just before the ar command, probably.
But does the direct commands support executing two commands put in a single command and separated by \n?
On *nix you can use &&, maybe.

Alpha:

--- Quote from: MortenMacFly on September 29, 2012, 05:39:00 am ---Why don't you simply use wxRemoveFile?

--- End quote ---

--- Quote from: oBFusCATed on September 29, 2012, 09:31:01 am ---Because the delete command won't be executed just before the ar command, probably.

--- End quote ---
Yes; so, for example, if the build is aborted, the previous library will not have been prematurely deleted.


--- Quote from: oBFusCATed on September 29, 2012, 09:31:01 am ---But does the direct commands support executing two commands put in a single command and separated by \n?

--- End quote ---
Yes; directcommands.cpp line 79:

--- Code: ---void DirectCommands::AddCommandsToArray(const wxString& cmds, wxArrayString& array, bool isWaitCmd, bool isLinkCmd)
{
    wxString cmd = cmds;
    while (!cmd.IsEmpty())
    {
        int idx = cmd.Find(_T("\n"));
        wxString cmdpart = idx != -1 ? cmd.Left(idx) : cmd;
        cmdpart.Trim(false);
        cmdpart.Trim(true);
        if (!cmdpart.IsEmpty())
        {
            if (isWaitCmd)
                array.Add(wxString(COMPILER_WAIT));
            if (isLinkCmd)
                array.Add(wxString(COMPILER_WAIT_LINK));
            array.Add(cmdpart);
        }
        if (idx == -1)
            break;
        cmd.Remove(0, idx + 1);
    }
}

--- End code ---

MortenMacFly:

--- Quote from: Alpha on September 30, 2012, 12:13:08 am ---Yes; so, for example, if the build is aborted, the previous library will not have been prematurely deleted.

--- End quote ---
OK -but in that casw we should check if:
- it works on Mac, too
- the deletion succeeded (i.e. the file is not restricted in its access)
- the commands used with their parametrisation are available on all target platforms

Alpha:
Well, Mac says it will work, but I do not have access to a Mac to test it.
Using -f on non-Windows will prevent from waiting for a prompt if it failed.  Also, I believe this is the correct way to only try to delete if the file exists.

--- Code: ---Index: src/plugins/compilergcc/directcommands.cpp
===================================================================
--- src/plugins/compilergcc/directcommands.cpp (revision 8428)
+++ src/plugins/compilergcc/directcommands.cpp (working copy)
@@ -733,6 +733,13 @@
         break;
     }
     wxString compilerCmd = compiler->GetCommand(ct);
+    if (ct == ctLinkStaticCmd) // static libraries should be deleted before recreation
+    {
+        if (platform::windows)
+            compilerCmd.Prepend(wxT("cmd /c if exist $static_output del $static_output\n"));
+        else
+            compilerCmd.Prepend(wxT("if [ -f $static_output ]; then rm -f $static_output; fi\n"));
+    }
     compiler->GenerateCommandLine(compilerCmd,
                                   target,
                                   0,

--- End code ---

Alpha:
Alternatively,

--- Code: ---if [ -w $static_output ]; then rm -f $static_output; fi

--- End code ---
could be used to only try to delete if write access is available on the file (under non-Windows).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version