Skip to content

fixing malparsed windows paths - #4374

Draft
tuix wants to merge 1 commit into
Ericsson:masterfrom
tuix:master
Draft

fixing malparsed windows paths#4374
tuix wants to merge 1 commit into
Ericsson:masterfrom
tuix:master

Conversation

@tuix

@tuix tuix commented Oct 23, 2024

Copy link
Copy Markdown

Fixes #4277

source_dir = entry['directory']

options = shlex.split(entry['command'])
options = shlex.split(entry['command'], posix=(os.name=='posix'))

@marc-h38 marc-h38 Oct 30, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The posix= parameter is designed to manage nuances between different Unix shells, so it's very mysterious how this helps with Windows and why?!

I realize this is still just a draft, but some... draft comments and a commit message draft would not hurt.

Generally speaking, shlex is NOT meant to help prepare Windows commands ("outputs"). According to its documentation, it's meant as a convenience to help parsing inputs to the program, like a simple configuration file or some parameters.
https://docs.python.org/3/library/shlex.html

Longer example of shlex abuse and Windows compatibility story in zephyrproject-rtos/west@94f8a04

@ferkulat ferkulat Aug 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marc-h38
"The posix= parameter is designed to manage nuances between different Unix shells, so it's very mysterious how this helps with Windows and why?!"
When the posix=false is not passed on windows, shlex is eating up back slashes:

image

And here with posix=False:
image

here is some related issue:
#mesonbuild/meson#5726

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The posix= parameter is designed to manage nuances between different Unix shells,

Correction: posix=True means backwards-compatibility=False. This could/should be better documented. I found the evidence here:
python/cpython#38314 (comment)

so it's very mysterious how this helps with Windows and why?!

When the posix=false is not passed on windows, shlex is eating up back slashes:

Right, escaping rules are different between posix and non-posix:
https://docs.python.org/3/library/shlex.html#parsing-rules

However this is just one difference among a long list of other differences. shlex is effectively two pretty different parsers in one. Those other differences should be understood and evaluated in this particular context and the commit message should tell that story. When not, the "Pragrammatic Programmer" book names this "programming by coincidence".

Or maybe I should say "called" in the past tense now since AI is writing all the code ;-)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is some related issue: #mesonbuild/meson#5726

Apparently, the fix there was to stop (ab)using shlex for cases it was not designed to handle, and replace it with something else entirely.

@marc-h38

This comment was marked as off-topic.

@ferkulat

Copy link
Copy Markdown
Contributor

Just found by chance that #5017 is another tentative fix.

no, #5017 is a fix for back slashes in the "file" field of compile_database.json. but not for failing to extract the compiler path, like this fix

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeChecker not parsing correctly windows escaped paths in compile_commands.json

3 participants