1#!/usr/bin/env vpython3 2 3# Copyright 2022 The Chromium Authors 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7import argparse 8import os 9import subprocess 10import sys 11 12# Set up path to load action_helpers.py which enables us to do 13# atomic output that's maximally compatible with ninja. 14sys.path.append( 15 os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir, 16 os.pardir, os.pardir, os.pardir, 'build')) 17import action_helpers 18 19 20def run(exe, args, output, is_header): 21 cmdargs = [os.path.abspath(exe)] 22 cmdargs.extend(args) 23 if is_header: 24 cmdargs.extend(["--header"]) 25 job = subprocess.run(cmdargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 26 messages = job.stderr.decode('utf-8') 27 if messages.rstrip(): 28 print(messages, file=sys.stderr) 29 if job.returncode != 0: 30 return job.returncode 31 with action_helpers.atomic_output(output) as output: 32 output.write(job.stdout) 33 return 0 34 35 36def main(): 37 parser = argparse.ArgumentParser("run_cxxbridge.py") 38 parser.add_argument("--exe", help="Path to cxxbridge", required=True), 39 parser.add_argument("--cc", help="output cc file", required=True) 40 parser.add_argument("--header", help="output h file", required=True) 41 parser.add_argument('args', 42 metavar='args', 43 nargs='+', 44 help="Args to pass through") 45 args = parser.parse_args() 46 v = run(args.exe, args.args, args.cc, False) 47 if v != 0: 48 return v 49 return run(args.exe, args.args, args.header, True) 50 51 52if __name__ == '__main__': 53 sys.exit(main()) 54