flake8_errs是初始化为空字符串('')的变量。
试图连接命令的输出。
flake8 --config=$(CI_DIR)/lint-configs/python/.flake8 $$py_file;
将每个.py文件设置为flake8_errs变量。
然后检查flake8_errs是否有某些内容并引发错误。
,这就是我迄今尝试过的:
flake8_errs =''
.PHONY: .flake8
.flake8:
. $(VIRTUALENV_DIR)/bin/activate; \
if [ "$${FORCE_CHECK_ALL_FILES}" = "true" ]; then \
find ./* -name "*.py" | while read py_file; do \
flake8_errs += flake8 --config=$(CI_DIR)/lint-configs/python/.flake8 $$py_file; \
done; \
else \
echo "No files have changed, skipping run..."; \
fi;
if [ ! -z "${flake8_errs}" ]; then \
exit 1; \
fi;发布于 2021-02-18 13:58:29
不能在菜谱中使用make函数,也不能分配用于在菜谱中创建变量。菜谱一旦完全展开,所有make结构都会被解析,然后调用shell并给出该展开的结果,然后make等待shell完成以确定它是否工作。
您不能“分散”shell和makefile内容,在这些内容中,shell必须运行一些内容,然后使构造被展开,然后shell运行更多的内容,等等。
应该使用只使用外壳结构编写整个规则:
.PHONY: .flake8
.flake8:
. $(VIRTUALENV_DIR)/bin/activate; \
files='$(CHANGED_PY)'; \
if [ '$(FORCE_CHECK_ALL_FILES)' = true ]; then \
files="$$(find ./* -name "*.py")"; \
fi; \
if [ -z "$$files" ]; then \
echo "No files have changed, skipping run..."; \
exit 0; \
fi; \
errors=; \
for file in $$files; do \
if [ -n "$$file" ]; then \
errors="$$errors $$(flake8 --config=$(CI_DIR)/lint-configs/python/.flake8 $$file)"; \
fi; \
done; \
if [ -n "$$errors" ]; then \
echo "got errors: $$errors"; \
exit 1; \
fi;https://stackoverflow.com/questions/66261400
复制相似问题