summaryrefslogtreecommitdiff
path: root/tools/perf/tests/shell/lib/setup_python.sh
blob: 2173215a05174dcd0cc968e44be6f88978bd9a86 (plain) (blame)
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
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

if [ "x$PYTHON" = "x" ]
then
  python3 --version >/dev/null 2>&1 && PYTHON=python3
fi
if [ "x$PYTHON" = "x" ]
then
  python --version >/dev/null 2>&1 && PYTHON=python
fi
if [ "x$PYTHON" = "x" ]
then
  echo Skipping test, python not detected please set environment variable PYTHON.
  exit 2
fi

# Set PYTHONPATH to find the in-tree built perf.so first, avoiding system-wide perf.so
if [ -n "$PERF_EXEC_PATH" ] && [ -d "$PERF_EXEC_PATH/python" ]; then
  PYTHONPATH_DIR="$PERF_EXEC_PATH/python"
elif [ -d "$(dirname "$0")/../../python" ]; then
  PYTHONPATH_DIR="$(dirname "$0")/../../python"
elif [ -d "$(dirname "$0")/../python" ]; then
  PYTHONPATH_DIR="$(dirname "$0")/../python"
fi

if [ -n "$PYTHONPATH_DIR" ]; then
  export PYTHONPATH="$PYTHONPATH_DIR${PYTHONPATH:+:$PYTHONPATH}"
fi