Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msys path conversion (or cygpath for msys?)

I need to pass /DEF:c:\filepath\myLib.def" command line option from a bash script to MS compiler/linker. The path is generated as part of build process by a bash script. Basically, the argument that my script passes is:

-DEF:/c/filepath/myLib.def 

MSYS path conversion can't handle it properly because it doesn't understand /DEF: part. It works if I do

-DEF=/c/filepath/myLib.def 

but then ms tools don't understand this parameter. In short, what's the proper way to write that parameter in MSYS bash so that it converts it to proper argument?

On cygwin I could use cygpath, but there is no equivalent, because somebody from msys thinks that it's not needed (even if there are scripts for cygwin that uses cygpath).

like image 852
Pavel P Avatar asked Aug 18 '12 02:08

Pavel P


People also ask

What is Cygpath?

The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style pathnames and vice versa. It can be used when a Cygwin program needs to pass a file name to a native Windows program, or expects to get a file name from a native Windows program.

How do I add MSYS2 to path?

Adding MSYS2 to your PATH variableClick on the “Environment Variables” button. In the “System Variables” section, scroll down and double-click on the “Path” variable. If you're on Windows 7/8, add the text C:\msys32\usr\bin;C:\msys32\usr\local\bin; to the beginning of the variable value.


1 Answers

Update (Aug-2016):

This question is no longer relevant, as msys2 now comes with cygpath in its installation.

...

I'll summarize my research here.

The cygpath equivalent in MSYS is to use this command:

{ cd /c/some/path && pwd -W; } | sed 's|/|\\|g' 

The problem with this approach is that it requires existing path, e.g. the c:\some\path has to be an existing directory; however, real cygpath supports paths that do not exist.

So, if you need to get path to a directory that doesn't exist, then you can fallback to sed conversion of the path:

{ cd 2>/dev/null /c/some/path && pwd -W ||   echo /c/some/path | sed 's|^/\([a-z,A-Z]\)/|\1:/|'; } | sed 's|/|\\|g' 

The mouthful of slashes is there to satisfy quoting rules of sed. So, if c:\some\path doesn't exist on your PC, it will try to convert forward to back slashes and replace /c/ with c:\ (or any other drive letter). The only drawback for this is that it won't work correctly non-existing paths that contain a mounted component, such as /bin/does-not-exist or /usr/bin/does-not-exist.

One more approach is to use cygpath from cygwin in MSYS. It seems that cygwin sets global environment variable CYGPATH, that is, you can use it from regular cmd.exe:

%CYGPATH% -w /c/some/path C:\some\path 

or from MSYS:

$CYGPATH -w /c/some/path C:\some\path 

as long as you set to point /c to /cygdrive/c in cygwin. But this approach will print you /usr located in cygwin installation, not in MSYS.

In short, I think msys should really include real cygpath in the default set of tools just for some cases that aren't handled automatically by msys command line argument conversion logic

like image 178
Pavel P Avatar answered Oct 12 '22 03:10

Pavel P