Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

My research on improving Auto Detection of Compilers

<< < (2/2)

stahta01:
The part of my future patch that changes any of the CB SDK


--- Code: ---Index: src/include/compiler.h
===================================================================
--- src/include/compiler.h (revision 7711)
+++ src/include/compiler.h (working copy)
@@ -142,7 +142,9 @@
 enum AutoDetectResult
 {
     adrDetected,
-    adrGuessed
+    adrGuessed,
+    adrDetectedDir,
+    adrDetectedToolChain
 };
 
 /// Struct to keep programs

--- End code ---

Tim S.

stahta01:
This is a completely safe patch to apply it fixes a few people issue on configuring CygWin automatically.

Tim S.


--- Code: ---Index: src/plugins/compilergcc/compilerCYGWIN.cpp
===================================================================
--- src/plugins/compilergcc/compilerCYGWIN.cpp (revision 7711)
+++ src/plugins/compilergcc/compilerCYGWIN.cpp (working copy)
@@ -35,9 +35,11 @@
 {
     CompilerMINGW::Reset();
 
-    m_Programs.C = _T("gcc.exe");
-    m_Programs.CPP = _T("g++.exe");
-    m_Programs.LD = _T("g++.exe");
+    // NOTE: Cygwin's gcc.exe is a file link and
+    // is not a good default name for running via cmd.exe
+    m_Programs.C = _T("gcc-3.exe");
+    m_Programs.CPP = _T("g++-3.exe");
+    m_Programs.LD = _T("g++-3.exe");
     m_Programs.DBG = _T("gdb.exe");
     m_Programs.LIB = _T("ar.exe");
     m_Programs.WINDRES = _T("windres.exe");

--- End code ---

stahta01:
This is my patch that requires minor SDK header file changes to enum type AutoDetectResult in Compiler.h.

Tim S.


--- Code: ---Index: src/plugins/compilergcc/compilerCYGWIN.cpp
===================================================================
--- src/plugins/compilergcc/compilerCYGWIN.cpp (revision 7711)
+++ src/plugins/compilergcc/compilerCYGWIN.cpp (working copy)
@@ -35,9 +35,11 @@
 {
     CompilerMINGW::Reset();
 
-    m_Programs.C = _T("gcc.exe");
-    m_Programs.CPP = _T("g++.exe");
-    m_Programs.LD = _T("g++.exe");
+    // NOTE: Cygwin's gcc.exe is a file link and
+    // is not a good default name for running via cmd.exe
+    m_Programs.C = _T("gcc-3.exe");
+    m_Programs.CPP = _T("g++-3.exe");
+    m_Programs.LD = _T("g++-3.exe");
     m_Programs.DBG = _T("gdb.exe");
     m_Programs.LIB = _T("ar.exe");
     m_Programs.WINDRES = _T("windres.exe");
@@ -48,24 +50,87 @@
     m_Options.AddOption(_("Do not use cygwin specific functionality"), _T("-mno-cygwin"), _("General"));
 }
 
+bool isNormalFileNotSymlink(const wxString& filename){
+    if (wxFileExists(filename)){
+        wxFile aFile(filename);
+        if (aFile.IsOpened()){
+            char buffer[10]={0};
+            aFile.Read(buffer,10);
+            if (memcmp("!<symlink>", buffer, 10) != 0){
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
 AutoDetectResult CompilerCYGWIN::AutoDetectInstallationDir()
 {
-    m_MasterPath = _T("C:\\Cygwin"); // just a guess
+    AutoDetectResult ret = adrGuessed;
+    wxString tempMasterPath = _T("C:\\Cygwin"); // just a guess
+    m_MasterPath = tempMasterPath;
+    bool validInstallationDir = false;
 
     // look in registry for Cygwin
 
     wxRegKey key; // defaults to HKCR
-    key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/"));
+    key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygwin\\setup"));
     if (key.Exists() && key.Open(wxRegKey::Read))
     {
-        // found; read it
-        key.QueryValue(_T("native"), m_MasterPath);
+        // found CygWin version 1.7 or newer; read it
+        key.QueryValue(_T("rootdir"), tempMasterPath);
+        if (wxDirExists(
+                tempMasterPath + wxFILE_SEP_PATH +
+                _T("bin"))
+        ){
+                validInstallationDir = true;
+        }
     }
-    AutoDetectResult ret = wxFileExists(m_MasterPath + wxFILE_SEP_PATH +
-                                        _T("bin") + wxFILE_SEP_PATH +
-                                        m_Programs.C)
-                            ? adrDetected
-                            : adrGuessed;
+    if (!validInstallationDir){
+        key.SetName(_T("HKEY_LOCAL_MACHINE\\Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/"));
+        if (key.Exists() && key.Open(wxRegKey::Read))
+        {
+            // found CygWin version 1.5 or older; read it
+            key.QueryValue(_T("native"), tempMasterPath);
+            if (wxDirExists(
+                    tempMasterPath + wxFILE_SEP_PATH +
+                    _T("bin")
+                )
+            ){
+                validInstallationDir = true;
+            }
+        }
+    }
+
+    if (validInstallationDir){
+        wxString cProgramDir = tempMasterPath + wxFILE_SEP_PATH +
+            _T("bin") + wxFILE_SEP_PATH;
+        wxString cProgramFullname = cProgramDir + m_Programs.C;
+        if (isNormalFileNotSymlink(cProgramFullname)){
+            m_MasterPath = tempMasterPath;
+            ret = adrDetected;
+        } else {
+            if (isNormalFileNotSymlink(cProgramDir + _T("gcc-4.exe"))){
+                m_Programs.C = _T("gcc-4.exe");
+                m_Programs.CPP = _T("g++-4.exe");
+                m_Programs.LD = _T("g++-4.exe");
+                m_MasterPath = tempMasterPath;
+                ret = adrDetectedToolChain;
+            } else if (isNormalFileNotSymlink(cProgramDir + _T("gcc-3.exe"))){
+                m_Programs.C = _T("gcc-3.exe");
+                m_Programs.CPP = _T("g++-3.exe");
+                m_Programs.LD = _T("g++-3.exe");
+                m_MasterPath = tempMasterPath;
+                ret = adrDetectedToolChain;
+            }
+        }
+    }
+
+    if (validInstallationDir && ret == adrGuessed){
+        m_MasterPath = tempMasterPath;
+        ret = adrDetectedDir;
+    }
+
     return ret;
 }
 
Index: src/plugins/compilergcc/compileroptionsdlg.cpp
===================================================================
--- src/plugins/compilergcc/compileroptionsdlg.cpp (revision 7711)
+++ src/plugins/compilergcc/compileroptionsdlg.cpp (working copy)
@@ -1299,6 +1299,37 @@
 
     switch (compiler->AutoDetectInstallationDir())
     {
+        case adrDetectedDir:
+        {
+            wxString msg;
+            msg.Printf(_("Auto-detected \"%s\";but, failed to find a valid C-Compiler\nin installation path of \"%s\"\n"
+                         "Do you want to use this installation directory?"),
+                        #if wxCHECK_VERSION(2, 9, 0)
+                        compiler->GetName().wx_str(), compiler->GetMasterPath().wx_str());
+                        #else
+                        compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
+                        #endif
+            if (cbMessageBox(msg, _("Confirmation"), wxICON_QUESTION | wxYES_NO) == wxID_NO)
+            {
+                compiler->SetMasterPath(backup);
+                compiler->SetExtraPaths(ExtraPathsBackup);
+            }
+        }
+        break;
+
+        case adrDetectedToolChain:
+        {
+            wxString msg;
+            #if wxCHECK_VERSION(2, 9, 0)
+            msg.Printf(_("Auto-detected \"%s\"\nwith different C-Compiler filename \nin installation path of \"%s\""), compiler->GetName().wx_str(), compiler->GetMasterPath().wx_str());
+            #else
+            msg.Printf(_("Auto-detected \"%s\"\nwith different C-Compiler filename \nin installation path of \"%s\""), compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
+            #endif
+            cbMessageBox(msg);
+            DoFillCompilerPrograms();
+        }
+        break;
+
         case adrDetected:
         {
             wxString msg;
Index: src/include/compiler.h
===================================================================
--- src/include/compiler.h (revision 7711)
+++ src/include/compiler.h (working copy)
@@ -142,7 +142,9 @@
 enum AutoDetectResult
 {
     adrDetected,
-    adrGuessed
+    adrGuessed,
+    adrDetectedDir,
+    adrDetectedToolChain
 };
 
 /// Struct to keep programs

--- End code ---

stahta01:
Updated patch tested it some; but, I have a cold and not thinking well.

Tim S.


--- Code: ---Index: src/plugins/compilergcc/compilerCYGWIN.cpp
===================================================================
--- src/plugins/compilergcc/compilerCYGWIN.cpp (revision 7879)
+++ src/plugins/compilergcc/compilerCYGWIN.cpp (working copy)
@@ -51,6 +51,20 @@
     m_Options.AddOption(_("Do not use cygwin specific functionality"), _T("-mno-cygwin"), _("General"));
 }
 
+bool isNormalFileNotSymlink(const wxString& filename){
+    if (wxFileExists(filename)){
+        wxFile aFile(filename);
+        if (aFile.IsOpened()){
+            char buffer[10]={0};
+            aFile.Read(buffer,10);
+            if (memcmp("!<symlink>", buffer, 10) != 0){
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
 AutoDetectResult CompilerCYGWIN::AutoDetectInstallationDir()
 {
     AutoDetectResult ret = adrGuessed;
@@ -81,24 +95,33 @@
         }
     }
 
-    if (!validInstallationDir)
-        return ret;
+    if (validInstallationDir){
+        wxString cProgramDir = tempMasterPath + wxFILE_SEP_PATH +
+            _T("bin") + wxFILE_SEP_PATH;
+        wxString cProgramFullname = cProgramDir + m_Programs.C;
+        if (isNormalFileNotSymlink(cProgramFullname)){
+            m_MasterPath = tempMasterPath;
+            ret = adrDetected;
+        } else {
+            if (isNormalFileNotSymlink(cProgramDir + _T("gcc-4.exe"))){
+                m_Programs.C = _T("gcc-4.exe");
+                m_Programs.CPP = _T("g++-4.exe");
+                m_Programs.LD = _T("g++-4.exe");
+                m_MasterPath = tempMasterPath;
+                ret = adrDetectedToolChain;
+            } else if (isNormalFileNotSymlink(cProgramDir + _T("gcc-3.exe"))){
+                m_Programs.C = _T("gcc-3.exe");
+                m_Programs.CPP = _T("g++-3.exe");
+                m_Programs.LD = _T("g++-3.exe");
+                m_MasterPath = tempMasterPath;
+                ret = adrDetectedToolChain;
+            }
+        }
+    }
 
-    wxString cProgramDir = tempMasterPath + wxFILE_SEP_PATH + _T("bin") + wxFILE_SEP_PATH;
-    wxString cProgramFullname = cProgramDir + m_Programs.C;
-    if ( !wxFileExists(cProgramFullname) )
-        return ret;
-
-    wxFile pfFile(cProgramFullname);
-    if ( !pfFile.IsOpened() )
-       return ret;
-
-    char buffer[10] = {0};
-    pfFile.Read(buffer,10);
-    if (memcmp("!<symlink>", buffer, 10) != 0)
-    {
+    if (validInstallationDir && ret == adrGuessed){
         m_MasterPath = tempMasterPath;
-        ret = adrDetected;
+        ret = adrDetectedDir;
     }
 
     return ret;
Index: src/plugins/compilergcc/compileroptionsdlg.cpp
===================================================================
--- src/plugins/compilergcc/compileroptionsdlg.cpp (revision 7879)
+++ src/plugins/compilergcc/compileroptionsdlg.cpp (working copy)
@@ -1299,6 +1299,37 @@
 
     switch (compiler->AutoDetectInstallationDir())
     {
+        case adrDetectedDir:
+        {
+            wxString msg;
+            msg.Printf(_("Auto-detected \"%s\";but, failed to find a valid C-Compiler\nin installation path of \"%s\"\n"
+                         "Do you want to use this installation directory?"),
+                        #if wxCHECK_VERSION(2, 9, 0)
+                        compiler->GetName().wx_str(), compiler->GetMasterPath().wx_str());
+                        #else
+                        compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
+                        #endif
+            if (cbMessageBox(msg, _("Confirmation"), wxICON_QUESTION | wxYES_NO) == wxID_NO)
+            {
+                compiler->SetMasterPath(backup);
+                compiler->SetExtraPaths(ExtraPathsBackup);
+            }
+        }
+        break;
+
+        case adrDetectedToolChain:
+        {
+            wxString msg;
+            #if wxCHECK_VERSION(2, 9, 0)
+            msg.Printf(_("Auto-detected \"%s\"\nwith different C-Compiler filename \nin installation path of \"%s\""), compiler->GetName().wx_str(), compiler->GetMasterPath().wx_str());
+            #else
+            msg.Printf(_("Auto-detected \"%s\"\nwith different C-Compiler filename \nin installation path of \"%s\""), compiler->GetName().c_str(), compiler->GetMasterPath().c_str());
+            #endif
+            cbMessageBox(msg);
+            DoFillCompilerPrograms();
+        }
+        break;
+
         case adrDetected:
         {
             wxString msg;
Index: src/include/compiler.h
===================================================================
--- src/include/compiler.h (revision 7879)
+++ src/include/compiler.h (working copy)
@@ -142,7 +142,9 @@
 enum AutoDetectResult
 {
     adrDetected,
-    adrGuessed
+    adrGuessed,
+    adrDetectedDir,
+    adrDetectedToolChain
 };
 
 /// Struct to keep programs

--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version