Skip to content

Commit

Permalink
Only when setup with --genvslite, made the RUN_TESTS and RUN_INSTALL …
Browse files Browse the repository at this point in the history
…projects the slightly simpler makefile-style projects whose build actions now runs the 'meson test/install -C [build dir for current buildtype/config] ...' command that selects the build dir appropriate for the current visual studio build config. Also ensured paths in the NMake build/rebuild/clean args are quoted, otherwise they'll choke if they contain spaces.
  • Loading branch information
GertyP committed Jun 8, 2023
1 parent 5108805 commit c1e488d
Showing 1 changed file with 94 additions and 42 deletions.
136 changes: 94 additions & 42 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ def generate(self, captured_compile_args_per_buildtype_and_target: dict = None):
self.sanitize = 'none'
sln_filename = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.sln')
projlist = self.generate_projects(captured_compile_args_per_buildtype_and_target)
self.gen_testproj('RUN_TESTS', os.path.join(self.environment.get_build_dir(), 'RUN_TESTS.vcxproj'))
self.gen_installproj('RUN_INSTALL', os.path.join(self.environment.get_build_dir(), 'RUN_INSTALL.vcxproj'))
self.gen_testproj()
self.gen_installproj()
self.gen_regenproj()
self.generate_solution(sln_filename, projlist)
self.generate_regen_info()
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def add_gen_lite_makefile_vcxproj_elements(
proj_to_build_dir_for_buildtype = str(os.path.join(proj_to_multiconfigured_builds_parent_dir, meson_build_dir_for_buildtype))
ET.SubElement(per_config_prop_group, 'OutDir').text = f'{proj_to_build_dir_for_buildtype}\\'
ET.SubElement(per_config_prop_group, 'IntDir').text = f'{proj_to_build_dir_for_buildtype}\\'
ET.SubElement(per_config_prop_group, 'NMakeBuildCommandLine').text = f'{nmake_base_meson_command} compile -C {proj_to_build_dir_for_buildtype}'
ET.SubElement(per_config_prop_group, 'NMakeBuildCommandLine').text = f'{nmake_base_meson_command} compile -C "{proj_to_build_dir_for_buildtype}"'
ET.SubElement(per_config_prop_group, 'NMakeOutput').text = f'$(OutDir){target.name}{target_ext}'
captured_build_args = captured_compile_args_per_buildtype_and_target[buildtype][target.get_id()]
# 'captured_build_args' is a dictionary, mapping from each src file type to a list of compile args to use for that type.
Expand All @@ -1250,8 +1250,8 @@ def add_gen_lite_makefile_vcxproj_elements(
primary_src_type_build_args = list(captured_build_args.values())[0]
ET.SubElement(per_config_prop_group, 'NMakePreprocessorDefinitions').text = Vs2010Backend.extract_nmake_preprocessor_defs(primary_src_type_build_args)
ET.SubElement(per_config_prop_group, 'NMakeIncludeSearchPath').text = Vs2010Backend.extract_nmake_include_paths(primary_src_type_build_args)
ET.SubElement(per_config_prop_group, 'NMakeReBuildCommandLine').text = f'{nmake_base_meson_command} compile -C {proj_to_build_dir_for_buildtype} --clean && {nmake_base_meson_command} compile -C {proj_to_build_dir_for_buildtype}'
ET.SubElement(per_config_prop_group, 'NMakeCleanCommandLine').text = f'{nmake_base_meson_command} compile -C {proj_to_build_dir_for_buildtype} --clean'
ET.SubElement(per_config_prop_group, 'NMakeReBuildCommandLine').text = f'{nmake_base_meson_command} compile -C "{proj_to_build_dir_for_buildtype}" --clean && {nmake_base_meson_command} compile -C "{proj_to_build_dir_for_buildtype}"'
ET.SubElement(per_config_prop_group, 'NMakeCleanCommandLine').text = f'{nmake_base_meson_command} compile -C "{proj_to_build_dir_for_buildtype}" --clean'
# Need to set the 'ExecutablePath' element for the above NMake... commands to be able to invoke the meson command.
ET.SubElement(per_config_prop_group, 'ExecutablePath').text = exe_search_paths
ET.SubElement(per_config_prop_group, 'AdditionalOptions').text = Vs2010Backend.extract_intellisense_additional_compiler_options(primary_src_type_build_args)
Expand Down Expand Up @@ -1865,7 +1865,7 @@ def gen_regenproj(self):
for buildtype in multi_config_buildtype_list:
meson_build_dir_for_buildtype = build_dir_tail[:-2] + buildtype # Get the buildtype suffixed 'builddir_[debug/release/etc]' from 'builddir_vs', for example.
proj_to_build_dir_for_buildtype = str(os.path.join(proj_to_multiconfigured_builds_parent_dir, meson_build_dir_for_buildtype))
reconfigure_all_cmd += f'{nmake_base_meson_command} setup --reconfigure {proj_to_build_dir_for_buildtype} {proj_to_src_dir}\n'
reconfigure_all_cmd += f'{nmake_base_meson_command} setup --reconfigure "{proj_to_build_dir_for_buildtype}" "{proj_to_src_dir}"\n'
ET.SubElement(all_configs_prop_group, 'NMakeBuildCommandLine').text = reconfigure_all_cmd
ET.SubElement(all_configs_prop_group, 'NMakeReBuildCommandLine').text = reconfigure_all_cmd
ET.SubElement(all_configs_prop_group, 'NMakeCleanCommandLine').text = ''
Expand Down Expand Up @@ -1894,50 +1894,102 @@ def gen_regenproj(self):
ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets')
self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)

def gen_testproj(self, target_name, ofname):
def gen_testproj(self):
project_name = 'RUN_TESTS'
ofname = os.path.join(self.environment.get_build_dir(), f'{project_name}.vcxproj')
guid = self.environment.coredata.test_guid
(root, type_config) = self.create_basic_project(target_name,
temp_dir='test-temp',
guid=guid)
if self.gen_lite:
(root, type_config) = self.create_basic_project(project_name,
temp_dir='install-temp',
guid=guid,
conftype='Makefile'
)
(nmake_base_meson_command, exe_search_paths) = Vs2010Backend.get_nmake_base_meson_command_and_exe_search_paths()
multi_config_buildtype_list = coredata.get_genvs_default_buildtype_list()
(_, build_dir_tail) = os.path.split(self.src_to_build)
proj_to_multiconfigured_builds_parent_dir = '..' # We know this .vcxproj will always be in the '[buildir]_vs' dir.
# Add appropriate 'test' commands for the 'build' action of this project, for all buildtypes
for buildtype in multi_config_buildtype_list:
meson_build_dir_for_buildtype = build_dir_tail[:-2] + buildtype # Get the buildtype suffixed 'builddir_[debug/release/etc]' from 'builddir_vs', for example.
proj_to_build_dir_for_buildtype = str(os.path.join(proj_to_multiconfigured_builds_parent_dir, meson_build_dir_for_buildtype))
test_cmd = f'{nmake_base_meson_command} test -C "{proj_to_build_dir_for_buildtype}" --no-rebuild'
if not self.environment.coredata.get_option(OptionKey('stdsplit')):
test_cmd += ' --no-stdsplit'
if self.environment.coredata.get_option(OptionKey('errorlogs')):
test_cmd += ' --print-errorlogs'
condition = f'\'$(Configuration)|$(Platform)\'==\'{buildtype}|{self.platform}\''
prop_group = ET.SubElement(root, 'PropertyGroup', Condition=condition)
ET.SubElement(prop_group, 'NMakeBuildCommandLine').text = test_cmd
#Need to set the 'ExecutablePath' element for the NMake... commands to be able to execute
ET.SubElement(prop_group, 'ExecutablePath').text = exe_search_paths
else:
(root, type_config) = self.create_basic_project(project_name,
temp_dir='test-temp',
guid=guid)

action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl')
ET.SubElement(midl, "AdditionalIncludeDirectories").text = '%(AdditionalIncludeDirectories)'
ET.SubElement(midl, "OutputDirectory").text = '$(IntDir)'
ET.SubElement(midl, 'HeaderFileName').text = '%(Filename).h'
ET.SubElement(midl, 'TypeLibraryName').text = '%(Filename).tlb'
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
# FIXME: No benchmarks?
test_command = self.environment.get_build_command() + ['test', '--no-rebuild']
if not self.environment.coredata.get_option(OptionKey('stdsplit')):
test_command += ['--no-stdsplit']
if self.environment.coredata.get_option(OptionKey('errorlogs')):
test_command += ['--print-errorlogs']
self.serialize_tests()
self.add_custom_build(root, 'run_tests', '"%s"' % ('" "'.join(test_command)))

action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl')
ET.SubElement(midl, "AdditionalIncludeDirectories").text = '%(AdditionalIncludeDirectories)'
ET.SubElement(midl, "OutputDirectory").text = '$(IntDir)'
ET.SubElement(midl, 'HeaderFileName').text = '%(Filename).h'
ET.SubElement(midl, 'TypeLibraryName').text = '%(Filename).tlb'
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
# FIXME: No benchmarks?
test_command = self.environment.get_build_command() + ['test', '--no-rebuild']
if not self.environment.coredata.get_option(OptionKey('stdsplit')):
test_command += ['--no-stdsplit']
if self.environment.coredata.get_option(OptionKey('errorlogs')):
test_command += ['--print-errorlogs']
self.serialize_tests()
self.add_custom_build(root, 'run_tests', '"%s"' % ('" "'.join(test_command)))
ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
self.add_regen_dependency(root)
self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)

