1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (c) 2023 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import os 17import sys 18import subprocess 19import argparse 20 21 22def run(cxx_exe, args, output, is_header_file): 23 sys.path.append( 24 os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) 25 from scripts.util import build_utils 26 run_cmd = [os.path.abspath(cxx_exe)] 27 run_cmd.extend(args) 28 if is_header_file: 29 run_cmd.extend(["--header"]) 30 res = subprocess.run(run_cmd, capture_output=True) 31 if res.returncode != 0: 32 return res.returncode 33 with build_utils.atomic_output(output) as output: 34 output.write(res.stdout) 35 return 0 36 37 38def main(): 39 parser = argparse.ArgumentParser("rust_cxxbridge.py") 40 parser.add_argument("--header", help="output h file with cxxbridge", required=True), 41 parser.add_argument("--cc", help="output cc file with cxxbridge", required=True), 42 parser.add_argument("--cxxbridge", help="The path of cxxbridge executable", required=True), 43 parser.add_argument('args', metavar='args', nargs='+', help="Args to pass through in script rust_cxxbridge.py"), 44 args = parser.parse_args() 45 ret = run(args.cxxbridge, args.args, args.header, True) 46 if ret != 0: 47 return ret 48 return run(args.cxxbridge, args.args, args.cc, False) 49 50 51if __name__ == '__main__': 52 sys.exit(main()) 53