User forums > Using Code::Blocks

Script C::B

<< < (3/6) > >>

Jenna:

--- Quote from: LETARTARE on December 06, 2011, 01:28:44 pm ---Translate by GOOGLE

Yes, of course, is much better.
Unfortunately, trying to svn7620, I found that 'Project * cbProject::GetFile (int)' was missing from svn 7588.
This method was replaced by 'FilesList * cbProject::GetFilesList()' and 'FilesList * ProjectBuildTarget::GetFilesList()', but without connection to the scripts !
I guess 'FileList' is difficult to link scripts.

For then there is no further access to a file indexing for scripts!
Also, most scripts become unusable.

Is this an oversight, or is it voluntary?


--- End quote ---
Project * cbProject::GetFile (int) was removed to speed up the loading time of large projects.
To make it possible I created FilesList * cbProject::GetFilesList(), but did not implement it for scripting. I am not sure, if this can be done easily. I will look into it.

FilesList * ProjectBuildTarget::GetFilesList() seems not to work. It was implemented in svn r1433, but m_Files (the member-variable, that is returned) was never filled as far as I can see after a quick look.
It's only used in Export targets as project, if I see correctly, and I nevr used this option, so I do not know, if it ever worked as expected.

LETARTARE:
Translation by Google
thank you very much for that.


--- Quote ---but m_Files (the member-variable, that is returned) was never filled
--- End quote ---
not because I use it (see below)

I do not see how to implement the type 'FilesList', also waiting for your result, I  added the method
'virtual wxArrayString ProjectBuildTarget::GetFiles () const'

 svn> = 7588:

--- Code: ---Index: src/include/projectbuildtarget.h
===================================================================
--- src/include/projectbuildtarget.h (révision 7622)
+++ src/include/projectbuildtarget.h (copie de travail)
@@ -115,6 +115,11 @@
         /** Provides an easy way to iterate all the files belonging in this target.
           * @return A list of files belonging in this target. */
         virtual FilesList& GetFilesList(){ return m_Files; }
+
+        /** Provides an easy way to iterate all the files belonging in this target.
+          * @return An array of files belonging in this target.*/
+ virtual wxArrayString GetFiles() const;
+
     private:
         friend class ProjectFile; // to allow it to add/remove files in FilesList
         cbProject* m_Project;
Index: src/sdk/projectbuildtarget.cpp
===================================================================
--- src/sdk/projectbuildtarget.cpp (révision 7622)
+++ src/sdk/projectbuildtarget.cpp (copie de travail)
@@ -44,6 +44,20 @@
     return m_Project->GetTitle() + _T(" - ") + GetTitle();
 }
 
+// get the list of files of this target
+wxArrayString ProjectBuildTarget::GetFiles() const
+{
+ wxArrayString filearray;
+ ProjectFile * pf;
+ FilesList::const_iterator it = m_Files.begin();
+ while (it != m_Files.end()) {
+ pf = *it++;
+ filearray.Add(pf->relativeFilename);
+ }
+
+ return filearray;
+}
+
 const wxString & ProjectBuildTarget::GetExternalDeps() const
 {
     return m_ExternalDeps;
Index: src/sdk/scripting/bindings/scriptbindings.cpp
===================================================================
--- src/sdk/scripting/bindings/scriptbindings.cpp (révision 7622)
+++ src/sdk/scripting/bindings/scriptbindings.cpp (copie de travail)
@@ -482,6 +482,7 @@
                 func(&CompileTargetBase::MakeCommandsModified, "MakeCommandsModified");
 
         SqPlus::SQClassDef<ProjectBuildTarget>("ProjectBuildTarget", "CompileTargetBase").
+ func(&ProjectBuildTarget::GetFiles, "GetFiles").
                 func(&ProjectBuildTarget::GetParentProject, "GetParentProject").
                 func(&ProjectBuildTarget::GetFullTitle, "GetFullTitle").
                 func(&ProjectBuildTarget::GetExternalDeps, "GetExternalDeps").
--- End code ---

and svn6283 .. 7587 this:

--- Code: ---Index: src/include/projectbuildtarget.h
===================================================================
--- src/include/projectbuildtarget.h (révision 6283)
+++ src/include/projectbuildtarget.h (copie de travail)
@@ -117,6 +117,10 @@
         /** Provides an easy way to iterate all the files belonging in this target.
           * @return A list of files belonging in this target. */
         virtual FilesList& GetFilesList(){ return m_Files; }
+ /** Provides an easy way to iterate all the files belonging in this target.
+          * @return An array of files belonging in this target.*/
+ virtual wxArrayString GetFiles() const;
+
     private:
         friend class ProjectFile; // to allow it to add/remove files in FilesList
         cbProject* m_Project;
Index: src/sdk/projectbuildtarget.cpp
===================================================================
--- src/sdk/projectbuildtarget.cpp (révision 6283)
+++ src/sdk/projectbuildtarget.cpp (copie de travail)
@@ -44,6 +44,20 @@
     return m_Project->GetTitle() + _T(" - ") + GetTitle();
 }
 
