Skip to content

Commit

Permalink
Add basic Debian package support
Browse files Browse the repository at this point in the history
  • Loading branch information
RadxaYuntian committed Jul 27, 2023
1 parent 809c3d6 commit c73fc23
Show file tree
Hide file tree
Showing 26 changed files with 448 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .github/container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian:bullseye

RUN dpkg --add-architecture arm64 && \
apt-get update && \
apt-get full-upgrade --no-install-recommends -y \
build-essential crossbuild-essential-arm64 git \
cmake debhelper devscripts lintian swig python3-dev:arm64 libjson-c-dev:arm64 && \
adduser --gecos runner --disabled-password runner && \
rm -rf /var/lib/apt/lists/*
98 changes: 98 additions & 0 deletions .github/container/build-deb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash

set -euo pipefail
shopt -s nullglob

build() {
local SCRIPT_DIR="$(dirname "$(realpath "$0")")"

local NATIVE_BUILD="false"
local CONTAINER_BACKEND="podman"
local CONTAINER_REGISTRY=""
local NO_CONTAINER_UPDATE="false"
local CONTAINER_SHELL="false"

if ! $NATIVE_BUILD
then
if [[ "$(basename "$CONTAINER_BACKEND")" == "docker" ]] && "$CONTAINER_BACKEND" -v | grep -q podman
then
echo "'$CONTAINER_BACKEND' backend is selected, but the functionality is actually provided by 'podman' backend. Updating accordingly..."
CONTAINER_BACKEND="$(command -v podman)"
fi

local CONTAINER_IMAGE="$($CONTAINER_BACKEND image ls "-qf=reference=${CONTAINER_REGISTRY}mraa:master")"
local CONTAINER_EXIT_CODE=0

if ! $NO_CONTAINER_UPDATE
then
if [[ -z $CONTAINER_REGISTRY ]]
then
$CONTAINER_BACKEND build --force-rm -t "${CONTAINER_REGISTRY}mraa:master" "$SCRIPT_DIR"
else
$CONTAINER_BACKEND pull "${CONTAINER_REGISTRY}mraa:master"
fi
fi

if [[ $CONTAINER_IMAGE != "$($CONTAINER_BACKEND image ls "-qf=reference=${CONTAINER_REGISTRY}mraa:master")" ]]
then
$CONTAINER_BACKEND container rm mraa &>/dev/null || true
$CONTAINER_BACKEND image rm "${CONTAINER_REGISTRY}mraa:builder" &>/dev/null || true
fi

CONTAINER_BUILDER="$($CONTAINER_BACKEND image ls "-qf=reference=${CONTAINER_REGISTRY}mraa:builder")"
if [[ -z $CONTAINER_BUILDER ]]
then
$CONTAINER_BACKEND tag "${CONTAINER_REGISTRY}mraa:master" "${CONTAINER_REGISTRY}mraa:builder"
fi

CONTAINER_OPTIONS=( "--name" "mraa" )
CONTAINER_OPTIONS+=( "--workdir" "$PWD" )
CONTAINER_OPTIONS+=( "--mount" "type=bind,source=$PWD,destination=$PWD" )
CONTAINER_OPTIONS+=( "--mount" "type=bind,source=$(realpath $SCRIPT_DIR/../../..),destination=$(realpath $SCRIPT_DIR/../../..)" )
if [[ -t 0 ]]
then
CONTAINER_OPTIONS+=( "-it" )
fi
if [[ "$PWD" != "$SCRIPT_DIR" ]]
then
CONTAINER_OPTIONS+=( "--mount" "type=bind,source=$SCRIPT_DIR,destination=$SCRIPT_DIR" )
fi
$CONTAINER_BACKEND container kill mraa &>/dev/null || true
$CONTAINER_BACKEND container rm mraa &>/dev/null || true
if [[ "$(basename "$CONTAINER_BACKEND")" == "podman" ]]
then
CONTAINER_OPTIONS+=( "--user" "root" )
if $CONTAINER_SHELL
then
if ! $CONTAINER_BACKEND run "${CONTAINER_OPTIONS[@]}" "${CONTAINER_REGISTRY}mraa:builder" bash
then
CONTAINER_EXIT_CODE="$($CONTAINER_BACKEND inspect mraa --format='{{.State.ExitCode}}')"
fi
else
if ! $CONTAINER_BACKEND run "${CONTAINER_OPTIONS[@]}" "${CONTAINER_REGISTRY}mraa:builder" make deb
then
CONTAINER_EXIT_CODE="$($CONTAINER_BACKEND inspect mraa --format='{{.State.ExitCode}}')"
fi
$CONTAINER_BACKEND container rm mraa
fi
else
local CONTAINER_SUDO="sed -i -E \"s/^(runner):(x?):([0-9]+):([0-9]+):(.*):(.*):(.*)$/\1:\2:$(id -u):$(id -g):\5:\6:\7/\" /etc/passwd && sudo -u runner"
if $CONTAINER_SHELL
then
if ! $CONTAINER_BACKEND run "${CONTAINER_OPTIONS[@]}" "${CONTAINER_REGISTRY}mraa:builder" bash -c "$CONTAINER_SUDO -i"
then
CONTAINER_EXIT_CODE="$($CONTAINER_BACKEND inspect mraa --format='{{.State.ExitCode}}')"
fi
else
if ! $CONTAINER_BACKEND run "${CONTAINER_OPTIONS[@]}" "${CONTAINER_REGISTRY}mraa:builder" bash -c "$CONTAINER_SUDO make deb"
then
CONTAINER_EXIT_CODE="$($CONTAINER_BACKEND inspect mraa --format='{{.State.ExitCode}}')"
fi
$CONTAINER_BACKEND container rm mraa
fi
fi
return $CONTAINER_EXIT_CODE
fi
}

build
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build & Release
on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Test
run: |
make test
- name: Build
run: |
sudo apt-get update
sudo apt-get build-dep --no-install-recommends -y .
make all
sudo apt install -y binfmt-support qemu-user-static
.github/container/build-deb
- name: Workaround actions/upload-artifact#176
run: |
echo "artifacts_path=$(realpath ..)" >> $GITHUB_ENV
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: |
${{ env.artifacts_path }}/*.deb
release:
runs-on: ubuntu-latest
needs: build
if: ${{ github.event_name != 'pull_request' && github.ref_name == 'master' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- uses: actions/download-artifact@v3
with:
name: ${{ github.event.repository.name }}
- name: Check if the latest version is releasable
run: |
version="$(dpkg-parsechangelog -S Version)"
echo "version=$version" >> $GITHUB_ENV
echo "changes<<EOF" >> $GITHUB_ENV
echo '```' >> $GITHUB_ENV
echo "$(dpkg-parsechangelog -S Changes)" >> $GITHUB_ENV
echo '```' >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
if [[ -n "$(git tag -l "$version")" ]]
then
echo "distro=UNRELEASED" >> $GITHUB_ENV
else
echo "distro=$(dpkg-parsechangelog -S Distribution)" >> $GITHUB_ENV
fi
echo "$version" > VERSION
if [[ -f pkg.conf.template ]]
then
sed "s/VERSION/$(dpkg-parsechangelog -S Version)/g" pkg.conf.template > pkg.conf
fi
- name: Release
if: env.distro != 'UNRELEASED'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.version }}
body_path: README.md
token: ${{ secrets.GITHUB_TOKEN }}
target_commitish: master
draft: false
fail_on_unmatched_files: true
files: |
*.deb
VERSION
- name: Append changelog
if: env.distro != 'UNRELEASED'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.version }}
body: |
## Changelog for ${{ env.version }}
${{ env.changes }}
append_body: true
- name: Update Test repos
if: env.distro != 'UNRELEASED'
uses: radxa-repo/update-repo-action@main
with:
test-repo: true
token: ${{ secrets.RADXA_APT_TEST_REPO_TOKEN }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ npm-debug.log
.scannerwork/

# Visual Studio Code
.vscode/
.vscode*

# CMake object files
obj-aarch64-linux-gnu

SOURCE
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
PROJECT ?= mraa
PREFIX ?= /usr
BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib
MANDIR ?= $(PREFIX)/share/man

.PHONY: all
all: build

#
# Test
#
.PHONY: test
test:

#
# Build
#
.PHONY: build
build: build-doc

SRC-DOC := .
DOCS := $(SRC-DOC)/SOURCE
.PHONY: build-doc
build-doc: $(DOCS)

$(SRC-DOC):
mkdir -p $(SRC-DOC)

.PHONY: $(SRC-DOC)/SOURCE
$(SRC-DOC)/SOURCE: $(SRC-DOC)
echo -e "git clone $(shell git remote get-url origin)\ngit checkout $(shell git rev-parse HEAD)" > "$@"

#
# Clean
#
.PHONY: distclean
distclean: clean

.PHONY: clean
clean: clean-doc clean-deb

.PHONY: clean-doc
clean-doc:
rm -rf $(DOCS)

.PHONY: clean-deb
clean-deb:
rm -rf obj-aarch64-linux-gnu debian/.debhelper debian/libmraa*/ debian/mraa-*/ debian/python3-mraa/ debian/tmp/ debian/debhelper-build-stamp debian/files debian/*.debhelper.log debian/*.*.debhelper debian/*.substvars

#
# Release
#
.PHONY: dch
dch: debian/changelog
gbp dch --debian-branch=master

.PHONY: deb
deb: debian
debuild --no-lintian --lintian-hook "lintian --fail-on error,warning --suppress-tags bad-distribution-in-changes-file -- %p_%v_*.changes" --no-sign -b -aarm64 -Pcross
10 changes: 10 additions & 0 deletions debian/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.debhelper
/debhelper-build-stamp
/files
/libmraa*/
/mraa-*/
/python3-mraa/
/tmp/
/*.debhelper.log
/*.debhelper
/*.substvars
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mraa (2.2.0-1) stable; urgency=medium

* Initial release

-- "Radxa Computer Co., Ltd" <[email protected]> Thu, 27 Jul 2023 18:54:14 +0800
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12
83 changes: 83 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Source: mraa
Maintainer: "Radxa Computer Co., Ltd" <[email protected]>
Section: misc
Priority: optional
Standards-Version: 4.6.0
Build-Depends: cmake (>= 3.15),
debhelper (>=12~),
devscripts,
lintian,
swig,
python3-dev,
libjson-c-dev

Package: libmraa2
Architecture: any
Section: libs
Priority: optional
Depends: ${shlibs:Depends},
${misc:Depends},
Homepage: http://iotdk.intel.com/docs/master/mraa/
Description: userspace I/O library (runtime)
mraa (libmraa) is library for interacting with userspace I/O on GNU/Linux
platforms. The library abstracts platform quirks away from the end user.
Currently interfaces supported include GPIO/PWM/I2C/SPI.
.
This package contains the library used at runtime.

Package: libmraa-dev
Architecture: any
Section: libdevel
Priority: optional
Depends: libmraa2 (= ${binary:Version}),
${misc:Depends}
Homepage: http://iotdk.intel.com/docs/master/mraa/
Description: userspace I/O library (development)
mraa (libmraa) is library for interacting with userspace I/O on GNU/Linux
platforms. The library abstracts platform quirks away from the end user.
Currently interfaces supported include GPIO/PWM/I2C/SPI.
.
This package contains the library development files.

Package: mraa-examples
Architecture: all
Section: doc
Priority: optional
Homepage: http://iotdk.intel.com/docs/master/mraa/
Description: examples for mraa
mraa (libmraa) is library for interacting with userspace I/O on GNU/Linux
platforms. The library abstracts platform quirks away from the end user.
Currently interfaces supported include GPIO/PWM/I2C/SPI.
.
This package contains mraa examples.

Package: mraa-tools
Architecture: any
Depends: libmraa2,
${shlibs:Depends},
${misc:Depends},
Section: utils
Priority: optional
Homepage: http://iotdk.intel.com/docs/master/mraa/
Description: userspace I/O tools (GPIO/I2C)
mraa (libmraa) is library for interacting with userspace I/O on GNU/Linux
platforms. The library abstracts platform quirks away from the end user.
Currently interfaces supported include GPIO/PWM/I2C/SPI.
.
This package contains mraa GPIO tool.

Package: python3-mraa
Architecture: any
Depends: libmraa2,
python3,
${shlibs:Depends},
${misc:Depends},
Section: python
Priority: optional
Homepage: http://iotdk.intel.com/docs/master/mraa/
Description: Python 3 binding for mraa
mraa (libmraa) is library for interacting with userspace I/O on GNU/Linux
platforms. The library abstracts platform quirks away from the end user.
Currently interfaces supported include GPIO/PWM/I2C/SPI.
.
This package contains mraa Python 3 binding.
Loading

0 comments on commit c73fc23

Please sign in to comment.