Skip to content

Commit

Permalink
Use correct environment for REGEN in VS backend.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
john-preston authored and jpakkane committed Dec 4, 2018
1 parent 8612f15 commit c17a80f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 31 additions & 2 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ def generate_regen_info(self):
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:
Expand Down Expand Up @@ -1096,7 +1123,7 @@ def gen_vcxproj(self, target, ofname, guid):
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))
Expand Down Expand Up @@ -1213,7 +1240,9 @@ def gen_regenproj(self, project_name, ofname):
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
Expand All @@ -1231,7 +1260,7 @@ def gen_regenproj(self, project_name, ofname):
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)
Expand Down
3 changes: 3 additions & 0 deletions mesonbuild/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c17a80f

Please sign in to comment.