From b4239a3813cfba92f6c91b9f3ce1df3c592f2cc9 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 31 May 2019 08:46:20 -0700 Subject: [PATCH 1/2] Add backports.shutil_which --- build.py | 6 ++++++ requirements/devel.txt | 1 + 2 files changed, 7 insertions(+) diff --git a/build.py b/build.py index 03948d39..452bfdd7 100755 --- a/build.py +++ b/build.py @@ -32,6 +32,12 @@ try: except ImportError: import pathlib2 as pathlib +try: + from shutil import which +except ImportError: + from backports.shutil_which import which + + from distutils.dep_util import newer, newer_group from buildtools.config import Config, msg, opj, posixjoin, loadETG, etg2sip, findCmd, \ phoenixDir, wxDir, copyIfNewer, copyFile, \ diff --git a/requirements/devel.txt b/requirements/devel.txt index 0fec2567..148aa6e0 100644 --- a/requirements/devel.txt +++ b/requirements/devel.txt @@ -10,3 +10,4 @@ pytest pytest-xdist pytest-timeout pathlib2 ; python_version < "3" +backports.shutil_which ; python_version < "3" From 23a99b974238e36e99edee6cc35de9833767e954 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 31 May 2019 15:49:32 -0700 Subject: [PATCH 2/2] Reduce dependency on cygwin, enable working with other bash implementations --- build.py | 80 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 17 deletions(-) diff --git a/build.py b/build.py index 452bfdd7..a48b86db 100755 --- a/build.py +++ b/build.py @@ -268,7 +268,7 @@ def setPythonVersion(args): # TOOLS = os.environ.get('TOOLS') if 'cygdrive' in TOOLS: - TOOLS = runcmd(getCygwinPath()+'/bin/cygpath -w '+TOOLS, True, False) + TOOLS = bash2dosPath(TOOLS) use64flag = '--x64' in args if use64flag: args.remove('--x64') @@ -816,23 +816,65 @@ def getWafBuildBase(): return base -def getCygwinPath(): +def getBashPath(): + """Check if there is a bash.exe on the PATH""" + bash = which('bash.exe') + return bash + + +def dos2bashPath(path): """ - Try to locate the path where cygwin is installed. - - If CYGWIN_BASE is set in the environment then use that. Otherwise look in - default install locations. + Convert an absolute dos-style path to one bash.exe can understand. """ - if os.environ.get('CYGWIN_BASE'): - return os.environ.get('CYGWIN_BASE') + path = path.replace('\\', '/') + cygpath = which('cygpath') + wsl = which('wsl') - for path in ['c:/cygwin', 'c:/cygwin64']: - if os.path.isdir(path): - return path - - return None + # If we have cygwin then we can use cygpath to convert the path. + # Note that MSYS2 (and Git Bash) now also have cygpath so this should + # work there too. + if cygpath: + path = runcmd('{} -u {}'.format(cygpath, path), getOutput=True, echoCmd=False) + return path + elif wsl: + # Are we using Windows System for Linux? (untested) + path = runcmd('{} wslpath -a -u {}'.format(wsl, path), getOutput=True, echoCmd=False) + return path + else: + # Otherwise, do a simple translate and hope for the best? + # c:/foo --> /c/foo + # TODO: Check this!! + drive, rest = os.path.splitdrive(path) + path = '/{}/{}'.format(drive[0], rest) + return path +def bash2dosPath(path): + """ + Convert an absolute unix-style path to one Windows can understand. + """ + cygpath = which('cygpath') + wsl = which('wsl') + + # If we have cygwin then we can use cygpath to convert the path. + # Note that MSYS2 (and Git Bash) now also have cygpath so this should + # work there too. + if cygpath: + path = runcmd('{} -w {}'.format(cygpath, path), getOutput=True, echoCmd=False) + return path + elif wsl: + # Are we using Windows System for Linux? (untested) + path = runcmd('{} wslpath -a -w {}'.format(wsl, path), getOutput=True, echoCmd=False) + return path + else: + # Otherwise, do a simple translate and hope for the best? + # /c/foo --> c:/foo + # There's also paths like /cygdrive/c/foo or /mnt/c/foo, but in those + # cases cygpath or wsl should be available. + components = path.split('/') + assert components[0] == '' and len(components[1]) == 1, "Expecting a path like /c/foo" + path = components[1] + ':/' + '/'.join(components[2:]) + return path #--------------------------------------------------------------------------- # Command functions and helpers @@ -844,14 +886,18 @@ def _doDox(arg): doxCmd = os.path.abspath(doxCmd) if isWindows: - cygwin_path = getCygwinPath() - doxCmd = doxCmd.replace('\\', '/') - doxCmd = runcmd(cygwin_path+'/bin/cygpath -u '+doxCmd, True, False) + bash = getBashPath() + if not bash: + raise RuntimeError("ERROR: Unable to find bash.exe, needed for running regen.sh") + + doxCmd = dos2bashPath(doxCmd) + print(doxCmd) os.environ['DOXYGEN'] = doxCmd os.environ['WX_SKIP_DOXYGEN_VERSION_CHECK'] = '1' + d = posixjoin(wxDir(), 'docs/doxygen') d = d.replace('\\', '/') - cmd = '%s/bin/bash.exe -l -c "cd %s && ./regen.sh %s"' % (cygwin_path, d, arg) + cmd = '{} -l -c "cd {} && ./regen.sh {}"'.format(bash, d, arg) else: os.environ['DOXYGEN'] = doxCmd os.environ['WX_SKIP_DOXYGEN_VERSION_CHECK'] = '1'