-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfsp
executable file
·82 lines (73 loc) · 3.02 KB
/
cfsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# /*******************************************************************************
# * Copyright 2016 -- 2022 IBM Corporation
# *
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *******************************************************************************/
# *
# * cloudFPGA
# * =============================================
# * Created: Apr 2019
# * Authors: FAB, WEI, NGL, DID
# *
# * Description:
# * Bash script to invoke the cFSP tool
# *
export cFsysPy3_cmd_hint_0=$(hash -d python3.8 2>>/dev/null; which python3.8 2>>/dev/null || echo "failed")
export cFsysPy3_cmd_hint_1=$(hash -d python3 2>>/dev/null; which python3 2>>/dev/null || echo "failed")
if [ -f cfenv/bin/activate ]; then
source cfenv/bin/activate
fi
# POSIX compliant version (as a replacement for readlink -f)
# Function adapted from https://github.com/bats-core/bats-core/pull/312
readlinkf_posix() {
[ "${1:-}" ] || return 1
max_symlinks=40
CDPATH='' # to avoid changing to an unexpected directory
target=$1
[ -e "${target%/}" ] || target=${1%"${1##*[!/]}"} # trim trailing slashes
[ -d "${target:-/}" ] && target="$target/"
cd -P . 2>/dev/null || return 1
while [ "$max_symlinks" -ge 0 ] && max_symlinks=$((max_symlinks - 1)); do
if [ ! "$target" = "${target%/*}" ]; then
case $target in
/*) cd -P "${target%/*}/" 2>/dev/null || break ;;
*) cd -P "./${target%/*}" 2>/dev/null || break ;;
esac
target=${target##*/}
fi
if [ ! -L "$target" ]; then
target="${PWD%/}${target:+/}${target}"
printf '%s\n' "${target:-/}"
return 0
fi
# `ls -dl` format: "%s %u %s %s %u %s %s -> %s\n",
# <file mode>, <number of links>, <owner name>, <group name>,
# <size>, <date and time>, <pathname of link>, <contents of link>
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html
link=$(ls -dl -- "$target" 2>/dev/null) || break
target=${link#*" $target -> "}
done
return 1
}
export cfsp_path=$(readlinkf_posix $0)
export cfsp_dir="`dirname $cfsp_path`/../lib/python*/site-packages"
# If cfsp is installed through pip, it should be located in the former path, else, if it is installed through git, it is just located in the current folder of cFSPlib.
if [ -d $cfsp_dir ]; then
python3 $cfsp_dir/cFSPlib/cFSP.py "$@"
elif [ -f ./cFSPlib/cFSP.py ]; then
python3 ./cFSPlib/cFSP.py "$@"
else
echo "ERROR: Cannot locate cFSPlib/cFSP.py. Check your cFSP installation. Aborting..."
exit -1
fi