def gen_installproj(self, target_name, ofname):
self.create_install_data_files()

def gen_installproj(self):
project_name = 'RUN_INSTALL'
ofname = os.path.join(self.environment.get_build_dir(), f'{project_name}.vcxproj')
guid = self.environment.coredata.install_guid
(root, type_config) = self.create_basic_project(target_name,
temp_dir='install-temp',
guid=guid)
if self.gen_lite:
(root, type_config) = self.create_basic_project(project_name,
temp_dir='install-temp',
guid=guid,
conftype='Makefile'
)
(nmake_base_meson_command, exe_search_paths) = Vs2010Backend.get_nmake_base_meson_command_and_exe_search_paths()
multi_config_buildtype_list = coredata.get_genvs_default_buildtype_list()
(_, build_dir_tail) = os.path.split(self.src_to_build)
proj_to_multiconfigured_builds_parent_dir = '..' # We know this .vcxproj will always be in the '[buildir]_vs' dir.
# Add appropriate 'install' commands for the 'build' action of this project, for all buildtypes
for buildtype in multi_config_buildtype_list:
meson_build_dir_for_buildtype = build_dir_tail[:-2] + buildtype # Get the buildtype suffixed 'builddir_[debug/release/etc]' from 'builddir_vs', for example.
proj_to_build_dir_for_buildtype = str(os.path.join(proj_to_multiconfigured_builds_parent_dir, meson_build_dir_for_buildtype))
install_cmd = f'{nmake_base_meson_command} install -C "{proj_to_build_dir_for_buildtype}" --no-rebuild'
condition = f'\'$(Configuration)|$(Platform)\'==\'{buildtype}|{self.platform}\''
prop_group = ET.SubElement(root, 'PropertyGroup', Condition=condition)
ET.SubElement(prop_group, 'NMakeBuildCommandLine').text = install_cmd
#Need to set the 'ExecutablePath' element for the NMake... commands to be able to execute
ET.SubElement(prop_group, 'ExecutablePath').text = exe_search_paths
else:
self.create_install_data_files()

