File: generate-mpris-interface.sh

package info (click to toggle)
rust-mpris 2.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 496 kB
  • sloc: sh: 50; makefile: 2
file content (53 lines) | stat: -rwxr-xr-x 1,268 bytes parent folder | download
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
#!/usr/bin/env bash
# Regenerates the MPRIS interface code using `dbus-codegen-rust`.
set -e

root="$(readlink -f "$(dirname "$0")/..")"
if [[ ! -d "$root" ]]; then
  echo "Could not find root $root"
  exit 1
fi

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/generated"

for spec in "$root"/mpris-spec/spec/org.mpris.*.xml; do
  basename=$(
    basename "$spec" | \
      sed -r 's/org\.mpris\.MediaPlayer2(\.(\w+))?\.xml/media_player_\2.rs/; s/_\.rs$/\.rs/' | \
      tr '[:upper:]' '[:lower:]'
  )
  dest_file="${dest}/${basename}"
  echo "Generating code from $(basename "${spec}") to ${basename}…"

  cat <<EOF > "$dest_file"
#![allow(unknown_lints)]
#![allow(clippy::all)]
#![allow(
    missing_debug_implementations,
    missing_copy_implementations,
    trivial_casts,
    trivial_numeric_casts,
    unsafe_code,
    unstable_features,
    unused_import_braces,
    unused_qualifications,
    unused_imports
)]
EOF
  dbus-codegen-rust -m None -c ffidisp < "$spec" >> "$dest_file"

  rustfmt ${dest_file}
done

echo "Done."