News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Make commands

Started by sorinev, April 06, 2016, 11:54:03 PM

Previous topic - Next topic

sorinev

Quote from: BlueHazzard on April 10, 2016, 08:48:40 PM
You can also try to use scripting: http://wiki.codeblocks.org/index.php?title=Scripting_commands
the "ExecuteAndGetOutput" command should help.
For more reading:
http://wiki.codeblocks.org/index.php/Variable_expansion#Script_expansion

greetings

Trying to get this working, but having trouble.

Previously, I had this (although I had to recompile C::B to not use the backtick cache; I've since changed it back so I can try the scripting) under the #defines tab of project compiler settings, which works:

BUILD_VERSION=\"`git describe --abbrev=5 --dirty --always --tags"`\"

Following the example in the C::B project file (I think it's under Other compiler options) I changed it to this:

BUILD_VERSION=\"[[IO.ExecuteAndGetOutput(_T("git describe --abbrev=5 --dirty --always --tags"))]]\"

But it always comes out blank. I tried adding .ToStdString().c_str(), but it complained that they were unknown or undefined or something.

So following this example from the C::B project itself:

[[if (GetCompilerFactory().GetCompilerVersionString(_T("gcc")) >= _T("4.8.0")) print(_T("-Wno-unused-local-typedefs"));]]

I tried changing mine to this:

BUILD_VERSION=\"[[print(_T(IO.ExecuteAndGetOutput(_T("git describe --abbrev=5 --dirty --always --tags"))))]]\"

but it fails, with a messagebox saying:


Filename: CommandLine
Error: Incorrect function argument
Details:


(Details were blank). So, I'm not sure how to do this since finding examples regarding the [[]] ability is turning up next to nothing. I couldn't figure how to to use the "allowInsecureScripts" constant to see if the macro was defined, and I tried grepping for the macro itself but it was nowhere to be found except in sc_io.cpp, where it's only checked. Regardless, I removed the #ifndef and recompiled C::B just to test if ExecuteAndGetOutput was returning blank because of security, but it still returns blank.

BlueHazzard

#16
I added this
TEST="[[print(IO.ExecuteAndGetOutput(_T("git --version")).RemoveLast(1))]]"
into Project->Build options->#defines

and it seems to work

greetings

[EDIT:] Corrected the code!!!! No ticks!!!

sorinev

I added the RemoveLast(1) part to my version (and removed the _T() part in print surrounding the ExecuteAndGetOutput()) and that seems to have been the issue. I never would have guessed that. Looking at the code, it seemed that it was just returning the plain result string already, but clearly not. Thanks.

BlueHazzard

#18
To clear things up:
RemoveLast(1) is needed because ?git? (or ExecuteAndGetOutput?) gives a "\n" at the end and this will interfere with the gcc command
_T() is only needed if you give native strings (closured in "") to a wxWidgets function
print is needed to transfer the string value outside the [[]] script environment

greetings

[EDIT:]
To develop this code you can use the scripting console from view->Scripting Console