Author Topic: Issue about saving the cbp project file  (Read 18161 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Issue about saving the cbp project file
« on: February 06, 2012, 01:50:51 am »
Steps to reproduce: (WinXP)
1, open a clean Codeblocks.cbp in a recent debugger branch nightly build.
2, change the command argument for src, like adding "-p=debugCC".
3, close this project.

Now, I can see that:
1, The EOL changing from CRLF to LF
2, There are many other changes like:
Code
Index: E:/code/cb/cb_trunk/src/CodeBlocks.cbp
===================================================================
--- E:/code/cb/cb_trunk/src/CodeBlocks.cbp (revision 7781)
+++ E:/code/cb/cb_trunk/src/CodeBlocks.cbp (working copy)
@@ -24,7 +24,7 @@
  </Linker>
  </Target>
  <Target title="tinyXML">
- <Option output="base\tinyxml\txml" prefix_auto="1" extension_auto="1" />
+ <Option output="base\tinyxml\libtxml" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option type="2" />
  <Option compiler="gcc" />
@@ -60,7 +60,7 @@
  </Compiler>
  </Target>
  <Target title="Squirrel">
- <Option output="sdk\scripting\lib\squirrel" prefix_auto="1" extension_auto="1" />
+ <Option output="sdk\scripting\lib\libsquirrel" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option type="2" />
  <Option compiler="gcc" />
@@ -74,7 +74,7 @@
  </Linker>
  </Target>
  <Target title="Squirrel std lib">
- <Option output="sdk\scripting\lib\sqstdlib" prefix_auto="1" extension_auto="1" />
+ <Option output="sdk\scripting\lib\libsqstdlib" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option external_deps="sdk\scripting\lib\libsquirrel.a;" />
  <Option type="2" />
@@ -89,7 +89,7 @@
  </Linker>
  </Target>
  <Target title="SqPlus">
- <Option output="sdk\scripting\lib\sqplus" prefix_auto="1" extension_auto="1" />
+ <Option output="sdk\scripting\lib\libsqplus" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option external_deps="sdk\scripting\lib\libsquirrel.a;sdk\scripting\lib\libsqstdlib.a;" />
  <Option type="2" />
@@ -104,7 +104,7 @@
  </Linker>
  </Target>
  <Target title="scintilla">
- <Option output="devel\wxscintilla_cb" prefix_auto="1" extension_auto="1" />
+ <Option output="devel\libwxscintilla_cb" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option type="2" />
  <Option compiler="gcc" />
@@ -205,7 +205,7 @@
  <Option external_deps="devel\libcodeblocks.a;" />
  <Option type="0" />
  <Option compiler="gcc" />
- <Option parameters="--debug-log --no-dde --no-check-associations --multiple-instance --no-splash-screen" />
+ <Option parameters="--debug-log --no-dde --no-check-associations --multiple-instance --no-splash-screen -p=debugCC" />
  <Option projectLinkerOptionsRelation="2" />
  <Compiler>
  <Add option="-DBUILDING_PLUGIN" />
@@ -316,7 +316,7 @@
  </Linker>
  </Target>
  <Target title="Compiler depslib">
- <Option output="plugins\compilergcc\depslib\depslib" prefix_auto="1" extension_auto="1" />
+ <Option output="plugins\compilergcc\depslib\libdepslib" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option type="2" />
  <Option compiler="gcc" />

So, Can I have some methods to solve this?

Thank you.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #1 on: February 06, 2012, 09:52:50 am »
So, Can I have some methods to solve this?
A known annoyance: The prefix policy is not correctly applied when the project file is saved. IIRC this is not easily possible because it depends on the compiler settings and a the point where this is written, you don't have access to the compiler (I might be wrong though!!!).

However, it doesn't really matter as C::B will handle this later (on load) just fine.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Issue about saving the cbp project file
« Reply #2 on: February 06, 2012, 10:20:02 am »
However, it doesn't really matter as C::B will handle this later (on load) just fine.
Hm, it matters a lot, because if you're not careful you'll do a useless commit.
Can you please give a better explanation, because I don't think I understood the reason for the bug?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #3 on: February 06, 2012, 10:43:15 am »
Can you please give a better explanation, because I don't think I understood the reason for the bug?
Have a look at:
ProjectLoader::ExportTargetAsProject(const wxString& filename, const wxString& onlyTarget, TiXmlElement* pExtensions)
While you do know the extension of the output file by its type, for the prefix you would need access to the compiler to query if and what prefix to apply to dynamic / static libraries.

It's simply not done, have a look at the code starting here:
if (target->GetTargetType() != ttCommandsOnly)

What's missing i something like:
Code
            if (prefixPolicy == tgfpPlatformDefault)
            {
                if (outputFileName.StartsWith(LIB_PREFIX_BY_COMPILER))
                    outputFileName = OUTPUT_FILE_NAME_WO_PREFIX;
            }
« Last Edit: February 06, 2012, 10:45:20 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #4 on: February 06, 2012, 10:50:13 am »
Code
            if (prefixPolicy == tgfpPlatformDefault)
            {
                if (outputFileName.StartsWith(LIB_PREFIX_BY_COMPILER))
                    outputFileName = OUTPUT_FILE_NAME_WO_PREFIX;
            }
...a better quick hack:
Code
            if (   prefixPolicy == tgfpPlatformDefault
                && (   (!platform::windows && target->GetTargetType() == ttDynamicLib)
                    || (target->GetTargetType() == ttStaticLib) ) )
            {
                wxString compilerId = target->GetCompilerID();
                Compiler* compiler = CompilerFactory::GetCompiler(compilerId);
                if (compiler)
                {
                    wxString compilerLibPrefix(compiler->GetSwitches()->libPrefix);
                    wxString outputFileNameWOPrefix;
                    if (outputFileName.StartsWith(compilerLibPrefix))
                        outputFileNameWOPrefix = outputFileName.Mid(compilerLibPrefix.Len());
                    if (!outputFileNameWOPrefix.IsEmpty())
                        outputFileName = outputFileNameWOPrefix;
                }
            }
NOT TESTED, NOT EVEN COMPILED!
...but something like this is needed.

EDIT: Fixed an obvious error, even in pseudo-code ;-)
« Last Edit: February 06, 2012, 11:00:26 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #5 on: February 06, 2012, 10:58:30 am »
...a better quick hack:
Hey, this one should actually already work - can someone try? (I don't have access to Code::Blocks to try myself at the moment).

Edit: Aaaah - nope, something is missing. If I read it correctly, then outputFileName at that point included the full path... that won't work. However, you surely get the idea...
« Last Edit: February 06, 2012, 11:01:47 am by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #6 on: February 06, 2012, 11:11:19 am »
...OK - another trial. Who will try this:
Code
            if (   (prefixPolicy == tgfpPlatformDefault)
                && (   (!platform::windows && target->GetTargetType() == ttDynamicLib)
                    || (target->GetTargetType() == ttStaticLib) ) )
            {
                wxString compilerId = target->GetCompilerID();
                Compiler* compiler = CompilerFactory::GetCompiler(compilerId);
                if (compiler)
                {
                    wxFileName fname(outputFileName);
                    wxString outputFileNameFile(fname.GetFullName());

                    wxString compilerLibPrefix(compiler->GetSwitches().libPrefix);
                    wxString outputFileNameWOPrefix;
                    if (outputFileNameFile.StartsWith(compilerLibPrefix))
                    {
                        outputFileNameWOPrefix = outputFileNameFile.Mid(compilerLibPrefix.Len());
                        if (!outputFileNameWOPrefix.IsEmpty())
                        {
                            fname.SetFullName(outputFileNameWOPrefix);
                            outputFileName = fname.GetFullPath();
                        }
                    }
                }
            }
?
;D
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Issue about saving the cbp project file
« Reply #7 on: February 06, 2012, 01:03:08 pm »
...OK - another trial. Who will try this:
Code
            if (   (prefixPolicy == tgfpPlatformDefault)
                && (   (!platform::windows && target->GetTargetType() == ttDynamicLib)
                    || (target->GetTargetType() == ttStaticLib) ) )
            {
                wxString compilerId = target->GetCompilerID();
                Compiler* compiler = CompilerFactory::GetCompiler(compilerId);
                if (compiler)
                {
                    wxFileName fname(outputFileName);
                    wxString outputFileNameFile(fname.GetFullName());

                    wxString compilerLibPrefix(compiler->GetSwitches().libPrefix);
                    wxString outputFileNameWOPrefix;
                    if (outputFileNameFile.StartsWith(compilerLibPrefix))
                    {
                        outputFileNameWOPrefix = outputFileNameFile.Mid(compilerLibPrefix.Len());
                        if (!outputFileNameWOPrefix.IsEmpty())
                        {
                            fname.SetFullName(outputFileNameWOPrefix);
                            outputFileName = fname.GetFullPath();
                        }
                    }
                }
            }
?
;D

I test it and the result looks like:
Code
 		<Build>
  <Target title="exchndl">
  <Option platforms="Windows;" />
- <Option output="devel\exchndl" prefix_auto="1" extension_auto="1" />
+ <Option output="devel\exchndl.dll" prefix_auto="1" extension_auto="1" />
  <Option working_dir="devel" />
  <Option type="3" />
  <Option compiler="gcc" />
@@ -24,7 +24,7 @@
  </Linker>
  </Target>
  <Target title="tinyXML">
- <Option output="base\tinyxml\txml" prefix_auto="1" extension_auto="1" />
+ <Option output="base\tinyxml\txml.a" prefix_auto="1" extension_auto="1" />
  <Option working_dir="" />
  <Option type="2" />
  <Option compiler="gcc" />
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #8 on: February 06, 2012, 01:05:55 pm »
I test it and the result looks like:
Code
-				<Option output="devel\exchndl" prefix_auto="1" extension_auto="1" />
+ <Option output="devel\exchndl.dll" prefix_auto="1" extension_auto="1" />
Hmmm... that is weird. Did you remove the extension policy? The code snippet was intended to be added and not to replace something.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Issue about saving the cbp project file
« Reply #9 on: February 06, 2012, 01:16:03 pm »
I test it and the result looks like:
Code
-				<Option output="devel\exchndl" prefix_auto="1" extension_auto="1" />
+ <Option output="devel\exchndl.dll" prefix_auto="1" extension_auto="1" />
Hmmm... that is weird. Did you remove the extension policy? The code snippet was intended to be added and not to replace something.
Oh, I removed the original code snippets in the if statement. I'm adding them and test again.
Do you mean like below:
Code
Index: E:/code/cb/cb_trunk/src/sdk/projectloader.cpp
===================================================================
--- E:/code/cb/cb_trunk/src/sdk/projectloader.cpp (revision 7781)
+++ E:/code/cb/cb_trunk/src/sdk/projectloader.cpp (working copy)
@@ -1163,8 +1163,29 @@
             target->GetTargetFilenameGenerationPolicy(prefixPolicy, extensionPolicy);
 
             wxString outputFileName = target->GetOutputFilename();
-            if (extensionPolicy == tgfpPlatformDefault)
+            if (   (prefixPolicy == tgfpPlatformDefault)
+                && (   (!platform::windows && target->GetTargetType() == ttDynamicLib)
+                    || (target->GetTargetType() == ttStaticLib) ) )
             {
+                wxString compilerId = target->GetCompilerID();
+                Compiler* compiler = CompilerFactory::GetCompiler(compilerId);
+                if (compiler)
+                {
+                    wxFileName fname(outputFileName);
+                    wxString outputFileNameFile(fname.GetFullName());
+
+                    wxString compilerLibPrefix(compiler->GetSwitches().libPrefix);
+                    wxString outputFileNameWOPrefix;
+                    if (outputFileNameFile.StartsWith(compilerLibPrefix))
+                    {
+                        outputFileNameWOPrefix = outputFileNameFile.Mid(compilerLibPrefix.Len());
+                        if (!outputFileNameWOPrefix.IsEmpty())
+                        {
+                            fname.SetFullName(outputFileNameWOPrefix);
+                            outputFileName = fname.GetFullPath();
+                        }
+                    }
+                }
                 wxFileName fname(outputFileName);
                 fname.ClearExt();
                 outputFileName = fname.GetFullPath();


I tested but it still give the same diff files.

EDIT
Oh, I made a mistake:
Code
-            if (extensionPolicy == tgfpPlatformDefault)
+            if (   (prefixPolicy == tgfpPlatformDefault)

I should preserve a old policy (if statement).

« Last Edit: February 06, 2012, 01:23:38 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Issue about saving the cbp project file
« Reply #10 on: February 06, 2012, 01:31:39 pm »
Ok, it works OK now, with this patch:
Code
Index: E:/code/cb/cb_trunk/src/sdk/projectloader.cpp
===================================================================
--- E:/code/cb/cb_trunk/src/sdk/projectloader.cpp (revision 7781)
+++ E:/code/cb/cb_trunk/src/sdk/projectloader.cpp (working copy)
@@ -1169,7 +1169,31 @@
                 fname.ClearExt();
                 outputFileName = fname.GetFullPath();
             }
+            if (   (prefixPolicy == tgfpPlatformDefault)
+                && (   (!platform::windows && target->GetTargetType() == ttDynamicLib)
+                    || (target->GetTargetType() == ttStaticLib) ) )
+            {
+                wxString compilerId = target->GetCompilerID();
+                Compiler* compiler = CompilerFactory::GetCompiler(compilerId);
+                if (compiler)
+                {
+                    wxFileName fname(outputFileName);
+                    wxString outputFileNameFile(fname.GetFullName());
 
+                    wxString compilerLibPrefix(compiler->GetSwitches().libPrefix);
+                    wxString outputFileNameWOPrefix;
+                    if (outputFileNameFile.StartsWith(compilerLibPrefix))
+                    {
+                        outputFileNameWOPrefix = outputFileNameFile.Mid(compilerLibPrefix.Len());
+                        if (!outputFileNameWOPrefix.IsEmpty())
+                        {
+                            fname.SetFullName(outputFileNameWOPrefix);
+                            outputFileName = fname.GetFullPath();
+                        }
+                    }
+                }
+            }
+
             TiXmlElement* outnode = AddElement(tgtnode, "Option", "output", outputFileName);
             outnode->SetAttribute("prefix_auto", prefixPolicy == tgfpPlatformDefault ? "1" : "0");
             outnode->SetAttribute("extension_auto", extensionPolicy == tgfpPlatformDefault ? "1" : "0");

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue about saving the cbp project file
« Reply #11 on: February 06, 2012, 01:59:12 pm »
Ok, it works OK now, with this patch:
Good to know. Feel free t commit making oBFusCATed happy... hopefully... ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Issue about saving the cbp project file
« Reply #12 on: February 06, 2012, 02:16:05 pm »
Ok, it works OK now, with this patch:
Good to know. Feel free t commit making oBFusCATed happy... hopefully... ;-)

OK, done At revision: 7782.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Issue about saving the cbp project file
« Reply #13 on: July 29, 2013, 10:52:50 am »
Hi, Morten, I need to bump this thread again, as I nowadays still find annoying issue about this:
Steps to reproduce: (WinXP)
1, open a clean Codeblocks.cbp in a recent debugger branch nightly build.
2, change the command argument for src, like adding "-p=debugCC".
3, close this project.

Now, I can see that:
1, The EOL changing from CRLF to LF

See, the cbp file was saved from CRLF to LF always. This always give me a warning if I commit to the git local repo. (git would say that: warning: LF will be replaced by CRLF in such cbp files in the repo.....)

I trace down and found that in the last stage of saving cbp file, we have such code:
Code
bool TinyXML::SaveDocument(const wxString& filename, TiXmlDocument* doc)
{
    if (!doc)
        return false;

    TiXmlPrinter printer;
    printer.SetIndent("\t");
    doc->Accept(&printer);

    return Manager::Get()->GetFileManager()->SaveUTF8(filename, printer.CStr(), printer.Size());
}

Here, we create a printer object, which has:
Code
class TiXmlPrinter : public TiXmlVisitor
{
public:
TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
buffer(), indent( "    " ), lineBreak( "\n" ) {}

Look, it always use lineBreak( "\n" ).

Can we fix it by setting the lineBreak by platform?
Thanks.


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Issue about saving the cbp project file
« Reply #14 on: July 29, 2013, 01:37:33 pm »
Look, if GIT is too stupid to handle files it shouldn't touch at all, then that's sad. In particular because GIT is a Linux revision control system, and these are Unix line endings. But frankly, it's GIT's problem, not ours. GIT has no reason to look into .cbp files at all, for all it knows, these are binary files, just like .conf files.

Please don't tamper with code that works fine only to make it worse just so some unimportant third party program doesn't complain. If users of this third party program are unhappy with its operation, they can either fix their settings so it properly ignores the files, or they can complain with the maintainer of that program.

There was a similar issue with people editing .conf files in a text editor and complaining that they were broken afterwards. Because, hey, if something looks like you could edit it, then it is totally necessary that you do. I was at some point tempted to rot13 encode config files only for that reason.
« Last Edit: July 29, 2013, 01:39:07 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."