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

Static code analysis fails when project path contains spaces #4927

Open
1 of 5 tasks
sssmc opened this issue Jun 3, 2024 · 1 comment
Open
1 of 5 tasks

Static code analysis fails when project path contains spaces #4927

sssmc opened this issue Jun 3, 2024 · 1 comment

Comments

@sssmc
Copy link

sssmc commented Jun 3, 2024

What kind of issue is this?

  • Question.
    This issue tracker is not the place for questions. If you want to ask how to do something,
    or to understand why something isn't working the way you expect it to,
    use Community Forums or Premium Support

  • PlatformIO IDE.
    All issues related to PlatformIO IDE should be reported to the
    PlatformIO IDE for VSCode repository

  • Development Platform or Board.
    All issues (building, uploading, adding new boards, etc.) related to PlatformIO development platforms
    should be reported to appropriate repository related to your hardware
    https://github.com/topics/platformio-platform

  • Feature Request.
    Start by telling us what problem you’re trying to solve. Often a solution
    already exists! Don’t send pull requests to implement new features without first getting our
    support. Sometimes we leave features out on purpose to keep the project small.

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

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system:
Windows 11 Version 23H2(OS Build 22631.3447)

PlatformIO Version (platformio --version):
PlatformIO Core, version 6.1.15

Description of problem

Running static code analysis in a project with a project path containing spaces cause the analysis to fail.

Steps to Reproduce

1.Start static code analysis from the inspect menu

Actual Results

Error: Checking nucleo_f446re > cppcheck (platform: ststm32; board: nucleo_f446re; framework: arduino)
--------------------------------------------------------------------------------
Warning: Failed to extract toolchain defines!

'C:\Users\Sebastien' is not recognized as an internal or external command,
operable program or batch file.

Warning: Failed to extract toolchain defines!

'C:\Users\Sebastien' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Sebastien Robitaille\.platformio\packages\tool-cppcheck\cppcheck --addon-python=C:\Users\Sebastien Robitaille\.platformio\penv\Scripts\python.exe --error-exitcode=3 --verbose --template="severity={severity}<&PIO&>message={message}<&PIO&>file={file}<&PIO&>line={line}<&PIO&>column={column}<&PIO&>callstack={callstack}<&PIO&>cwe={cwe}<&PIO&>id={id}" --inline-suppr --platform=unspecified --enable=warning,style,performance,portability,unusedFunction --language=c++ --std=c++17 -DPLATFORMIO=60115 -DSTM32F446xx -DSTM32F4xx -DARDUINO=10808 -DARDUINO_ARCH_STM32 -DNDEBUG -DARDUINO_NUCLEO_F446RE -DBOARD_NAME="NUCLEO_F446RE" -DHAL_UART_MODULE_ENABLED -DUSE_FULL_LL_DRIVER -DVARIANT_H="variant_NUCLEO_F446RE.h" -DVECT_TAB_OFFSET=0x0 --includes-file=C:\Users\SEBAST~1\AppData\Local\Temp\tmpf2jrg_2p "C:\Users\Sebastien Robitaille\Documents\git\BugTesting\src\main.cpp"
Checking C:\Users\Sebastien Robitaille\Documents\git\BugTesting\src\main.cpp ...

Defines:PLATFORMIO=60115;STM32F446xx=1;STM32F4xx=1;ARDUINO=10808;ARDUINO_ARCH_STM32=1;NDEBUG=1;ARDUINO_NUCLEO_F446RE=1;BOARD_NAME="NUCLEO_F446RE";HAL_UART_MODULE_ENABLED=1;USE_FULL_LL_DRIVER=1;VARIANT_H="variant_NUCLEO_F446RE.h";VECT_TAB_OFFSET=0x0

Undefines:

