8000 Added ability to freeze multiple directories; freeze neopixel library… · boneskull/circuitpython@74cfdeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 74cfdeb

Browse files
dhalberttannewt
authored andcommitted
Added ability to freeze multiple directories; freeze neopixel library in cpx build (adafruit#199)
Reworked frozen module support: clean up makefiles and handle multiple directories. Modules to freeze are included as git submodules. Add neopixel to circuitplayground express build. Fixes adafruit#56
1 parent 16ef611 commit 74cfdeb

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
[submodule "tools/uf2"]
1818
path = tools/uf2
1919
url = https://github.com/Microsoft/uf2.git
20+
[submodule "atmel-samd/frozen/Adafruit_CircuitPython_NeoPixel"]
21+
path = frozen/Adafruit_CircuitPython_NeoPixel
22+
url = https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel

atmel-samd/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ CFLAGS += -DMICROPY_MODULE_FROZEN_STR
145145
CFLAGS += -Wno-error=lto-type-mismatch
146146
endif
147147

148-
ifneq ($(FROZEN_MPY_DIR),)
149148
# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and
150-
# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch).
149+
# then invoke make with FROZEN_MPY_DIR=frozen or FROZEN_MPY_DIRS="dir1 dir2"
150+
# (be sure to build from scratch).
151+
152+
ifneq ($(FROZEN_MPY_DIRS),)
151153
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
152154
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
153155
CFLAGS += -Wno-error=lto-type-mismatch

atmel-samd/boards/circuitplayground_express/mpconfigboard.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ USB_PID = 0x8019
55
FLASH_IMPL = spi_flash.c
66

77
CHIP_VARIANT = SAMD21G18A
8+
9+
# Include these Python libraries in firmware.
10+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel

py/mkenv.mk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ endif
4242
PY_SRC ?= $(TOP)/py
4343
BUILD ?= build
4444

45-
RM = rm
4645
ECHO = @echo
46+
47+
CD = cd
4748
CP = cp
49+
FIND = find
4850
MKDIR = mkdir
49-
SED = sed
5051
PYTHON = python
52+
RM = rm
53+
RSYNC = rsync
54+
SED = sed
5155

5256
AS = $(CROSS_COMPILE)as
5357
CC = $(CROSS_COMPILE)gcc

py/mkrules.mk

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,30 @@ $(BUILD)/frozen.c: $(wildcard $(FROZEN_DIR)/*) $(HEADER_BUILD) $(FROZEN_EXTRA_DE
101101
$(Q)$(MAKE_FROZEN) $(FROZEN_DIR) > $@
102102
endif
103103

104-
ifneq ($(FROZEN_MPY_DIR),)
104+
ifneq ($(FROZEN_MPY_DIRS),)
105105
# to build the MicroPython cross compiler
106-
$(TOP)/mpy-cross/mpy-cross: $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/windows/fmode.c
106+
# Currently not used, because the wrong mpy-cross may be left over from a previous build. Build by hand to make sure.
107+
$(MPY_CROSS): $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/windows/fmode.c
107108
$(Q)$(MAKE) -C $(TOP)/mpy-cross
108109

109-
# make a list of all the .py files that need compiling and freezing
110-
BLAH := $(info $(shell pwd))
111-
112-
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py' | $(SED) -e 's=^$(FROZEN_MPY_DIR)/==')
113-
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/frozen_mpy/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
114-
115-
# to build .mpy files from .py files
116-
$(BUILD)/frozen_mpy/%.mpy: $(FROZEN_MPY_DIR)/%.py
117-
@$(ECHO) "MPY $<"
118-
$(Q)$(MKDIR) -p $(dir $@)
119-
$(Q)$(MPY_CROSS) -o $@ -s $(<:$(FROZEN_MPY_DIR)/%=%) $(MPY_CROSS_FLAGS) $<
110+
# Copy all the modules and single python files to freeze to a common area, omitting top-level dirs (the repo names).
111+
# Remove any conf.py (sphinx config) and setup.py (module install info) files, which are not meant to be frozen.
112+
# Then compile .mpy files from all the .py files, placing them in the same directories as the .py files.
113+
$(BUILD)/frozen_mpy: $(FROZEN_MPY_DIRS)
114+
$(ECHO) FREEZE $(FROZEN_MPY_DIRS)
115+
$(Q)$(MKDIR) -p $@
116+
$(Q)$(RSYNC) -rL --include="*/" --include='*.py' --exclude="*" $(addsuffix /*,$(FROZEN_MPY_DIRS)) $@
117+
$(Q)$(RM) -f $@/conf.py $@/setup.py
118+
$(Q)$(CD) $@ && \
119+
$(FIND) -L . -type f -name '*.py' | sed 's=^\./==' | \
120+
xargs -n1 $(abspath $(MPY_CROSS)) $(MPY_CROSS_FLAGS)
120121

121122
# to build frozen_mpy.c from all .mpy files
122123
# You need to define MPY_TOOL_LONGINT_IMPL in mpconfigport.mk
123124
# if the default will not work (mpz is the default).
124-
$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
125+
$(BUILD)/frozen_mpy.c: $(BUILD)/frozen_mpy $(BUILD)/genhdr/qstrdefs.generated.h
125126
$(STEPECHO) "Creating $@"
126-
$(Q)$(PYTHON) $(MPY_TOOL) $(MPY_TOOL_LONGINT_IMPL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(FROZEN_MPY_MPY_FILES) > $@
127+
$(Q)$(PYTHON) $(MPY_TOOL) $(MPY_TOOL_LONGINT_IMPL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h $(shell $(FIND) -L $(BUILD)/frozen_mpy -type f -name '*.mpy') > $@
127128
endif
128129

129130
ifneq ($(PROG),)

py/py.mk

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,15 @@ PY_O = $(addprefix $(PY_BUILD)/, $(PY_O_BASENAME))
247247

248248
# object file for frozen files
249249
ifneq ($(FROZEN_DIR),)
250-
PY_O += $(BUILD)/$(BUILD)/frozen.o
250+
PY_O += $(BUILD)/frozen.o
251251
endif
252252

253+
# Combine old singular FROZEN_MPY_DIR with new multiple value form.
254+
FROZEN_MPY_DIRS += $(FROZEN_MPY_DIR)
255+
253256
# object file for frozen bytecode (frozen .mpy files)
254-
ifneq ($(FROZEN_MPY_DIR),)
255-
PY_O += $(BUILD)/$(BUILD)/frozen_mpy.o
257+
ifneq ($(FROZEN_MPY_DIRS),)
258+
PY_O += $(BUILD)/frozen_mpy.o
256259
endif
257260

258261
# Sources that may contain qstrings

0 commit comments

Comments
 (0)
0