【问题标题】:make file target to check for installed dependencies制作文件目标以检查已安装的依赖项
【发布时间】:2019-05-25 13:59:38
【问题描述】:

我有一个 makefile,其中的目标依赖于安装了一些外部客户端(python3、libxml2 等)。

这是我的生成文件

.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重写一些jmeter测试......所以如果您对上述方法有任何想法,请随时分享。

谢谢, 菲尔

【问题讨论】:

  • 无论如何,只要你致力于 GNU make,你可以考虑使用它的 $(eval) 函数。您应该能够将其与循环结合以动态生成 真正的 规则。不过,恐怕目前我还没有准备好解决所有细节。

标签: python makefile


【解决方案1】:

看不出问题出在哪里。对我来说它看起来非常简单,因为 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2015-04-01
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多