@@ -5,73 +5,97 @@ FROM $BASE_OS:$BASE_CODENAME AS build-stage
55
66# Download build dependencies
77RUN <<EOR
8- set -eu
8+ set -eu
99
10- apt-get update
11- apt-get install -y --no-install-recommends \
12- gcc \
13- librsvg2-bin \
14- linux-headers-generic \
15- python3-dev \
16- python3-setuptools \
17- python-is-python3
18- apt-get clean && rm -rf /var/lib/apt/lists/*
10+ # Workaround for outstanding fix of https://bugs.launchpad.net/ubuntu/+source/python-build/+bug/1992108
11+ if grep -q ^UBUNTU_CODENAME=jammy /etc/os-release; then
12+ echo >>/etc/apt/sources.list.d/jammy-proposed.list 'deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-proposed universe'
13+ echo >>/etc/apt/sources.list.d/jammy-proposed.list 'deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ jammy-proposed universe'
14+ fi
15+
16+ apt-get update
17+ apt-get install -y --no-install-recommends \
18+ gcc \
19+ librsvg2-bin \
20+ linux-headers-generic \
21+ python3-dev \
22+ python3-setuptools \
23+ python3-venv \
24+ python-is-python3
25+
26+ # Workaround for Focal lacking an apt package for python3-build
27+ dep=build
28+ package="python3-${dep}"
29+ if apt-cache search --names-only "^${package}$" | grep -q .; then
30+ apt-get install -y --no-install-recommends "${package}"
31+ else
32+ apt-get install -y --no-install-recommends python3-pip
33+ pip install "${dep}"
34+ fi
35+
36+ apt-get clean && rm -rf /var/lib/apt/lists/*
1937EOR
2038# Prepare working directory and target
2139COPY . /work
2240WORKDIR /work
23- ARG TARGET=/build/usr
41+ ARG TARGET=/build
2442ARG DAEMON_VERSION
2543ARG GIT_DESCRIPTION
2644
2745# Build and install
2846RUN <<EOR
29- set -eu
47+ set -eu
48+
49+ # #
50+ # Converts the output of `git describe` to a valid python version (PEP 440),
51+ # e.g. `v0.4.9.2` to `0.4.9.2` or `ver0.4.8.11-3-123-g030686f` to `0.4.8.11.3.123.dev3172463`
52+ # #
53+ convert_git_description_to_python_version() {
54+ description="${1}"
55+ hash="${description##*-g}"
56+ version="$(printf %s " ${description%-g*}" | tr -c -s [0-9.] .)"
57+ version="${version#.}"
58+ version="${version%.}"
59+ if [ "${hash}" != "${description}" ]; then
60+ version="${version}.dev$(printf %d " 0x${hash}")"
61+ fi
62+ printf '%s\n ' "${version}"
63+ }
64+ if [ -z "${DAEMON_VERSION-}" ] && [ "${GIT_DESCRIPTION-}" ]; then
65+ DAEMON_VERSION="$(convert_git_description_to_python_version " ${GIT_DESCRIPTION}")"
66+ fi
67+ if [ "${DAEMON_VERSION-}" ]; then
68+ sed -i -E "s/^ *DAEMON_VERSION *= *.+/DAEMON_VERSION = \" ${DAEMON_VERSION}\" /" scc/constants.py
69+ fi
3070
31- # #
32- # Converts the output of `git describe` to a valid python version (PEP 440),
33- # e.g. `v0.4.9.2` to `0.4.9.2` or `ver0.4.8.11-3-123-g030686f` to `0.4.8.11.3.123.dev3172463`
34- # #
35- convert_git_description_to_python_version() {
36- description="${1}"
37- hash="${description##*-g}"
38- version="$(printf %s " ${description%-g*}" | tr -c -s [0-9.] .)"
39- version="${version#.}"
40- version="${version%.}"
41- if [ "${hash}" != "${description}" ]; then
42- version="${version}.dev$(printf %d " 0x${hash}")"
43- fi
44- printf '%s\n ' "${version}"
45- }
46- if [ -z "${DAEMON_VERSION-}" ] && [ "${GIT_DESCRIPTION-}" ]; then
47- DAEMON_VERSION="$(convert_git_description_to_python_version " ${GIT_DESCRIPTION}")"
48- fi
49- if [ "${DAEMON_VERSION-}" ]; then
50- sed -i -E "s/^ *DAEMON_VERSION *= *.+/DAEMON_VERSION = \" ${DAEMON_VERSION}\" /" scc/constants.py
51- fi
71+ python -m build --wheel
72+ python -m venv .env
73+ .env/bin/activate
74+ pip install --prefix "${TARGET}/usr" dist/*.whl
75+ # fix shebangs of scripts from '#!/work/.env/bin/python'
76+ find "${TARGET}/usr/bin" -type f | xargs sed -i 's:work/.env:usr:'
5277
53- python setup.py build --executable "/usr/bin/env python3"
54- python setup.py install --single-version-externally-managed --home "${TARGET}" --record /dev/null
78+ # Provide input-event-codes.h as fallback for runtime systems without linux headers
79+ cp -a \
80+ "$(find /usr -type f -name input-event-codes.h -print -quit)" \
81+ "$(find " ${TARGET}" -type f -name uinput.py -printf '%h\n ' -quit)"
5582
56- # Provide input-event-codes.h as fallback for runtime systems without linux headers
57- cp -a \
58- "$(find /usr -type f -name input-event-codes.h -print -quit) " \
59- "$(find " ${TARGET} " -type f -name uinput.py -printf '%h \n ' -quit)"
83+ # Create short name symlinks for static libraries
84+ suffix= ".cpython-*-$(uname -m)-linux-gnu.so"
85+ find "${TARGET}" -type f -path "*/site-packages/*${suffix} " \
86+ | while read -r path; do ln -sfr "${path}" "${path%${suffix}}.so" ; done
6087
61- # Create short name symlinks for static libraries
62- suffix=".cpython-*-$(uname -m)-linux-gnu.so"
63- find "${TARGET}" -type f -path "*/site-packages/*${suffix}" \
64- | while read -r path; do ln -sfr "${path}" "${path%${suffix}}.so" ; done
88+ share="${TARGET}/usr/share"
6589
66- # Put AppStream metadata to required location according to https://wiki.debian.org/AppStream/Guidelines
67- metainfo=/build/usr/ share/metainfo
68- mkdir -p "${metainfo}"
69- cp -a scripts/sc-controller.appdata.xml "${metainfo}"
90+ # Put AppStream metadata to required location according to https://wiki.debian.org/AppStream/Guidelines
91+ metainfo="${ share} /metainfo"
92+ mkdir -p "${metainfo}"
93+ cp -a scripts/sc-controller.appdata.xml "${metainfo}"
7094
71- # Convert icon to png format (required for icons in .desktop file)
72- iconpath="${TARGET}/ share/icons/hicolor/512x512/apps"
73- mkdir -p "${iconpath}"
74- rsvg-convert --background-color none -o "${iconpath}/sc-controller.png" images/sc-controller.svg
95+ # Convert icon to png format (required for icons in .desktop file)
96+ iconpath="${share} /icons/hicolor/512x512/apps"
97+ mkdir -p "${iconpath}"
98+ rsvg-convert --background-color none -o "${iconpath}/sc-controller.png" images/sc-controller.svg
7599EOR
76100
77101# Store build metadata
0 commit comments