Hi,
Before every builds and for every projects, I have create this script to set my envars without to use that: VAR1 = [[parse cfg, get keyvalue return value]]
local deps_config_filename = _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
print("groupName " + i + ": " + groupName);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
for(local k = 0; k < keyvalue.GetCount(); k++)
{
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
// $(key) = value;
print("key: " + key + " value: " + value));
}
}
}
}
But I don't know how to set the value.
$(key) = value;
Can you help me ?
:o
If i copy past the script into:
Project build options > Pre/post build steps:
I have this error:
Running project pre-build steps
local deps_config_filename = _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
/bin/sh: 1: Syntax error: "(" unexpected
Process terminated with status 2 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
If attach the script from the Project/target > Build Scripts
I have this error:
AN ERROR HAS OCCURED [assertion failed]
CALLSTACK
*FUNCTION [main()] /home/gandi/Working/Ma/code/API//src/LoadConfig.script line [4]
LOCALS
[config_exist] false
[deps_config_filename] INSTANCE
[this] TABLE
The relative path doesn't work (but it's work from the scriping console)
I have to fix it and will say you if it's work or not.
Thank you for you answer.
With this attached script it doesn't work (Project/target > Build Scripts):
// http://wiki.codeblocks.org/index.php/Build_scripts
function SetBuildOptions(base)
{
local deps_config_filename = ::ReplaceMacros(_T("$(PROJECT_DIR)"));
deps_config_filename += _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
//print("groupName " + i + ": " + groupName);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
// $(key) = value;
print(key + "=" + value +"\n");
}
}
}
}
I have try to use SetCommandsBeforeBuild. But nothing happen. The echo command send to the CommandsBeforeBuild doesn't appear/works.
function SetBuildOptions(base)
{
local deps_config_filename = ::ReplaceMacros(_T("$(PROJECT_DIR)"));
deps_config_filename += _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
local commands = wxArrayString();
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
//print("groupName " + i + ": " + groupName);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
// $(key) = value;
commands.Add(key + _T("=\"") + value + _T("\""), 1);
commands.Add(_T("echo $(") + key + _T(")"), 1);
//print(key + "=" + value +"\n");
}
}
for(local i = 0; i < commands.GetCount(); i++)
{
print(commands.Item(i));
}
base.SetCommandsBeforeBuild(commands);
}
}
Oo thank you BuelHazzard…Really.
Here you have the git project:
https://framagit.org/Suryavarman/ma/
Here the codeblocks workspace ( i don't like how cmake generate CB project. i prefer to use CB without makefile and with a Workspace)
https://framagit.org/Suryavarman/ma/
Here one of the three projects:
https://framagit.org/Suryavarman/ma/blob/master/code/API/API.cbp
Here the bash script to create the dependencies.cfg and to build some dependencies.
https://framagit.org/Suryavarman/ma/blob/master/dependencies/install_dependencies.sh
Here some config files exemples:
https://framagit.org/Suryavarman/ma/blob/master/dependencies/dependencies_kubuntu18.04.cfg
https://framagit.org/Suryavarman/ma/blob/master/dependencies/dependencies_mageia6.cfg
Here the squirrel scripts to be place into the:
- «Project/target > Build Scripts»:
https://framagit.org/Suryavarman/ma/blob/master/code/API/src/LoadConfig.script
- «project pre-build steps»:
https://framagit.org/Suryavarman/ma/blob/master/code/API/src/LoadConfigPreBuild.script
Here an output example from LoadConfigPostBuild.script :
MA_PYTHON_PATH="/usr/bin/python3.7m"
MA_PYTHONENV_PATH="/home/blabla/Ma/dependencies/venv-test"
MA_PYTHONENV_SP_PATH="/home/blabla/Ma/dependencies/venv-test/lib64/python3.7/site-packages"
MA_PYTHONENV_INCLUDE_PATH="/home/blabla/Ma/dependencies/venv-test/include/python3.7m"
MA_WXPYTHON_PATH="/home/blabla/Ma/dependencies/wxPython"
MA_WX_MINOR_VERSION="0"
MA_WX_SO_SUFFIX=".so.0"
MA_CPPCLAY_PATH="/home/blabla/Ma/dependencies/CppClay/CppClay"
MA_CPPCLAYDLL_PATH="/home/blabla/Ma/dependencies/CppClay/CppClay/src/clay"
MA_PYBIND11_PATH="/home/blabla/Ma/dependencies/pybind11"
MA_OGRE_INCLUDE_PATH="/usr/include/OGRE"
MA_LINUX_GTK3_INCLUDE_PATH="/usr/include/gtk-3.0"
MA_LINUX_GLIB_INCLUDE_PATH="/usr/include/glib-2.0"
MA_LINUX_GLIBCONFIG_INCLUDE_PATH="/usr/lib64/glib-2.0/include"
MA_LINUX_PANGO_INCLUDE_PATH="/usr/include/pango-1.0"
MA_LINUX_CAIRO_INCLUDE_PATH="/usr/include/cairo"
MA_LINUX_GDKPIXBUF_INCLUDE_PATH="/usr/include/gdk-pixbuf-2.0"
MA_LINUX_ATK_INCLUDE_PATH="/usr/include/atk-1.0"
Ok, i found the function to set environment variables and a quick test worked. I did not test your project, but please report if it works for you!
the syntax is
EnvvarApply(wxString vraname, wxString value)
this worked for me on windows in the prebuild steps:
[[EnvvarApply(_("test"), _("theValueOfTest"));]]
echo %test%
There are other functions, provided by envar plugin:
wxArrayString EnvvarGetEnvvarSetNames()
wxArrayString EnvvarGetActiveSetName()
wxArrayString EnvVarGetEnvvarsBySetPath(wxString path)
bool EnvvarSetExists(wxString path)
EnvvarSetApply(wxString setName, bool evenIfActive)
EnvvarSetDiscard(wxString setName)
EnvvarApply(wxString key, wxString value)
EnvvarDiscard(wxString key)
Thats so great, it's Works :)
8)
Here my code to load a config file: class Dependencies
{
constructor()
{
local deps_config_filename = ::ReplaceMacros(_T("$(PROJECT_DIR)"));
deps_config_filename += _T("./../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
local commands = wxArrayString();
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
key_paths.rawset(key, value);
EnvvarApply(key, value);
}
}
}
}
key_paths = {};
}
function SetBuildOptions(base)
{
local deps = Dependencies();
}
I take advantage of the opportunity to ask if codeblocks have plane to:
1 - make a bijection between wxString <-> Squirrel String.
2 - make possible to use wxString to define Data.key like that :
local data = {};
local value = 2;
data.rawset{_T("KEY"), value);
print(data.rawget(_T("KEY"))); // error there are no key.
Actually this code works:
local data = {};
local key = _T("KEY");
local value = 2;
data.rawset(key, value);
print(data.rawget(key)); // print 2 because key pointer adress is using by Squirrel to find the key.
data.
1 - make a bijection between wxString <-> Squirrel String.
we have an experimental build where this was possible. Maybe in the future we will work on this more.
The first step in the near future is to update squirrel to the latest release, because codeblocks uses the old version 2 and not 3.1.
In general you can normally use squirrel strings everywhere, and put them trough in the last step before the codeblocks function...
local iAmAsquirrelString = "hello";
iAmAsquirrelString += " world";
// Now you put it into a codeblocks function, use _T() to convert it
Log(_T(iAmAsquirrelString ));
Basically the same is the other way around by using the function:
Log(_T(_T("test").tostring()));
I really would like to improve the squirrel support, but there are tons of other things on the todo list, and time is limited...