aboutsummaryrefslogtreecommitdiff
path: root/run_c2a.sh
blob: 5140545d9ffab48b5b4b1b7453fec7736c9b0224 (plain)
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
#!/bin/bash

# Run cargo2android.py with the appropriate arguments for the crate in the
# supplied directory.

set -e

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 CRATE_DIRECTORY"
  exit 1
fi
cd $1

if ! [ -x "$(command -v bpfmt)" ]; then
  echo 'Error: bpfmt not found.' >&2
  exit 1
fi

C2A_ARGS=""
if [[ -f "cargo2android.json" ]]; then
  # If the crate has a cargo2android config, let it handle all the flags.
  C2A_ARGS+=" --config cargo2android.json"
else
  # Otherwise, set common flags.
  C2A_ARGS+=" --run --device --tests --global_defaults=crosvm_defaults --add_workspace"
  # If there are subdirectories with crates, then pass --no-subdir.
  if [ -n "$(find . -mindepth 2 -name "Cargo.toml")" ]; then
    C2A_ARGS+=" --no-subdir"
  fi
fi

C2A=${C2A:-cargo2android.py}
echo "Using $C2A to run this script."
$C2A $C2A_ARGS
rm -f cargo.out
rm -rf target.tmp || /bin/true

if [[ -f "Android.bp" ]]; then
  bpfmt -w Android.bp || /bin/true
fi