Author Topic: Passing exe filename to an external tool  (Read 7742 times)

Offline vserghi

  • Multiple posting newcomer
  • *
  • Posts: 13
Passing exe filename to an external tool
« on: August 01, 2005, 06:06:54 pm »
Is there a way to pass the exe filename to an external tool?

I have a graphical version of Insite installed, and it needs the exe name passed to it for it to work from C::B. I could manually open the exe from Insite when it opens, but it would be useful to pass it the exe from C::B.

I can only see;
PROJECT_FILENAME
PROJECT_NAME
PROJECT_DIR
ACTIVE_EDITOR_FILENAME
ALL_PROJECT_FILES
MAKEFILE

and just so I'm not making a mistake; I type in "${macro name}" (no quotes) into the Parameters box, this is correct isn't it?

Vasilis.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Passing exe filename to an external tool
« Reply #1 on: August 01, 2005, 07:12:05 pm »
The six vars you stated are the only builtin ones unless I am mistaken (--> macrosmanager.cpp).
However, there is a "Custom variables" tab where you can enter whatever you want, so as a temporary workaround, you could use that.

Maybe you want to submit a feature request on the SF project site as this sure is something more people might find useful.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Passing exe filename to an external tool
« Reply #2 on: August 01, 2005, 07:46:26 pm »
Back from dinner, thinking about it again... looks quite simple, actually.
Did not compile this, but it might just work:
Code: [Select]
Index: src/sdk/macrosmanager.cpp
===================================================================
RCS file: /cvsroot/codeblocks/codeblocks/src/sdk/macrosmanager.cpp,v
retrieving revision 1.5
diff -u -r1.5 macrosmanager.cpp
--- src/sdk/macrosmanager.cpp 8 Jul 2005 09:49:04 -0000 1.5
+++ src/sdk/macrosmanager.cpp 1 Aug 2005 17:39:22 -0000
@@ -34,6 +34,7 @@
 #include "cbproject.h"
 #include "cbeditor.h"
 #include "managerproxy.h"
+#include "compiletargetbase.h"
 
 MacrosManager* MacrosManager::Get()
 {
@@ -100,6 +101,7 @@
  ${ACTIVE_EDITOR_FILENAME}
  ${ALL_PROJECT_FILES}
  ${MAKEFILE}
+ ${OUTPUT_EXECUTABLE}
 
  ${AMP} TODO: implement AddMacro() for custom macros (like this)
  */
@@ -118,7 +120,7 @@
  buffer.Replace("${PROJECT_NAME}", project->GetTitle());
  buffer.Replace("${PROJECT_DIR}", UnixFilename(project->GetBasePath()));
  buffer.Replace("${MAKEFILE}", UnixFilename(project->GetMakefile()));
-
+ buffer.Replace("${OUTPUT_EXECUTABLE}", UnixFilename(project->GetTargetType() == ttExecutable ? project->GetExecutableFilename() : ""));
  wxString files;
  for (int i = 0; i < project->GetFilesCount(); ++i)
  files << UnixFilename(project->GetFile(i)->relativeFilename) << " ";
@@ -131,6 +133,7 @@
  buffer.Replace("${PROJECT_DIR}", wxEmptyString);
  buffer.Replace("${MAKEFILE}", wxEmptyString);
  buffer.Replace("${ALL_PROJECT_FILES}", wxEmptyString);
+ buffer.Replace("${OUTPUT_EXECUTABLE}", UnixFilename(project->GetTargetType() == ttExecutable ? project->GetExecutableFilename() : ""));
  }
 
  EditorBase* editor = Manager::Get()->GetEditorManager()->GetActiveEditor();
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Passing exe filename to an external tool
« Reply #3 on: August 01, 2005, 08:22:39 pm »
Why don't you send that to the patch requests after you test it?

I had submitted a RFE for exactly this feature and forgot it after a couple of months of waiting.

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Passing exe filename to an external tool
« Reply #4 on: August 01, 2005, 09:01:11 pm »
thomas, your patch seems to restrict this to executables. Why? In some cases it might be handy to pass other output filenames to tools (to pass .dll to strip, for example).

