Author Topic: Make commands  (Read 6365 times)

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #15 on: April 11, 2016, 08:22:29 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:

Code
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:

Code
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:

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

I tried changing mine to this:

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

but it fails, with a messagebox saying:

Code
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.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Make commands
« Reply #16 on: April 11, 2016, 10:15:41 pm »
I added this
Code
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!!!
« Last Edit: April 11, 2016, 10:30:09 pm by BlueHazzard »

Offline sorinev

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: Make commands
« Reply #17 on: April 11, 2016, 10:56:29 pm »
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.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Make commands
« Reply #18 on: April 11, 2016, 11:29:24 pm »
To clear things up:
Code
RemoveLast(1)
is needed because ?git? (or ExecuteAndGetOutput?) gives a "\n" at the end and this will interfere with the gcc command
Code
_T()
is only needed if you give native strings (closured in "") to a wxWidgets function
Code
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
« Last Edit: April 11, 2016, 11:31:15 pm by BlueHazzard »