Skip to content

Commit

Permalink
ardupilot: add to package.sh and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Sep 10, 2024
1 parent f447c0c commit 72f9e65
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,40 @@ jobs:
rust-version: 1.74
- name: Run MPS tests
run: RUST_LOG=trace MPS_DEBUG=1 python3 src/vm_runner/tests/mps/run_tests.py

ardupilot:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout submodules
run: |
git submodule update --init components/autopilot/ardupilot
- name: Hash inputs
id: hash
run: |
cache_key="$(bash src/pkvm_setup/package.sh cache_key ardupilot)"
echo "Cache key: $cache_key"
echo "CACHE_KEY=$cache_key" >>$GITHUB_OUTPUT
echo "CACHE_KEY=$cache_key" >>$GITHUB_ENV
- name: Cache results
id: cache
uses: actions/cache@v3
with:
key: ${{ env.CACHE_KEY }}
path: packages/${{ env.CACHE_KEY }}.tar.gz
- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
name: Install dependencies
run: |
BUILD_ONLY=1 bash components/autopilot/ardupilot_install_deps.sh
- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
name: Fetch additional submodules for build
run: |
bash components/autopilot/ardupilot_init_submodules.sh
- if: ${{ steps.cache.outputs.cache-hit != 'true' }}
name: Build ArduPilot
run: |
bash src/pkvm_setup/package.sh full_build ardupilot
outputs:
CACHE_KEY: ${{ steps.hash.outputs.CACHE_KEY }}

18 changes: 18 additions & 0 deletions components/autopilot/ardupilot_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -euo pipefail

# Script for installing ArduPilot build dependencies.

cd "$(dirname "$0")/ardupilot"

edo() {
echo " >> $*" 1>&2
"$@"
}

. venv/bin/activate
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
export LD=aarch64-linux-gnu-g++
./waf -o build.aarch64 configure --board sitl
./waf -o build.aarch64 build --target bin/arduplane
22 changes: 22 additions & 0 deletions components/autopilot/ardupilot_init_submodules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -euo pipefail

# Initialize additional submodules that are needed for the ArduPilot build.

cd "$(dirname "$0")/ardupilot"

edo() {
echo " >> $*" 1>&2
"$@"
}

modules=(
waf
DroneCAN/dronecan_dsdlc
DroneCAN/pydronecan
DroneCAN/DSDL
DroneCAN/libcanard
)
for x in "${modules[@]}"; do
edo git submodule update --init "modules/$x"
done
57 changes: 57 additions & 0 deletions components/autopilot/ardupilot_install_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
set -euo pipefail

# Script for installing ArduPilot build dependencies.

cd "$(dirname "$0")/ardupilot"

edo() {
echo " >> $*" 1>&2
"$@"
}

first() {
echo "$1"
}

install_if_missing() {
local package="$1"
local file="$2"

# If `$2` is a glob pattern, expand it to the first matching file if one
# exists.
if [[ ! -f "$(IFS='' first $file)" ]]; then
echo "missing $file - need to install package $package" 1>&2
edo sudo apt-get install -y "$package"
if [[ ! -f "$(IFS='' first $file)" ]]; then
echo "actual contents of $package:" 1>&2
dpkg-query -L "$package" 1>&2
echo "error: expected package $package to provide $file, but it did not" 1>&2
return 1
fi
fi
}

# Create Python virtualenv if it doesn't yet exist.
if [[ ! -d venv ]]; then
edo install_if_missing python3-virtualenv /usr/bin/virtualenv
virtualenv venv
fi

# Install Python dependencies into the virtualenv. `pip install` is a no-op if
# the package is already installed.
(
. venv/bin/activate
pip3 install pexpect empy==3.3.4 future
if [[ -z "${BUILD_ONLY:+x}" ]]; then
pip3 install pymavlink MAVProxy opencv-python matplotlib

# Extra system package needed for building wxPython
edo install_if_missing libgtk-3-dev /usr/lib/*/pkgconfig/gtk+-3.0.pc
# Note: the wxPython install builds from source, which takes a while
pip3 install wxPython
fi
)

install_if_missing gcc-aarch64-linux-gnu /usr/bin/aarch64-linux-gnu-gcc
install_if_missing g++-aarch64-linux-gnu /usr/bin/aarch64-linux-gnu-g++
22 changes: 22 additions & 0 deletions src/pkvm_setup/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ vm_images_list_outputs() {
}


# ardupilot

ardupilot_get_input_hashes() {
(
cd components/autopilot
sha1sum ardupilot_build.sh
sha1sum ardupilot_init_submodules.sh
sha1sum ardupilot_install_deps.sh
)
( cd components/autopilot/ardupilot && git rev-parse HEAD:./ )
}

ardupilot_build() {
bash components/autopilot/ardupilot_build.sh
}

ardupilot_list_outputs() {
echo components/autopilot/ardupilot/build.aarch64/sitl/bin/arduplane
echo components/autopilot/ardupilot/Tools/autotest/models/plane.parm
}


# Actions. Each `do_foo` function can be called via `bash package.sh foo
# package_name`.

Expand Down

0 comments on commit 72f9e65

Please sign in to comment.