As an added bonus, the code to get it will be shorter and simpler:
Code: [Select]
UnixFilename(project->GetOutputFilename())instead of
Code: [Select]
UnixFilename(project->GetTargetType() == ttExecutable ? project->GetExecutableFilename() : "")
If you change this, don't forget to change the macro name to something more general like $(OUTPUT_FILE).

Oh, and that last added line should probably have wxEmptyString instead of the above code fragment. Unless you like null-pointer dereferences, of course ;)

EDIT: used <> instead of [] :?
« Last Edit: August 01, 2005, 09:54:51 pm by Urxae »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Passing exe filename to an external tool
« Reply #5 on: August 01, 2005, 09:20:22 pm »
That's a valid point (although you would surely pass -s to the linker rather than call strip ;) ). But yes, you are 100% right, it is stupid to limit oneself to executables.
The wxEmptyString objection is correct, too. Should be that way.

Did you actually compile it? If so, mind making a better patch?

"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Passing exe filename to an external tool
« Reply #6 on: August 01, 2005, 09:52:58 pm »
That's a valid point (although you would surely pass -s to the linker rather than call strip ;) ).
Actually, knowing myself I'd probably open an explorer window and right click -> strip (added manually) :D.
But that's beside the point, there are probably other reasons to pass library filenames to tools. I just couldn't think of any others at the time. Still can't. Why are you all looking at me like that? :P

Quote
Did you actually compile it? If so, mind making a better patch?
Sorry, I patched it in my head. I was switching to cvs HEAD and I was bored while compiling :D.

However, continuing my trend of doing things manually, maybe this'll work:
<WARNING>Manually edited patch file, and even the original wasn't tested. This patch never touched a compiler.</WARNING>
Code: [Select]
Index: src/sdk/macrosmanager.cpp
===================================================================
RCS file: /cvsroot/codeblocks/codeblocks/src/sdk/macrosmanager.cpp,v
retrieving revision 1.5
diff -u -r1.5 macrosmanager.cpp
--- src/sdk/macrosmanager.cpp 8 Jul 2005 09:49:04 -0000 1.5
+++ src/sdk/macrosmanager.cpp 1 Aug 2005 17:39:22 -0000
@@ -34,6 +34,7 @@
#include "cbproject.h"
#include "cbeditor.h"
#include "managerproxy.h"
+#include "compiletargetbase.h"

MacrosManager* MacrosManager::Get()
{
@@ -100,6 +101,7 @@
${ACTIVE_EDITOR_FILENAME}
${ALL_PROJECT_FILES}
${MAKEFILE}
+ ${OUTPUT_FILE}

${AMP} TODO: implement AddMacro() for custom macros (like this)
*/
@@ -118,7 +120,7 @@
buffer.Replace("${PROJECT_NAME}", project->GetTitle());
buffer.Replace("${PROJECT_DIR}", UnixFilename(project->GetBasePath()));
buffer.Replace("${MAKEFILE}", UnixFilename(project->GetMakefile()));
-
+ buffer.Replace("${OUTPUT_FILE}", UnixFilename(project->GetOutputFilename()));
wxString files;
for (int i = 0; i < project->GetFilesCount(); ++i)
files << UnixFilename(project->GetFile(i)->relativeFilename) << " ";
@@ -131,6 +133,7 @@
buffer.Replace("${PROJECT_DIR}", wxEmptyString);
buffer.Replace("${MAKEFILE}", wxEmptyString);
buffer.Replace("${ALL_PROJECT_FILES}", wxEmptyString);
+ buffer.Replace("${OUTPUT_FILE}", wxEmptyString);
}

EditorBase* editor = Manager::Get()->GetEditorManager()->GetActiveEditor();

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Passing exe filename to an external tool
« Reply #7 on: August 15, 2005, 04:59:06 pm »
Getting back to an old subject...

I felt like actually compiling this today. The attached patch introduces two new macro names, OUTPUT_FILE, and OUTPUT_DIR.

It does compile fine, but it seems to me that no macro substitution is actually done? Not only regarding the new ones, but in general? That is also true for the non-modified RC1-1 executable.

