aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Preston <johnprestonmail@gmail.com>2018-11-28 18:22:28 +0400
committerJussi Pakkanen <jpakkane@gmail.com>2018-12-04 20:19:19 +0200
commitc17a80f47b772d759aeb0878aa767a768a6fdd0c (patch)
tree568b959bd2023617f38752fe33d506cc99a62366
parent8612f1543f280342fcbff69863b8401319fccc7d (diff)
downloadmeson-c17a80f47b772d759aeb0878aa767a768a6fdd0c.zip
meson-c17a80f47b772d759aeb0878aa767a768a6fdd0c.tar.gz
meson-c17a80f47b772d759aeb0878aa767a768a6fdd0c.tar.bz2
Use correct environment for REGEN in VS backend.
Try to guess which VS Command Prompt was used for the Meson call. If one is chosen invoke it before calling Meson in REGEN command.
-rw-r--r--mesonbuild/backend/vs2010backend.py33
-rw-r--r--mesonbuild/environment.py3
2 files changed, 34 insertions, 2 deletions
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index ea52f12..f9f7b93 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -189,6 +189,33 @@ class Vs2010Backend(backends.Backend):
with open(filename, 'wb') as f:
pickle.dump(regeninfo, f)
+ def get_vcvars_command(self):
+ has_arch_values = 'VSCMD_ARG_TGT_ARCH' in os.environ and 'VSCMD_ARG_HOST_ARCH' in os.environ
+
+ # Use vcvarsall.bat if we found it.
+ if 'VCINSTALLDIR' in os.environ:
+ vs_version = os.environ['VisualStudioVersion'] \
+ if 'VisualStudioVersion' in os.environ else None
+ relative_path = 'Auxiliary\\Build\\' if vs_version == '15.0' else ''
+ script_path = os.environ['VCINSTALLDIR'] + relative_path + 'vcvarsall.bat'
+ if os.path.exists(script_path):
+ if has_arch_values:
+ target_arch = os.environ['VSCMD_ARG_TGT_ARCH']
+ host_arch = os.environ['VSCMD_ARG_HOST_ARCH']
+ else:
+ target_arch = os.environ.get('Platform', 'x86')
+ host_arch = target_arch
+ arch = host_arch + '_' + target_arch if host_arch != target_arch else target_arch
+ return '"%s" %s' % (script_path, arch)
+
+ # Otherwise try the VS2017 Developer Command Prompt.
+ if 'VS150COMNTOOLS' in os.environ and has_arch_values:
+ script_path = os.environ['VS150COMNTOOLS'] + 'VsDevCmd.bat'
+ if os.path.exists(script_path):
+ return '"%s" -arch=%s -host_arch=%s' % \
+ (script_path, os.environ['VSCMD_ARG_TGT_ARCH'], os.environ['VSCMD_ARG_HOST_ARCH'])
+ return ''
+
def get_obj_target_deps(self, obj_list):
result = {}
for o in obj_list:
@@ -1096,7 +1123,7 @@ class Vs2010Backend(backends.Backend):
elif targetplatform == 'arm':
targetmachine.text = 'MachineARM'
else:
- raise MesonException('Unsupported Visual Studio target machine: ' + targetmachine)
+ raise MesonException('Unsupported Visual Studio target machine: ' + targetplatform)
meson_file_group = ET.SubElement(root, 'ItemGroup')
ET.SubElement(meson_file_group, 'None', Include=os.path.join(proj_to_src_dir, build_filename))
@@ -1213,7 +1240,9 @@ class Vs2010Backend(backends.Backend):
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
regen_command = self.environment.get_build_command() + ['--internal', 'regencheck']
private_dir = self.environment.get_scratch_dir()
+ vcvars_command = self.get_vcvars_command()
cmd_templ = '''setlocal
+call %s > NUL
"%s" "%s"
if %%errorlevel%% neq 0 goto :cmEnd
:cmEnd
@@ -1231,7 +1260,7 @@ if %%errorlevel%% neq 0 goto :VCEnd'''
message = ET.SubElement(custombuild, 'Message')
message.text = 'Checking whether solution needs to be regenerated.'
ET.SubElement(custombuild, 'Command').text = cmd_templ % \
- ('" "'.join(regen_command), private_dir)
+ (vcvars_command, '" "'.join(regen_command), private_dir)
ET.SubElement(custombuild, 'Outputs').text = Vs2010Backend.get_regen_stampfile(self.environment.get_build_dir())
deps = self.get_regen_filelist()
ET.SubElement(custombuild, 'AdditionalInputs').text = ';'.join(deps)
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 36b66ff..9e25add 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -188,6 +188,9 @@ def detect_windows_arch(compilers):
platform = os.environ.get('BUILD_PLAT', 'x86')
if platform == 'Win32':
return 'x86'
+ elif 'VSCMD_ARG_TGT_ARCH' in os.environ:
+ # On MSVC 2017 'Platform' is not set in VsDevCmd.bat
+ return os.environ['VSCMD_ARG_TGT_ARCH']
else:
# On MSVC 2010 and later 'Platform' is only set when the
# target arch is not 'x86'. It's 'x64' when targeting