cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX Designer adds redundant line ending to .cproject file

TouchGFX adds a redundant line ending to .cproject file when clicking generate code even if nothing has changed.

This causes changes to show up in git and also makes merging and pull requests more complicated.

In STM32CubeIDE the line ending is removed after making any change to the project (and optionally reverting the change).

 

-<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+<?fileVersion 4.0.0?>
+<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">

 

I'm using TouchGFX 4.23.2, but the problem was also present in older versions. Using STM32CubeIDE 1.15.1, but older version had the same effect.

Please fix this.

 

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
14 REPLIES 14
jchernus-fikst
Associate III

I am very sad to share that this behaviour continues in 4.25. 

It's caused me plenty of unnecessary pain - most times I remember to open the file in VS Code and run the "Convert Indentation to Tabs" quick action.. but sometimes I don't, and then I have to fix what's been checked into Git.

I really hope this is fixed in the next minor release!

It's why I use git gui to check in files. I visually inspect all files before creating any commit. I never do "git add .".

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
GaetanGodart
ST Employee

Hello @jchernus-fikst and @unsigned_char_array ,

 

The issue won't be fixed because TouchGFX and STM32CubeIDE both uses a different 3rd party library to generate the .cproject file.

 

As @unsigned_char_array said, you can manually check the content of the .cproject if it has changed and check if the change is only that line ending difference to choose to commit it or not.
Git GUI or other GUI based Git manager are good for that.

 

Something else you could do -and this seems like the right solution- is to use a .gitattributes file like so :

*.cproject text eol=lf
*.cproject -diff

 

 Other solutions could be to use a git merge driver by adding

*.cproject merge=ours

to the .gitattributes file and configure the merge driver in bash with this command :
git config --global merge.ours.driver true

 

Finally, you could use a custom script to check for the specific line ending.

 

Regards,

Gaetan Godart
Software engineer at ST (TouchGFX)

@GaetanGodart wrote:

The issue won't be fixed because TouchGFX and STM32CubeIDE both uses a different 3rd party library to generate the .cproject file.

I don't understand this reasoning. I don't know what programming language and tools you use for developing.
The library outputs a string that's written to a file or it directly writes to a file. In the first case a simple regex can fix the string and then write the correct string to the file. In case of the latter you can read, apply regex and write to the file again after the file was modified. This is only a few lines of code.
Example:
https://regex101.com/r/MqQ7Mv/1

from code generator (C#):

 

string pattern = @"(<\?fileVersion 4\.0\.0\?>)\s";
string substitution = @"$1";
RegexOptions options = RegexOptions.Multiline;        
Regex regex = new Regex(pattern, options);
string result = regex.Replace(input, substitution);

 

From code generator (python):

 

import re

regex = r"(<\?fileVersion 4\.0\.0\?>)\s"
subst = "$1"
result = re.sub(regex, subst, input, count=0, flags=re.MULTILINE)

 

Or write a bug report for the 3rd party library in question.


@GaetanGodart wrote:

you can manually check the content of the .cproject if it has changed and check if the change is only that line ending difference to choose to commit it or not.
Git GUI or other GUI based Git manager are good for that.


That's the entire problem. It's a manual check that can be forgotten. We work in teams on the same project and this obstructs our workflow. When discovered it's often too late and rewriting git history is something we like to avoid. TouchGFX should not modify .cproject if nothing has changed. It should be consistent with STM32CubeIDE.

 


@GaetanGodart wrote:

Something else you could do -and this seems like the right solution- is to use a .gitattributes file like so :

 

*.cproject text eol=lf
*.cproject -diff

 

 


This is not going to fix the problem. It doesn't matter what the line ending is. The problem is that an extra line ending is added.

 


@GaetanGodart wrote:

 Other solutions could be to use a git merge driver by adding

 

*.cproject merge=ours

 

This will mask the problem of merge conflicts in .cproject. And we don't know if "ours" is the correct version. So this won't work.


@GaetanGodart wrote:

Finally, you could use a custom script to check for the specific line ending.


Again the issue is not the type of line ending, but the fact an extra one is inserted and inconsistent with STM32CubeIDE. The "custom script" is called TouchGFX and it should be consistent with other tools such as STM32CubeMX and STM32CubeIDE. The only thing it's consistent with is this forum as this forum also adds extra line endings to posts when editing posts.
Post Generate Target Command:

touchgfx update_project

I would hate it if I have to do regex in a batch file just to fix this issue.

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
jchernus-fikst
Associate III

I agree entirely with @unsigned_char_array, the fix isn't hard, but it impedes the velocity at which our teams develop.

We only use one set of tools on our project - ST tools. To have them conflict with each other feels unpolished.

 

Am I the only one for whom TouchGFX also converts all tabs to spaces? Have others found a fix for that?