-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgenerate-nm-interfaces.sh
executable file
·71 lines (58 loc) · 1.61 KB
/
generate-nm-interfaces.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
66
67
68
69
70
71
#!/usr/bin/env bash
set -e
readonly NETWORKMANAGER_RELEASE="1.24.2"
if !which git &> /dev/null; then
echo "Git must be installed!!"
exit 1
fi
root="$(readlink -f "$(dirname "$0")")"
if [[ ! -d "$root" ]]; then
echo "Could not find root $root"
exit 1
fi
mkdir -p $root/tmp
git clone https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git $root/tmp/
cd tmp
git checkout tags/$NETWORKMANAGER_RELEASE
cd ..
if ! hash dbus-codegen-rust 2> /dev/null; then
echo "Could not find dbus-codegen-rust binary. Do you want to install it using Cargo?"
echo -n "[Yn] > "
read -r c
if [[ $c == "y" || $c == "Y" ]]; then
cargo install dbus-codegen
else
exit 1
fi
fi
dest="$root/src/gen"
mkdir -p $dest
alltraits=()
allmods=()
for spec in $root/tmp/introspection/*.xml; do
basename=$(basename "$spec" .xml)
trait=( $(IFS=. ; printf '%s ' $basename) )
trait=$(echo ${trait[@]^} | tr -d "[:space:]")
alltraits+=($trait)
modname=${basename#org.freedesktop.NetworkManager}
modname=nm${modname//./_}
modname=$(echo $modname | tr '[:upper:]' '[:lower:]')
allmods+=($modname)
dest_file="${dest}/${modname}".rs
echo "Generating code from $(basename "${spec}") to ${modname}…"
dbus-codegen-rust -m None < "$spec" > "$dest_file"
done
echo "#![allow(warnings)]" > $dest/mod.rs
for mod in ${allmods[@]}; do
echo "mod "$mod";" >> $dest/mod.rs
done
echo -e "\n" >> $dest/mod.rs
for ((i=0;i<${#allmods[@]};++i)); do
echo "pub(super) use ${allmods[i]}::${alltraits[i]};" >> $dest/mod.rs
done
echo "Formatting code... "
rustfmt $dest/*.rs
echo "Done."
echo "Cleaning up..."
rm -rf $root/tmp
echo "Done."