Entering
Code: [Select]
echo projectdir ${PROJECT_DIR} ${PROJECT_FILENAME}
echo outputfile ${OUTPUT_FILE}
echo outputdir ${OUTPUT_DIR}
into Pre-build steps gives this output for me:
Code: [Select]
Project   : Code::Blocks (wx2.6)
Compiler  : GNU GCC Compiler (called directly)
Directory : D:\checkout\head\codeblocks\src\
--------------------------------------------------------------------------------
echo projectdir ${PROJECT_DIR} ${PROJECT_FILENAME}
projectdir
echo outputfile ${OUTPUT_FILE}
outputfile
echo outputdir ${OUTPUT_DIR}
outputdir

Also, I noticed that while these macros have the syntax ${NAME}, the ones used during compilation have the syntax $(NAME). Is that intentional?


EDIT:  Aaaah, bad attachment, sorry. This one should be it.
EDIT 2: Seems like someone here is too stupid to attach the correct file? Here goes...
Please ignore the first two of them, they contain "+++" and "???" strings which I inserted to see if anything was being replaced at all (could have been that only project->GetOutputFilename() returns an empty string).
Maybe I'll get some sleep now...

[attachment deleted by admin]
« Last Edit: August 15, 2005, 05:06:31 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Passing exe filename to an external tool
« Reply #8 on: August 15, 2005, 05:11:36 pm »
Also, I noticed that while these macros have the syntax ${NAME}, the ones used during compilation have the syntax $(NAME). Is that intentional?

You could try it with ${NAME}, see if that works.
IIRC it shouldn't matter: both should do the exact same thing. If they don't, you might want to file a bug report. And If I didn't Recall Correctly, make that a feature request ;).

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Passing exe filename to an external tool
« Reply #9 on: August 15, 2005, 05:33:31 pm »
You could try it with ${NAME}, see if that works.
Did certainly, neither works.

This little modification:
Code: [Select]
Manager::Get()->GetMessageManager()->Log("### ReplaceMacros called");
    SANITY_CHECK();
Manager::Get()->GetMessageManager()->Log("### past sanity check");
if (buffer.IsEmpty())
return;
Manager::Get()->GetMessageManager()->Log("### buffer not empty");

if (envVarsToo)
        ReplaceEnvVars(buffer);

buffer.Replace("${AMP}", "&");

cbProject* project = Manager::Get()->GetProjectManager()->GetActiveProject();
if (project)
{
Manager::Get()->GetMessageManager()->Log("### if branch");
wxFileName fname(project->GetFilename());
buffer.Replace("${PROJECT_FILENAME}", UnixFilename(fname.GetFullName()));
buffer.Replace("${PROJECT_NAME}", project->GetTitle());
buffer.Replace("${PROJECT_DIR}", UnixFilename(project->GetBasePath()));
buffer.Replace("${MAKEFILE}", UnixFilename(project->GetMakefile()));
buffer.Replace("${OUTPUT_FILE}", UnixFilename(project->GetOutputFilename())+"+++");
buffer.Replace("${OUTPUT_DIR}", UnixFilename(wxFileName(project->GetOutputFilename()).GetPath(wxPATH_GET_VOLUME)));

wxString files;
for (int i = 0; i < project->GetFilesCount(); ++i)
files << UnixFilename(project->GetFile(i)->relativeFilename) << " ";
buffer.Replace("${ALL_PROJECT_FILES}", files);
}
else
{
Manager::Get()->GetMessageManager()->Log("### else branch");
Produces exactly no log output.
So I believe it is pretty certain that the function is never really called. Will submit a bug report.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Passing exe filename to an external tool
« Reply #10 on: September 01, 2005, 12:11:50 pm »
I 've fixed these issues in CVS.
All vars used (built-ins and environment) can be used in any of the following ways:

$NAME
$(NAME)
${NAME}
%NAME%

Also added <TARGET_TITLE>_OUTPUT_FILE and <TARGET_TITLE>_OUTPUT_DIR builtins.
Notice that TARGET_TITLE must be in upper-case.
Be patient!
This bug will be fixed soon...