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

My research on improving Auto Detection of Compilers

(1/2) > >>

stahta01:
I spent the last few hours helping "eb" on a CygWin Compiler issue.

I decided it was time to update the CompilerCYGWIN::AutoDetectInstallationDir method.

Here's the patch. I tested it as much as I can on just my Computer.
Edit: I plan to test it at School to see if it works on a 64 Bit Machine.
Edit: I have already thought up two changes to this patch.
Edit: I have decided that much more research is needed.



Tim S.

stahta01:
Patch to get auto detect for Cygwin working.
Not as good as I wanted; I need to change the CB SDK to get more improvements.

Tim S.

Submitted as [ Patch #3249 ] Cygwin Compiler Autodetect fix https://developer.berlios.de/patch/?func=detailpatch&patch_id=3249&group_id=5358


--- 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,60 @@
     m_Options.AddOption(_("Do not use cygwin specific functionality"), _T("-mno-cygwin"), _("General"));
 }
 
+bool isCygwinSymbolicLink(const wxString& filename){
+    if (wxFileExists(filename)){
+        wxFile aFile(filename);
+        char buffer[11];
+        aFile.Read(buffer,10);
+        if (strcmp("!<symlink>", buffer) == 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;
 
     // 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);
+        wxString cProgram = tempMasterPath + wxFILE_SEP_PATH +
+            _T("bin") + wxFILE_SEP_PATH + m_Programs.C;
+
+        if (wxFileExists(cProgram)){
+            wxFile testFile(cProgram);
+            if (!isCygwinSymbolicLink(cProgram)){
+                ret = adrDetected;
+            }
+        }
     }
-    AutoDetectResult ret = wxFileExists(m_MasterPath + wxFILE_SEP_PATH +
-                                        _T("bin") + wxFILE_SEP_PATH +
-                                        m_Programs.C)
-                            ? adrDetected
-                            : adrGuessed;
+    if (ret == adrGuessed){
+        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 (wxFileExists(
+                    tempMasterPath + wxFILE_SEP_PATH +
+                    _T("bin") + wxFILE_SEP_PATH + m_Programs.C
+                )
+            ){
+                ret = adrDetected;
+            }
+        }
+    }
+    if (ret == adrDetected){
+        m_MasterPath = tempMasterPath;
+    }
     return ret;
 }
 

--- End code ---

MortenMacFly:

--- Quote from: stahta01 on January 21, 2012, 05:46:45 pm ---I need to change the CB SDK to get more improvements.

--- End quote ---
...but your patch doesn't change the SDK, does it?! ???

stahta01:

--- Quote from: MortenMacFly on January 21, 2012, 06:32:50 pm ---
--- Quote from: stahta01 on January 21, 2012, 05:46:45 pm ---I need to change the CB SDK to get more improvements.

--- End quote ---
...but your patch doesn't change the SDK, does it?! ???

--- End quote ---

The patch submitted does not and the patch in this thread does not.
But, I am working on one that will require very minor changes to the SDK.

Tim S.

stahta01:
Re-wrote logic till I found my bug (I used strcmp instead of memcmp)

A re-write of the Auto detection of CygWin Compiler patch (does NOT require or do SDK changes).

I am having issues getting the patch that requires the SDK changes to work right.

Tim S.

Updated patch 23Jan2012; planning to test it on 64 bit computers today.

--- 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,68 @@
     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;
+        }
+    }
+
     return ret;
 }
 


--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version