【发布时间】:2020-10-16 10:38:51
【问题描述】:
我正在处理一个使用许多我无法控制的导入 Makefile 的项目。我只控制 repo 根目录下的单个 Makefile。其他 Makefile 之一中的目标对我正在处理的代码运行测试。但是,我的代码还有一个额外的设置和拆卸要求。
我可以将一个目标添加到我的本地 Makefile 作为公共目标的依赖项。这允许安装程序运行。但是,我也需要事后拆除。拆除需要始终进行,即使 make 目标失败。示例代码如下:
.PHONY: common/test local/setup local/teardown
# This includes the setup as needed
common/test: local/setup
local/setup:
# Alter files to allow destruction of test resources
# But how do I ensure this runs? Depending on the user to run it is error prone...
# Also, this step needs to run EVEN IF the common/test target failed
local/teardown:
# Revert files so they don't get committed to source control
# because we need resource destruction disallowed in production
【问题讨论】:
-
“即使目标失败”是否包括失败场景,例如有人点击 ^C 或发送 SIGINT?还是您只担心
common/test配方是否以正常方式失败(以非 0 退出代码退出)? -
好问题,我主要关注常见/测试配方的失败。如果用户中断 make,他们可以期望清理部分状态。
标签: makefile