Skip to content

Commit d21d029

Browse files
committed
py/mkrules.mk: Add "clean-frozen" target to clean frozen script/modules dir.
This target removes any stray files (i.e. something not committed to git) from scripts/ and modules/ dirs (or whatever FROZEN_DIR and FROZEN_MPY_DIR is set to). The expected workflow is: 1. make clean-frozen 2. micropython -m upip -p modules <packages_to_freeze> 3. make As it can be expected that people may drop random thing in those dirs which they can miss later, the content is actually backed up before cleaning.
1 parent a35d923 commit d21d029

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

py/mkrules.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ clean:
160160
$(RM) -rf $(BUILD) $(CLEAN_EXTRA)
161161
.PHONY: clean
162162

163+
# Clean every non-git file from FROZEN_DIR/FROZEN_MPY_DIR, but making a backup.
164+
# We run rmdir below to avoid empty backup dir (it will silently fail if backup
165+
# is non-empty).
166+
clean-frozen:
167+
if [ -n "$(FROZEN_MPY_DIR)" ]; then \
168+
backup_dir=$(FROZEN_MPY_DIR).$$(date +%Y%m%dT%H%M%S); mkdir $$backup_dir; \
169+
cd $(FROZEN_MPY_DIR); git status --ignored -u all -s . | awk ' {print $$2}' \
170+
| xargs --no-run-if-empty cp --parents -t ../$$backup_dir; \
171+
rmdir ../$$backup_dir 2>/dev/null || true; \
172+
git clean -d -f .; \
173+
fi
174+
175+
if [ -n "$(FROZEN_DIR)" ]; then \
176+
backup_dir=$(FROZEN_DIR).$$(date +%Y%m%dT%H%M%S); mkdir $$backup_dir; \
177+
cd $(FROZEN_DIR); git status --ignored -u all -s . | awk ' {print $$2}' \
178+
| xargs --no-run-if-empty cp --parents -t ../$$backup_dir; \
179+
rmdir ../$$backup_dir 2>/dev/null || true; \
180+
git clean -d -f .; \
181+
fi
182+
.PHONY: clean-frozen
183+
163184
print-cfg:
164185
$(ECHO) "PY_SRC = $(PY_SRC)"
165186
$(ECHO) "BUILD = $(BUILD)"

0 commit comments

Comments
 (0)