Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

portability - msys path conversion (or cygpath for msys?)

I need to pass /DEF:c:filepathmyLib.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).

question from:https://stackoverflow.com/questions/12015348/msys-path-conversion-or-cygpath-for-msys

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:somepath 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:somepath 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:somepath or from MSYS: $CYGPATH -w /c/some/path C:somepath 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...