Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/IRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ IRPrinter::IRPrinter(ostream &s)
int val = std::atoi(opt);
use_colors = val != 0;
} else {
use_colors = supports_ansi(stream);
// Respect NO_COLOR in addition to whether we're writing to a
// terminal, matching the profiler report's color gate.
const char *no_color = getenv("NO_COLOR");
use_colors = !(no_color && no_color[0]) && supports_ansi(stream);
}
if (use_colors) {
ansi = true;
Expand Down
2 changes: 1 addition & 1 deletion src/LLVM_Runtime_Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ void add_underscore_to_posix_call(llvm::CallInst *call, llvm::Function *fn, llvm
* of mcjit, so we just rewrite uses of these functions to include an
* underscore. */
void add_underscores_to_posix_calls_on_windows(llvm::Module *m) {
string posix_fns[] = {"vsnprintf", "open", "close", "write", "fileno"};
string posix_fns[] = {"vsnprintf", "open", "close", "write", "fileno", "isatty"};

string *posix_fns_begin = posix_fns;
string *posix_fns_end = posix_fns + sizeof(posix_fns) / sizeof(posix_fns[0]);
Expand Down
22 changes: 18 additions & 4 deletions src/runtime/profiler_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,24 @@ ALWAYS_INLINE bool counter_is_approximate(const halide_profiler_func_stats *fs,
WEAK void halide_profiler_report_unlocked(void *user_context, halide_profiler_state *s) {
StringStreamPrinter<1024> sstr(user_context);

bool support_colors = false;
const char *term = getenv("TERM");
if (term && (strstr(term, "color") || strstr(term, "xterm"))) {
support_colors = true;
// Decide whether to emit ANSI color escapes. HL_COLORS, if set, is an
// explicit override matching IRPrinter: "0" forces colors off, anything
// else on. Otherwise honor NO_COLOR and auto-detect a color-capable
// terminal. Checking TERM alone isn't enough: CI and other redirected
// environments often set TERM=xterm-256color while stdout is a pipe or
// file, which would splatter escape codes into the captured log. The
// report is printed via halide_print, whose default writes to stdout.
bool support_colors;
const char *hl_colors = getenv("HL_COLORS");
if (hl_colors) {
support_colors = atoi(hl_colors) != 0;
} else {
const char *no_color = getenv("NO_COLOR");
const char *term = getenv("TERM");
support_colors =
!(no_color && no_color[0]) &&
term && (strstr(term, "color") || strstr(term, "xterm")) &&
isatty(STDOUT_FILENO);
}

// Column-aligned rows are produced from `const char *` templates. A
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ int fclose(void *);
int close(int);
size_t fwrite(const void *, size_t, size_t, void *);
ssize_t write(int fd, const void *buf, size_t bytes);
int isatty(int fd);
int remove(const char *pathname);
int ioctl(int fd, unsigned long request, ...);
char *strncpy(char *dst, const char *src, size_t n);
Expand Down