import os
import sys
import subprocess
import argparse
def run(cxx_exe, args, output, is_header_file):
sys.path.append(
os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
from scripts.util import build_utils
run_cmd = [os.path.abspath(cxx_exe)]
run_cmd.extend(args)
if is_header_file:
run_cmd.extend(["--header"])
res = subprocess.run(run_cmd, capture_output=True)
if res.returncode != 0:
return res.returncode
with build_utils.atomic_output(output) as output:
output.write(res.stdout)
return 0
def main():
parser = argparse.ArgumentParser("rust_cxxbridge.py")
parser.add_argument("--header", help="output h file with cxxbridge", required=True),
parser.add_argument("--cc", help="output cc file with cxxbridge", required=True),
parser.add_argument("--cxxbridge", help="The path of cxxbridge executable", required=True),
parser.add_argument('args', metavar='args', nargs='+', help="Args to pass through in script rust_cxxbridge.py"),
args = parser.parse_args()
ret = run(args.cxxbridge, args.args, args.header, True)
if ret != 0:
return ret
return run(args.cxxbridge, args.args, args.cc, False)
if __name__ == '__main__':
sys.exit(main())