vs: refactor regen target creation

pull/4918/head
Nicolas Schneider 6 years ago
parent b1c3d150fe
commit e004e711b1
  1. 44
      mesonbuild/backend/vs2010backend.py

@ -1263,31 +1263,13 @@ class Vs2010Backend(backends.Backend):
ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c' ET.SubElement(midl, 'InterfaceIdentifierFilename').text = '%(Filename)_i.c'
ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c' ET.SubElement(midl, 'ProxyFileName').text = '%(Filename)_p.c'
regen_command = self.environment.get_build_command() + ['--internal', 'regencheck'] regen_command = self.environment.get_build_command() + ['--internal', 'regencheck']
private_dir = self.environment.get_scratch_dir() cmd_templ = '''call %s > NUL
vcvars_command = self.get_vcvars_command() "%s" "%s"'''
cmd_templ = '''setlocal regen_command = cmd_templ % \
call %s > NUL (self.get_vcvars_command(), '" "'.join(regen_command), self.environment.get_scratch_dir())
"%s" "%s" self.add_custom_build(root, 'regen', regen_command, deps=self.get_regen_filelist(),
if %%errorlevel%% neq 0 goto :cmEnd outputs=[Vs2010Backend.get_regen_stampfile(self.environment.get_build_dir())],
:cmEnd msg='Checking whether solution needs to be regenerated.')
endlocal & call :cmErrorLevel %%errorlevel%% & goto :cmDone
:cmErrorLevel
exit /b %%1
:cmDone
if %%errorlevel%% neq 0 goto :VCEnd'''
igroup = ET.SubElement(root, 'ItemGroup')
rulefile = os.path.join(self.environment.get_scratch_dir(), 'regen.rule')
if not os.path.exists(rulefile):
with open(rulefile, 'w', encoding='utf-8') as f:
f.write("# Meson regen file.")
custombuild = ET.SubElement(igroup, 'CustomBuild', Include=rulefile)
message = ET.SubElement(custombuild, 'Message')
message.text = 'Checking whether solution needs to be regenerated.'
ET.SubElement(custombuild, 'Command').text = cmd_templ % \
(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)
ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets') ET.SubElement(root, 'Import', Project=r'$(VCTargetsPath)\Microsoft.Cpp.targets')
ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets') ET.SubElement(root, 'ImportGroup', Label='ExtensionTargets')
self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)
@ -1409,13 +1391,16 @@ if %%errorlevel%% neq 0 goto :VCEnd'''
self.add_regen_dependency(root) self.add_regen_dependency(root)
self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname) self._prettyprint_vcxproj_xml(ET.ElementTree(root), ofname)
def add_custom_build(self, node, rulename, command, output_file=None): def add_custom_build(self, node, rulename, command, deps=None, outputs=None, msg=None):
igroup = ET.SubElement(node, 'ItemGroup') igroup = ET.SubElement(node, 'ItemGroup')
rulefile = os.path.join(self.environment.get_scratch_dir(), rulename + '.rule') rulefile = os.path.join(self.environment.get_scratch_dir(), rulename + '.rule')
if not os.path.exists(rulefile): if not os.path.exists(rulefile):
with open(rulefile, 'w', encoding='utf-8') as f: with open(rulefile, 'w', encoding='utf-8') as f:
f.write("# Meson regen file.") f.write("# Meson regen file.")
custombuild = ET.SubElement(igroup, 'CustomBuild', Include=rulefile) custombuild = ET.SubElement(igroup, 'CustomBuild', Include=rulefile)
if msg:
message = ET.SubElement(custombuild, 'Message')
message.text = msg
cmd_templ = '''setlocal cmd_templ = '''setlocal
%s %s
if %%errorlevel%% neq 0 goto :cmEnd if %%errorlevel%% neq 0 goto :cmEnd
@ -1426,12 +1411,15 @@ exit /b %%1
:cmDone :cmDone
if %%errorlevel%% neq 0 goto :VCEnd''' if %%errorlevel%% neq 0 goto :VCEnd'''
ET.SubElement(custombuild, 'Command').text = cmd_templ % command ET.SubElement(custombuild, 'Command').text = cmd_templ % command
if not output_file: if not outputs:
# Use a nonexistent file to always consider the target out-of-date. # Use a nonexistent file to always consider the target out-of-date.
output_file = os.path.join(self.environment.get_scratch_dir(), 'outofdate.file') output_file = os.path.join(self.environment.get_scratch_dir(), 'outofdate.file')
while os.path.exists(output_file): while os.path.exists(output_file):
output_file += '0' output_file += '0'
ET.SubElement(custombuild, 'Outputs').text = output_file outputs = [output_file]
ET.SubElement(custombuild, 'Outputs').text = ';'.join(outputs)
if deps:
ET.SubElement(custombuild, 'AdditionalInputs').text = ';'.join(deps)
def generate_debug_information(self, link): def generate_debug_information(self, link):
# valid values for vs2015 is 'false', 'true', 'DebugFastLink' # valid values for vs2015 is 'false', 'true', 'DebugFastLink'

Loading…
Cancel
Save