Skip to content

Commit 64873ed

Browse files
authored
[one-cmds] one-codegen backward compatibility (#6300)
This commit makes one-codegen support deprecated interface for backward compatibility. ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>
1 parent 64ca9da commit 64873ed

File tree

4 files changed

+145
-7
lines changed

4 files changed

+145
-7
lines changed

compiler/one-cmds/one-codegen

+13-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _get_backends_list():
4242

4343

4444
def _get_parser():
45-
codegen_usage = 'one-codegen [-h] [-v] [-C CONFIG] [-b BACKEND] -- [COMMANDS FOR BACKEND]'
45+
codegen_usage = 'one-codegen [-h] [-v] [-C CONFIG] [-b BACKEND] [--] [COMMANDS FOR BACKEND]'
4646
parser = argparse.ArgumentParser(
4747
description='command line tool for code generation', usage=codegen_usage)
4848

@@ -74,27 +74,33 @@ def _verify_arg(parser, args):
7474
def _parse_arg(parser):
7575
codegen_args = []
7676
backend_args = []
77+
unknown_args = []
7778
argv = copy.deepcopy(sys.argv)
7879
# delete file name
7980
del argv[0]
8081
# split by '--'
8182
args = [list(y) for x, y in itertools.groupby(argv, lambda z: z == '--') if not x]
82-
if len(args) >= 1:
83+
# one-codegen has two interfaces
84+
# 1. one-codegen [-h] [-v] [-C CONFIG] [-b BACKEND] [COMMANDS FOR BACKEND]
85+
if len(args) == 1:
8386
codegen_args = args[0]
87+
codegen_args, unknown_args = parser.parse_known_args(codegen_args)
88+
# 2. one-codegen [-h] [-v] [-C CONFIG] [-b BACKEND] -- [COMMANDS FOR BACKEND]
8489
if len(args) == 2:
90+
codegen_args = args[0]
8591
backend_args = args[1]
86-
codegen_args = parser.parse_args(codegen_args)
92+
codegen_args = parser.parse_args(codegen_args)
8793
# print version
88-
if codegen_args.version:
94+
if len(args) and codegen_args.version:
8995
_utils._print_version_and_exit(__file__)
9096

91-
return codegen_args, backend_args
97+
return codegen_args, backend_args, unknown_args
9298

9399

94100
def main():
95101
# parse arguments
96102
parser = _get_parser()
97-
args, backend_args = _parse_arg(parser)
103+
args, backend_args, unknown_args = _parse_arg(parser)
98104

99105
# parse configuration file
100106
_utils._parse_cfg(args, 'one-codegen')
@@ -105,7 +111,7 @@ def main():
105111
# make a command to run given backend driver
106112
dir_path = os.path.dirname(os.path.realpath(__file__))
107113
codegen_path = os.path.join(dir_path, getattr(args, 'backend') + '-compile')
108-
codegen_cmd = [codegen_path] + backend_args
114+
codegen_cmd = [codegen_path] + backend_args + unknown_args
109115
if _utils._is_valid_attr(args, 'command'):
110116
codegen_cmd += getattr(args, 'command').split()
111117

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# run one-codegen with dummy-compile driver
18+
19+
filename_ext="$(basename -- $0)"
20+
filename="${filename_ext%.*}"
21+
22+
trap_err_onexit()
23+
{
24+
echo "${filename_ext} FAILED"
25+
rm -rf ../bin/dummy-compile
26+
exit 255
27+
}
28+
29+
trap trap_err_onexit ERR
30+
31+
outputfile="sample.tvn"
32+
33+
rm -rf ${outputfile}
34+
35+
# copy dummy-compile to bin folder
36+
cp dummy-compile ../bin/dummy-compile
37+
38+
# run test
39+
one-codegen -b dummy -o ${outputfile} "dummy.circle"
40+
41+
if [[ ! -s "${outputfile}" ]]; then
42+
trap_err_onexit
43+
fi
44+
45+
rm -rf ../bin/dummy-compile
46+
47+
echo "${filename_ext} SUCCESS"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# run one-codegen with dummy-compile driver
18+
19+
filename_ext="$(basename -- $0)"
20+
filename="${filename_ext%.*}"
21+
22+
trap_err_onexit()
23+
{
24+
echo "${filename_ext} FAILED"
25+
rm -rf ../bin/dummy-compile
26+
exit 255
27+
}
28+
29+
trap trap_err_onexit ERR
30+
31+
outputfile="sample.tvn"
32+
33+
rm -rf ${outputfile}
34+
35+
# copy dummy-compile to bin folder
36+
cp dummy-compile ../bin/dummy-compile
37+
38+
# run test
39+
one-codegen -b dummy -- -o ${outputfile} "dummy.circle"
40+
41+
if [[ ! -s "${outputfile}" ]]; then
42+
trap_err_onexit
43+
fi
44+
45+
rm -rf ../bin/dummy-compile
46+
47+
echo "${filename_ext} SUCCESS"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# print one-codegen's help message
18+
19+
filename_ext="$(basename -- $0)"
20+
filename="${filename_ext%.*}"
21+
22+
trap_err_onexit()
23+
{
24+
echo "${filename_ext} FAILED"
25+
exit 255
26+
}
27+
28+
trap trap_err_onexit ERR
29+
30+
# run test
31+
one-codegen -h > ${filename}.log
32+
33+
if grep -q "command line tool for code generation" "${filename}.log"; then
34+
echo "${filename_ext} SUCCESS"
35+
exit 0
36+
fi
37+
38+
trap_err_onexit

0 commit comments

Comments
 (0)