Reland "mc: Copy over checked-in outputs on non-Windows hosts."

This reverts commit ea662297506102da12eb1ee04e40fad15b77a1d5.

This also reverts https://chromium-review.googlesource.com/c/chromium/src/+/584691
for non-iOS to make sure that remoting .mc outputs are not different in
official and unofficial builds.

Change-Id: I58fc96c40d1639c9145f576136afca2468459389
Bug: 756607,747637
Reviewed-on: https://chromium-review.googlesource.com/648113
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#499409}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 6cff7e77ad345f90dcc46b106620baf4cab3cef8
This commit is contained in:
Nico Weber 2017-09-03 02:59:23 +00:00
Родитель d1ab008ba2
Коммит 61717683e1
1 изменённых файлов: 59 добавлений и 11 удалений

Просмотреть файл

@ -7,22 +7,67 @@
#
# Usage: message_compiler.py <environment_file> [<args to mc.exe>*]
import distutils.dir_util
import filecmp
import os
import re
import shutil
import subprocess
import sys
import tempfile
def main():
env_file, rest = sys.argv[1], sys.argv[2:]
# Parse some argument flags.
header_dir = None
resource_dir = None
input_file = None
for i, arg in enumerate(rest):
if arg == '-h' and len(rest) > i + 1:
assert header_dir == None
header_dir = rest[i + 1]
elif arg == '-r' and len(rest) > i + 1:
assert resource_dir == None
resource_dir = rest[i + 1]
elif arg.endswith('.mc') or arg.endswith('.man'):
assert input_file == None
input_file = arg
# Copy checked-in outputs to final location.
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
assert header_dir == resource_dir
source = os.path.join(THIS_DIR, "..", "..",
"third_party", "win_build_output",
re.sub(r'^(?:[^/]+/)?gen/', 'mc/', header_dir))
distutils.dir_util.copy_tree(source, header_dir, preserve_times=False)
# On non-Windows, that's all we can do.
if sys.platform != 'win32':
return
# On Windows, run mc.exe on the input and check that its outputs are
# identical to the checked-in outputs.
# Read the environment block from the file. This is stored in the format used
# by CreateProcess. Drop last 2 NULs, one for list terminator, one for
# trailing vs. separator.
env_pairs = open(sys.argv[1]).read()[:-2].split('\0')
env_pairs = open(env_file).read()[:-2].split('\0')
env_dict = dict([item.split('=', 1) for item in env_pairs])
# mc writes to stderr, so this explicitly redirects to stdout and eats it.
try:
tmp_dir = tempfile.mkdtemp()
delete_tmp_dir = True
if header_dir:
rest[rest.index('-h') + 1] = tmp_dir
header_dir = tmp_dir
if resource_dir:
rest[rest.index('-r') + 1] = tmp_dir
resource_dir = tmp_dir
# This needs shell=True to search the path in env_dict for the mc
# executable.
rest = sys.argv[2:]
subprocess.check_output(['mc.exe'] + rest,
env=env_dict,
stderr=subprocess.STDOUT,
@ -35,15 +80,6 @@ def main():
# it generates an ANSI header, and includes broken versions of the message
# text in the comment before the value. To work around this, for any invalid
# // comment lines, we simply drop the line in the header after building it.
header_dir = None
input_file = None
for i, arg in enumerate(rest):
if arg == '-h' and len(rest) > i + 1:
assert header_dir == None
header_dir = rest[i + 1]
elif arg.endswith('.mc') or arg.endswith('.man'):
assert input_file == None
input_file = arg
if header_dir:
header_file = os.path.join(
header_dir, os.path.splitext(os.path.basename(input_file))[0] + '.h')
@ -55,9 +91,21 @@ def main():
header_contents.append(line)
with open(header_file, 'wb') as f:
f.write(''.join(header_contents))
# mc.exe invocation and post-processing are complete, now compare the output
# in tmp_dir to the checked-in outputs.
diff = filecmp.dircmp(tmp_dir, source)
if diff.diff_files or set(diff.left_list) != set(diff.right_list):
print >>sys.stderr, 'mc.exe output different from files in %s, see %s' % (
source, tmp_dir)
delete_tmp_dir = False
sys.exit(1)
except subprocess.CalledProcessError as e:
print e.output
sys.exit(e.returncode)
finally:
if os.path.exists(tmp_dir) and delete_tmp_dir:
shutil.rmtree(tmp_dir)
if __name__ == '__main__':
main()