From d21d029d55ddc026fcaf6673f2b712a645286dce Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 10 Dec 2017 01:05:29 +0200 Subject: [PATCH] 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 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. --- py/mkrules.mk | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/py/mkrules.mk b/py/mkrules.mk index 72a5c3de06..96f6e35a64 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -160,6 +160,27 @@ clean: $(RM) -rf $(BUILD) $(CLEAN_EXTRA) .PHONY: clean +# Clean every non-git file from FROZEN_DIR/FROZEN_MPY_DIR, but making a backup. +# We run rmdir below to avoid empty backup dir (it will silently fail if backup +# is non-empty). +clean-frozen: + if [ -n "$(FROZEN_MPY_DIR)" ]; then \ + backup_dir=$(FROZEN_MPY_DIR).$$(date +%Y%m%dT%H%M%S); mkdir $$backup_dir; \ + cd $(FROZEN_MPY_DIR); git status --ignored -u all -s . | awk ' {print $$2}' \ + | xargs --no-run-if-empty cp --parents -t ../$$backup_dir; \ + rmdir ../$$backup_dir 2>/dev/null || true; \ + git clean -d -f .; \ + fi + + if [ -n "$(FROZEN_DIR)" ]; then \ + backup_dir=$(FROZEN_DIR).$$(date +%Y%m%dT%H%M%S); mkdir $$backup_dir; \ + cd $(FROZEN_DIR); git status --ignored -u all -s . | awk ' {print $$2}' \ + | xargs --no-run-if-empty cp --parents -t ../$$backup_dir; \ + rmdir ../$$backup_dir 2>/dev/null || true; \ + git clean -d -f .; \ + fi +.PHONY: clean-frozen + print-cfg: $(ECHO) "PY_SRC = $(PY_SRC)" $(ECHO) "BUILD = $(BUILD)"