|
1 | 1 | #!/bin/bash
|
| 2 | +# |
| 3 | +# FreeRTOS STM32 Reference Integration |
| 4 | +# |
| 5 | +# Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 8 | +# this software and associated documentation files (the "Software"), to deal in |
| 9 | +# the Software without restriction, including without limitation the rights to |
| 10 | +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 11 | +# the Software, and to permit persons to whom the Software is furnished to do so, |
| 12 | +# subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 19 | +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 20 | +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 21 | +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | +# |
| 24 | +# https://www.FreeRTOS.org |
| 25 | +# https://github.com/FreeRTOS |
| 26 | +# |
| 27 | +# |
| 28 | +if [ -n "${BASH_SOURCE[0]}" ]; then |
| 29 | + TOOLS_PATH=$( realpath "$(cd "$(dirname "${BASH_SOURCE[0]}")" || return; pwd )" ) |
| 30 | +else |
| 31 | + TOOLS_PATH=$( realpath "$(cd "$(dirname "${0}")" || return; pwd )" ) |
| 32 | +fi |
| 33 | +echo "TOOLS_PATH: ${TOOLS_PATH}" |
2 | 34 |
|
3 |
| -which python3 || alias python3=python |
| 35 | +VENV_PATH=$(realpath "${TOOLS_PATH}/..")/.venv |
| 36 | +echo "VENV_PATH: ${VENV_PATH}" |
| 37 | +echo |
| 38 | + |
| 39 | +which python > /dev/null 2>&1 || alias python=python3 |
| 40 | +which python > /dev/null 2>&1 || { |
| 41 | + echo "Failed to find a validate python installation." |
| 42 | + return 1 |
| 43 | +} |
4 | 44 |
|
5 | 45 | load_venv()
|
6 | 46 | {
|
7 |
| - if [ -e ${PWD}/.venv/Scripts ]; then |
8 |
| - source ${PWD}/.venv/Scripts/activate |
9 |
| - elif [ -e ${PWD}/.venv/bin ]; then |
10 |
| - source ${PWD}/.venv/bin/activate |
| 47 | + if [ -e "${VENV_PATH}"/Scripts ]; then |
| 48 | + source "${VENV_PATH}"/Scripts/activate |
| 49 | + elif [ -e "${VENV_PATH}"/bin ]; then |
| 50 | + source "${VENV_PATH}"/bin/activate |
11 | 51 | else
|
12 | 52 | echo "Error. Could not find python virtual environment activation script."
|
13 |
| - exit -1 |
| 53 | + return 1 |
14 | 54 | fi
|
| 55 | + |
| 56 | + echo "Adding tools directory to path." |
| 57 | + export PATH="${TOOLS_PATH}:${PATH}" |
15 | 58 | }
|
16 | 59 |
|
17 |
| -[ -e ${PWD}/.venv ] || { |
| 60 | +if [ ! -d "${VENV_PATH}" ]; then |
18 | 61 | echo "Setting up python virtual environment"
|
19 |
| - python3 -m virtualenv ${PWD}/.venv || exit -1 |
20 |
| - load_venv || exit -1 |
21 |
| - pip3 install -r $(dirname "$0")/requirements.txt || rm -rf ${PWD}/.venv |
22 |
| -} |
| 62 | + python -m virtualenv "${VENV_PATH}" || return 1 |
| 63 | + |
| 64 | + echo "Activating vritual environment." |
| 65 | + load_venv || return 1 |
23 | 66 |
|
24 |
| -load_venv || exit -1 |
| 67 | + pip3 install -r "${TOOLS_PATH}"/requirements.txt || { |
| 68 | + rm -rf "${VENV_PATH}" |
| 69 | + echo "Error while installing requried python packages. Removing incomplete virtual environment." |
| 70 | + return 1 |
| 71 | + } |
| 72 | +else |
| 73 | + load_venv || return 1 |
| 74 | +fi |
| 75 | +echo "Done." |
0 commit comments