blob: 86aba4f93009f0a8cee7c1eee3deaf2962ddc1c2 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001# Copyright 2015 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Runs the Microsoft Message Compiler (mc.exe). This Python adapter is for the
6# GN build, which can only run Python and not native binaries.
7#
8# Usage: message_compiler.py <environment_file> [<args to mc.exe>*]
9
10import subprocess
11import sys
12
13# Read the environment block from the file. This is stored in the format used
14# by CreateProcess. Drop last 2 NULs, one for list terminator, one for trailing
15# vs. separator.
16env_pairs = open(sys.argv[1]).read()[:-2].split('\0')
17env_dict = dict([item.split('=', 1) for item in env_pairs])
18
19# mc writes to stderr, so this explicitly redirects to stdout and eats it.
20try:
21 # This needs shell=True to search the path in env_dict for the mc executable.
22 subprocess.check_output(["mc.exe"] + sys.argv[2:],
23 env=env_dict,
24 stderr=subprocess.STDOUT,
25 shell=True)
26except subprocess.CalledProcessError as e:
27 print e.output
28 sys.exit(e.returncode)