Author Topic: Script hooks added to build system  (Read 18075 times)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Script hooks added to build system
« on: January 21, 2006, 09:01:22 pm »
It's true. Finally AngelScript will be used for something in C::B :)
Here's a little overview of the new feature.

You can attach one or more scripts to the project and/or any build targets. These scripts will be run in order just before the project/target (depending where the script is attached) gets built. Therefore it is obvious that using these scripts you can actually setup the whole build process.
Build hook scripts provide two functions:
Code
void SetBuildOptions(CompileOptionsBase@ base);
void UnsetBuildOptions(CompileOptionsBase@ base)
Don't get confused by AngelsScript's handle symbol @. If you don't know what it is, ignore it :). It's just used for reference counting.

SetBuildOptions() runs before the project/target is built, while UnsetBuildOptions() runs after the project/target has been built. The latter allows us to undo the changes SetBuildOptions() has made :).

Here's a sample script that enables debugging symbols for GCC:

Code: cpp
// Debug configuration

void SetBuildOptions(CompileOptionsBase@ base)
{
    // remember state
    bool wasModified = base.GetModified();

    // compiler settings
    base.AddCompilerOption("-O0");
    base.AddCompilerOption("-ggdb");

    // restore state
    base.SetModified(wasModified);
}

void UnsetBuildOptions(CompileOptionsBase@ base)
{
    // remember state
    bool wasModified = base.GetModified();

    // compiler settings
    base.RemoveCompilerOption("-O0");
    base.RemoveCompilerOption("-ggdb");

    // restore state
    base.SetModified(wasModified);
}

You would attach this script to any target that would produce a "Debug" output.
Simple stuff :)
By the way, CompileOptionsBase is a base class in C::B and the script supports it so look at sdk/compileoptionsbase.h to see what other methods you can use.

Why is this feature handy (to say the least)?
Because you do not need to setup anything in "Project->Build options". You can setup the whole project by just attaching scripts to the project/targets.
Also, because scripts are regular files, you can just copy/paste them to use them in other projects. Initial setup time becomes almost 0 :), since you don't have to fiddle with all the options in "Project->Build options". Just copy some scripts from another project, attach them to your project/targets and build :).

Finally, I 've attached a sample wxWidgets project that uses build scripts so you can immediately see it in action (Project->Properties->Scripts).
Keep in mind that you will need revision 1825 for this to work.

I will be waiting for feedback ;).

[attachment deleted by admin]
Be patient!
This bug will be fixed soon...

takeshimiya

  • Guest
Re: Script hooks added to build system
« Reply #1 on: January 21, 2006, 10:47:55 pm »
<- :o :o Amazing! I've thinking something like that for a long time. If C::B was powerful, now it's more! :D

I'll try it when I conclude something on another build system I'm trying.

PS: Yiannis, can you update AngelScript to 2.5.0 (latest stable), so I can diff the patch to fix 64 bits compilation?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #2 on: January 21, 2006, 10:58:33 pm »
PS: Yiannis, can you update AngelScript to 2.5.0 (latest stable), so I can diff the patch to fix 64 bits compilation?

Sure, I already planned to. I will do it tomorrow.
Be patient!
This bug will be fixed soon...

Offline duncanka

  • Multiple posting newcomer
  • *
  • Posts: 53
Re: Script hooks added to build system
« Reply #3 on: January 22, 2006, 03:21:10 am »
I haven't yet played around with this feature (don't have the build yet), but I have 2 questions about its usage:
1. Doesn't this risk a CB project version of DLL hell, with build settings located in far-flung files unlinked to the project?  Should there be some sort of management system to prevent you from going crazy trying to figure out where in your build process the build options you've set are being altered?
2. Might it be possible to set up a special dialog to create a build options dialog specifically for generating scripts?  Like, instead of clicking "OK" on the dialog to set the options for the project, you would click "Generate script" and it would save the settings you entered as a script?
Anyway, kudos on a really cool feature! :D
« Last Edit: January 22, 2006, 03:22:55 am by duncanka »

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Script hooks added to build system
« Reply #4 on: January 22, 2006, 05:30:20 am »
Uk not understand scripting hooks... Uk thinks spooky magic. Uk stays away :lol:

(Translation: Can somebody explain a little further please? :) thanks! )

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #5 on: January 22, 2006, 08:18:06 am »
I haven't yet played around with this feature (don't have the build yet), but I have 2 questions about its usage:
<snip>
Anyway, kudos on a really cool feature! :D

When you go into "Project->Build options" a nice red message is displayed that your project is using build scripts so any options you set there might be overriden (depending on the scripts).

Uk not understand scripting hooks... Uk thinks spooky magic. Uk stays away :lol:
(Translation: Can somebody explain a little further please? :) thanks! )

