cancel
Showing results for 
Search instead for 
Did you mean: 

Bug report: TouchGFX generates .cproject using spaces, CubeMX uses tabs

Tuoman
Senior II

This will result to version control to annoyingly showing the whole file as changed when you use both generation tools now and then.

Please fix either CubeMX or TouchGFX to use same format? Thanks!

4 REPLIES 4

Hello Tuoman,

Thanks for your feedback, but the problem doesn't seem very clear. Could you please precise the scenario you have reproduced ? Which MCU are you working with and what version of CubeMX are you using?

It will be helpful to investigate the root cause of the problem.

I will be waiting for your response.

Thanks in advance,

Khouloud.

>Thanks for your feedback, but the problem doesn't seem very clear. Could you please precise the scenario you have reproduced ?

  1. Create TouchGFX project in CubeMX
  2. Open TouchGFX project (.touchgfx file in the project folder)
  3. Click Generate Code
  4. TouchGFX will generate .cproject file using spaces
  5. Open CubeMX project (.ioc file in the project folder)
  6. Generate Code in CubeMX
  7. CubeMX will generate .cproject file using tabs, showing in version control that 100% of lines have changed, even without any changes

>Which MCU are you working with and what version of CubeMX are you using?

CubeMX 6.1.0, STM32H7B3. This should not have anything to do with specific MCU.

Issue seems quite clear to me. TouchGFX and CubeMX both generate code to the same .cproject file. However, CubeMX generates the .cproject using tabs when generated using CubeMX, and TouchGFX generates the .cproject using spaces when generated with TouchGFX.

This is annoying for version control, when it always overrides the whole file when nothing is actually changed in the .cproject file.

And there is no reason that other generator uses spaces, and the other generator uses tabs. Choose one or another for both.

Hi Tuoman,

Thanks for this detailed description. I have reported your request internally to be reviewed and fixed.

I will keep posted.

Thank you for your contribution,

Khouloud.

ferro
Lead

https://community.st.com/t5/stm32cubeide-mcus/cube-1-16-1-and-gfxdesigner-4-24-1-generates-different-cproject/m-p/778202/highlight/true#M34644

 

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")