From cdae69c0f8c5623f9e563c15a50e453530366e3d Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 10 Apr 2017 01:12:35 +0530 Subject: vs: Pretty-print all vcxproj output We were more hesitant to do this earlier because it might have messed up custom_target command lines, but since we always use a wrapper for that now, it should be ok to do this. Add a test in the form of a funky generator script. --- mesonbuild/backend/vs2010backend.py | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'mesonbuild/backend/vs2010backend.py') diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index feae79e..79ad840 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -427,8 +427,7 @@ class Vs2010Backend(backends.Backend): ET.SubElement(customstep, 'Command').text = cmd_templ % tuple(cmd) ET.SubElement(customstep, 'Message').text = 'Running custom command.' ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets') - tree = ET.ElementTree(root) - tree.write(ofname, encoding='utf-8', xml_declaration=True) + self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) def gen_custom_target_vcxproj(self, target, ofname, guid): root = self.create_basic_crap(target) @@ -452,8 +451,7 @@ class Vs2010Backend(backends.Backend): ET.SubElement(customstep, 'Inputs').text = ';'.join(srcs) ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets') self.generate_custom_generator_commands(target, root) - tree = ET.ElementTree(root) - tree.write(ofname, encoding='utf-8', xml_declaration=True) + self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) @classmethod def lang_from_source_file(cls, src): @@ -579,6 +577,13 @@ class Vs2010Backend(backends.Backend): return c raise MesonException('Could not find a C or C++ compiler. MSVC can only build C/C++ projects.') + def _prettyprint_vcxproj_xml(self, tree, ofname): + tree.write(ofname, encoding='utf-8', xml_declaration=True) + # ElementTree can not do prettyprinting so do it manually + doc = xml.dom.minidom.parse(ofname) + with open(ofname, 'w') as of: + of.write(doc.toprettyxml()) + def gen_vcxproj(self, target, ofname, guid): mlog.debug('Generating vcxproj %s.' % target.name) entrypoint = 'WinMainCRTStartup' @@ -1023,19 +1028,7 @@ class Vs2010Backend(backends.Backend): ig = ET.SubElement(root, 'ItemGroup') pref = ET.SubElement(ig, 'ProjectReference', Include=os.path.join(self.environment.get_build_dir(), 'REGEN.vcxproj')) ET.SubElement(pref, 'Project').text = self.environment.coredata.regen_guid - tree = ET.ElementTree(root) - tree.write(ofname, encoding='utf-8', xml_declaration=True) - # ElementTree can not do prettyprinting so do it manually - doc = xml.dom.minidom.parse(ofname) - with open(ofname, 'w') as of: - of.write(doc.toprettyxml()) - # World of horror! Python insists on not quoting quotes and - # fixing the escaped " into " whereas MSVS - # requires quoted but not fixed elements. Enter horrible hack. - with open(ofname, 'r') as of: - txt = of.read() - with open(ofname, 'w') as of: - of.write(txt.replace('"', '"')) + self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) def gen_regenproj(self, project_name, ofname): root = ET.Element('Project', {'DefaultTargets': 'Build', @@ -1114,8 +1107,7 @@ if %%errorlevel%% neq 0 goto :VCEnd''' ET.SubElement(custombuild, 'AdditionalInputs').text = ';'.join(deps) ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets') ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets') - tree = ET.ElementTree(root) - tree.write(ofname, encoding='utf-8', xml_declaration=True) + self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) def gen_testproj(self, target_name, ofname): project_name = target_name @@ -1189,8 +1181,4 @@ if %%errorlevel%% neq 0 goto :VCEnd''' ET.SubElement(postbuild, 'Command').text =\ cmd_templ % ('" "'.join(test_command)) ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets') - tree = ET.ElementTree(root) - tree.write(ofname, encoding='utf-8', xml_declaration=True) - # ElementTree can not do prettyprinting so do it manually - # doc = xml.dom.minidom.parse(ofname) - # open(ofname, 'w').write(doc.toprettyxml()) + self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) -- cgit v1.1 From 711c0cbd674a84fc2d28d0b92dfb62124180d3ef Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 10 Apr 2017 03:19:10 +0530 Subject: vs: Fix depend_files support in custom targets This was totally broken and we didn't notice because we had no tests for it at all. --- mesonbuild/backend/vs2010backend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'mesonbuild/backend/vs2010backend.py') diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py index 79ad840..46eab11 100644 --- a/mesonbuild/backend/vs2010backend.py +++ b/mesonbuild/backend/vs2010backend.py @@ -437,6 +437,7 @@ class Vs2010Backend(backends.Backend): # from the target dir, not the build root. target.absolute_paths = True (srcs, ofilenames, cmd) = self.eval_custom_target_command(target, True) + depend_files = self.get_custom_target_depend_files(target, True) # Always use a wrapper because MSBuild eats random characters when # there are many arguments. tdir_abs = os.path.join(self.environment.get_build_dir(), self.get_target_dir(target)) @@ -448,7 +449,7 @@ class Vs2010Backend(backends.Backend): '--internal', 'exe', exe_data] ET.SubElement(customstep, 'Command').text = ' '.join(self.quote_arguments(wrapper_cmd)) ET.SubElement(customstep, 'Outputs').text = ';'.join(ofilenames) - ET.SubElement(customstep, 'Inputs').text = ';'.join(srcs) + ET.SubElement(customstep, 'Inputs').text = ';'.join([exe_data] + srcs + depend_files) ET.SubElement(root, 'Import', Project='$(VCTargetsPath)\Microsoft.Cpp.targets') self.generate_custom_generator_commands(target, root) self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) -- cgit v1.1