Skip to content

Commit ef74fbf

Browse files
committed
Initial commit
- See https://github.com/robotpy/roborio-packages for history
0 parents  commit ef74fbf

12 files changed

+978
-0
lines changed

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.ipk
2+
*.gz
3+
*.tgz
4+
5+
/data
6+
/data.old
7+
/dbgdata
8+
/dbgdata.old
9+
/dbgtmp
10+
/devdata
11+
/devdata.old
12+
/devtmp

Makefile

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
include ./Mk/pkgdata.mk
2+
3+
DEPS = binutils-symlinks gcc-symlinks g++-symlinks libgcc-s-dev gcov make libreadline-dev openssl-dev libz-dev libsqlite3-dev libexpat-dev libxml2-dev libbz2-dev liblzma-dev libgdbm-dev libffi-dev pkgconfig
4+
5+
BUILD_CMD = CXX=/usr/bin/g++ ./configure --enable-shared --with-system-expat --with-system-ffi --enable-optimizations && make
6+
7+
INSTALL_CMD = make install
8+
9+
GETDATA_TARARGS = --exclude=usr/local/lib/python3.12/site-packages/numpy\* \
10+
--exclude=usr/local/lib/python3.12/test \
11+
--exclude=usr/local/lib/python3.12/config-3.12-arm-linux-gnueabi/libpython3.12.a \
12+
--exclude=usr/local/lib/python3.12/lib-dynload/.debug \
13+
--exclude=\*.py[co] \
14+
--exclude=__pycache__ \
15+
usr/local/include/python3.12/pyconfig.h \
16+
usr/local/lib/libpython3* \
17+
usr/local/bin/*3.12 \
18+
usr/local/bin/2to3 \
19+
usr/local/bin/idle3 \
20+
usr/local/bin/pip3 \
21+
usr/local/bin/pydoc3 \
22+
usr/local/bin/python3 \
23+
usr/local/bin/python3-config \
24+
usr/local/lib/python3.12 \
25+
usr/local/bin/python3.12-config
26+
27+
GETDATA_DEV_TARARGS = --exclude=usr/local/include/python3.12/pyconfig.h \
28+
usr/local/include/python3.12 \
29+
usr/local/lib/pkgconfig/python3.pc \
30+
usr/local/lib/pkgconfig/python3-embed.pc \
31+
usr/local/lib/pkgconfig/python-3.12.pc \
32+
usr/local/lib/pkgconfig/python-3.12-embed.pc \
33+
usr/local/lib/python3.12/config-3.12-arm-linux-gnueabi/libpython3.12.a
34+
35+
GETDATA_DBG_TARARGS = usr/local/bin/.debug/python3.debug \
36+
usr/local/lib/.debug/libpython3* \
37+
usr/local/lib/python3.12/lib-dynload/.debug
38+
39+
EXTRA_CONTROL = postinst prerm
40+
41+
EXES = usr/local/bin/python3.12 \
42+
usr/local/lib/libpython3.12.so.1.0 \
43+
usr/local/lib/python3.12/lib-dynload/*.so
44+
45+
include ./Mk/remote_build.mk
46+
include ./Mk/ipk.mk

Mk/globals.mk

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Defines globals used in all the make types
3+
#
4+
5+
ifneq ("$(wildcard $(BUILD_ROOT)/vars)","")
6+
include ${BUILD_ROOT}/vars
7+
endif
8+
9+
YEAR = 2024
10+
RELEASE = ${YEAR}-dev
11+
ARCH ?= cortexa9-vfpv3
12+
13+
ifndef PACKAGE
14+
$(error PACKAGE is not set, error in makefile)
15+
endif
16+
17+
ifndef VERSION
18+
$(error VERSION is not set, error in makefile)
19+
endif
20+

Mk/ipk.mk

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.PHONY: ipk clean package
2+
3+
IPK_DEST ?= ${BUILD_ROOT}/${RELEASE}
4+
IPK_NAME ?= ${IPK_DEST}/${PACKAGE}_${VERSION}_${ARCH}.ipk
5+
6+
ifdef GETDATA_DEV_TARARGS
7+
IPK_NAME_DEV = ${IPK_DEST}/${PACKAGE}-dev_${VERSION}_${ARCH}.ipk
8+
endif
9+
10+
ifdef GETDATA_DBG_TARARGS
11+
IPK_NAME_DBG = ${IPK_DEST}/${PACKAGE}-dbg_${VERSION}_${ARCH}.ipk
12+
endif
13+
14+
ipk: ${IPK_NAME} ${IPK_NAME_DEV} ${IPK_NAME_DBG}
15+
16+
package:
17+
$(MAKE) clean
18+
$(MAKE) getdata
19+
$(MAKE) ipk
20+
21+
clean:
22+
rm -f control.tar.gz
23+
rm -f data.tar.gz
24+
rm -rf devtmp dbgtmp
25+
rm -f ${IPK_NAME} ${IPK_NAME_DEV} ${IPK_NAME_DBG} ${EXTRA_CLEAN}
26+
27+
${IPK_NAME}: data control ${EXTRA_CONTROL}
28+
mkdir -p ${IPK_DEST}
29+
tar -czvf control.tar.gz --owner=0 --group=0 control ${EXTRA_CONTROL}
30+
cd data && tar -czvf ../data.tar.gz --owner=0 --group=0 . && cd ..
31+
echo 2.0 > debian-binary
32+
ar r ${IPK_NAME} control.tar.gz data.tar.gz debian-binary
33+
rm debian-binary
34+
35+
ifdef GETDATA_DEV_TARARGS
36+
${IPK_NAME_DEV}: devdata control
37+
mkdir -p ${IPK_DEST}
38+
rm -rf devtmp
39+
mkdir devtmp
40+
sed \
41+
-e "s/^Package: .*/Package: ${PACKAGE}-dev/" \
42+
-e "s/\(^Description: .*\)/\1 development files/" \
43+
-e "s/^Section: .*/Section: devel/" \
44+
-e "s/^Depends: .*/Depends: ${PACKAGE} (= ${VERSION})/" \
45+
control > devtmp/control
46+
cd devtmp && tar -czvf control.tar.gz --owner=0 --group=0 control
47+
cd devdata && tar -czvf ../devtmp/data.tar.gz --owner=0 --group=0 .
48+
echo 2.0 > devtmp/debian-binary
49+
cd devtmp && ar r ${IPK_NAME_DEV} control.tar.gz data.tar.gz debian-binary
50+
endif
51+
52+
ifdef GETDATA_DBG_TARARGS
53+
${IPK_NAME_DBG}: dbgdata control
54+
mkdir -p ${IPK_DEST}
55+
rm -rf dbgtmp
56+
mkdir dbgtmp
57+
sed \
58+
-e "s/^Package: .*/Package: ${PACKAGE}-dbg/" \
59+
-e "s/\(^Description: .*\)/\1 debug symbols/" \
60+
-e "s/^Section: .*/Section: devel/" \
61+
-e "s/^Depends: .*/Depends: ${PACKAGE} (= ${VERSION})/" \
62+
control > dbgtmp/control
63+
cd dbgtmp && tar -czvf control.tar.gz --owner=0 --group=0 control
64+
cd dbgdata && tar -czvf ../dbgtmp/data.tar.gz --owner=0 --group=0 .
65+
echo 2.0 > dbgtmp/debian-binary
66+
cd dbgtmp && ar r ${IPK_NAME_DBG} control.tar.gz data.tar.gz debian-binary
67+
endif

Mk/pkgdata.mk

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
ifneq ("$(wildcard data.py)", "")
3+
PACKAGE ?= $(shell python3 -c "g={};exec(open('data.py').read(), g);print(g['name'])")
4+
VERSION ?= $(shell python3 -c "g={};exec(open('data.py').read(), g);print(g['version'])")
5+
6+
# forces getdata to convert symlinks to normal files
7+
GETDATA_EXTRA_TARARGS = -h
8+
else
9+
PACKAGE ?= $(shell grep Package: control | cut -c 10-)
10+
VERSION ?= $(shell grep Version: control | cut -c 10-)
11+
ARCH ?= $(shell grep Architecture: control | cut -c 15-)
12+
SOURCE ?= $(shell grep Source: control | cut -c 9-)
13+
endif
14+
15+
# Sets IPK_DEST, IPK_NAME
16+
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
17+
BUILD_ROOT = $(abspath ${mkfile_path}/../..)
18+
include ${BUILD_ROOT}/Mk/globals.mk

Mk/remote_build.mk

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Variables:
2+
#
3+
# ROBORIO - the RoboRIO DNS name / IP address (expected to be set by user)
4+
# BUILD_USER - the RoboRIO login to use (defaults to admin)
5+
# BUILD_HOME - where build packages should be extracted (defaults to home)
6+
#
7+
# TGZ - the tar.gz source code file; defaults to last part of SOURCE
8+
# EXTRA_CLEAN - extra files to be cleaned in clean
9+
# BUILD_DEPS - a space-delimited list of opkg dependencies (for install-deps)
10+
# BUILD_DIR - the directory where the TGZ gets extracted to.
11+
# defaults to TGZ with .tgz and .tar.gz stripped
12+
# BUILD_DIR_EXTRA - the directory inside the TGZ that builds should happen in
13+
# BUILD_WARNING - warning to print before build
14+
# BUILD_CMD - the build command
15+
# INSTALL_CMD - the install command
16+
# GETDATA_TARARGS - the args to use for tar when getting data
17+
# GETDATA_DEV_TARARGS - if specified args to use for tar when getting development data
18+
# GETDATA_DBG_TARARGS - if specified args to use for tar when getting debug data
19+
# EXTRA_CONTROL - extra files to include in control.tar.gz
20+
#
21+
TGZ ?= $(lastword $(subst /, ,${SOURCE}))
22+
BUILD_DIR ?= $(subst .tgz,,$(subst .tar.gz,,${TGZ}))
23+
BUILD_USER ?= admin
24+
STACK_SIZE ?= 4096
25+
26+
# Used by ipkwhl
27+
GETDATA_EXTRA_TARARGS ?=
28+
29+
30+
ifndef ROBORIO
31+
$(error ROBORIO is not set, use 'make ROBORIO=roborio-XXXX-frc.local')
32+
endif
33+
34+
.PHONY: all init-ssh sync-date install-deps fetch extract build install strip-exes fetch-src getdata getdata-pkg getdata-dev getdata-dbg
35+
36+
ifdef GETDATA_DEV_TARARGS
37+
GETDATA_DEV_TARGET=getdata-dev
38+
endif
39+
40+
ifdef GETDATA_DBG_TARARGS
41+
GETDATA_DBG_TARGET=getdata-dbg
42+
endif
43+
44+
ALLTARGETS ?= clean \
45+
sync-date install-deps \
46+
fetch extract build install strip-exes \
47+
getdata ipk
48+
all: ${ALLTARGETS}
49+
50+
init-ssh:
51+
ssh ${BUILD_USER}@${ROBORIO} 'mkdir -p .ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
52+
53+
sync-date:
54+
ifneq (${NOSETDATE}, 1)
55+
ssh ${BUILD_USER}@${ROBORIO} "date -s '`date -u +'%Y-%m-%d %H:%m:%S'`'"
56+
endif
57+
58+
install-deps:
59+
ifneq ($(strip ${DEPS}),)
60+
ssh ${BUILD_USER}@${ROBORIO} 'opkg update && opkg install ${DEPS} && (opkg clean || true)'
61+
endif
62+
63+
fetch: ${TGZ}
64+
${TGZ}:
65+
wget ${SOURCE}
66+
67+
extract: ${TGZ}
68+
ssh ${BUILD_USER}@${ROBORIO} 'cd ${BUILD_HOME} && rm -rf ${BUILD_DIR}'
69+
cat ${TGZ} | ssh ${BUILD_USER}@${ROBORIO} 'cd ${BUILD_HOME} && mkdir ${BUILD_DIR} && cd ${BUILD_DIR} && tar xzf - --strip-components=1'
70+
ifdef PATCHES
71+
$(foreach patch, $(PATCHES), ssh ${BUILD_USER}@${ROBORIO} 'cd ${BUILD_HOME} && cd ${BUILD_DIR} && patch -p1' < $(patch))
72+
endif
73+
74+
build:
75+
ifdef BUILD_WARNING
76+
@echo "--------------------------------------------------------------"
77+
@echo "${BUILD_WARNING}"
78+
@echo "--------------------------------------------------------------"
79+
@echo "Press ENTER to continue"
80+
@bash -c read
81+
endif
82+
ssh ${BUILD_USER}@${ROBORIO} 'ulimit -s ${STACK_SIZE} && cd ${BUILD_HOME} && cd ${BUILD_DIR}/${BUILD_DIR_EXTRA} && ${BUILD_CMD}'
83+
84+
install:
85+
ssh ${BUILD_USER}@${ROBORIO} 'ulimit -s ${STACK_SIZE} && cd ${BUILD_HOME} && cd ${BUILD_DIR}/${BUILD_DIR_EXTRA} && ${INSTALL_CMD}'
86+
87+
strip-exes:
88+
ifneq ($(strip ${EXES}),)
89+
ssh ${BUILD_USER}@${ROBORIO} 'for exes in ${EXES}; do for exe in /$$exes; do \
90+
fdir=$$(dirname $$exe) && fbase=$$(basename "$$exe") && \
91+
fdebug="$${fbase%.*}.debug" && \
92+
mkdir -p "$$fdir"/.debug && \
93+
chmod u+w $$exe && \
94+
objcopy --only-keep-debug $$exe "$$fdir/.debug/$$fdebug" && \
95+
chmod 755 "$$fdir/.debug/$$fdebug" && \
96+
objcopy --strip-debug "$$exe" && \
97+
objcopy --add-gnu-debuglink="$$fdir/.debug/$$fdebug" "$$exe"; \
98+
done; done'
99+
endif
100+
101+
getdata: getdata-pkg ${GETDATA_DEV_TARGET} ${GETDATA_DBG_TARGET}
102+
103+
getdata-pkg:
104+
mkdir -p data
105+
rm -rf data.new
106+
mkdir data.new
107+
set -o pipefail; cd data.new && ssh ${BUILD_USER}@${ROBORIO} 'cd / && tar ${GETDATA_EXTRA_TARARGS} -cf - ${GETDATA_TARARGS}' | tar xf -
108+
rm -rf data.old && mv data data.old && mv data.new data
109+
[ ! -d extra ] || cp -r extra/* data/
110+
111+
ifdef GETDATA_DEV_TARARGS
112+
getdata-dev:
113+
mkdir -p devdata
114+
rm -rf devdata.new
115+
mkdir devdata.new
116+
set -o pipefail; cd devdata.new && ssh ${BUILD_USER}@${ROBORIO} 'cd / && tar ${GETDATA_EXTRA_TARARGS} -cf - ${GETDATA_DEV_TARARGS}' | tar xf -
117+
rm -rf devdata.old && mv devdata devdata.old && mv devdata.new devdata
118+
[ ! -d extradev ] || cp -r extradev/* devdata/
119+
endif
120+
121+
ifdef GETDATA_DBG_TARARGS
122+
getdata-dbg:
123+
mkdir -p dbgdata
124+
rm -rf dbgdata.new
125+
mkdir dbgdata.new
126+
set -o pipefail; cd dbgdata.new && ssh ${BUILD_USER}@${ROBORIO} 'cd / && tar ${GETDATA_EXTRA_TARARGS} -cf - ${GETDATA_DBG_TARARGS}' | tar xf -
127+
rm -rf dbgdata.old && mv dbgdata dbgdata.old && mv dbgdata.new dbgdata
128+
[ ! -d extradev ] || cp -r extradev/* dbgdata/
129+
endif

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
roborio-python
2+
==============
3+
4+
This repository holds builds of Python for the RoboRIO, and associated build
5+
scripts. You don't need to build this yourself, instead use the robotpy-installer
6+
and execute `robotpy-installer download-python` to download them.
7+
8+
Build process
9+
-------------
10+
11+
Compiling this can eat up most of your RoboRIO's disk space, so you'll probably
12+
want to reimage it before using the RoboRIO in a competition.
13+
14+
There are several non-automated steps:
15+
16+
* You must execute this build from a Linux environment
17+
* Make a USB flash drive to be swap
18+
* Use `cfdisk` to partition your USB drive
19+
* Use `mkswap` to initialize the space
20+
* Mount it on the roborio via `swapon`
21+
* Make another USB flash drive to be extra storage space
22+
* Use `cfdisk` to partition as linux partition
23+
* Use `mkfs.ext2` to format it
24+
* Plug it into the roborio and you should see it at /media/sda1
25+
* Run the following to redirect the install folders to your drive:
26+
27+
```
28+
mkdir /media/sda1/bin
29+
mkdir /media/sda1/include
30+
mkdir /media/sda1/lib
31+
32+
ln -s /media/sda1/bin /usr/local/bin
33+
ln -s /media/sda1/include /usr/local/include
34+
ln -s /media/sda1/lib /usr/local/lib
35+
```
36+
37+
Once your RoboRIO is sufficiently mangled, execute this from your host:
38+
39+
make ROBORIO=roborio-XXXX-frc.local all
40+
41+
Building on a first generation RoboRIO takes about half a day.

control

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Package: python312
2+
Version: 3.12.0-r1
3+
Description: Python programming language
4+
Section: devel
5+
Priority: optional
6+
Maintainer: RobotPy Developers <[email protected]>
7+
License: BSD
8+
Architecture: cortexa9-vfpv3
9+
OE: python312
10+
Homepage: http://www.python.org
11+
Depends: libc6
12+
Recommends: libreadline6
13+
Source: https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

postinst

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
if [ x"$D" = "x" ]; then
3+
if [ -x /sbin/ldconfig ]; then /sbin/ldconfig ; fi
4+
fi
5+
# compile library files
6+
/usr/bin/env PYTHONPATH=/usr/local/lib/python3.12 LD_LIBRARY_PATH=/usr/local/lib \
7+
/usr/local/bin/python3 -Wi /usr/local/lib/python3.12/compileall.py \
8+
-d lib/python3.12 -f -q \
9+
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
10+
/usr/local/lib/python3.12
11+
/usr/bin/env PYTHONPATH=/usr/local/lib/python3.12 LD_LIBRARY_PATH=/usr/local/lib \
12+
/usr/local/bin/python3 -Wi -O /usr/local/lib/python3.12/compileall.py \
13+
-d lib/python3.12 -f -q \
14+
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
15+
/usr/local/lib/python3.12
16+
/usr/bin/env PYTHONPATH=/usr/local/lib/python3.12 LD_LIBRARY_PATH=/usr/local/lib \
17+
/usr/local/bin/python3 -Wi /usr/local/lib/python3.12/compileall.py \
18+
-d lib/python3.12/site-packages -f -q \
19+
-x badsyntax /usr/local/lib/python3.12/site-packages
20+
/usr/bin/env PYTHONPATH=/usr/local/lib/python3.12 LD_LIBRARY_PATH=/usr/local/lib \
21+
/usr/local/bin/python3 -Wi -O /usr/local/lib/python3.12/compileall.py \
22+
-d lib/python3.12/site-packages -f -q \
23+
-x badsyntax /usr/local/lib/python3.12/site-packages
24+
25+
# Fix pip to not warn when running as root because we don't care
26+
sed -i 's/def warn_if_run_as_root() -> None:$/def warn_if_run_as_root() -> None: return\ndef _unused():/g' \
27+
/usr/local/lib/python3.12/site-packages/pip/_internal/cli/req_command.py
28+
29+
# Let user program set RT thread priorities by making CAP_SYS_NICE
30+
# permitted, inheritable, and effective. See "man 7 capabilities"
31+
# for docs on capabilities and file capability sets.
32+
setcap cap_sys_nice+eip /usr/local/bin/python3.12

prerm

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
# delete compiled library files
3+
find /usr/local/lib/python3.12 -name __pycache__ -type d -prune -exec rm -r '{}' ';'

0 commit comments

Comments
 (0)