blob: 910a97f19382f869d5ed40f9d916d9ea81141676 [file] [log] [blame]
#!/usr/bin/env python2.7
# Copyright 2020 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Run the 'fidlc' host tool to generate a C header from a list of libraries given in a response file.
This also takes care of generating a dependency file."""
import argparse
import itertools
import shlex
import subprocess
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--name', required=True, help='Fidl library name')
'--c-header', required=True, help='Path to output header file')
'--fidlc', required=True, help='Path to fidlc tool binary')
help='Path to the rsp file with file references',
'--dep-file', help='Path to the depfile to generate', required=True)
args = parser.parse_args()
# Run 'fidlc' to generate the header.
args.fidlc, '--c-header', args.c_header, '--name',,
'@' + args.rsp_file
# Generate the depfile from the content of the response file.
with open(args.rsp_file, 'r') as rsp_file:
lines = rsp_file.readlines()
# Generate something looking like a proper command line.
command = shlex.split(' '.join(l.strip() for l in lines))
# Use argparse to parse that command line!
files_parser = argparse.ArgumentParser()
files_parser.add_argument('--files', nargs='*', action='append')
# Flatten the resulting list of lists.
files = list(itertools.chain(*files_parser.parse_args(command).files))
with open(args.dep_file, 'w') as dep_file:
dep_file.write('%s: %s' % (args.c_header, ' '.join(files)))
return 0
if __name__ == '__main__':