如何检查Make规则中的命令输出?

时间:2015-01-16 01:10:01

标签: php makefile

在我的lint和单元测试之间,我想检查是否有任何php文件生成任何输出。

我正在尝试这样的事情,这显然不起作用:

.PHONY: php_inc
php_inc:
    ifneq (,$(shell php -e src/*inc))
        $(error PHP include files should not have any output when parsed)
    endif
关于如何写这个或更好的方法来解决问题的建议?

2 个答案:

答案 0 :(得分:1)

您可以这样做,以避免执行php两次:

@output=`php -e src/*inc`; \
if [ ! -z "$$output" ]; then \
 echo "PHP include files should not output. Got:"; \
 echo $$output; \
 exit 1; \
fi

我不知道输出对于shell来说可能会变得太大而无法处理。每当我必须解决其状态我必须根据输出而不是退出状态检查的工具时,输出相当适中。

答案 1 :(得分:0)

记录我当前的工作:

@if [ ! -z "`php -e src/*inc`" ]; then \
    echo "PHP include files should not output. Got:"; \
    php -e src/*inc; \
    exit 1; \
fi

或者更像一点......但我喜欢那里的引用。给我一种温暖的安全感:))

@if [ ! -z $(shell $(PHP) -e src/*inc) ]; then \