scons: Improve validation of XML dialogs, and make it work on Windows if xmllint is installed

This commit is contained in:
2015-09-13 23:55:32 -04:00
parent a38a8e3a7d
commit 19197a64e7
2 changed files with 31 additions and 21 deletions

View File

@@ -320,11 +320,15 @@ elif str(platform) == "win32":
target_dirs = ["#build/Blades of Exile", "#build/test"]
for lib in bundled_libs:
for lpath in env['LIBPATH']:
if 'Visual Studio' in lpath:
lpath = lpath.replace('lib', 'bin')
src_file = path.join(lpath, lib + ".dll")
if path.exists(src_file):
for targ in target_dirs:
env.Install(targ, src_file)
break
elif 'lib' in lpath:
src_file = path.join(lpath.replace('lib', 'bin'), lib + ".dll")
if path.exists(src_file):
for targ in target_dirs:
env.Install(targ, src_file)
break

View File

@@ -21,26 +21,32 @@ env.Install(path.join(data_dir, "shaders"), Glob("#src/tools/mask.*"))
env.Install(path.join(install_dir, "Blades of Exile Scenarios"), Glob("Blades of Exile Scenarios/*.exs") + Glob("Blades of Exile Scenarios/*.meg"))
env.Install(path.join(install_dir, "Blades of Exile Base"), Glob("Blades of Exile Bases/*.exs"))
if str(platform) != "win32" and subprocess.call(['which', '-s', 'xmllint']) == 0:
have_xmllint = False
if ((str(platform) != "win32" and subprocess.call(['which', '-s', 'xmllint']) == 0) or
(str(platform) == "win32" and subprocess.call(['where', '/Q', 'xmllint'])) == 0):
have_xmllint = True
xmllint_command = ('xmllint', '--nonet', '--noout', '--schema', '../schemas/dialog.xsd')
if have_xmllint: # This is separate so that alternate xml validators could be user
def validate_dialogs(target, source, env):
sources = source
if have_xmllint: # This is separate so that alternate xml validators could be used
def validate_dialog(target, source, env):
PIPE = subprocess.PIPE
with open(target[0].path, 'w') as log:
for source in sources:
src_name = path.basename(source.path)
if src_name == 'dialog.xsd':
continue
cmd_line = xmllint_command + (src_name,)
print(*cmd_line)
p = subprocess.Popen(cmd_line,
bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE,
cwd=Dir('rsrc/dialogs').abspath
)
out, err = p.communicate()
print(err, end='')
print(err, file=log)
env.Command('#build/dialogs.log', Glob('dialogs/*.xml') + ['schemas/dialog.xsd'], validate_dialogs)
with open(target[0].abspath, 'w') as log:
src_name = path.basename(source[0].path)
cmd_line = xmllint_command + (src_name,)
print(*cmd_line)
p = subprocess.Popen(cmd_line,
bufsize=1, stdin=PIPE, stdout=PIPE, stderr=PIPE,
cwd=source[0].Dir('.').abspath
)
out, err = p.communicate()
print(err, end='')
print(err, file=log)
return p.returncode
# We use these .log files as dummy targets, basically (though they also store the validation results)
env.Append(BUILDERS={"ValidateDialogXml": Builder(action=validate_dialog,suffix='.log',src_suffix='.xml')})
for dlg in Glob('dialogs/*.xml'):
dlg = path.basename(dlg.path).split('.')[0]
env.ValidateDialogXml(path.join("#build/dialogs", dlg), path.join("dialogs", dlg))
else:
print("Note: Skipping XML dialog validation since no validator tool was found.")