Skip to content

Commit 706a4f6

Browse files
authored
Make build system respect FORCE_COLOR and NO_COLOR settings (#56346)
Follow up to #53742, but for the build system. CC: @omus.
1 parent dc57caf commit 706a4f6

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

Make.inc

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,51 @@ SPACE:=$(eval) $(eval)
118118
export LC_ALL=C
119119
export LANG=C
120120

121+
# Respect `FORCE_COLOR` environment variable: <https://force-color.org/>.
122+
ifndef FORCE_COLOR
123+
FORCE_COLOR := ""
124+
endif
125+
126+
# Respect `NO_COLOR` environment variable: <https://no-color.org/>.
127+
ifndef NO_COLOR
128+
NO_COLOR := ""
129+
endif
130+
131+
# When both `FORCE_COLOR` and `NO_COLOR` are defined, the former has precedence.
132+
ifneq ($(FORCE_COLOR), "")
133+
NO_COLOR = ""
134+
endif
135+
136+
WARNCOLOR:="\033[33;1m"
137+
ENDCOLOR:="\033[0m"
138+
139+
CCCOLOR:="\033[34m"
140+
LINKCOLOR:="\033[34;1m"
141+
PERLCOLOR:="\033[35m"
142+
FLISPCOLOR:="\033[32m"
143+
JULIACOLOR:="\033[32;1m"
144+
DTRACECOLOR:="\033[32;1m"
145+
146+
SRCCOLOR:="\033[33m"
147+
BINCOLOR:="\033[37;1m"
148+
JULCOLOR:="\033[34;1m"
149+
150+
ifneq ($(NO_COLOR), "")
151+
WARNCOLOR:=""
152+
ENDCOLOR:=""
153+
154+
CCCOLOR:=""
155+
LINKCOLOR:=""
156+
PERLCOLOR:=""
157+
FLISPCOLOR:=""
158+
JULIACOLOR:=""
159+
DTRACECOLOR:=""
160+
161+
SRCCOLOR:=""
162+
BINCOLOR:=""
163+
JULCOLOR:=""
164+
endif
165+
121166
# We need python for things like BB triplet recognition and relative path computation.
122167
# We don't really care about version, generally, so just find something that works:
123168
PYTHON := "$(shell which python 2>/dev/null || which python3 2>/dev/null || which python2 2>/dev/null || echo "{python|python3|python2} not found")"
@@ -140,7 +185,7 @@ ifeq ($(BUILDROOT),)
140185
ifeq ("$(origin O)", "command line")
141186
BUILDROOT := $(abspath $O)
142187
BUILDDIR := $(abspath $(BUILDROOT)/$(call rel_path,$(JULIAHOME),$(SRCDIR)))
143-
$(info $(shell printf '\033[32;1mBuilding into $(BUILDROOT)\033[0m')) # use printf to expand the escape sequences
188+
$(info $(shell printf '$(JULIACOLOR)Building into $(BUILDROOT)$(ENDCOLOR)')) # use printf to expand the escape sequences
144189
else
145190
BUILDROOT:=$(JULIAHOME)
146191
endif
@@ -1759,24 +1804,10 @@ ifndef VERBOSE
17591804
VERBOSE := 0
17601805
endif
17611806

1762-
WARNCOLOR:="\033[33;1m"
1763-
ENDCOLOR:="\033[0m"
1764-
17651807
ifeq ($(VERBOSE), 0)
17661808

17671809
QUIET_MAKE = -s
17681810

1769-
CCCOLOR:="\033[34m"
1770-
LINKCOLOR:="\033[34;1m"
1771-
PERLCOLOR:="\033[35m"
1772-
FLISPCOLOR:="\033[32m"
1773-
JULIACOLOR:="\033[32;1m"
1774-
DTRACECOLOR:="\033[32;1m"
1775-
1776-
SRCCOLOR:="\033[33m"
1777-
BINCOLOR:="\033[37;1m"
1778-
JULCOLOR:="\033[34;1m"
1779-
17801811
GOAL=$(subst ','\'',$(subst $(abspath $(JULIAHOME))/,,$(abspath $@)))
17811812

17821813
PRINT_CC = printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$(GOAL)$(ENDCOLOR); $(1)
@@ -1797,7 +1828,7 @@ PRINT_FLISP = echo '$(subst ','\'',$(1))'; $(1)
17971828
PRINT_JULIA = echo '$(subst ','\'',$(1))'; $(1)
17981829
PRINT_DTRACE = echo '$(subst ','\'',$(1))'; $(1)
17991830

1800-
endif
1831+
endif # VERBOSE
18011832

18021833
# Makefile debugging trick:
18031834
# call print-VARIABLE to see the runtime value of any variable

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ testall1: check-whitespace $(JULIA_BUILD_MODE)
650650

651651
test-%: check-whitespace $(JULIA_BUILD_MODE) .FORCE
652652
@([ $$(( $$(date +%s) - $$(date -r $(build_private_libdir)/sys.$(SHLIB_EXT) +%s) )) -le 100 ] && \
653-
printf '\033[93m HINT The system image was recently rebuilt. Are you aware of the test-revise-* targets? See CONTRIBUTING.md. \033[0m\n') || true
653+
printf '$(WARNCOLOR) HINT The system image was recently rebuilt. Are you aware of the test-revise-* targets? See CONTRIBUTING.md. $(ENDCOLOR)\n') || true
654654
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test $* JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)
655655

656656
test-revise-%: .FORCE

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ Command-line option changes
5757
* The `-m/--module` flag can be passed to run the `main` function inside a package with a set of arguments.
5858
This `main` function should be declared using `@main` to indicate that it is an entry point.
5959
* Enabling or disabling color text in Julia can now be controlled with the
60-
[`NO_COLOR`](https://no-color.org/) or [`FORCE_COLOR`](https://force-color.org/) environment
61-
variables. ([#53742]).
60+
[`NO_COLOR`](https://no-color.org/) or [`FORCE_COLOR`](https://force-color.org/) environment
61+
variables. These variables are also honored by Julia's build system ([#53742], [#56346]).
6262
* `--project=@temp` starts Julia with a temporary environment.
6363
* New `--trace-compile-timing` option to report how long each method reported by `--trace-compile` took
6464
to compile, in ms. ([#54662])

0 commit comments

Comments
 (0)