2022-04-22 7:15 PM
When TouchGFX generates code to a project's .cproject, it uses spaces. When STM32CubeIDE saves to .cproject, spaces are replaced by Tabs. This causes Git (SourceTree) to label every line in an otherwise identical project file as changed. The actions of the two environments need to be coordinated such that both use the same whitespace characters (preferably spaces).
2022-04-23 1:44 AM
C'mon, STM32CubeIDE (Eclipse) is an IDE and should be capable of dealing with both.
https://stackoverflow.com/questions/407929/how-do-i-change-eclipse-to-use-spaces-instead-of-tabs
2022-04-24 3:35 PM
Thanks for the suggestion. I'm aware that Eclipse can be configured to use spaces, and I've been setting my code style preferences for C/C++, Java, xml, etc. for many years to use spaces (in both Eclipse proper, and in a number of manufacturer IDEs based on Eclipse). However, in STM32CubeIDE, the .cproject file (an XML file), the IDE does not apply Tabs vs Spaces settings when saving the .cproject file. Indeed, an XML editor is not installed in the IDE by default. I don't care if it's tabs or spaces---I'm simply asking that ST coordinate its tools so that one need not deal with this issue.
2025-03-03 2:02 AM - edited 2025-03-03 2:03 AM
This python script fixes the .cproject
#
# Tested on Windows, Cube 1.17, Gfx 4.24.1
# This script processes a `.cproject` file with the following modifications:
# 1. Replaces every two-space indentation with a tab.
# 2. Uses CRLF (`\r\n`) as the newline format.
# 3. Merges lines 2 and 3 into line 2 with no extra characters between them.
# 4. Ensures the last line is exactly `</cproject>`, with no EOF or trailing newline.
#
import os
def process_cproject_file(filename):
with open(filename, 'r', encoding='utf-8') as file:
content = file.read()
# Force CRLF as the newline type
newline_type = '\r\n'
# Split into lines while preserving newline characters
lines = content.splitlines()
# Replace leading spaces with corresponding number of tabs
processed_lines = []
for line in lines:
leading_spaces = len(line) - len(line.lstrip())
tabs = '\t' * (leading_spaces // 2) # Each two spaces become one tab
processed_lines.append(tabs + line.lstrip())
# Combine lines 2 and 3 into line 2 with no extra space
if len(processed_lines) > 2:
processed_lines[1] = processed_lines[1].rstrip() + processed_lines[2].lstrip()
del processed_lines[2]
# Ensure last element is exactly '</cproject>' with no extra newlines or EOF
processed_lines[-1] = '</cproject>'
# Write back changes using CRLF and ensure no trailing newline
with open(filename, 'w', encoding='utf-8', newline='') as file:
file.write(newline_type.join(processed_lines))
if __name__ == "__main__":
process_cproject_file(".cproject")
2025-03-03 2:54 AM
This is a known issue:
https://community.st.com/t5/stm32-mcus-touchgfx-and-gui/touchgfx-designer-adds-redundant-line-ending-to-cproject-file/td-p/674111
Last version I tested it with was 4.24.1. Maybe it's fixed in the newer version? I haven't checked yet. Please check.