我有一个makefile,其中的目标依赖于安装了一些外部客户端(python3、libxml2等)。
这是我的makefile
.PHONY: test install-packages mac-setup checkenv target help
EXTERNALS = python3 pip3 xmllint pytest pipenv
P := $(foreach exec,$(EXTERNALS),$(if $(shell which $(exec)),missing,$(warning "===>>>WARNING: No required `$(exec)` in PATH, run `make mac-setup` + `make install-packages` <<<===")))
test: ## run all tests in test directory
pipenv run pytest -v --ignore=path payload_files .
install-packages: ##install python packages listed in Pipfile
pipenv install
mac-setup: ## setup mac for testing
brew install libxml2
brew install python3
brew install pipenv
# see https://github.mycompany.com/ea/ea_test_player_unified/blob/master/run-feature.sh
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help
请注意这一行
P := $(foreach exec,$(EXTERNALS),$(if $(shell which $(exec)),missing,$(warning "===>>>WARNING: No required `$(exec)` in PATH, run `make mac-setup` + `make install-packages` <<<===")))
这将检查所需的二进制文件。这行得通..。但是,我更希望有一个checkenv
目标来执行此操作和错误,这样我就可以附加太具体的目标,比如test
,而不是打印出可能会被忽略的警告。
想要:
checkenv: # error if which ${binary} fails or *even better* if if binary --version doesn't return the right version: python3 pip3 xmllint pytest pipenv
我尝试了我在网络上找到的各种技术,包括stackoverflow……但大多数都使用我在上面使用的技术,不使用make目标,或者只检查一个二进制文件。我尝试通过一个二进制文件数组构建一个循环,但由于make是一个PITA,所以无法获得正确的语法:)
有什么建议吗?
注意,我是一个python新手,任务是用python....so重写一些jmeter测试,如果你对上面的方法有任何想法,请随意分享。
谢谢,菲尔
发布于 2019-05-25 13:36:09
看不出问题出在哪里。在我看来,它非常简单,因为make允许在同一行上使用多个目标:
EXTERNALS := python3 pip3 xmllint pytest pipenv
python3_version := Python 3.7.3
pip3_version := ...
...
.PHONY: checkenv $(EXTERNALS)
checkenv: $(EXTERNALS)
$(EXTERNALS):
if [ "`$@ --version`" != "$($@_version)" ]; then echo "$@ check failed"; false; fi
https://stackoverflow.com/questions/56298165
复制相似问题