Author Topic: Global addition of build options (in this case search directories), in Squirrel!  (Read 9826 times)

Offline xod

  • Single posting newcomer
  • *
  • Posts: 7
*EDIT* Misplaced post. Kindly move to the plugin devel forum, thanks! */EDIT*

Hello there! After unsuccessfully trying the IRC channel yesterday, I decided to register and try my luck here in the forum.

I have created a script that provides a menu entry, and when clicked..

..it does..
1) Execute a 'cmd.exe' script that iterates over a preselected (by me) folder's contained folders, detects whether they have either/both of 'include' and 'lib' folders, and ouputs the full path to those detected folders.

..and is supposed to also do..
2) Add those paths (output by 'cmd.exe') to the global compiler and linker search paths.

Question is how to do that, if possible ? I have trial-and-error tested (not completely sure whether it is supposed to be method or static function):

* CompileOptionsBase().AddIncludeDir(PATH);
* CompileOptionsBase.AddIncludeDir(PATH);

which do nothing and are silently ignored. Maybe the class/object is initialized at build-time ?!
I have also tried (for starters):

* GetCompilerFactory().GetCompilerByName(_T("GNU GCC Compiler"));

which fails, saying the index 'GetCompilerByName' doesn't exist. I have not evaluated ConfigManager yet, largely because I don't know what actual arguments are expected. I'd be grateful for any solutions to my problem.
« Last Edit: August 14, 2016, 01:55:24 pm by xod »

Offline gamemusta

  • Single posting newcomer
  • *
  • Posts: 5
Are you familiar with Squirrel syntax in respect to Code::Blocks? You should maybe study this: http://wiki.codeblocks.org/index.php/Scripting_commands. I suggest getting the compiler by ID instead. Not much I can do without first seeing your actual attempt though. Maybe post the script file contents?

Offline xod

  • Single posting newcomer
  • *
  • Posts: 7
Thank you for replying, much appreciated. I'm not too familiar with Squirrel, that's true, but my knowledge is not a showstopper as far as the test script goes.

Here's the script. I've stripped it down so it tries to add an 'include' search path directly instead of using 'cmd.exe'. Better for the purpose of illustration:

Code
// not called: clearly needs to be executed as build script
function SetBuildOptions(baseOptions)
{
Log(_T("***** [xod] SetBuildOptions() *****"));
}



// called
function OnMenuClick()
{
// nothing happens
CompileOptionsBase().AddIncludeDir(_T("E:\\applications\\__inpath__\\allegro\\include"));
CompileOptionsBase.AddIncludeDir(_T("E:\\applications\\__inpath__\\allegro\\include"));
}



Log(_T("***** xod - begin *****"));

local scriptManager = GetScriptingManager();
scriptManager.RegisterScriptMenu(_T("Settings/[xod] Add __inpath__ SDK paths"), _T("OnMenuClick"), true); // ok

local compilerFactory = GetCompilerFactory();
Log(_T("Number of compilers: " + compilerFactory.GetCompilersCount())); // index 'GetCompilersCount' not found
local gcc = compilerFactory.GetCompilerByName(_T("GNU GCC Compiler")); // same here, would this line execute

Log(_T("***** xod - end *****"));

I had hoped that a startup script could register (or merely define) callbacks for events relating to the various stages of C::B's build progress, and provide contextual interfaces obviously. I much prefer my scripts to not be attached per project manually and instead be global and start on C::B's startup. Is that possible ?

*EDIT*

Like you wrote, I should have used GetCompilerIDByName(). Problem is though that the apparent CompilerFactory API exposed to scripts merely returns wsStrings, bools, and ints. No objects. I suppose I looked in the C++ 'SDK documentation' and presumed the (full) C++ CompilerFactory API be exposed to scripts too.

*EDIT 2*

I have made a script plugin as well, but no new API under the sun there as far as I can tell; I didn't find any doc on cbScriptPlugin..
« Last Edit: August 14, 2016, 10:40:43 pm by xod »

Offline gamemusta

  • Single posting newcomer
  • *
  • Posts: 5
Code::Blocks ships with an example plugin and such as far as I know. Get to reading bro:

http://wiki.codeblocks.org/index.php/Scripting_commands

Are you sure you searched on the topic of script Plugins?

http://wiki.codeblocks.org/index.php/Script_plugins
http://wiki.codeblocks.org/index.php/Category:Scripting_Code::Blocks

Quote
Code
// nothing happens
CompileOptionsBase().AddIncludeDir(_T("E:\\applications\\__inpath__\\allegro\\include"));
CompileOptionsBase.AddIncludeDir(_T("E:\\applications\\__inpath__\\allegro\\include"));

By the way, using CompileOptionsBase() by itself will net you null (pun intended) since it's just a base. GetProjectManager().GetActiveProject().GetCurrentlyCompilingTarget().AddIncludeDir(<dir>) or GetProjectManager().GetActiveProject().GetbuildTargets() which fields a wxArrayString for an an index or identifier to a specific target which can be obtained with GetProjectManager().GetActiveProject().GetbuildTarget(<identifier>) and used with GetProjectManager().GetActiveProject().GetbuildTarget(<identifier>).AddIncludeDir(<dir>), are your best bet.

Quote
Code
Log(_T("Number of compilers: " + compilerFactory.GetCompilersCount())); // index 'GetCompilersCount' not found

GetCompilersCount? no. Check the first link for valid commands. GetDefaultCompilerID() yields "gcc", for example. GetCompilerIDByName(), not GetCompilerByName(), is for when you're looking for a specific compiler you know the exact name of. You also might wanna brush up on your Squirrel bud, just in case:

