Small fix to detect msys environment
Looks promising,
This doesn't solve all the problems,
ie the pattern match doesn't work when the output comes from CMake+Ninja (have not tested make),
Ninja looks like
101 C:\work\file.cpp:234: errormessage
And I haven't tested cmake+MSVC yet.
I see there are a lot more patches on the 'project' branch, but that has a lot of errors when I tried to use it.
Note that I'm using with vim, importing with
Plug 'LucHermitte/lh-vim-lib'
Plug 'LucHermitte/vim-build-tools-wrapper'
Plug 'powerman/vim-plugin-AnsiEsc'
But as you suggest in stackoverflow, I only really need that vim cygwin bit.
I'm not sure you could use cygwin.pl as it use cygpath to do the path conversions -- in order to correctly translate /cygdrive/Z/... in the correct windows path (with forward slashes). Is this command available on MSYS as well?
Yes cygpath is in msys, and it correctly converts c:\folder\file.txt to /c/folder/file.txt
Note that I'm using the git-for-windows-sdk, with Vim 8.2.3582. I tried nvim/neovim but it has a weird bug that freezes itself when you press ctrl-Z or type :suspend so that was a deal breaker. I use git-for-windows so I can install with pacman.
but, I see that git-for-windows vanilla will have cygpath you can try, and vim. If you like to try, you can install that, and you also get a button for opening a Git-Bash tab in "Windows Terminal".
I also have cygwin installed but I'm migrating to msys.
I suspect we are working in the exact opposite scenario. Meaning I'm converting cygwin paths into windows paths, while you want to convert windows paths into msys paths.
I guess that if you use cygpath with -wl (?) instead of -m it should do what you need -- I'm not sure about the exact option. I see a few other hardcoded things in cygwin.pl that need to be taken care of. Which means I need another filter, and an intuitive name :)
Note: I'm mostly under Linux nowadays, I won't be able to test it before a few days.
No rush, I'll be in a position to test more perhaps tomorrow or next week. I appreciate anything you can do. I tried to adjust the script but I don't know enough perl RE (I'm ok with vim re). I didn't think to adjust the flag, maybe that is all it takes.
It is the filtering technique that concerns me the most. It is already a PITA to have to do
:set makeprg=ninja\ \-C\ ../build
all those backslashes are annoying, can't seem to just use "" quotes.
Your filter trick is neat, but it assumes make. Needs to be more general? Or perhaps I just need a ninja-msys script that will execute ninja and push it through the filter ...
I tried to adjust the script but I don't know enough perl RE (I'm ok with vim re).
I used to know Perl RE, nowadays, I'll have to search a little ^^'. Anyway, here, the main difference is that we are mainly in magic mode by default.
I didn't think to adjust the flag, maybe that is all it takes.
I'm afraid not as I test things like /cygdrive for instance.
all those backslashes are annoying, can't seem to just use "" quotes.
You can use :let instead. For instance
let &makeprg = 'set -o pipefail ; ninja -C ../build 2>&1 | the-future-win2msys-path-converter.dot.py.or.pl.or.sh'
Your filter trick is neat, but it assumes make. Needs to be more general?
With this plugin, you can already use ninja with :BTW set ninja.
:BTW set(local) does set the compilation chain, while :BTW add(local) adds extra filters like path converters, scripts that simplify error messages (like the old STLfilt for C++), my other filter that conceals patterns, and so on.
However, it'll not use the -C option, but try to cd to the b:/g:BTW_compilation_dir (in the project branch, the option name has changed; and I'm currently trying to do some magic incantations to autodetect build directory in CMake environments)
I don't think you could possibly auto-detect the build folder ... I can have several build folders for one source folder (thanks to out-of-source builds in cmake). eg I'll have a Release folder and a Debug folder, and I switch between them by changing the -C So the source folder can't know what I want ...
Thanks for the :let tip
Maybe we need a non-vim specific bash script or other, to be put in the $PATH or $HOME/bin or wherever, and then users can do thefilter ninja -flag -flag and so it doesn't matter if it is ninja or make or cmake --build or conan build or whatever ...
Regarding auto detection of build directories.
That's my situation as well. The heuristic is quite complex. First I try to follow compile_commands.json if it's a symbolic link. This would give a compilation directory, if there are sibling directories with CMakeCache.txt, then they are the build directories.
Otherwise, I search in the parent directory of the project root directory (where there is the .git/ folder for instance), and in the source directory whether there is any build* directory, or any '*/CMakeCache.txt` file. I mainly try to support my way of doing things. --> not the last version
Regarding other things like calling ninja. In BuildToolsWrapper new architecture, I can detect&load compilation chains. While I'm mainly focusing of CMake. I should be able to have some tweakings for ninja, which will be registered here
wow
What about the following that you could drop into compiler/BTW/win2msys.pl.
#!/usr/bin/perl
# Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
# <URL:http://hermitte.free.fr/vim>
# Purpose: Convert plain Winddows pathames to MSYS pathnames.
# Defined as a filter to use on make's result.
# Meant to be used by Vim.
# Created: 30th Jun 2022
# Last Update: 30th Jun 2022
### Code {{{1
## Includes {{{2
use strict ;
use File::Spec ; # splitpath()
## Globals {{{2
# Hash table for the paths already translated with ``realname'', or cygpath
my %h = () ;
## Functions {{{2
sub parent # {{{3
{
my ($path) = @_;
my ($vol,$dir,$file) = File::Spec->splitpath($path);
# print "vol: '$vol'; dir: '$dir'; file: '$file'\n";
return ("$vol$dir", $file);
}
# Proxy function: returns the realname of the path
# This function looks for converted paths into the hastable, if nothing is
# found in the table, the result is built and added into the table
# TODO: follow mounted things
sub UnixPath # {{{3
{
my ($path) = @_ ;
# print "testing $path\n";
if ( exists( $h{$path} ) ) {
return $h{$path} ;
} else {
# Get the real location of the file
my $upath = `realpath "$path"`;
chomp ($upath);
my ($dir, $file) = parent($upath);
if (exists( $h{$dir} )) {
my $udir = $h{$dir};
} else {
# Convert the dir to UNIX form
my $udir = `cygpath -u $dir`;
chomp($udir);
# Add the dir to the hash-table
$h{$dir} = $udir;
# print "cygpath '$dir' --> '$udir'\n";
}
$upath = File::Spec->catfile($h{$dir}, $file);
# Add the path into the hash-table
$h{$path} = $upath ;
return $upath ;
}
}
## Main {{{2
# Main loop: convert MsWindows paths into Unix paths
while (<>)
{
chop;
if ( m#^( *[A-Za-z]:[\\/].*?)(\:\d*\:?.*$)# ) {
printf UnixPath($1)."$2\n";
} else {
print "$_\n";
}
}
# ======================================================================
# vim600: set foldmethod=marker:
# vim:et:ts=4:tw=79:
Given compiler/BTW/win2msys.vim that would contain at least
let s:file = substitute(expand('<sfile>:p:h'), ' ', '\\ ', 'g') " not sure about the need for substitute()
let g:BTW_filter_program_win2msys = s:file."/win2msys.pl"
Then, with build-tools-wrapper you could simply use it with :BTW add(local) win2msys
Otherwise, you just need to pipe ninja/make/cmake/... compilation results into this perl script
let &makeprg = 'set -o pipefail ; ninja -C ../build 2>&1 | perl /path/to/win2msys.pl
I'll check it out next week, got swamped