Includes: -IC:/Users/Sebastien Robitaille/Documents/git/BugTesting/include/ -IC:/Users/Sebastien Robitaille/Documents/git/BugTesting/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/avr/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/LL/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/OpenAMP/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/hid/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/stm32/usb/cdc/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F4xx_HAL_Driver/Inc/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Drivers/STM32F4xx_HAL_Driver/Src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/STM32F4xx/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/open-amp/lib/include/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/libmetal/lib/include/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Middlewares/OpenAMP/virtual_driver/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-cmsis/CMSIS/Core/Include/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F4xx/Include/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/system/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-cmsis/CMSIS/DSP/Include/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-cmsis/CMSIS/DSP/PrivateInclude/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/cores/arduino/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/variants/STM32F4xx/F446R(C-E)T/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/CMSIS_DSP/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/EEPROM/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/IWatchdog/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/Keyboard/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/Mouse/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/RGB_LED_TLC59731/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/SPI/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/Servo/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/SoftwareSerial/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/SubGhz/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/framework-arduinoststm32/libraries/Wire/src/ -IC:/Users/Sebastien Robitaille/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/12.3.1/ -IC:/Users/Sebastien Robitaille/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/c++/12.3.1/arm-none-eabi/ -IC:/Users/Sebastien Robitaille/.platformio/packages/toolchain-gccarmnoneeabi/lib/gcc/arm-none-eabi/12.3.1/include/ -IC:/Users/Sebastien Robitaille/.platformio/packages/toolchain-gccarmnoneeabi/lib/gcc/arm-none-eabi/12.3.1/include-fixed/ -IC:/Users/Sebastien Robitaille/.platformio/packages/toolchain-gccarmnoneeabi/arm-none-eabi/include/

Platform:unspecified

Error: Found a breaking defect '#error GCC version 6.3 or higher is required' in C:\Users\Sebastien Robitaille\.platformio\packages\framework-arduinoststm32\cores\arduino\Arduino.h:29
Please note: check results might not be valid!
Try adding --skip-packages

"severity=error<&PIO&>message=#error "GCC version 6.3 or higher is required"<&PIO&>file=C:\Users\Sebastien Robitaille\.platformio\packages\framework-arduinoststm32\cores\arduino\Arduino.h<&PIO&>line=29<&PIO&>column=0<&PIO&>callstack=[C:\Users\Sebastien Robitaille\.platformio\packages\framework-arduinoststm32\cores\arduino\Arduino.h:29]<&PIO&>cwe=0<&PIO&>id=preprocessorErrorDirective"


Error: cppcheck failed to perform check! Please examine tool output in verbose mode.



========================== [FAILED] Took 4.40 seconds ==========================
Environment Tool Status Duration
------------- -------- -------- ------------
nucleo_f446re cppcheck FAILED 00:00:04.404
==================== 1 failed, 0 succeeded in 00:00:04.404 ====================

Expected Results

Successfully completed analysis.

Additional info

Path to project folder:
C:\Users\Sebastien Robitaille\Documents\git\BugTesting
Performing the analysis with a identical project that had a path not containing no spaces yielded no errors.

The error appears to originate from: platformio/project/helpers.py

def _get_toolchain_defines(self):
        def _extract_defines(language, includes_file):
            build_flags = self.cxx_flags if language == "c++" else self.cc_flags
            defines = []
            cmd = "echo | %s -x %s %s %s -dM -E -" % (
                self.cc_path,
                language,
                " ".join(
                    [f for f in build_flags if f.startswith(("-m", "-f", "-std"))]
                ),
                includes_file,
            )
            result = proc.exec_command(cmd, shell=True)

            if result["returncode"] != 0:
                click.echo("Warning: Failed to extract toolchain defines!")
                if self.options.get("verbose"):
                    click.echo(result["out"])
                    click.echo(result["err"])

I just wanted to get some consensus that this is the cause of this issue before attempting a pull request.

@joyfullservice
Copy link

I had the same issue on my system where my username contains a space. Thanks to the clues from @sssmc I was able to find the affected file and adjust it to quote the path. After making the change, I was able to successfully run the inspection tool.

In my case, I needed to change C:\Users\Adam Waller\.platformio\penv\Lib\site-packages\platformio\check\tools\base.py line 93 as shown below:

           # I changed this
            cmd = "echo | %s -x %s %s %s -dM -E -" % (
           
           # To this
            cmd = 'echo | "%s" -x %s %s %s -dM -E -' % (

I am happy to provide a PR if that would be helpful.

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

4 participants