Skip to content

Commit

Permalink
Make build system respect FORCE_COLOR and NO_COLOR settings (#56346)
Browse files Browse the repository at this point in the history
Follow up to #53742, but for the build system.  CC: @omus.
  • Loading branch information
giordano authored Nov 1, 2024
1 parent dc57caf commit 706a4f6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
63 changes: 47 additions & 16 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,51 @@ SPACE:=$(eval) $(eval)
export LC_ALL=C
export LANG=C

# Respect `FORCE_COLOR` environment variable: <https://force-color.org/>.
ifndef FORCE_COLOR
FORCE_COLOR := ""
endif

# Respect `NO_COLOR` environment variable: <https://no-color.org/>.
ifndef NO_COLOR
NO_COLOR := ""
endif

# When both `FORCE_COLOR` and `NO_COLOR` are defined, the former has precedence.
ifneq ($(FORCE_COLOR), "")
NO_COLOR = ""
endif

WARNCOLOR:="\033[33;1m"
ENDCOLOR:="\033[0m"

CCCOLOR:="\033[34m"
LINKCOLOR:="\033[34;1m"
PERLCOLOR:="\033[35m"
FLISPCOLOR:="\033[32m"
JULIACOLOR:="\033[32;1m"
DTRACECOLOR:="\033[32;1m"

SRCCOLOR:="\033[33m"
BINCOLOR:="\033[37;1m"
JULCOLOR:="\033[34;1m"

ifneq ($(NO_COLOR), "")
WARNCOLOR:=""
ENDCOLOR:=""

CCCOLOR:=""
LINKCOLOR:=""
PERLCOLOR:=""
FLISPCOLOR:=""
JULIACOLOR:=""
DTRACECOLOR:=""

SRCCOLOR:=""
BINCOLOR:=""
JULCOLOR:=""
endif

# We need python for things like BB triplet recognition and relative path computation.
# We don't really care about version, generally, so just find something that works:
PYTHON := "$(shell which python 2>/dev/null || which python3 2>/dev/null || which python2 2>/dev/null || echo "{python|python3|python2} not found")"
Expand All @@ -140,7 +185,7 @@ ifeq ($(BUILDROOT),)
ifeq ("$(origin O)", "command line")
BUILDROOT := $(abspath $O)
BUILDDIR := $(abspath $(BUILDROOT)/$(call rel_path,$(JULIAHOME),$(SRCDIR)))
$(info $(shell printf '\033[32;1mBuilding into $(BUILDROOT)\033[0m')) # use printf to expand the escape sequences
$(info $(shell printf '$(JULIACOLOR)Building into $(BUILDROOT)$(ENDCOLOR)')) # use printf to expand the escape sequences
else
BUILDROOT:=$(JULIAHOME)
endif
Expand Down Expand Up @@ -1759,24 +1804,10 @@ ifndef VERBOSE
VERBOSE := 0
endif

WARNCOLOR:="\033[33;1m"
ENDCOLOR:="\033[0m"

ifeq ($(VERBOSE), 0)

QUIET_MAKE = -s

CCCOLOR:="\033[34m"
LINKCOLOR:="\033[34;1m"
PERLCOLOR:="\033[35m"
FLISPCOLOR:="\033[32m"
JULIACOLOR:="\033[32;1m"
DTRACECOLOR:="\033[32;1m"

SRCCOLOR:="\033[33m"
BINCOLOR:="\033[37;1m"
JULCOLOR:="\033[34;1m"

GOAL=$(subst ','\'',$(subst $(abspath $(JULIAHOME))/,,$(abspath $@)))

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

endif
endif # VERBOSE

# Makefile debugging trick:
# call print-VARIABLE to see the runtime value of any variable
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ testall1: check-whitespace $(JULIA_BUILD_MODE)

test-%: check-whitespace $(JULIA_BUILD_MODE) .FORCE
@([ $$(( $$(date +%s) - $$(date -r $(build_private_libdir)/sys.$(SHLIB_EXT) +%s) )) -le 100 ] && \
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
printf '$(WARNCOLOR) HINT The system image was recently rebuilt. Are you aware of the test-revise-* targets? See CONTRIBUTING.md. $(ENDCOLOR)\n') || true
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/test $* JULIA_BUILD_MODE=$(JULIA_BUILD_MODE)

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

0 comments on commit 706a4f6

Please sign in to comment.