本文介绍了msys路径转换(或用于msys的cygpath?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将bash脚本中的/DEF:c:\filepath\myLib.def命令行选项传递给MS编译器/链接器.该路径是bash脚本在构建过程中生成的.我的脚本通过的是:

 >

...

我将在这里总结我的研究.

MSYS中的 cygpath 等效项是使用以下命令:

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

此方法的问题在于它需要现有路径,例如c:\some\path必须是现有目录;但是,实际的 cygpath 支持不存在的路径.

因此,如果您需要获取不存在的目录的路径,则可以回退到该路径的sed转换:

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

这里有大量的斜杠以满足sed的引用规则.因此,如果您的PC上不存在c:\some\path,它将尝试正向转换为反斜杠,并将/c/替换为c:\(或任何其他驱动器号).唯一的缺点是,它将无法正确运行包含已安装组件(例如/bin/does-not-exist或/usr/bin/does-not-exist)的不存在的路径.

另一种方法是在MSYS中使用cygwin的 cygpath .似乎cygwin设置了全局环境变量CYGPATH,也就是说,您可以从常规cmd.exe中使用它:

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

或从MSYS:

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

只要您将cygwin中的/c指向/cygdrive/c指向

.但是这种方法将在cygwin安装中而不是在MSYS中打印/usr.

简而言之,我认为msys确实应该在默认工具集中包含真正的cygpath,仅用于某些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).

解决方案

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

这篇关于msys路径转换(或用于msys的cygpath?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 08:09