Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space in compilator path not escaped in compilation_db #4998

Closed
1 task
HanyzPAPU opened this issue Oct 14, 2024 · 6 comments
Closed
1 task

Space in compilator path not escaped in compilation_db #4998

HanyzPAPU opened this issue Oct 14, 2024 · 6 comments

Comments

@HanyzPAPU
Copy link

HanyzPAPU commented Oct 14, 2024

  • PlatformIO Core.
    If you’ve found a bug, please provide an information below.

Configuration

Operating system:

Windows, with a username who has a space in the username.

PlatformIO Version (platformio --version):

PlatformIO Core, version 6.1.16

Description of problem

When the path to the .platformio contains a space (for example in the username), the compile_commands.json produced by running pio run -t compiledb does not escape the compiler executable path in the command fields.

Steps to Reproduce

  1. Have a user with a space in the username
  2. Install PlatformIO, create a new project.
  3. Run pio run -t compiledb

Actual Results

Example of a malformed command:

{"command": "C:\\Users\\Karel Mezera\\.platformio\\packages\\toolchain-gccarmnoneeabi\\bin\\arm-none-eabi-g++.exe -o .pio\\build\\nrf52840_dk\\FrameworkArduinoVariant\\variant.cpp.o -c -fno-rtti -fno-exceptions -std=gnu++11 -fno-threadsafe-statics -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib --param max-inline-insns-single=500 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -DPLATFORMIO=60116 -DARDUINO_NRF52_DK -DARDUINO=10805 -DF_CPU=16000000L -DARDUINO_ARCH_NRF5 -DNRF5 -DNRF52 -DUSE_LFXO \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\drivers_nrf\\delay\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\device\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\toolchain\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\toolchain\\CMSIS\\Include\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\variants\\nRF52DK\" \"C:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\variants\\nRF52DK\\variant.cpp\"",
        "directory": "C:\\Users\\Karel Mezera\\Documents\\CLionProjects\\untitled",
        "file": "C:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\variants\\nRF52DK\\variant.cpp",
        "output": ".pio\\build\\nrf52840_dk\\FrameworkArduinoVariant\\variant.cpp.o"
    }

Expected Results

{"command": "\"C:\\Users\\Karel Mezera\\.platformio\\packages\\toolchain-gccarmnoneeabi\\bin\\arm-none-eabi-g++.exe\" -o .pio\\build\\nrf52840_dk\\FrameworkArduinoVariant\\variant.cpp.o -c -fno-rtti -fno-exceptions -std=gnu++11 -fno-threadsafe-statics -Os -ffunction-sections -fdata-sections -Wall -mthumb -nostdlib --param max-inline-insns-single=500 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -DPLATFORMIO=60116 -DARDUINO_NRF52_DK -DARDUINO=10805 -DF_CPU=16000000L -DARDUINO_ARCH_NRF5 -DNRF5 -DNRF52 -DUSE_LFXO \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\drivers_nrf\\delay\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\device\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\toolchain\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\cores\\nRF5\\SDK\\components\\toolchain\\CMSIS\\Include\" \"-IC:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\variants\\nRF52DK\" \"C:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\variants\\nRF52DK\\variant.cpp\"",
        "directory": "C:\\Users\\Karel Mezera\\Documents\\CLionProjects\\untitled",
        "file": "C:\\Users\\Karel Mezera\\.platformio\\packages\\framework-arduinonordicnrf5\\variants\\nRF52DK\\variant.cpp",
        "output": ".pio\\build\\nrf52840_dk\\FrameworkArduinoVariant\\variant.cpp.o"
    }

Notice the added \" around the compiler executable.

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:nrf52840_dk]
platform = nordicnrf52
board = nrf52840_dk
framework = arduino

Source file to reproduce issue:

#include <Arduino.h>
void setup(){}
void loop(){}
@ivankravets
Copy link
Member

Could you point to the specification that documents {"command": "\"C:\?

@HanyzPAPU
Copy link
Author

JSON Compilation Database Format Specification allows shell escaping inside of the command string.

Windows Command Prompt syntax remarks states that a path with spaces should be enclosed in quotation marks.

To achieve this, the quotation marks have to be inside of the JSON string, and according to the JSON specification should be escaped as \".

@ivankravets
Copy link
Member

How do we reproduce this issue? With which type of software do you use compilation_db?

Indeed, the end command runner (3rd party software, shell, etc) is responsible to handle "spaces" in the path.

@HanyzPAPU
Copy link
Author

How do we reproduce this issue?

Parsing the compilation_db by any JSON parser (to correctly unescape the strings) and consequently trying to run the content of the "command" field in Command Prompt should be able to reproduce.

With which type of software do you use compilation_db?

The compilation_db is used by the plugin for CLion.

@ivankravets ivankravets added this to the 6.1.17 milestone Oct 17, 2024
@ivankravets
Copy link
Member

Thanks for the report. Please re-test with pio upgrade --dev.

@HanyzPAPU
Copy link
Author

Just tried it out, and the problem's gone. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants