Skip to content

Commit

Permalink
Merge 360065d into d26c59a
Browse files Browse the repository at this point in the history
  • Loading branch information
dmoody256 committed Jan 9, 2019
2 parents d26c59a + 360065d commit 8889c92
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 36 deletions.
93 changes: 77 additions & 16 deletions src/engine/SCons/Tool/MSCommon/vc.py
Expand Up @@ -99,6 +99,9 @@ class BatchFileExecutionError(VisualCException):
("x86", "ia64"): "x86_ia64"
}

def get_msvc_version_numeric(msvc_version):
return ''.join([x for x in msvc_version if x in string_digits + '.'])

def get_host_target(env):
debug('vc.py:get_host_target()')

Expand Down Expand Up @@ -189,7 +192,7 @@ def get_host_target(env):
}

def msvc_version_to_maj_min(msvc_version):
msvc_version_numeric = ''.join([x for x in msvc_version if x in string_digits + '.'])
msvc_version_numeric = get_msvc_version_numeric(msvc_version)

t = msvc_version_numeric.split(".")
if not len(t) == 2:
Expand Down Expand Up @@ -312,7 +315,7 @@ def find_batch_file(env,msvc_version,host_arch,target_arch):
debug('vc.py: find_batch_file() pdir:{}'.format(pdir))

# filter out e.g. "Exp" from the version name
msvc_ver_numeric = ''.join([x for x in msvc_version if x in string_digits + "."])
msvc_ver_numeric = get_msvc_version_numeric(msvc_version)
vernum = float(msvc_ver_numeric)
if 7 <= vernum < 8:
pdir = os.path.join(pdir, os.pardir, "Common7", "Tools")
Expand Down Expand Up @@ -344,29 +347,86 @@ def find_batch_file(env,msvc_version,host_arch,target_arch):

__INSTALLED_VCS_RUN = None

def cached_get_installed_vcs():
def _check_cl_exists_in_vc_dir(env, vc_dir, msvc_version):
ver_num = float(get_msvc_version_numeric(msvc_version))
found_cl = False
(host_platform, target_platform,req_target_platform) = get_host_target(env)

# check to see if the x86 or 64 bit compiler is in the bin dir
if ver_num > 14:
try:
f = open(os.path.join(vc_dir, r'Auxiliary\Build\Microsoft.VCToolsVersion.default.txt'))
vc_specific_version = f.readlines()[0].strip()
except:
return False

if host_platform in ('amd64','x86_64'):
host_dir = "Hostx64"
elif host_platform in ('i386','i686','x86'):
host_dir = "Hostx86"
else:
return False

if target_platform in ('amd64','x86_64'):
target_dir = "x64"
elif target_platform in ('i386','i686','x86'):
target_dir = "x86"
else:
return False

if os.path.exists(os.path.join(vc_dir, r'Tools\MSVC', vc_specific_version, 'bin', host_dir, target_dir, 'cl.exe')):
return True
elif ver_num <= 14:
if host_platform in ('amd64','x86_64'):
host_dir = "amd64"
elif host_platform in ('i386','i686','x86'):
host_dir = "x86"
else:
return False


if target_platform in ('amd64','x86_64'):
target_dir = "amd64"
elif target_platform in ('i386','i686','x86'):
target_dir = "x86"
elif target_platform in ('ia64'):
target_dir = "ia64"
else:
return False

host_target_dir = _HOST_TARGET_ARCH_TO_BAT_ARCH[(host_dir, target_dir)]
if host_target_dir == 'x86':
host_target_dir == ''
else:
host_target_dir += '\\'
cl_dir = 'bin\\' + host_target_dir + 'cl.exe'
print(os.path.join(vc_dir, cl_dir))
if os.path.exists(os.path.join(vc_dir, cl_dir)):
return True
return False


def cached_get_installed_vcs(env):
global __INSTALLED_VCS_RUN

if __INSTALLED_VCS_RUN is None:
ret = get_installed_vcs()
ret = get_installed_vcs(env)
__INSTALLED_VCS_RUN = ret

return __INSTALLED_VCS_RUN

def get_installed_vcs():
def get_installed_vcs(env):
installed_versions = []
for ver in _VCVER:
debug('trying to find VC %s' % ver)
try:
VC_DIR = find_vc_pdir(ver)
if VC_DIR:
debug('found VC %s' % ver)
# check to see if the x86 or 64 bit compiler is in the bin dir
if (os.path.exists(os.path.join(VC_DIR, r'bin\cl.exe'))
or os.path.exists(os.path.join(VC_DIR, r'bin\amd64\cl.exe'))):
if _check_cl_exists_in_vc_dir(env, VC_DIR, ver):
installed_versions.append(ver)
else:
debug('find_vc_pdir no cl.exe found %s' % ver)
debug('find_vc_pdir no compiler found %s' % ver)
else:
debug('find_vc_pdir return None for ver %s' % ver)
except VisualCException as e:
Expand Down Expand Up @@ -423,7 +483,7 @@ def get_default_version(env):
% (msvc_version, msvs_version))
return msvs_version
if not msvc_version:
installed_vcs = cached_get_installed_vcs()
installed_vcs = cached_get_installed_vcs(env)
debug('installed_vcs:%s' % installed_vcs)
if not installed_vcs:
#msg = 'No installed VCs'
Expand All @@ -446,7 +506,7 @@ def msvc_setup_env_once(env):
msvc_setup_env(env)
env["MSVC_SETUP_RUN"] = True

def msvc_find_valid_batch_script(env,version):
def msvc_find_valid_batch_script(env,version,modify_env=True):
debug('vc.py:msvc_find_valid_batch_script()')
# Find the host platform, target platform, and if present the requested
# target platform
Expand All @@ -472,7 +532,8 @@ def msvc_find_valid_batch_script(env,version):
d = None
for tp in try_target_archs:
# Set to current arch.
env['TARGET_ARCH']=tp
if modify_env:
env['TARGET_ARCH']=tp

debug("vc.py:msvc_find_valid_batch_script() trying target_platform:%s"%tp)
host_target = (host_platform, tp)
Expand Down Expand Up @@ -500,7 +561,7 @@ def msvc_find_valid_batch_script(env,version):
warn_msg = "VC version %s not installed. " + \
"C/C++ compilers are most likely not set correctly.\n" + \
" Installed versions are: %s"
warn_msg = warn_msg % (version, cached_get_installed_vcs())
warn_msg = warn_msg % (version, cached_get_installed_vcs(env))
SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)
continue

Expand Down Expand Up @@ -529,7 +590,7 @@ def msvc_find_valid_batch_script(env,version):

# If we cannot find a viable installed compiler, reset the TARGET_ARCH
# To it's initial value
if not d:
if not d and modify_env:
env['TARGET_ARCH']=req_target_platform

return d
Expand Down Expand Up @@ -579,8 +640,8 @@ def msvc_setup_env(env):
SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning,
"Could not find MSVC compiler 'cl.exe', it may need to be installed separately with Visual Studio")

def msvc_exists(version=None):
vcs = cached_get_installed_vcs()
def msvc_exists(env, version=None):
vcs = cached_get_installed_vcs(env)
if version is None:
return len(vcs) > 0
return version in vcs
2 changes: 1 addition & 1 deletion src/engine/SCons/Tool/midl.py
Expand Up @@ -79,7 +79,7 @@ def generate(env):
env['BUILDERS']['TypeLibrary'] = midl_builder

def exists(env):
return msvc_exists()
return msvc_exists(env)

# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion src/engine/SCons/Tool/mslib.py
Expand Up @@ -55,7 +55,7 @@ def generate(env):
env['LIBSUFFIX'] = '.lib'

def exists(env):
return msvc_exists()
return msvc_exists(env)

# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion src/engine/SCons/Tool/mslink.py
Expand Up @@ -328,7 +328,7 @@ def generate(env):
env['LDMODULECOM'] = compositeLdmodAction

def exists(env):
return msvc_exists()
return msvc_exists(env)

# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion src/engine/SCons/Tool/msvc.py
Expand Up @@ -289,7 +289,7 @@ def generate(env):
env['ENV']['SystemRoot'] = SCons.Platform.win32.get_system_root()

def exists(env):
return msvc_exists()
return msvc_exists(env)

# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion src/engine/SCons/Tool/msvs.py
Expand Up @@ -1990,7 +1990,7 @@ def generate(env):
env['SCONS_HOME'] = os.environ.get('SCONS_HOME')

def exists(env):
return msvc_exists()
return msvc_exists(env)

# Local Variables:
# tab-width:4
Expand Down
2 changes: 1 addition & 1 deletion test/AS/ASFLAGS.py
Expand Up @@ -42,7 +42,7 @@
if sys.platform == 'win32':
import SCons.Tool.MSCommon as msc

if msc.msvc_exists():
if msc.msvc_exists(test.Environment()):
o_c = ' -x'

