Skip to content

Support for Posix shell emulation (MSYS, Cygwin) pathname conven…#110

Open
andrewstevens-infineon wants to merge 4 commits into
nickdiego:mainfrom
andrewstevens-infineon:master
Open

Support for Posix shell emulation (MSYS, Cygwin) pathname conven…#110
andrewstevens-infineon wants to merge 4 commits into
nickdiego:mainfrom
andrewstevens-infineon:master

Conversation

@andrewstevens-infineon

Copy link
Copy Markdown

The final pasting of working dir and captured filenames from make output uses python native pathname joining. This cannot allow for the special pathname conventions Posix shell environments (MSYS, cygwin) use to handle Windows drive-letters.
This PR allows the shell environment being used to be specified and adjusts pathname pasting to create a legal Windows pathname.

@TunaCici

TunaCici commented Feb 5, 2024

Copy link
Copy Markdown

Hey,

I've tested this PR against MSYS2 on my Windows 10 machine. I liked the overall approach you took. However, there are some edge cases that needs to be handled and improvements to be made.

  • New function to_native_pathname() assumes that pathname starts with either "/..." OR "/cygdrive". This causes a NoneType return if pathname is just a file name (e.g. HelloWorld.c). One simply (but ugly) fix would be to add else tags for both # MSYS and # Cygwin.
  • joined_path_name seems to be unused. Could be removed.
  • The drive letters are lowercase; they could be uppercase to fit into the Windows styling.
  • In the PR description you could mention that --win-posix-shell is added to CLI.

The first issue NEEDS to be handled otherwise the program crashes :/

Thanks again for the PR ☀️

@mlt

mlt commented Feb 13, 2026

Copy link
Copy Markdown

Uhm…isn't it cleaner just to unconditionally strip away msys/cygwin stuff at the very end? At least that is what I had before I saw this PR.

diff --git a/compiledb/parser.py b/compiledb/parser.py
index 9f4c550..2f9f31b 100755
--- a/compiledb/parser.py
+++ b/compiledb/parser.py
@@ -18,6 +18,7 @@
 #   You should have received a copy of the GNU General Public License
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+import sys
 import bashlex
 import re
 import logging
@@ -152,6 +153,9 @@ def parse_build_log(build_log, proj_dir, exclude_files, command_style=False, add
 
             logger.debug("Adding command {}: {}".format(len(result.compdb), command_str))
 
+            if sys.platform == 'win32':
+                working_dir = re.sub(r'^(?:/mnt|/cygdrive)?/([a-zA-Z])/', r'\1:/', working_dir)
+
             if command_style:
                 result.compdb.append({
                     'directory': working_dir,

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.

3 participants