aboutsummaryrefslogtreecommitdiff
path: root/android-merge-2-cargo-embargo.sh
blob: ceaaa1dedc981189f3f41afa6da50274c3742c9a (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
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
#!/bin/bash

# Run cargo_embargo with the appropriate arguments.

set -e -u

function usage() { echo "$0 [-r]" && exit 1; }

REUSE=""
while getopts 'r' FLAG; do
  case ${FLAG} in
    r)
      REUSE="--reuse-cargo-out"
      ;;
    ?)
      echo "unknown flag."
      usage
      ;;
  esac
done

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

# If there is need to verify installation of some packages, add them here in pkges.
pkges='meson protobuf-compiler'
for pkg in $pkges; do
  result="$(dpkg-query -W --showformat='${db:Status-Status}' "$pkg" 2>&1)"
  if [ ! $? = 0 ] || [ ! "$result" = installed ]; then
    echo $pkg' not found. Please install.' >&2
    exit 1
  fi
done

# Use the specific rust version that crosvm upstream expects.
#
# TODO: Consider reading the toolchain from external/crosvm/rust-toolchain
#
# TODO: Consider using android's prebuilt rust binaries. Currently doesn't work
# because they try to incorrectly use system clang and llvm.
RUST_TOOLCHAIN="1.73.0"
rustup which --toolchain $RUST_TOOLCHAIN cargo || \
  rustup toolchain install $RUST_TOOLCHAIN
CARGO_BIN="$(dirname $(rustup which --toolchain $RUST_TOOLCHAIN cargo))"

cd $ANDROID_BUILD_TOP/external/crosvm

if [ ! "$REUSE" ]; then
  rm -f cargo.out cargo.metadata
  rm -rf target.tmp || /bin/true
fi

set -x
cargo_embargo $REUSE --cargo-bin "$CARGO_BIN" generate cargo_embargo.json
set +x

if [ ! "$REUSE" ]; then
  rm -f cargo.out cargo.metadata
  rm -rf target.tmp || /bin/true
fi

# Revert changes to Cargo.lock caused by cargo_embargo.
#
# Android diffs in Cargo.toml files can cause diffs in the Cargo.lock when
# cargo_embargo runs. This didn't happen with cargo2android.py because it
# ignored the lock file.
git restore Cargo.lock