oooo annoying, scroot refuses to go if done in wrong directory
[dev-env-setup.git] / pia-install
1 #!/bin/bash
2 set -e
3 if ! command -v rustup &> /dev/null; then
4 echo "Rustup could not be found, it can be installed by"
5 echo "running the following command: "
6 echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" >& 2
7 exit 1
8 fi
9 cd ~/src
10 rustup default stable
11 rustup update
12
13 # use the authorised copy controlled under the Libre-SOC git server,
14 # not unauthorised uncontrolled servers (debian salsa)
15 git clone https://git.libre-soc.org/git/power-instruction-analyzer.git pia
16 cd pia
17
18 # do not use external scripts.
19
20 function fail()
21 {
22 echo "error: $@" >&2
23 exit 1
24 }
25
26 if [[ "$VIRTUAL_ENV" == "" ]]; then
27 user=( "--user" )
28 else
29 user=()
30 fi
31 cargo_version="$(cargo --version)" || \
32 fail "can't find cargo, install it from https://rustup.rs/"
33 [[ "$cargo_version" =~ ^'cargo 1.'([0-9]+)'.'[0-9]+' ' ]] || \
34 fail "can't parse cargo's version string"
35 (( "${BASH_REMATCH[1]}" >= 53 )) || \
36 fail 'your rust version is not recent enough, update your rust version using `rustup update`'
37 python3 -m pip install "${user[@]}" 'maturin>=0.11,<0.12'
38 if [[ "$VIRTUAL_ENV" == "" ]]; then
39 scripts="$(python3 -m sysconfig | \
40 sed 's@^\tuserbase = "\([^"]\+\)"$@\1/bin@p; d')"
41 else
42 scripts="$(python3 -m sysconfig | \
43 sed 's/^\tscripts = "\([^"]\+\)"$/\1/p; d')"
44 fi
45 echo "$scripts"
46 [[ -d "$scripts" ]] || fail "can't find python's \`scripts\` directory"
47 rm -f target/wheels/power_instruction_analyzer-*.whl
48 "$scripts"/maturin build --compatibility linux \
49 --cargo-extra-args=--features=python-extension \
50 -i python3 --release --no-sdist
51 python3 -m pip install --force "${user[@]}" \
52 target/wheels/power_instruction_analyzer-*.whl