首页 > 解决方案 > Windows GNU Make 在某些情况下会破坏 POSIX 颜色代码,但为什么呢?

问题描述

我在 Windows 10 上的 GNU make 项目有一些问题。我正在尝试在我的 Makefile 中添加 google 单元测试,并开始尝试以下目标:

utest_compile:
 @echo Compile unit test
 g++ -o Utest.exe $(COMPILE_FLAGS) $(SOURCES)
 @echo Compile finished!

utest_run:
 @echo Running unit tests
 Utest.exe --gtest_color="yes"
 @echo Run finished!

utest: utest_compile utest_run

运行utest_complieutest_run单独运行完美,但是当尝试运行时utest,输出中的颜色代码不知何故变得一团糟,比如[0;32m[ OK ] [mDummytest以默认颜色打印而不[ OK ] Dummytest 是以绿色打印。

我试图搜索 GNU make 如何解析输出并将其传递,特别是关于虚假目标及其依赖项,但我能找到的任何规则似乎都不适用于这种情况。(例如,将输出存储在变量中或重定向到文件时的规则等)

你知道这里应用了什么样的解析/格式化规则,以及如何防止颜色代码被破坏吗?

编辑 同时我发现了以下内容:这很好用(打印彩色文本):

utest: utest_compile
    @echo Run unit tests...
    -$(TARGET_DIR)/UTest.exe --gtest_color="yes" > ut.log
    @echo Result:
    @tail -n 1 ut.log
    @echo Unit test execution finished. 

但这失败了(打印无色的模糊文本):

utest: utest_compile
    @echo Run unit tests...
    $(RM) -f ut.log
    -$(TARGET_DIR)/UTest.exe --gtest_color="yes" > ut.log
    @echo Result:
    @tail -n 1 ut.log
    @echo Unit test execution finished. 

我的怀疑是额外的行 - 使用 rm - 可能在终端模式之间切换。我正在使用 Windows 10 内置的 linux 终端解释器,它很可能仍处于测试阶段,因此它可以解释问题,但我仍然不知道这里的实际细节,我很乐意提供任何信息。

标签: windowsmakefilegnugoogletestoutput-formatting

解决方案


推荐阅读