-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.sh
executable file
·65 lines (54 loc) · 2.13 KB
/
update.sh
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
#!/usr/bin/env bash
# Path to `svd`/`svdtools`
SVDTOOLS="${SVDTOOLS:-svdtools}"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
set -exuo pipefail
cargo install --version 0.33.4 svd2rust --locked
cargo install --version 0.12.1 form --locked
rustup component add rustfmt
if [ "$SVDTOOLS" == "svdtools" ]; then
cargo install --version 0.3.20 svdtools --locked
else
python3 -mvenv --clear .venv
source .venv/bin/activate
pip3 install --upgrade "svdtools==0.1.25"
fi
$SVDTOOLS patch svd/RP2350.yaml
if [ "$SVDTOOLS" != "svdtools" ]; then
deactivate
fi
# Most of the code is from Cortex-M mode
tmp_dir=$(mktemp -d -t svd2rust-XXXX)
pushd ${tmp_dir}
svd2rust -i ${SCRIPT_DIR}/svd/RP2350.svd.patched -c ${SCRIPT_DIR}/svd2rust.toml --target cortex-m
form -i mod.rs -o inner
rustfmt inner/lib.rs
mv inner/lib.rs inner/mod_cortex_m.rs
rm -rf ${SCRIPT_DIR}/src/inner
mv inner ${SCRIPT_DIR}/src
popd
rm -rf ${tmp_dir}
# But RISC-V mode needs a custom mod.rs
tmp_dir=$(mktemp -d -t svd2rust-XXXX)
pushd ${tmp_dir}
svd2rust -i ${SCRIPT_DIR}/svd/RP2350.svd.patched -c ${SCRIPT_DIR}/svd2rust.toml --target riscv
form -i mod.rs -o inner
rustfmt inner/lib.rs
mv inner/lib.rs ${SCRIPT_DIR}/src/inner/mod_risc_v.rs
# This module isn't in the Cortex-M version - everything else is
mv inner/interrupt* ${SCRIPT_DIR}/src/inner
popd
rm -rf ${tmp_dir}
cargo fmt
# Original svd has \n (two chars) in it, which gets converted to "\n" by svd2rust
# If we convert them to newline characters in the SVD, they don't turn up in markdown so docs suffers
# So, convert \n to [spc] [spc] [newline], then strip the spaces out if there are consecutive [newlines]
# This means that by the time we're in markdown \n\n becomes new paragraph, and \n becomes a new line
if [ "$(uname)" == "Darwin" ]; then
find src -name '*.rs' -exec sed -i '' -e 's/\\n/ \n/g' -e 's/\n \n/\n\n/g' {} \;
else
find src -name '*.rs' -exec sed -i -e 's/\\n/ \n/g' -e 's/\n \n/\n\n/g' {} \;
fi
# Sort specified fields alphanumerically for easier consumption in docs.rs
./sortFieldsAlphaNum.sh src/inner/mod_cortex_m.rs
./sortFieldsAlphaNum.sh src/inner/mod_risc_v.rs