makefile - Makefile 目标不识别依赖动作
问题描述
我写了这个简单的 Makefile 来说明我的问题。
$make target
- 调用
dep
作为依赖项并拉取图像 - 但是随后的检查
docker image list -q $(IMG)
没有找到我的图像。
这里发生了什么,我应该如何解决这个问题?
IMG := hello-world
.PHONY: target
target: dep
ifeq ($(shell docker image list -q $(IMG)),)
echo "docker image list did not recognize the pull"
endif
.PHONY: dep
dep:
@docker pull $(IMG)
解决方案
该测试不是后续的。它在读取时被替换到 Makefile 中,在执行任何规则之前。
您可能希望在规则的命令中执行该测试target
:
target: dep
if test -z "$$(docker image list -q $(IMG))"; then \
echo "docker image list did not recognize the pull" >&2; \
false; \
fi
我们可以将命令更改为仅运行docker image inspect
- 如果图像存在则返回 true 状态,否则返回 false :
target: dep
if ! docker image inspect "$(IMG))" >/dev/null 2>&1; then \
echo "docker image list did not recognize the pull" >&2; \
false; \
fi
推荐阅读
- javascript - 如何将 Fabric js 与 React Native 集成?
- android - 自 Chrome 72 以来,WebView 无法解析 SVG
- python - 使用 Selenium/Python 处理“无标题”页面
- reactjs - Redux 一个接一个地同步调度多个动作
- c++ - OPC-UA:由(自发行)CA 签名的证书返回 NULL 而没有错误消息,我错过了什么?
- spring - Spring Security 从 OAuth2AuthenticationToken 获取 tokenValue
- typo3 - 如何将内联元素添加到 flexforms 中并使其工作
- apache - httpd-vhosts.conf 中的重定向无法在 XAMPP 中按预期工作
- python - 如何比较两列数据以确保没有数据匹配
- java - 如何在 Java 中从数组中添加或删除随机数?