test.write('SConstruct', """
Expand Down
2 changes: 1 addition & 1 deletion test/AS/ASPPFLAGS.py
Expand Up @@ -42,7 +42,7 @@
if sys.platform == 'win32':
import SCons.Tool.MSCommon as msc

if msc.msvc_exists():
if msc.msvc_exists(test.Environment()):
o_c = ' -x'

test.write('SConstruct', """
Expand Down
2 changes: 1 addition & 1 deletion test/CC/CCFLAGS.py
Expand Up @@ -32,7 +32,7 @@
if sys.platform == 'win32':
import SCons.Tool.MSCommon as msc

if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
fooflags = '-DFOO'
barflags = '-DBAR'
else:
Expand Down
2 changes: 1 addition & 1 deletion test/CC/CFLAGS.py
Expand Up @@ -47,7 +47,7 @@
if sys.platform == 'win32':
import SCons.Tool.MSCommon as msc

if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
fooflags = '-DFOO'
barflags = '-DBAR'
else:
Expand Down
2 changes: 1 addition & 1 deletion test/LINK/SHLINKCOMSTR.py
Expand Up @@ -73,7 +73,7 @@

if sys.platform == "win32":
import SCons.Tool.MSCommon as msc
if msc.msvc_exists():
if msc.msvc_exists(test.Environment()):
# Now test an actual compile and link. Since MS Windows
# resets the link actions, this could fail even if the above
# test passed.
Expand Down
2 changes: 1 addition & 1 deletion test/Libs/LIBPREFIXES.py
Expand Up @@ -31,7 +31,7 @@
if sys.platform == 'win32':
_lib = '.lib'
import SCons.Tool.MSCommon as msc
if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
_lib = '.a'
else:
_lib = '.a'
Expand Down
6 changes: 4 additions & 2 deletions test/Libs/LIBS.py
Expand Up @@ -27,17 +27,19 @@
import TestSCons
import sys

test = TestSCons.TestSCons()

if sys.platform == 'win32':
_exe = '.exe'
bar_lib = 'bar.lib'
import SCons.Tool.MSCommon as msc
if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
bar_lib = 'libbar.a'
else:
_exe = ''
bar_lib = 'libbar.a'

test = TestSCons.TestSCons()


test.subdir('sub1', 'sub2')

Expand Down
6 changes: 3 additions & 3 deletions test/Libs/LIBSUFFIXES.py
Expand Up @@ -28,16 +28,16 @@
import sys
import TestSCons

test = TestSCons.TestSCons()

if sys.platform == 'win32':
lib_ = ''
import SCons.Tool.MSCommon as msc
if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
lib_ = 'lib'
else:
lib_ = 'lib'

test = TestSCons.TestSCons()

test.write('SConstruct', """
env = Environment(LIBSUFFIX = '.xxx',
LIBSUFFIXES = ['.xxx'])
Expand Down
2 changes: 1 addition & 1 deletion test/Libs/SharedLibraryIxes.py
Expand Up @@ -42,7 +42,7 @@
isMingw = False
if isWindows:
import SCons.Tool.MSCommon as msc
if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
# We can't seem to find any MSVC version, so we assume
# that MinGW is installed instead. Accordingly, we use the
# standard gcc/g++ conventions for lib prefixes and suffixes
Expand Down
2 changes: 1 addition & 1 deletion test/long-lines/live.py
Expand Up @@ -43,7 +43,7 @@
linkflag_init = '/LIBPATH:' + test.workpath()
linkflag = ' /LIBPATH:' + test.workpath()
import SCons.Tool.MSCommon as msc
if not msc.msvc_exists():
if not msc.msvc_exists(test.Environment()):
lib_shared_dll = 'shared.dll'
lib_static_lib = 'libstatic.a'
arflag_init = 'r'
Expand Down
2 changes: 1 addition & 1 deletion test/sconsign/script/dblite.py
Expand Up @@ -114,7 +114,7 @@ def escape_drive_case(s):

if sys.platform == 'win32':
import SCons.Tool.MSCommon as msc
if msc.msvc_exists():
if msc.msvc_exists(test.Environment()):
manifest = r"""
embedManifestExeCheck\(target, source, env\)"""
else:
Expand Down
2 changes: 1 addition & 1 deletion testing/framework/TestSCons.py
Expand Up @@ -1072,7 +1072,7 @@ def skip_if_not_msvc(self, check_platform=True):

try:
import SCons.Tool.MSCommon as msc
if not msc.msvc_exists():
if not msc.msvc_exists(self.Environment()):
msg = "No MSVC toolchain found...skipping test\n"
self.skip_test(msg)
except:
Expand Down

0 comments on commit 8889c92

Please sign in to comment.