+// get the list of files of this target
+wxArrayString ProjectBuildTarget::GetFiles() const {
+ wxArrayString filearray;
+ ProjectFile * pf;
+ FilesList::Node * node = m_Files.GetFirst();
+ while (node) {
+ pf = node->GetData();
+ filearray.Add(pf->relativeFilename);
+ // the next
+ node = node->GetNext();
+ }
+ return filearray;
+}
+
 const wxString & ProjectBuildTarget::GetExternalDeps() const
 {
     return m_ExternalDeps;
Index: src/sdk/scripting/bindings/scriptbindings.cpp
===================================================================
--- src/sdk/scripting/bindings/scriptbindings.cpp (révision 6283)
+++ src/sdk/scripting/bindings/scriptbindings.cpp (copie de travail)
@@ -482,6 +482,7 @@
                 func(&CompileTargetBase::MakeCommandsModified, "MakeCommandsModified");
 
         SqPlus::SQClassDef<ProjectBuildTarget>("ProjectBuildTarget", "CompileTargetBase").
+      func(&ProjectBuildTarget::GetFiles, "GetFiles").
                 func(&ProjectBuildTarget::GetParentProject, "GetParentProject").
                 func(&ProjectBuildTarget::GetFullTitle, "GetFullTitle").
                 func(&ProjectBuildTarget::GetExternalDeps, "GetExternalDeps").
--- End code ---

positive tests have been carried out with the script extension following:

--- Code: ---///-----------------------------------------------------------------------------
/// ===> use a new method to 'wxArrayString ProjectBuildTarget::GetFiles()' <===
/// get the list of files of this target
///-----------------------------------------------------------------------------

///-----------------------------------------------------------------------------
/// display all files project
// affiche tous les fichiers du projet
///-----------------------------------------------------------------------------
class DisplayAllFilesTargets extends cbScriptPlugin {
/// members
// membres
VERSION = _T("1.0.2");
///-----------------------------------------------------------------------------
/// mandatory to init script plugin
// obligatoire pour initialiser le script d'extension
///-----------------------------------------------------------------------------
constructor() {
/// constructor base class
// constructeur de la classe de base
cbScriptPlugin.constructor();
/// setup the plugin's info
// les informations de l'extension
info.name = _T("DisplayAllFilesTargets");
info.title = _("Display files targets");
info.version = VERSION;
info.license = _T("GPL");
}
///-----------------------------------------------------------------------------
/// to create context menu entries
// pour créer les entrées du menu de contexte
///-----------------------------------------------------------------------------
function GetModuleMenu(who, data) {
local entries = ::wxArrayString();
    if (who == ::mtProjectManager)   {
            entries.Add(_("Display files targets"), 1);
    }
return entries;
}
///-----------------------------------------------------------------------------
/// calback for context menu items clicking
// évènement lors d'une action sur les entrées du menu de contexte
///-----------------------------------------------------------------------------
function OnModuleMenuClicked(index) {
local result = main();
}
///-----------------------------------------------------------------------------
///displays all files of each target
//
function main() {
///
local Projet = GetProjectManager().GetActiveProject();
local Nt = Projet.GetBuildTargetsCount() ;
//----------------------------------------------
/// file relative name
// le nom relatif d'un fichier
local file;
local tabfile = ::wxArrayString();
local target ;
local i=0;
local good = false;
/// informations
local Mes = _T("Project : '") + Projet.GetTitle() + _T("' : ") ;
Mes += Projet.GetFilesCount().tostring() + _T(" files, ") ;
Mes +=  Nt.tostring() + _T(" targets : ") ;
::print(Mes );
/// all project targets
// toutes les cibles du projet
for (local ci=0; ci < Nt ; ci++ ) {
target = Projet.GetBuildTarget(ci) ;
::print(_T("\nTarget ") + ci.tostring() + _T(" : '") + target.GetFullTitle() + _T("'"));
/// the array of files name
// le tableau des noms de fichiers relatifs associés à cette cible
///------------- patch to 'ProjectBuildTarget' class ---------------------------
tabfile = target.GetFiles(ci);
///-----------------------------------------------------------------------------
/// all files target
// analyser tous les fichiers de la cible
for (local u=0; u < tabfile.GetCount(); u++) {
file = tabfile.Item(u);
::print (_T("   ") + u.tostring() + _T(" : '") + file + _T("'"));
i++;
}
}
::print(_T("\nTotal files associated to targets : ") + i.tostring());
}
///-----------------------------------------------------------------------------

} /// class end

///-----------------------------------------------------------------------------
/// this call actually registers the script plugin with Code::Blocks
// register le script d'extension dans Code::Blocks
///-----------------------------------------------------------------------------
RegisterPlugin(DisplayAllFilesTargets());
///-----------------------------------------------------------------------------
/// if you want to call this plugin's Execute() function, use this in a script:
// si vous désirez appeler, depuis un script, la fonction 'Execute' de l'extension
///-----------------------------------------------------------------------------
// ExecutePlugin(_T("QtPreBuildPlugin"));
///-----------------------------------------------------------------------------
--- End code ---

because I needed to list the files of each target (not all files in the project)

soon.

Jenna:

--- Quote from: jens on December 06, 2011, 08:24:53 pm ---Project * cbProject::GetFile (int) was removed to speed up the loading time of large projects.
To make it possible I created FilesList * cbProject::GetFilesList(), but did not implement it for scripting. I am not sure, if this can be done easily. I will look into it.

--- End quote ---
I will see, if I can reimplement it, just for looping through the files.
NOTE: if it works, the index should not be used for looping through the list, because after any change (or even reload of the same project) it might differ, because the real list is stored in a hash-map without guaranteed order.
If it does not work, I use your approach.
And I will test both ways, to see which one is faster (just a simple wxStopWatch measuring over a for-loop through all files of a large project).


--- Quote from: jens on December 06, 2011, 08:24:53 pm ---FilesList * ProjectBuildTarget::GetFilesList() seems not to work. It was implemented in svn r1433, but m_Files (the member-variable, that is returned) was never filled as far as I can see after a quick look.
It's only used in Export targets as project, if I see correctly, and I nevr used this option, so I do not know, if it ever worked as expected.

--- End quote ---

It definitely worked before, but seems to be broken due to my changes, I will fix this.

LETARTARE:
Well, good luck.
 I just did the test this morning
I have not tried speed, only the use for scripts, because I need to validate a
the project.

Pecan:

--- Quote from: jens on December 06, 2011, 08:24:53 pm ---FilesList * ProjectBuildTarget::GetFilesList() seems not to work. It was implemented in svn r1433, but m_Files (the member-variable, that is returned) was never filled as far as I can see after a quick look.
It's only used in Export targets as project, if I see correctly, and I nevr used this option, so I do not know, if it ever worked as expected.

--- End quote ---

It looks quite confusing, but I think you'll find that m_Files in ProjectBuildTarget is filled by the project loader when the targets are built by ProjectFile.

Look for the line

--- Code: ---file->AddBuildTarget(targetName);
--- End code ---
in projectloader.cpp

ProjectFile.cpp line 78

--- Code: ---void ProjectFile::AddBuildTarget(const wxString& targetName)
{
    if (buildTargets.Index(targetName) == wxNOT_FOUND)
        buildTargets.Add(targetName);

    // add this file to the target's list of files
    if (project)
    {
        ProjectBuildTarget* target = project->GetBuildTarget(targetName);
        if (target && (target->m_Files.find(this) == target->m_Files.end()))
            target->m_Files.insert(this);
    }

    // also do this for auto-generated files
    for (size_t i = 0; i < generatedFiles.size(); ++i)
        generatedFiles[i]->AddBuildTarget(targetName);
}

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version