2 ''''export SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # '''
3 ''''export PY_PATH=${SCRIPT_PATH}/venv/bin/python # '''
4 ''''test -f ${PY_PATH} && exec ${PY_PATH} "$0" "$@" # '''
5 ''''echo "Error: Virtual environment not found. Please run 'one-prepare-venv' command." # '''
8 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
28 import utils as _utils
31 def _get_backends_list():
32 dir_path = os.path.dirname(os.path.realpath(__file__))
33 files = [f for f in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, f))]
36 if cand.endswith('-compile'):
37 # 8 : length of '-compile'
38 backends_list.append(cand[:-8])
43 parser = argparse.ArgumentParser(description='command line tool for code generation')
45 _utils._add_default_arg(parser)
47 # get backend list in the directory
48 backends_list = _get_backends_list()
50 backends_list_message = '(There is no available backend drivers)'
52 backends_list_message = '(available backend drivers: ' + '.'.join(
54 backend_help_message = 'backend name to use ' + backends_list_message
55 parser.add_argument('-b', '--backend', type=str, help=backend_help_message)
60 def _verify_arg(parser, args):
61 """verify given arguments"""
62 # check if required arguments is given
64 if not _utils._is_valid_attr(args, 'backend'):
65 missing.append('-b/--backend')
67 parser.error('the following arguments are required: ' + ' '.join(missing))
70 def _parse_arg(parser):
71 args, unknown_args = parser.parse_known_args()
74 _utils._print_version_and_exit(__file__)
76 return args, unknown_args
81 parser = _get_parser()
82 args, unknown_args = _parse_arg(parser)
84 # parse configuration file
85 _utils._parse_cfg(args, 'one-codegen')
88 _verify_arg(parser, args)
90 # make a command to run given backend driver
91 dir_path = os.path.dirname(os.path.realpath(__file__))
92 codegen_path = os.path.join(dir_path, getattr(args, 'backend') + '-compile')
93 codegen_cmd = [codegen_path] + unknown_args
94 if _utils._is_valid_attr(args, 'command'):
95 codegen_cmd += getattr(args, 'command').split()
98 with subprocess.Popen(
99 codegen_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
101 for line in p.stdout:
102 sys.stdout.buffer.write(line)
105 if __name__ == '__main__':