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.
This commit is contained in:
Paul Sokolovsky 2017-12-10 01:05:29 +02:00
parent a35d923cdf
commit d21d029d55
1 changed files with 21 additions and 0 deletions

View File

@ -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)"