From 17ab44e7d718f9f12b91c35bc37ab7eec5521078 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 6 Sep 2021 17:43:26 -0400 Subject: [PATCH] Meta: Make BuildClang.sh produce less output when running in a TTY Ninja disables its fancy output mode when it's not writing to a TTY. So don't pipe its output into something else, so that it writes to a TTY if the invoking terminal is a TTY. --- Toolchain/BuildClang.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Toolchain/BuildClang.sh b/Toolchain/BuildClang.sh index 07013da877..dbafecbb58 100755 --- a/Toolchain/BuildClang.sh +++ b/Toolchain/BuildClang.sh @@ -76,7 +76,18 @@ BINUTILS_BASE_URL="https://ftp.gnu.org/gnu/binutils" buildstep() { NAME=$1 shift - "$@" 2>&1 | sed $'s|^|\x1b[34m['"${NAME}"$']\x1b[39m |' + "$@" 2>&1 | sed $'s|^|\e[34m['"${NAME}"$']\e[39m |' +} + +buildstep_ninja() { + # When ninja writes to a pipe, it strips ANSI escape codes and prints one line per buildstep. + # Instead, use NINJA_STATUS so that we get colored output from LLVM's build and fewer lines of output when running in a tty. + # ANSI escape codes in NINJA_STATUS are slightly janky (ninja thinks that "\e[34m" needs 5 output characters instead of 5, so + # it's middle elision is slightly off; also it would happily elide the "\e39m" which messes up the output if the terminal is too + # narrow), but it's still working better than the alternative. + NAME=$1 + shift + env NINJA_STATUS=$'\e[34m['"${NAME}"$']\e[39m [%f/%t] ' "$@" } # === DEPENDENCIES === @@ -263,7 +274,7 @@ pushd "$DIR/Build/clang/$ARCH" -DLLVM_INSTALL_UTILS=OFF \ ${dev:+"-DLLVM_CCACHE_BUILD=ON"} || exit 1 - buildstep "llvm+clang/build" ninja -j "$MAKEJOBS" || exit 1 + buildstep_ninja "llvm+clang/build" ninja -j "$MAKEJOBS" || exit 1 buildstep "llvm+clang/install" ninja install || exit 1 popd @@ -298,7 +309,7 @@ pushd "$DIR/Build/clang/$ARCH" -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DCOMPILER_RT_BUILD_XRAY=OFF || exit 1 - buildstep "compiler-rt/build" ninja -j "$MAKEJOBS" || exit 1 + buildstep_ninja "compiler-rt/build" ninja -j "$MAKEJOBS" || exit 1 buildstep "compiler-rt/install" ninja install || exit 1 popd @@ -319,7 +330,7 @@ pushd "$DIR/Build/clang/$ARCH" -DLIBUNWIND_TARGET_TRIPLE="$LLVM_TARGET" \ -DLIBUNWIND_SYSROOT="$SYSROOT" || exit 1 - buildstep "libunwind/build" ninja -j "$MAKEJOBS" || exit 1 + buildstep_ninja "libunwind/build" ninja -j "$MAKEJOBS" || exit 1 buildstep "libunwind/install" ninja install || exit 1 popd @@ -343,7 +354,7 @@ pushd "$DIR/Build/clang/$ARCH" -DLIBCXXABI_ENABLE_ASSERTIONS=OFF \ -DLIBCXXABI_BAREMETAL=ON || exit 1 - buildstep "libcxxabi/build" ninja -j "$MAKEJOBS" || exit 1 + buildstep_ninja "libcxxabi/build" ninja -j "$MAKEJOBS" || exit 1 buildstep "libcxxabi/install" ninja install || exit 1 popd