Author Topic: How to add pre/post build steps by script in Code::Blocks? AddCommandsAfterBuild  (Read 4678 times)

Offline ololuki

  • Single posting newcomer
  • *
  • Posts: 2
I have existing project in Code::Blocks 17.12 and I would like to add command after build using script (Properties -> build scripts).
Are pre/post build steps in Code:Blocks doing same thing as AddCommandsBeforeBuild/AddCommandsAfterBuild scripting commands? How to use AddCommandsBeforeBuild and AddCommandsAfterBuild?

I tried to add post build commands to existing project using script:

Code
// My script - why it does not work?
function SetBuildOptions(base)
{
    base.AddCommandsBeforeBuild(_T("cmd /c mkdir bbb"));
    base.AddCommandsAfterBuild(_T("cmd /c mkdir ccc"));
}
but it doesn't work. If I put the following command directly to the Build options -> Pre/post build steps it works fine:
Code
cmd /c mkdir ok

Script in general also works fine, because if I put following example in script, the directory is created and compiler option is added:

Code
// My script - example of working commands
function SetBuildOptions(base)
{
    IO.Execute(_T("cmd /c mkdir aaa"));
    base.AddCompilerOption(_T("-Os"));
}
In addiction AddCompilerOption and AddCommandsAfterBuild are both defined in same base: http://wiki.codeblocks.org/index.php/Scripting_commands#CompileOptionsBase

I noticed that AddCommandsAfterBuild is used (for example) in AVR template like this:

Code
 // Template avr/wizard.script
function SetupProject(project)
{
    project.AddCommandsAfterBuild(pb_lockhex);
}
but if I put that function to my script it doesn't work.

Is it even possible to use AddCommandsAfterBuild in normal (not template) script with existing project?
« Last Edit: July 02, 2018, 05:41:15 pm by ololuki »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
What is base in the first example?
Do you see any errors in the script console?
Have you tried to execute your scripts in the script console to debug them?
Have you added some prints to debug what is going on?

AddCommandsAfterBuild is the correct function/method to call if you want to add post build commands.

There are very few APIs which work only in wizards. Most of the APIs work everywhere.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ololuki

  • Single posting newcomer
  • *
  • Posts: 2
The "base" parameter in this function is a CompileTargetBase instance. Source:http://wiki.codeblocks.org/index.php/Build_scripts

When I load sript into scripting console it only say "Script loaded successfully". There are no other errors in Scripting console nor Build log when I build project.

I never used scripting console before :-[

I typed this in console:
Code
GetProjectManager().GetActiveProject().AddCommandsBeforeBuild(_T("cmd /c mkdir abc"));
This option just permamently ads pre build step to project build options -> Pre/post build steps so I think this command is meant to be used mainly in wizard scripts.
I decided to not use script for this. I will just put my pre/post build steps directly in build options -> Pre/post build steps.

Thanks for help.

Offline Daniel.1954

  • Single posting newcomer
  • *
  • Posts: 4
EDIT: This is an English-only forum. Non-English content has been removed. Please respect the forum policies you agreed to when registering here. Thank you!
« Last Edit: October 22, 2018, 09:36:07 am by MortenMacFly »

Offline Daniel.1954

  • Single posting newcomer
  • *
  • Posts: 4
EDIT: This is an English-only forum. Non-English content has been removed. Please respect the forum policies you agreed to when registering here. Thank you!
« Last Edit: October 22, 2018, 09:36:15 am by MortenMacFly »