Cleanup path handling when building on windows

This commit is contained in:
Kovid Goyal 2021-03-18 21:41:15 +05:30
parent 26c0108beb
commit 0f2aff9a4a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 21 additions and 9 deletions

View File

@ -405,7 +405,7 @@ class Build(Command):
If something is missing (qmake e.g.) you get a non-informative error If something is missing (qmake e.g.) you get a non-informative error
self.check_call(qmc + [ext.name+'.pro']) self.check_call(qmc + [ext.name+'.pro'])
so you would have to look a the source to see the actual command. so you would have to look at the source to see the actual command.
""" """
try: try:
subprocess.check_call(*args, **kwargs) subprocess.check_call(*args, **kwargs)

View File

@ -7,25 +7,37 @@ __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, subprocess, re, shutil import os, subprocess, re, shutil
from distutils.spawn import find_executable
from setup import ismacos, iswindows, is64bit, islinux, ishaiku from setup import ismacos, iswindows, is64bit, islinux, ishaiku
NMAKE = RC = msvc = MT = win_inc = win_lib = win_cc = win_ld = None NMAKE = RC = msvc = MT = win_inc = win_lib = win_cc = win_ld = None
def merge_paths(a, b):
a = [os.path.normcase(os.path.normpath(x)) for x in a.split(os.pathsep)]
for q in b.split(os.pathsep):
q = os.path.normcase(os.path.normpath(q))
if q not in a:
a.append(q)
return os.pathsep.join(a)
if iswindows: if iswindows:
from setup.vcvars import query_vcvarsall from setup.vcvars import query_vcvarsall
env = query_vcvarsall(is64bit) env = query_vcvarsall(is64bit)
NMAKE = shutil.which('nmake.exe', path=env['PATH']) win_path = env['PATH']
RC = shutil.which('rc.exe', path=env['PATH']) os.environ['PATH'] = merge_paths(env['PATH'], os.environ['PATH'])
MT = shutil.which('mt.exe', path=env['PATH']) NMAKE = 'nmake.exe'
win_cc = shutil.which('cl.exe', path=env['PATH']) RC = 'rc.exe'
win_ld = shutil.which('link.exe', path=env['PATH']) MT = 'mt.exe'
win_cc = 'cl.exe'
win_ld = 'link.exe'
win_inc = [x for x in env['INCLUDE'].split(';') if x] win_inc = [x for x in env['INCLUDE'].split(';') if x]
win_lib = [x for x in env['LIB'].split(';') if x] win_lib = [x for x in env['LIB'].split(';') if x]
QMAKE = 'qmake' QMAKE = 'qmake'
for x in ('qmake-qt5', 'qt5-qmake', 'qmake'): for x in ('qmake-qt5', 'qt5-qmake', 'qmake'):
q = find_executable(x) q = shutil.which(x)
if q: if q:
QMAKE = q QMAKE = q
break break
@ -33,7 +45,7 @@ QMAKE = os.environ.get('QMAKE', QMAKE)
if iswindows and not QMAKE.lower().endswith('.exe'): if iswindows and not QMAKE.lower().endswith('.exe'):
QMAKE += '.exe' QMAKE += '.exe'
PKGCONFIG = find_executable('pkg-config') PKGCONFIG = shutil.which('pkg-config')
PKGCONFIG = os.environ.get('PKG_CONFIG', PKGCONFIG) PKGCONFIG = os.environ.get('PKG_CONFIG', PKGCONFIG)
if (islinux or ishaiku) and not PKGCONFIG: if (islinux or ishaiku) and not PKGCONFIG:
raise SystemExit('Failed to find pkg-config on your system. You can use the environment variable PKG_CONFIG to point to the pkg-config executable') raise SystemExit('Failed to find pkg-config on your system. You can use the environment variable PKG_CONFIG to point to the pkg-config executable')