Patch #2583 2008-11-02 19:01

gryphon

unify clean/build/rebuild{workspace} normal/make behaviour
Download
2583-unify_clean_bu.patch (17.7 KB)
Category
Plugin::Bugfix
Status
Accepted
Close date
2009-01-28 07:01
Assigned to
mortenmacfly
Index: src/plugins/compilergcc/compilergcc.h
===================================================================
--- src/plugins/compilergcc/compilergcc.h    (revision 5296)
+++ src/plugins/compilergcc/compilergcc.h    (working copy)
@@ -52,6 +52,7 @@
 {
     bsNone = 0,
     bsProjectPreBuild,
+    bsTargetClean,
     bsTargetPreBuild,
     bsTargetBuild,
     bsTargetPostBuild,
@@ -67,6 +68,12 @@
     ltAll       = 0xff
 };
 
+enum BuildAction
+{
+    baClean = 0,
+    baBuild
+};
+
 class wxTimerEvent;
 class wxComboBox;
 class wxStaticText;
@@ -187,13 +194,15 @@
         void LogMessage(const wxString& message, CompilerLineType lt = cltNormal, LogTarget log = ltAll, bool forceErrorColour = false, bool isTitle = false, bool updateProgress = false);
         void SaveBuildLog();
         void InitBuildLog(bool workspaceBuild);
-        void PrintBanner(cbProject* prj = 0, ProjectBuildTarget* target = 0);
-        bool UseMake(ProjectBuildTarget* target = 0);
+        void PrintBanner(BuildAction action, cbProject* prj = 0, ProjectBuildTarget* target = 0);
+        bool UseMake(cbProject *prj = 0);
         bool CompilerValid(ProjectBuildTarget* target = 0);
         ProjectBuildTarget* GetBuildTargetForFile(ProjectFile* pf);
         ProjectBuildTarget* GetBuildTargetForFile(const wxString& file);
         wxString GetMakeCommandFor(MakeCommand cmd, cbProject* project, ProjectBuildTarget* target);
-        int DoBuild();
+        int DoBuild(bool clean, bool build);
+        int DoBuild(const wxString& target, bool clean, bool build);
+        int DoWorkspaceBuild(const wxString& target, bool clean, bool build);
         void CalculateWorkspaceDependencies(wxArrayInt& deps);
         void CalculateProjectDependencies(cbProject* prj, wxArrayInt& deps);
         void InitBuildState(BuildJob job, const wxString& target);
@@ -276,6 +285,9 @@
         BuildState m_NextBuildState;
         cbProject* m_pLastBuildingProject;
         ProjectBuildTarget* m_pLastBuildingTarget;
+        // Clean and Build
+        bool m_Clean;
+        bool m_Build;
         // to decide if post-build steps should run
         bool m_RunTargetPostBuild;
         bool m_RunProjectPostBuild;
Index: src/plugins/compilergcc/compilergcc.cpp
===================================================================
--- src/plugins/compilergcc/compilergcc.cpp    (revision 5296)
+++ src/plugins/compilergcc/compilergcc.cpp    (working copy)
@@ -363,6 +363,8 @@
     m_pLastBuildingTarget = 0;
     m_RunTargetPostBuild = false;
     m_RunProjectPostBuild = false;
+    m_Clean = false;
+    m_Build = false;
     m_DeleteTempMakefile = true;
     m_IsWorkspaceOperation = false;
 
@@ -967,6 +969,9 @@
     if (m_IsWorkspaceOperation)
         return;
 
+    if (IsProcessRunning())
+        return;
+
     CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_Log);
     Manager::Get()->ProcessEvent(evtSwitch);
 
@@ -1475,15 +1480,16 @@
     m_LastTempMakefile = _T("");
 }
 
-bool CompilerGCC::UseMake(ProjectBuildTarget* target)
+bool CompilerGCC::UseMake(cbProject *prj)
 {
-    if (!m_Project)
+    if (!prj)
+        prj = m_Project;
+    if (!prj)
         return false;
-    wxString idx = m_Project->GetCompilerID();
+    wxString idx = prj->GetCompilerID();
     if (CompilerFactory::GetCompiler(idx))
     {
-        if (m_Project->IsMakefileCustom())
-            return true;
+        return prj->IsMakefileCustom();
     }
     return false;
 }
@@ -1553,7 +1559,7 @@
         }
     }
 
-    PrintBanner();
+    PrintBanner(baBuild);
     wxSetWorkingDirectory(m_Project->GetBasePath());
 
     if (UseMake())
@@ -1572,7 +1578,7 @@
     return true;
 }
 
-void CompilerGCC::PrintBanner(cbProject* prj, ProjectBuildTarget* target)
+void CompilerGCC::PrintBanner(BuildAction action, cbProject* prj, ProjectBuildTarget* target)
 {
     if (!CompilerValid(target))
         return;
@@ -1583,8 +1589,14 @@
     if (!prj)
         prj = m_Project;
 
+    wxString Action = _("Build");
+    if (action ==  baClean)
+    {
+        Action = _("Clean");
+    }
     wxString banner;
-    banner.Printf(_("-------------- Build: %s in %s ---------------"),
+    banner.Printf(_("-------------- %s: %s in %s ---------------"),
+                    Action.c_str(),
                     target
                         ? target->GetTitle().c_str()
                         : _("\"no target\""),
@@ -1922,63 +1934,7 @@
 
 int CompilerGCC::Clean(const wxString& target)
 {
-    wxString realTarget = target;
-    if (realTarget.IsEmpty())
-        realTarget = GetTargetString();
-    if (realTarget.IsEmpty())
-        return -1;
-
-    if (!m_IsWorkspaceOperation)
-    {
-        DoPrepareQueue();
-    }
-
-    wxArrayString clean;
-    if (!m_Project)
-    {
-        if (!Manager::Get()->GetEditorManager()->GetActiveEditor())
-          return -1;
-
-        DirectCommands dc(this, CompilerFactory::GetDefaultCompiler(), 0, m_PageIndex);
-        clean = dc.GetCleanSingleFileCommand(
download for full patch...
gryphon 2008-11-02 19:03

This patch unifies how clean, build and rebuilds are handled both per-project and in a workspace. It simplifies the code in compilergcc.cpp and provides a consistent experience when using codeblocks projects or projects based on custom makefiles.

mortenmacfly 2009-01-28 07:01

Applied (modified) in SVN trunk Thanks!