[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / third_party / yasm / run_yasm.py
blobcbd79ccea177250abb74080b6b2f3b7e3ac779c5
1 # Copyright 2014 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.
5 """A wrapper to run yasm.
7 Its main job is to provide a Python wrapper for GN integration, and to write
8 the makefile-style output yasm generates in stdout to a .d file for dependency
9 management of .inc files.
11 Run with:
12 python run_yasm.py <yasm_binary_path> <all other yasm args>
14 Note that <all other yasm args> must include an explicit output file (-o). This
15 script will append a ".d" to this and write the dependencies there. This script
16 will add "-M" to cause yasm to write the deps to stdout, so you don't need to
17 specify that.
18 """
20 import argparse
21 import sys
22 import subprocess
24 # Extract the output file name from the yasm command line so we can generate a
25 # .d file with the same base name.
26 parser = argparse.ArgumentParser()
27 parser.add_argument("-o", dest="objfile")
28 options, _ = parser.parse_known_args()
30 objfile = options.objfile
31 depfile = objfile + '.d'
33 # Assemble.
34 result_code = subprocess.call(sys.argv[1:])
35 if result_code != 0:
36 sys.exit(result_code)
38 # Now generate the .d file listing the dependencies. The -M option makes yasm
39 # write the Makefile-style dependencies to stdout, but it seems that inhibits
40 # generating any compiled output so we need to do this in a separate pass.
41 # However, outputting deps seems faster than actually assembling, and yasm is
42 # so fast anyway this is not a big deal.
44 # This guarantees proper dependency management for assembly files. Otherwise,
45 # we would have to require people to manually specify the .inc files they
46 # depend on in the build file, which will surely be wrong or out-of-date in
47 # some cases.
48 deps = subprocess.check_output(sys.argv[1:] + ['-M'])
49 with open(depfile, "wb") as f:
50 f.write(deps)