http://www.squirrel-lang.org/doc/squirrel3.html
« Last Edit: August 15, 2016, 03:21:03 am by gamemusta »

Offline xod

  • Single posting newcomer
  • *
  • Posts: 7
Code::Blocks ships with an example plugin and such as far as I know. Get to reading bro:

http://wiki.codeblocks.org/index.php/Scripting_commands

Are you sure you searched on the topic of script Plugins?

http://wiki.codeblocks.org/index.php/Script_plugins
http://wiki.codeblocks.org/index.php/Category:Scripting_Code::Blocks

I believe I did write that I wrote a script plugin as well. Yes the Script_Plugin page has "some" documentation, but I assumed there were more functions involved than those in that page.

Quote
Quote
Code
// nothing happens
CompileOptionsBase().AddIncludeDir(_T("E:\\applications\\__inpath__\\allegro\\include"));
CompileOptionsBase.AddIncludeDir(_T("E:\\applications\\__inpath__\\allegro\\include"));

By the way, using CompileOptionsBase() by itself will net you null (pun intended) since it's just a base. GetProjectManager().GetActiveProject().GetCurrentlyCompilingTarget().AddIncludeDir(<dir>) or GetProjectManager().GetActiveProject().GetbuildTargets() which fields a wxArrayString for an an index or identifier to a specific target which can be obtained with GetProjectManager().GetActiveProject().GetbuildTarget(<identifier>) and used with GetProjectManager().GetActiveProject().GetbuildTarget(<identifier>).AddIncludeDir(<dir>), are your best bet.

Thanks for the explanation. However, I want to add search paths (include and lib folders) globally, across projects. Or in other words, I want to configure global compiler/linker options. C::B has global search path settings, but question is if we can programmatically configure. If ConfigManager is the way, I guess I have to see some script/snippet/tutorial around that.

Quote
Quote
Code
Log(_T("Number of compilers: " + compilerFactory.GetCompilersCount())); // index 'GetCompilersCount' not found

GetCompilersCount? no. Check the first link for valid commands. GetDefaultCompilerID() yields "gcc", for example. GetCompilerIDByName(), not GetCompilerByName(), is for when you're looking for a specific compiler you know the exact name of. You also might wanna brush up on your Squirrel bud, just in case:

http://www.squirrel-lang.org/doc/squirrel3.html

Those were for testing/illustration purpose, to illustrate that the (C++) CompilerFactory API is not fully exposed to squirrel. I know the Scripting_commands page only shows what's actually exposed to squirrel, but it was just a curious test and a big question mark I suppose. And no, mastering squirrel is no interest of mine, not as long as I'm unsure of whether the API allows me to programmatically configure the global (not per-project) compiler options or not. Looks like the Compiler object returned by some of the CompilerManager functions would do the job, but unfortunately those functions aren't exposed to squirrel.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
I don't know if it is possible, but generally it is not a good idea to add paths there.
Can you explain why you want to change them with a script?
The idea of the scripting engine is to make configuring projects easier - for example you can make a script plugin that registers a menu which modifies all projects in the workspace when invoked.
(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 xod

  • Single posting newcomer
  • *
  • Posts: 7
Thanks for replying.

I understand that. The reason that I keep SDKs isolated in separate folders is because I can manage them much easier this way. Far from always do the file names contain common affixes. So that allows me to easily make propder association of files. And this leads to why I want to have a script doing this for me. As I keep installing/updating/uninstalling of SDKs, it would be (and has been) a pain in the butt to keep configuring the IDE manually. I intend to do more scripts for automation, where that is possible. I suppose I have to do it on project level for now. It would be more than nice though to have the full CompilerManager API available for squirrel.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7790
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline xod

  • Single posting newcomer
  • *
  • Posts: 7
Learn about CB Global vars. http://wiki.codeblocks.org/index.php/Global_compiler_variables

Thanks for that. I knew about them, but it seems that I cannot programmatically access (add/modify) global variables either. That is needed for many types of automation scripts.

ConfigManager has only the Read() and Write() functions exposed, so I'm assuming they access only 'default.conf' ? Or is the (C++) 'SetPath()' function setting the path for the node in the XML (default.conf) for Read()/Write() ? If not the latter, what is the format of the key/name parameter to those functions in order to access a node with correct path ?
I have tried things like: "app.version", "app.version.str", "app/version", "/app/version", "app/version/str", "/app/version/str" as parameter to Read(). Read(_T(KEY), _T("undefined")) returns "undefined". Any help would be appreciated. Else, I'd have no choice but to reluctantly dig in the source code, which I cannot do right now.
« Last Edit: August 16, 2016, 01:21:26 pm by xod »

Offline xod

  • Single posting newcomer
  • *
  • Posts: 7
Apparently the ConfigManager Squirrel-exposed API (only exposing Read() and Write()) provides isolated/sandboxed 'default.conf' root node :|

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Thanks for that. I knew about them, but it seems that I cannot programmatically access (add/modify) global variables either. That is needed for many types of automation scripts.

Can you add a feature request on the source forge page for this? I would like to implement it, but have no working machine at the moment, and i will forget this if it is not fixed somewhere...

thanks, greetings

Offline xod

  • Single posting newcomer
  • *
  • Posts: 7
Can you add a feature request on the source forge page for this? I would like to implement it, but have no working machine at the moment, and i will forget this if it is not fixed somewhere...

thanks, greetings

I don't have time for the moment, but if my interest doesn't fade within next x weeks, I might do as you request. Thanks for your (previous) feedback.