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.
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 (https://developer.berlios.de/patch/?func=detailpatch&patch_id=3249&group_id=5358)
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;
}
Quote from: stahta01 on January 21, 2012, 05:46:45 PM
I need to change the CB SDK to get more improvements.
...but your patch doesn't change the SDK, does it?! ???
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.
...but your patch doesn't change the SDK, does it?! ???
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.
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.
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;
}
The part of my future patch that changes any of the CB SDK
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
Tim S.
This is a completely safe patch to apply it fixes a few people issue on configuring CygWin automatically.
Tim S.
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");
This is my patch that requires minor SDK header file changes to enum type AutoDetectResult in Compiler.h.
Tim S.
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
Updated patch tested it some; but, I have a cold and not thinking well.
Tim S.
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