forked from olofk/corescore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourceme.sh
More file actions
77 lines (67 loc) · 2.1 KB
/
sourceme.sh
File metadata and controls
77 lines (67 loc) · 2.1 KB
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
#!/usr/bin/env bash
# Python virtual environment
PYEXE=python3.12
THIS_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
VENV_DIR=${THIS_DIR}/.venv
PYREQS_FILE=requirements.txt
VENV_REQS=${THIS_DIR}/${PYREQS_FILE}
VENV_NAME=$(basename ${THIS_DIR})
export VENV_ACT=${VENV_DIR}/bin/activate
# Corescore
export WORKSPACE=${THIS_DIR}
FUSESOC_CONF=${WORKSPACE}/fusesoc.conf
FUSESOC_CORES=fusesoc_cores
FUSESOC_CORES_URL=https://github.com/fusesoc/fusesoc-cores
CORESCORE_CORE=corescore
#CORESCORE_CORE_URL=https://github.com/olofk/corescore
CORESCORE_CORE_URL=.
# ########################
# ## Helper functions ##
# ########################
function prepend_path_unique() {
if [ -n "${PATH}" ]; then
export PATH=$1:$(sed -r "s,(:$1$)|($1:),,g" <<< "$PATH")
else
export PATH=$1
fi
}
function create_venv() {
${PYEXE} -m venv --prompt ${VENV_NAME} ${VENV_DIR}
. ${VENV_ACT}
python -m pip install --upgrade pip
pip install wheel
if [ ! -f ${VENV_REQS} ]; then
printf "\n\t${PYREQS_FILE} not found...skipping\n\n"
else
printf "\n\tInstalling packages listed in ${PYREQS_FILE}...\n\n"
pip install -r ${VENV_REQS}
fi
}
function venv_setup() {
if [ ! -d ${VENV_DIR} ]; then
printf " - Python virtual environment NOT found\n"
printf " -> Setting up Python virtual environment\n"
create_venv
else
printf " - Python virtual environment found\n"
printf " -> Activating Python virtual environment\n"
. ${VENV_ACT}
fi
}
function corescore_setup() {
if [ ! -f ${FUSESOC_CONF} ]; then
printf "\nAdding FuseSoC standard cores library\n"
fusesoc library add ${FUSESOC_CORES} ${FUSESOC_CORES_URL}
printf "\nAdding (local) FuseSoC corescore library\n"
fusesoc library add ${CORESCORE_CORE} ${CORESCORE_CORE_URL}
fi
}
# ########################
# ## Setup & run ##
# ########################
# Create the venv if it does not already exist and/or activate it
venv_setup
# Setup the CORESCORE libraries (if they don't already exist)
corescore_setup
# Return to setup dir
cd ${THIS_DIR}