(root, type_config) = self.create_basic_project(project_name,
temp_dir='install-temp',
guid=guid)

action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl')
ET.SubElement(midl, "AdditionalIncludeDirectories").text = '%(AdditionalIncludeDirectories)'
ET.SubElement(midl, "OutputDirectory").text = '$(IntDir)'
ET.SubElement(midl, 'HeaderFileName').text = '%(Filename).h'
ET.SubElement(midl, 'TypeLibraryName').text = '%(Filename).tlb'
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
install_command = self.environment.get_build_command() + ['install', '--no-rebuild']
self.add_custom_build(root, 'run_install', '"%s"' % ('" "'.join(install_command)))

action = ET.SubElement(root, 'ItemDefinitionGroup')
midl = ET.SubElement(action, 'Midl')
ET.SubElement(midl, "AdditionalIncludeDirectories").text = '%(AdditionalIncludeDirectories)'
ET.SubElement(midl, "OutputDirectory").text = '$(IntDir)'
ET.SubElement(midl, 'HeaderFileName').text = '%(Filename).h'
ET.SubElement(midl, 'TypeLibraryName').text = '%(Filename).tlb'
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
install_command = self.environment.get_build_command() + ['install', '--no-rebuild']
self.add_custom_build(root, 'run_install', '"%s"' % ('" "'.join(install_command)))
ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
self.add_regen_dependency(root)
self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)
Expand Down

0 comments on commit c1e488d

Please sign in to comment.