Open the attached project and go to "Project->Properties". Then open a script to see how it looks. Then go to "Settings->Compiler->Other" and enable full logging to see the command-linw when building.
Everything will suddenly make sense ;)
Be patient!
This bug will be fixed soon...

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #6 on: January 22, 2006, 11:04:10 am »
To further explain why it is a really cool feature, read along.

Using build scripts, you can group compiler/linker options into logical units. For example, "optimizations turned on" might mean "-O3 -s" in the compiler and the linker options.
Or for a more complex example, "my app uses unicode wxWidgets" mean pass "-D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -mthreads" as compiler options, add "$(WX)\include" etc in compiler search paths, add similar paths to the linker, etc.
Build scripts allow you to "define" such groups of options. If you look at the sample project I attached, there is a wx*.script which does what I just said.

Now, if I want to create a new wxWidgets-based app all I have to do is copy the script to the new app's folder, attach it to the project and hit "Build" :). See? No fiddling with all kinds of different settings in "Project->Build options". Instant project setup.
Not to mention the fact that the script may use custom variables and global variables ;).

Note however that using build scripts has not rendered "Project->Build options" obsolete. You can still use both. The scripts in the sample app set/unset specific options, they do not override the current build settings (although they could). So for example, I was able to set the "Warnings" compiler flag in the build options (as a project-wide setting) and not in the scripts.

Hope this makes more clear why build hook scripts are the best thing since sliced bread ;) :P.
Be patient!
This bug will be fixed soon...

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #7 on: January 22, 2006, 11:13:07 am »
PS: Yiannis, can you update AngelScript to 2.5.0 (latest stable), so I can diff the patch to fix 64 bits compilation?

Updated in r1828.
Be patient!
This bug will be fixed soon...

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Script hooks added to build system
« Reply #8 on: January 22, 2006, 06:16:44 pm »
So I just want to get the order of precendence right.  If have turned on debug(-g) turned on in the project build settings but one of my build scripts for a target turns this off do I have still have the debug for that target.?  Also can scripts add new options to the build options dialog? Or when you say "optimizations turned on" are you speeking of haveing a script called "optimizations turned on" attached to a target.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #9 on: January 22, 2006, 06:28:39 pm »
Quote
So I just want to get the order of precendence right.

Scripts are executed before the build options are evaluated.
This means the script might alter the build options in any way imaginable.

Quote
If have turned on debug(-g) turned on in the project build settings but one of my build scripts for a target turns this off do I have still have the debug for that target.?

Project build options are not inherited by targets but rather added to them. So, if a project build option is unset and the target does not specifically sets it, then it's unset for the target too.

Quote
Also can scripts add new options to the build options dialog?

No.

Quote
Or when you say "optimizations turned on" are you speeking of haveing a script called "optimizations turned on" attached to a target.

Exactly.

Basically, if you start using scripts, you would only use "Project->Build options" for simple project-wide options (like enable warnings, set the target CPU, etc).
Be patient!
This bug will be fixed soon...

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: Script hooks added to build system
« Reply #10 on: January 22, 2006, 06:32:38 pm »
But remember, it can set options that aren't in the build dialog. You won't see them, but they'll get passed to the compiler. :)
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Scripts = Solution to Cross Platform Projects
« Reply #11 on: January 22, 2006, 07:08:25 pm »
Ok, we have a wxWidgets build script call it, wxGTK_MSW_Unicode.  This script has in it all the needed settings and for both wxMSW and wxGTK projects, but at compile it checks a codeblocks function that returns the current platform and applies only the proper set.  This would allow you to have a single project for multiple platforms.  From what I have seen here this is entirely possible at that you need is to have that function in a Code::Blocks API accessible by the scripts.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #12 on: January 22, 2006, 07:20:48 pm »
But remember, it can set options that aren't in the build dialog. You won't see them, but they'll get passed to the compiler. :)

As a matter of fact, It can set any option your compiler supports.

From what I have seen here this is entirely possible at that you need is to have that function in a Code::Blocks API accessible by the scripts.

Right and I was going to add it today but I 've been busy with the general preferences dialog revamping.
The point is that, yes, these scripts will be able to detect the platform. They 're scripts after all, so they can employ logic ;)
Be patient!
This bug will be fixed soon...

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: Script hooks added to build system
« Reply #13 on: January 22, 2006, 07:28:25 pm »
Does this mean removal of two project files for codeblocks?

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Script hooks added to build system
« Reply #14 on: January 22, 2006, 08:16:43 pm »
Does this mean removal of two project files for codeblocks?

Yes, if we switch to scripts for building C::B ;)
I will create such a build tomorrow and see how it works out and if it is worth to change it (I believe so).
Be patient!
This bug will be fixed soon...