Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Directory separator in project file (.cbp)
rblenis:
I have devs using windows and linux builds of CodeBlocks, and each version keeps flipping the directory separator ('/' vs '\'), making it a pain to see what the is actually changed in the project when viewing diffs. Is there a way to make CodeBlocks stop changing it, or make both versions always use the same (I prefer linux '/'). I could look at doing it myself, but wanted to make sure I had not overlooked a configuration option, and would not want to invest time in adding/modifying code if others thought this was not useful or it would cause other problems that I'm not thinking about.
Hadomunt:
Code BLocks is not changing this but the operating systems are.
Maybe it would be a good idea to standardize on directory separator and newline symbols in code blocks files.
Since Code::Blocks itself is cross platform it seems very practical to make file descriptions also cross platform.
Using '/' (also my preference) for directory separator and /r/n for a new line. (There is a technical reason to use this and not /n, but I forgot what that was.)
Alpha:
Try this patch:
--- Code: ---Index: src/sdk/globals.cpp
===================================================================
--- src/sdk/globals.cpp (revision 8133)
+++ src/sdk/globals.cpp (working copy)
@@ -201,6 +201,11 @@
return result;
}
+wxString NativeToUnix(const wxString& filename)
+{
+ wxFileName fname(filename);
+ return fname.GetFullPath(wxPATH_UNIX);
+}
void QuoteStringIfNeeded(wxString& str)
{
Index: src/sdk/projectloader.cpp
===================================================================
--- src/sdk/projectloader.cpp (revision 8133)
+++ src/sdk/projectloader.cpp (working copy)
@@ -1175,7 +1175,7 @@
{
wxFileName fname(outputFileName);
fname.ClearExt();
- outputFileName = fname.GetFullPath();
+ outputFileName = fname.GetFullPath(wxPATH_UNIX);
}
if ( (prefixPolicy == tgfpPlatformDefault)
@@ -1197,7 +1197,7 @@
if (!outputFileNameWOPrefix.IsEmpty())
{
fname.SetFullName(outputFileNameWOPrefix);
- outputFileName = fname.GetFullPath();
+ outputFileName = fname.GetFullPath(wxPATH_UNIX);
}
}
}
@@ -1207,19 +1207,19 @@
if (target->GetTargetType() == ttDynamicLib)
{
if (target->GetDynamicLibImportFilename() != _T("$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)"))
- outnode->SetAttribute("imp_lib", cbU2C(target->GetDynamicLibImportFilename()));
+ outnode->SetAttribute("imp_lib", cbU2C(NativeToUnix(target->GetDynamicLibImportFilename())));
if (target->GetDynamicLibImportFilename() != _T("$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME)"))
- outnode->SetAttribute("def_file", cbU2C(target->GetDynamicLibDefFilename()));
+ outnode->SetAttribute("def_file", cbU2C(NativeToUnix(target->GetDynamicLibDefFilename())));
}
outnode->SetAttribute("prefix_auto", prefixPolicy == tgfpPlatformDefault ? "1" : "0");
outnode->SetAttribute("extension_auto", extensionPolicy == tgfpPlatformDefault ? "1" : "0");
if (target->GetWorkingDir() != _T("."))
- AddElement(tgtnode, "Option", "working_dir", target->GetWorkingDir());
+ AddElement(tgtnode, "Option", "working_dir", NativeToUnix(target->GetWorkingDir()));
if (target->GetObjectOutput() != _T(".objs"))
- AddElement(tgtnode, "Option", "object_output", target->GetObjectOutput());
+ AddElement(tgtnode, "Option", "object_output", NativeToUnix(target->GetObjectOutput()));
if (target->GetDepsOutput() != _T(".deps"))
- AddElement(tgtnode, "Option", "deps_output", target->GetDepsOutput());
+ AddElement(tgtnode, "Option", "deps_output", NativeToUnix(target->GetDepsOutput()));
}
if (!target->GetExternalDeps().IsEmpty())
AddElement(tgtnode, "Option", "external_deps", target->GetExternalDeps());
@@ -1377,7 +1377,7 @@
ProjectFile* f = pfa[i];
FileType ft = FileTypeOf(f->relativeFilename);
- TiXmlElement* unitnode = AddElement(prjnode, "Unit", "filename", f->relativeFilename);
+ TiXmlElement* unitnode = AddElement(prjnode, "Unit", "filename", NativeToUnix(f->relativeFilename));
if (!f->compilerVar.IsEmpty())
{
wxString ext = f->relativeFilename.AfterLast(_T('.')).Lower();
@@ -1404,7 +1404,7 @@
AddElement(unitnode, "Option", "weight", f->weight);
if (!f->virtual_path.IsEmpty())
- AddElement(unitnode, "Option", "virtualFolder", f->virtual_path);
+ AddElement(unitnode, "Option", "virtualFolder", NativeToUnix(f->virtual_path));
// loop and save custom build commands
for (pfCustomBuildMap::iterator it = f->customBuild.begin(); it != f->customBuild.end(); ++it)
Index: src/include/globals.h
===================================================================
--- src/include/globals.h (revision 8133)
+++ src/include/globals.h (working copy)
@@ -181,6 +181,7 @@
extern DLLIMPORT void AppendArray(const wxArrayString& from, wxArrayString& to);
extern DLLIMPORT wxString UnixFilename(const wxString& filename);
+extern DLLIMPORT wxString NativeToUnix(const wxString& filename);
extern DLLIMPORT void QuoteStringIfNeeded(wxString& str);
/// Escapes spaces and tabs (NOT quoting the string)
--- End code ---
MortenMacFly:
--- Quote from: Alpha on July 16, 2012, 04:05:41 am ---Try this patch:
--- End quote ---
This is a nice work, however, it is not that easy, and therefoe this patch is incomplete:
* include directories are not converted
* commands are not converted (that's a tricky part, as e.g. zip -jq9 devel/share/CodeBlocks/resources.zip *.png won't work on some zip distros on Windows)
* command line parameters are not converted, tricky, too
* external deps are not converted
* UNC names / path's are not handled correctly
* Why didn't you use the existing UnixFilename method? NativeToUnix won'T work with macros IMHO, and macros should be considered for path's.
So in the end the user is responsible for doing some of these points, maybe, but nevertheless you still get two different project files if you save the same under Linux and Windows. :-\ :(
MortenMacFly:
...just an idea: Wouldn't it be enough to use generally use UnixFilename (including the places where you converted wxFileName to wxPATH_UNIX and used NativeToUnix), but then implement the Windows part in this method as following:
--- Code: --- if (platform::windows)
{
bool unc_name = result.StartsWith(_T("\\\\"));
while (result.Replace(_T("/"), _T("\\")))
;
while (result.Replace(_T("\\\\"), _T("\\")))
;
if (unc_name)
result = _T("\\") + result;
else // THIS PART IS NEW!!!
{
while (result.Replace(_T("\\"), _T("/")))
;
}
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version