Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / one-cmds / one-import
1 #!/bin/bash
2
3 # Copyright (c) 2020 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 DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18
19 function Usage()
20 {
21   echo "Usage: one-import [FRAMEWORK] ..."
22   echo "Available FRAMEWORK drivers:"
23   framework_exist=0
24   for file in "$DRIVER_PATH"/one-import-*;
25   do
26     framework_driver=$(basename $file)
27     framework=${framework_driver:11} # 11 is length of "one-import-"
28     echo "  $framework"
29     framework_exist=1
30   done
31   if [ $framework_exist == 0 ]; then
32     echo "  (There is no available import drivers)"
33   fi
34
35   exit 255
36 }
37
38 function version()
39 {
40   $DRIVER_PATH/one-version one-import-tf
41   exit 255
42 }
43
44 # Get command from command-line
45 FRAMEWORK=$1
46 if [[ -z ${FRAMEWORK} ]]; then
47   Usage
48 fi
49 shift
50
51 if [ ${FRAMEWORK} = "--version" ]; then
52   version
53 fi
54
55 FRAMEWORK_DRIVER="one-import-$FRAMEWORK"
56
57 FRAMEWORK_DRIVER_CMD="${DRIVER_PATH}/${FRAMEWORK_DRIVER}"
58
59 if [[ ! -f "${FRAMEWORK_DRIVER_CMD}" ]]; then
60   echo "ERROR: '${FRAMEWORK_DRIVER}' is not supported"
61   Usage
62 fi
63
64 "${FRAMEWORK_DRIVER_CMD}" "$@"