dependencies: Convert /c/foo/bar paths to C:/foo/bar

MSVC cannot handle MinGW-esque /c/foo paths, convert them to C:/foo.
We cannot resolve other paths starting with / like /home/foo so leave
them as-is so the user gets an error/warning from the compiler/linker.

These paths are commonly found in pkg-config files generated using
Autotools inside MinGW/MSYS and MinGW/MSYS2 environments.

Currently this is only done for PkgConfigDependency.
pull/2703/head
Nirbheek Chauhan 7 years ago
parent 554b484468
commit 390f0b8b52
  1. 15
      mesonbuild/dependencies/base.py
  2. 16
      test cases/unit/17 pkgconfig static/meson.build

@ -22,6 +22,7 @@ import shlex
import shutil import shutil
import textwrap import textwrap
from enum import Enum from enum import Enum
from pathlib import PurePath
from .. import mlog from .. import mlog
from .. import mesonlib from .. import mesonlib
@ -424,6 +425,20 @@ class PkgConfigDependency(ExternalDependency):
self.link_args = [] self.link_args = []
libpaths = [] libpaths = []
for lib in shlex.split(out): for lib in shlex.split(out):
# MSVC cannot handle MinGW-esque /c/foo paths, convert them to C:/foo.
# We cannot resolve other paths starting with / like /home/foo so leave
# them as-is so the user gets an error/warning from the compiler/linker.
if self.compiler.id == 'msvc':
# Library search path
if lib.startswith('-L/'):
pargs = PurePath(lib[2:]).parts
if len(pargs) > 1 and len(pargs[1]) == 1:
lib = '-L{}:/{}'.format(pargs[1], '/'.join(pargs[2:]))
# Full path to library or .la file
elif lib.startswith('/'):
pargs = PurePath(lib).parts
if len(pargs) > 1 and len(pargs[1]) == 1:
lib = '{}:/{}'.format(pargs[1], '/'.join(pargs[2:]))
# If we want to use only static libraries, we have to look for the # If we want to use only static libraries, we have to look for the
# file ourselves instead of depending on the compiler to find it # file ourselves instead of depending on the compiler to find it
# with -lfoo or foo.lib. However, we can only do this if we already # with -lfoo or foo.lib. However, we can only do this if we already

@ -5,8 +5,22 @@ if build_machine.system() != 'windows'
else else
# pkg-config files should not use paths with \ # pkg-config files should not use paths with \
prefix_parts = meson.source_root().split('\\') prefix_parts = meson.source_root().split('\\')
prefix = '/'.join(prefix_parts) # If the path is C:/foo/bar, convert it to /c/foo/bar so we can test if our
# automatic conversion to C:/foo/bar inside PkgConfigDependency is working.
if prefix_parts[0][1] == ':'
drive = prefix_parts[0][0]
else
drive = prefix_parts[0]
endif
new_parts = []
foreach part : prefix_parts
if part != prefix_parts[0]
new_parts += part
endif
endforeach
prefix = '/@0@/@1@'.format(drive, '/'.join(new_parts))
endif endif
message(prefix)
# Escape spaces # Escape spaces
prefix_parts = prefix.split(' ') prefix_parts = prefix.split(' ')

Loading…
Cancel
Save