From 6305a57a7336f7e02933b29dd4f2a9b22625af6d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 6 Jun 2019 13:28:38 +1000 Subject: [PATCH] build: account for msys2's duplicity in path schemes --- wrapper.py.in | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/wrapper.py.in b/wrapper.py.in index f87ec71..817df45 100755 --- a/wrapper.py.in +++ b/wrapper.py.in @@ -76,12 +76,41 @@ defaults = { env = defaults.copy() env.update(os.environ) +# MinGW pretends to be its own platform. Try to work around their deception by +# testing if the platform string looks like something that's actually useful. +def is_really_windows() -> bool: + name = platform.system() + + if name == 'Windows': + return True + if name.startswith('MINGW'): + return True + return False + + +# MSYS2 wants to fuck us over by supplying a CMake that gives something +# approximating native paths, and by _also_ providing an environment that +# cannot use these paths in places like PATH. +# +# Break the paths to conform to their expectations if we're under Windows. +def break_path_for_msys2(path): + if not is_really_windows(): + return path + + # Test if we have a path of the form "C:/foo" (as opposed to a + # relative path, or an MSYS2 path like "/c/foo") + if path[1] != ':': + return path + + return '/' + path[0] + path[2:] + + # Windows has its own unique rules for library lookups. We record the # environment variable which effects path lookups and the separator and the # target directory for Windows and for every single other system we're likely # to ever deal with... -if platform.system() == 'Windows': - separator = ';' +if is_really_windows(): + separator = ':' depsdir = ['bin'] searchvar = 'PATH' else: @@ -92,7 +121,7 @@ else: # append the in-tree dependencies to the library path search = separator.join( - "@CMAKE_CURRENT_BINARY_DIR@/deps/" + i for i in depsdir + break_path_for_msys2("@CMAKE_CURRENT_BINARY_DIR@/deps/") + i for i in depsdir ) if searchvar in env: