Skip to content

Commit 9b5e35a

Browse files
committed
feat(kmkpy): make dist -> uf2 files for each supported NRF board, with KMK bundled
1 parent ee7094e commit 9b5e35a

File tree

5 files changed

+64
-58
lines changed

5 files changed

+64
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,4 @@ kmk/release_info.py
126126
kmk/release_info.mpy
127127
*.mpy
128128
.vscode
129+
.dist

Dockerfile

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
1-
FROM python:3.7-alpine
1+
FROM python:3.9-slim-buster
22

3-
RUN mkdir -p /app
4-
WORKDIR /app
3+
ARG KMKPY_REF
4+
ARG KMKPY_URL
5+
6+
ENV KMKPY_REF ${KMKPY_REF}
7+
ENV KMKPY_URL ${KMKPY_URL}
58

6-
RUN apk update && apk add alpine-sdk coreutils curl gettext git git-lfs openssh rsync wget zip
9+
RUN mkdir -p /app /dist
10+
WORKDIR /app
711

12+
RUN apt-get update && apt-get install -y build-essential curl gettext git git-lfs rsync wget zip lbzip2
813
RUN pip install pipenv
914

10-
### Get a local copy of CircuitPython and its dependencies
11-
# Our absolute baseline is 4.0.0, which (as of writing) shares MPY compat
12-
# with all future versions. Our baseline will need to update as MPY compat
13-
# changes
14-
RUN git clone --branch 4.0.0 --depth 1 https://github.com/adafruit/CircuitPython /opt/circuitpython
15-
RUN git -C /opt/circuitpython submodule update --init
15+
# Pull CircuitPython-designated ARM GCC to avoid mismatches/weird
16+
# inconsistencies with upstream
17+
RUN curl -L -o /tmp/gcc-arm.tar.bz2 https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-none-eabi-9-2019-q4-major-x86_64-linux.tar.bz2 && \
18+
tar -C /usr --strip-components=1 -xaf /tmp/gcc-arm.tar.bz2 && \
19+
rm -rf /tmp/gcc-arm.tar.bz2
20+
21+
# Get a local copy of KMKPython and its dependencies. We don't provide MPY
22+
# builds for kmkpython anymore, so we can get away with being opinionated
23+
# here.
24+
RUN git init /opt/kmkpython && \
25+
git -C /opt/kmkpython remote add origin ${KMKPY_URL} && \
26+
git -C /opt/kmkpython fetch --depth 1 origin ${KMKPY_REF} && \
27+
git -C /opt/kmkpython checkout FETCH_HEAD && \
28+
git -C /opt/kmkpython submodule update --init --recursive
29+
30+
# Build the MPY compiler
31+
RUN make -C /opt/kmkpython/mpy-cross
32+
33+
ENV PATH=/opt/kmkpython/mpy-cross:${PATH}
1634

17-
### Build the MPY compiler
18-
RUN make -C /opt/circuitpython/mpy-cross
35+
RUN mkdir -p /opt/kmkpython/frozen/kmk/kmk
36+
COPY ./build_kmkpython_release.sh /app/
37+
COPY ./kmk /opt/kmkpython/frozen/kmk/kmk
1938

20-
ENV PATH=/opt/circuitpython/mpy-cross:${PATH}
39+
CMD /app/build_kmkpython_release.sh

Makefile

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
.SILENT:
22

33
.PHONY: \
4+
clean-dist \
45
devdeps \
6+
dist \
7+
dockerbase \
58
lint
69

710
.DEFAULT: all
@@ -23,6 +26,8 @@ MPY_TARGET_DIR ?= .compiled
2326
PY_KMK_TREE = $(shell find $(MPY_SOURCES) -name "*.py")
2427
DIST_DESCRIBE = $(shell $(DIST_DESCRIBE_CMD))
2528

29+
TIMESTAMP := $(shell date +%s)
30+
2631
all: copy-kmk copy-bootpy copy-keymap copy-board
2732

2833
compile: $(MPY_TARGET_DIR)/.mpy.compiled
@@ -39,56 +44,23 @@ endif
3944
@rm -rf $(MPY_SOURCES)/release_info.py
4045
@touch $(MPY_TARGET_DIR)/.mpy.compiled
4146

42-
dist: dist/kmk-latest.zip dist/kmk-latest.unoptimized.zip dist/$(DIST_DESCRIBE).zip dist/$(DIST_DESCRIBE).unoptimized.zip
43-
44-
dist-deploy: devdeps dist
45-
@echo "===> Uploading artifacts to https://cdn.kmkfw.io/"
46-
@$(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-$(DIST_DESCRIBE).zip dist/kmk-$(DIST_DESCRIBE).unoptimized.zip s3://kmk-releases/ >/dev/null
47-
@[[ "$${CIRCLE_BRANCH}" == "master" ]] && echo "====> Uploading artifacts as 'latest' to https://cdn.kmkfw.io/" || true
48-
@[[ "$${CIRCLE_BRANCH}" == "master" ]] && $(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-latest.zip dist/kmk-latest.unoptimized.zip s3://kmk-releases/ >/dev/null || true
49-
@[[ -n "$${CIRCLE_TAG}" ]] && echo "====> Uploading artifacts as '$${CIRCLE_TAG}' to https://cdn.kmkfw.io/" || true
50-
@[[ -n "$${CIRCLE_TAG}" ]] && $(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-latest.zip s3://kmk-releases/$${CIRCLE_TAG}.zip >/dev/null || true
51-
@[[ -n "$${CIRCLE_TAG}" ]] && $(PIPENV) run s3cmd -c .s3cfg put -P dist/kmk-latest.unoptimized.zip s3://kmk-releases/$${CIRCLE_TAG}.unoptimized.zip >/dev/null || true
52-
53-
dist/kmk-latest.zip: compile boot.py
54-
@echo "===> Building optimized ZIP"
55-
@mkdir -p dist
56-
@cd $(MPY_TARGET_DIR) && zip -r ../dist/kmk-latest.zip kmk 2>&1 >/dev/null
57-
@zip -r dist/kmk-latest.zip boot.py 2>&1 >/dev/null
58-
59-
dist/$(DIST_DESCRIBE).zip: dist/kmk-latest.zip
60-
@echo "===> Aliasing optimized ZIP"
61-
@cp dist/kmk-latest.zip dist/kmk-$(DIST_DESCRIBE).zip
62-
63-
dist/kmk-latest.unoptimized.zip: $(PY_KMK_TREE) boot.py
64-
@echo "===> Building unoptimized ZIP"
65-
@mkdir -p dist
66-
@echo "KMK_RELEASE = '$(DIST_DESCRIBE)'" > kmk/release_info.py
67-
@zip -r dist/kmk-latest.unoptimized.zip kmk boot.py 2>&1 >/dev/null
68-
@rm -rf kmk/release_info.py
69-
70-
dist/$(DIST_DESCRIBE).unoptimized.zip: dist/kmk-latest.unoptimized.zip
71-
@echo "===> Aliasing unoptimized ZIP"
72-
@cp dist/kmk-latest.unoptimized.zip dist/kmk-$(DIST_DESCRIBE).unoptimized.zip
73-
74-
.docker_base: Dockerfile
75-
@echo "===> Building Docker base image kmkfw/base:${DOCKER_BASE_TAG}"
76-
@docker build -t kmkfw/base:${DOCKER_BASE_TAG} .
77-
@touch .docker_base
78-
79-
docker-base: .docker_base
80-
81-
docker-base-deploy: docker-base
82-
@echo "===> Pushing Docker base image kmkfw/base:${DOCKER_BASE_TAG} to Docker Hub"
83-
@docker push kmkfw/base:${DOCKER_BASE_TAG}
84-
8547
.devdeps: Pipfile.lock
8648
@echo "===> Installing dependencies with pipenv"
8749
@$(PIPENV) sync --dev
8850
@touch .devdeps
8951

9052
devdeps: .devdeps
9153

54+
dist: clean-dist dockerbase
55+
@mkdir -p .dist
56+
@docker run --rm -it -v $$(pwd)/.dist:/dist kmkpy:$(TIMESTAMP)
57+
58+
dockerbase:
59+
docker build . \
60+
-t kmkpy:$(TIMESTAMP) \
61+
--build-arg KMKPY_URL=$$(cut -f1 < kmkpython_ref.tsv) \
62+
--build-arg KMKPY_REF=$$(cut -f2 < kmkpython_ref.tsv)
63+
9264
lint: devdeps
9365
@$(PIPENV) run flake8
9466

@@ -98,10 +70,14 @@ fix-formatting: devdeps
9870
fix-isort: devdeps
9971
@find kmk/ user_keymaps/ boards/ -name "*.py" | xargs $(PIPENV) run isort
10072

101-
clean:
73+
clean: clean-dist
10274
@echo "===> Cleaning build artifacts"
10375
@rm -rf .devdeps build dist $(MPY_TARGET_DIR)
10476

77+
clean-dist:
78+
@echo "===> Cleaning KMKPython dists"
79+
@rm -rf .dist
80+
10581
# This is mostly a leftover from the days we vendored stuff from
10682
# micropython-lib via submodules. Leaving this here mostly in case someone goes
10783
# exploring through the history of KMK's repo and manages to screw up their
@@ -173,5 +149,4 @@ ifdef BOARD
173149
copy-board: $(MOUNTPOINT)/kb.py
174150
endif # BOARD
175151

176-
177152
endif # MOUNTPOINT

build_kmkpython_release.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
TIMESTAMP=$(date +%s)
4+
TARGETS=${TARGETS:-"nice_nano itsybitsy_nrf52840_express"}
5+
6+
for TARGET in ${TARGETS}; do
7+
make -C /opt/kmkpython/ports/nrf BOARD="${TARGET}"
8+
cp "/opt/kmkpython/ports/nrf/build-${TARGET}/firmware.uf2" "/dist/${TARGET}-${TIMESTAMP}.uf2"
9+
echo "===> Built /dist/${TARGET}-${TIMESTAMP}.uf2"
10+
done

kmkpython_ref.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/kmkfw/kmkpython b55fe4abc344bf1f509e8ef036d2a4cf13d6be63

0 commit comments

Comments
 (0)