jbenden / vscode-c-cpp-flylint

A VS Code extension for advanced, modern, static analysis of C/C++ that supports a number of back-end analyzer programs.
MIT License
153 stars 29 forks source link

${workspaceFolder} not expanded on Windows #139

Closed cvaliere closed 2 years ago

cvaliere commented 3 years ago

we have, in settings.json:

"c-cpp-flylint.cppcheck.addons": [
    ".vscode/misra.json",
],

and, in misra.json:

{
    "script": "misra.py",
    "args": [
        "--rule-texts=${workspaceFolder}/misra-rule-texts.txt"
    ]
}

it works on Linux it doesn't work on Windows; opening any C file results in

Bailing out from checking c:\lib\printf\printf.c since there was an internal error: Failed to execute 'python.exe "C:\Program Files\Cppcheck\addons\misra.py" --cli --rule-texts=${workspaceFolder}\misra-rule-texts.txt c:\lib\printf\printf.c.dump'. Fatal error: file is not found: ${workspaceFolder}\misra-rule-texts.txtCppCheck(internalError)

any idea?

thanks!

jbenden commented 2 years ago

Hello,

The extension does not process the misra.json file, so it would not perform variable substitution of the workspaceFolder variable within. I suggest trying a relative path to the file.

Best regards, -Joe

cvaliere commented 2 years ago

I'm surprised that the extension does not process the misra.json file, because the same setup works on Linux.

I tried all flavours of relative paths, without success. I guess that, if the extension does not process the file, the path is not relative to the VSCode but to the installation folder of cppcheck (or to the folder of the misra.py file) ? If so, that's not usable, as different developers on the same project can have different installation folders.

jbenden commented 2 years ago

Hi,

Would you please enable c-cpp-flylint.debug and post the full output of the C/C++ Flylint log window? The more I look at it, I wonder where exactly the problem may be...

Thanks in advance, -Joe

cvaliere commented 2 years ago

sure, here it is (I obfuscated the paths, but apart from that, it's a copy-paste from the output when I open a file)

onDidOpen starting analysis.
Incoming request for isTrusted property. Have true.
Could not find or parse the workspace c_cpp_properties.json file; continuing...
c:\PATH_TO\example.c force = false.
c:\PATH_TO\example.c is now at version number 1.
Performing lint scan of c:\PATH_TO\example.c...
executing:  C:\Program Files\Cppcheck\cppcheck.EXE --inline-suppr --enable=warning,style,performance,portability,information --addon=.vscode/misra.json --std=c99 --language=c --platform=native --template="{file}  {line}  {severity} {id}: {message}" --force c:\PATH_TO\example.c
[
  'Checking c:\\PATH_TO\\example.c ...',
  'Checking c:\\PATH_TO\\example.c: PLATFORM_HAS_HALL_SENSOR_INPUT=0...',
  'Checking c:\\PATH_TO\\example.c: USE_ADC2...',
  ''
]
[
  '"c:\\PATH_TO\\example.c  0  information internalError: Bailing out from checking c:\\PATH_TO\\example.c since there was an internal error: Failed to execute \'python.exe "C:\\Program Files\\Cppcheck\\addons\\misra.py" --cli --rule-texts=${workspaceFolder}/misra-rule-texts.txt c:\\PATH_TO\\example.c.dump\'. Fatal error: file is not found: ${workspaceFolder}\\misra-rule-texts.txt"',
  '"nofile  0  information missingIncludeSystem: Cppcheck cannot find all the include files (use --check-config for details)"',
  ''
]
Completed lint scans...
Skipping analysis because ON_SAVE !== ON_TYPE.
jbenden commented 2 years ago

Hello,

I'm afraid to say that the misra.json file is a part (a configuration) of CppCheck, which is outside the processing realm of this extension.

The CppCheck manual shows on page 28 (of the PDF) shows using absolute folders for various projects. This might be important as the text data of the MISRA rules is proprietary, and probably should not be contained within the development repository...

Another option is to ask the project to resolve the path of files inside the JSON file to be next to the location of that JSON file...

Sorry! -Joe