Sarcasm / compdb

The compilation database Swiss army knife
MIT License
292 stars 23 forks source link

Handle non-posix path in commands #17

Closed ifree closed 5 years ago

ifree commented 5 years ago

Hi, on Windows the path in commands is not always posix compatible, when doing arguments splitting using shlex.split we may need to specify posix parameter accordingly.

Below is a quick fix. (Sorry for not sending the PR, it won't pass the tests due to the path separator and string quote issue

diff --git a/compdb/backend/json.py b/compdb/backend/json.py
index 415630a..7a783aa 100644
--- a/compdb/backend/json.py
+++ b/compdb/backend/json.py
@@ -45,7 +45,7 @@ class JSONCompilationDatabase(CompilationDatabaseInterface):
         else:
             # PERFORMANCE: I think shlex is inherently slow,
             # something performing better may be necessary
-            arguments = shlex.split(d['command'])
+            arguments = shlex.split(d['command'], posix = os.name == "posix")
         return CompileCommand(d['directory'], d['file'], arguments,
                               d.get('output'))
Sarcasm commented 5 years ago

Thanks, I applied the fix. And that's too bad for the tests, but it's too time consuming for me to develop on Windows just for that. ¯\_(ツ)_/¯