Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue276 silent color makefiles #282

Merged
merged 6 commits into from
Jul 12, 2019
Merged
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
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ INSTALL_FLIT_CONFIG = $(PREFIX)/share/flit/scripts/flitconfig.py
CAT := $(if $(filter $(OS),Windows_NT),type,cat)
VERSION := $(shell $(CAT) $(CONFIG_DIR)/version.txt)

-include tests/color_out.mk

# Be silent by default
ifndef VERBOSE
.SILENT:
endif

.PHONY : all
all: $(TARGET)

Expand All @@ -67,10 +74,14 @@ help:
@echo

$(TARGET): $(OBJ)
@$(call color_out_noline,CYAN, mkdir)
@echo " lib"
mkdir -p lib
@$(call color_out,BLUE,Building $(TARGET))
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)

$(SRCDIR)/%.o: $(SRCDIR)/%.cpp Makefile
@$(call color_out,CYAN, $< -> $@)
$(CXX) $(CXXFLAGS) $(DEPFLAGS) -c $< -o $@

.PRECIOUS: src/%.d
Expand All @@ -89,9 +100,11 @@ clean:
veryclean: distclean
distclean: clean
$(RM) $(TARGET)
$(RMDIR) $(LIBDIR)

.PHONY: install
install: $(TARGET)
@$(call color_out,BLUE,Installing...)
mkdir -m 0755 -p $(PREFIX)/bin
mkdir -m 0755 -p $(PREFIX)/lib
mkdir -m 0755 -p $(PREFIX)/include/flit
Expand Down Expand Up @@ -123,7 +136,7 @@ install: $(TARGET)
install -m 0644 $(LITMUS_TESTS) $(PREFIX)/share/flit/litmus-tests/
install -m 0644 LICENSE $(PREFIX)/share/licenses/flit/
cp -r benchmarks/* $(PREFIX)/share/flit/benchmarks/
@echo "Generating $(INSTALL_FLIT_CONFIG)"
@$(call color_out,CYAN, Generating $(INSTALL_FLIT_CONFIG))
@# Make the flitconfig.py script specifying this installation information
@echo "'''" > $(INSTALL_FLIT_CONFIG)
@echo "Contains paths and other configurations for the flit installation." >> $(INSTALL_FLIT_CONFIG)
Expand Down Expand Up @@ -171,6 +184,7 @@ install: $(TARGET)

.PHONY: uninstall
uninstall:
@$(call color_out,BLUE,Uninstalling...)
$(RMDIR) $(PREFIX)/include/flit
$(RMDIR) $(PREFIX)/share/flit
$(RMDIR) $(PREFIX)/share/licenses/flit
Expand Down
47 changes: 46 additions & 1 deletion data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ else
LDFLAGS += -Wl,-rpath=$(realpath $(FLIT_LIB_DIR))
endif

# Be silent by default
ifndef VERBOSE
.SILENT:
endif

# Helper functions to determine if the compiler is a particular version of GCC

# Returns the compiler name as output by the --version flag
Expand Down Expand Up @@ -196,6 +201,38 @@ TESTS = $(wildcard tests/*.cpp)
SOURCE = $(wildcard *.cpp)
SOURCE += $(TESTS)

# A Makefile function
# @param 1: color (e.g. BLUE or GREEN)
# @param 2: message to be printed in the color
color_out_noline = \
if [ -t 1 ]; then \
/bin/echo -ne "$(BASH_$1)$2$(BASH_CLEAR)"; \
else \
/bin/echo -n "$2"; \
fi
color_out = \
if [ -t 1 ]; then \
/bin/echo -e "$(BASH_$1)$2$(BASH_CLEAR)"; \
else \
/bin/echo "$2"; \
fi

BASH_CLEAR := \e[0m
BASH_BLACK := \e[0;30m
BASH_BROWN := \e[0;33m
BASH_GRAY := \e[0;37m
BASH_GREY := \e[0;37m
BASH_DARKGRAY := \e[1;30m
BASH_DARKGREY := \e[1;30m
BASH_RED := \e[1;31m
BASH_GREEN := \e[1;32m
BASH_YELLOW := \e[1;33m
BASH_BLUE := \e[1;34m
BASH_PURPLE := \e[1;35m
BASH_CYAN := \e[1;36m
BASH_WHITE := \e[1;37m


.PHONY: help
help:
@echo 'You can run the Makefile directly, but it is recommended to use'
Expand Down Expand Up @@ -301,6 +338,7 @@ endif
# @param 7: extra compiler flags
define COMPILE_RULE
$2: $1 Makefile custom.mk | $(patsubst %/,%,$(dir $2))
@$(call color_out,CYAN, $(strip $1) -> $(strip $2))
$3 $4 $5 -c $7 $(CXXFLAGS) $(DEPFLAGS) $(2:%.o=%.d) $1 -o $2 \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(strip $3)"' \
Expand Down Expand Up @@ -328,6 +366,8 @@ R_CUR_SWITCHES ?=
dirs: $(ALL_DIRS)

$(ALL_DIRS):
@$(call color_out_noline,CYAN, mkdir)
@echo " $@"
mkdir -p $@

# If we are in a recursion
Expand Down Expand Up @@ -356,6 +396,7 @@ endif
endif

$(R_TARGET): $(R_OBJ) | $(RUNBUILD_DIR)
@$(call color_out,CYAN, Creating $(R_TARGET))
$($(R_CUR_COMPILER)) $($(R_CUR_OPTL)) $($(R_CUR_SWITCHES)) \
$($(R_CUR_COMPILER)_CXXFLAGS) $(CXXFLAGS) \
$(R_OBJ) -o $@ \
Expand Down Expand Up @@ -416,7 +457,7 @@ TARGETS += $$(RUNBUILD_DIR)/$(strip $1)_$$(HOSTNAME)_$(strip $3)_$(strip $2)
# rebuilt, so does each recursive target.

$$(RUNBUILD_DIR)/$(strip $1)_$$(HOSTNAME)_$(strip $3)_$(strip $2): $$(GT_TARGET) | $$(OBJ_DIR) $$(RUNBUILD_DIR)
-+@$$(MAKE) rec --no-print-directory \
-+$$(MAKE) rec --no-print-directory \
R_IS_RECURSED=True \
R_CUR_COMPILER=$(strip $1) \
R_CUR_OPTL=$(strip $2) \
Expand All @@ -437,6 +478,7 @@ $(RESULTS_DIR)/%-out: $(RUNBUILD_DIR)/% | $(RESULTS_DIR)

# specify how to get comparison
%-out-comparison.csv: %-out $(GT_OUT) $(GT_TARGET)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$(GT_TARGET) --compare-mode --compare-gt $(GT_OUT) --suffix "-comparison.csv" $< -o /dev/null

#
Expand Down Expand Up @@ -510,6 +552,7 @@ endif # ifeq ($(UNAME_S),Darwin): meaning, we are on a mac

# Dev compilation rules first (easier to understand)
$(DEV_TARGET): $(DEV_OBJ) Makefile custom.mk
@$(call color_out,BLUE,Building $(DEV_TARGET))
$(DEV_CXX) $(CXXFLAGS) $(DEV_CXXFLAGS) \
-o $@ $(DEV_OBJ) $(LDFLAGS) $(DEV_LDFLAGS) $(LDLIBS)

Expand All @@ -525,9 +568,11 @@ $(foreach s,$(SOURCE),\

# Ground truth compilation rules
$(GT_OUT): $(GT_TARGET)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$(GT_TARGET) --output $(GT_OUT) --no-timing

$(GT_TARGET): $(GT_OBJ) Makefile custom.mk
@$(call color_out,BLUE,Building $(GT_TARGET))
$(GT_CXX) $(CXXFLAGS) $(GT_CXXFLAGS) \
-o $@ $(GT_OBJ) $(LDFLAGS) $(GT_LDFLAGS) $(LDLIBS)

Expand Down
19 changes: 16 additions & 3 deletions data/Makefile_bisect_binary.in
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ $(GT_LIB_TARGET): $(FLIT_LIB_DIR)/libflit.so
endif # ifeq ($(UNAME_S),Darwin): meaning we are on a mac

$(GT_LIB_OUT): $(GT_LIB_TARGET)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$(GT_LIB_TARGET) --output $(GT_LIB_OUT) --no-timing --precision "$(PRECISION)" $(TEST_CASE)

$(GT_LIB_TARGET): $(GT_OBJ) Makefile custom.mk $(MAKEFILE)
@$(call color_out,BLUE,Building $@)
$(GT_CXX) $(CXXFLAGS) -o $@ $(GT_OBJ) $(LDFLAGS) $(LDLIBS)

$(BISECT_RESULT): $(BISECT_OUT) $(GT_LIB_OUT) $(GT_LIB_TARGET)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$(GT_LIB_TARGET) --compare-mode --compare-gt $(GT_LIB_OUT) --suffix "-comparison.csv" $< -o /dev/null

endif # ifeq ($(BUILD_GT_LOCAL),true): meaning we are making a local gt
Expand All @@ -217,15 +220,19 @@ endif # ifeq ($(BUILD_GT_LOCAL),true): meaning we are making a local gt
-include $(SPLIT_DEPS)

$(BISECT_OUT): $(BISECT_TARGET) | $(BISECT_DIR)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$< --precision "$(PRECISION)" --output $@ $(TEST_CASE) --no-timing
$(TROUBLE_TARGET_OUT): $(TROUBLE_TARGET) | $(BISECT_DIR)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$< --precision "$(PRECISION)" --output $@ $(TEST_CASE) --no-timing

$(BISECT_TARGET): $(BISECT_OBJ) $(SPLIT_OBJ) Makefile custom.mk | $(BISECT_DIR)
@$(call color_out,BLUE,Building $@)
$(GT_CXX) $(CXXFLAGS) $(GT_CXXFLAGS) -o $@ $(BISECT_OBJ) $(SPLIT_OBJ) \
$(LDFLAGS) $(GT_LDFLAGS) $(LDLIBS)

$(TROUBLE_TARGET): $(TROUBLE_TARGET_OBJ) Makefile custom.mk | $(BISECT_DIR)
@$(call color_out,BLUE,Building $@)
$(TROUBLE_CXX) $(CXXFLAGS) $(TROUBLE_CXXFLAGS) -o $@ $(TROUBLE_TARGET_OBJ) \
$(LDFLAGS) $(TROUBLE_LDFLAGS) $(LDLIBS)

Expand Down Expand Up @@ -267,6 +274,8 @@ bisect-distclean: bisect-clean
dirs: $(MORE_DIRS)

$(MORE_DIRS):
@$(call color_out_noline,CYAN, mkdir)
@echo " $@"
mkdir -p $@

# Copied mostly from Makefile.in COMPILE_RULE, but customized for bisect
Expand All @@ -283,8 +292,10 @@ $(MORE_DIRS):
define FPIC_COMPILE_RULE
$2: $1 Makefile custom.mk | $(LOCAL_OBJ_DIR)
if [ -f "$3" ]; then \
ln -s "../../$(strip 3)" "$(strip $2)"; \
$(call color_out,CYAN, ../../$(strip $3) -> $@); \
ln -s "../../$(strip $3)" "$(strip $2)"; \
else \
$(call color_out,CYAN, $< -> $@); \
$4 $5 $6 -c $8 $(CXXFLAGS) -fPIC $(DEPFLAGS) $(2:%.o=%.d) $1 -o $2 \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(strip $4)"' \
Expand All @@ -298,7 +309,7 @@ $(foreach s,$(SOURCE),\
$(eval $(call FPIC_COMPILE_RULE,\
$s,\
$(LOCAL_OBJ_DIR)/$(notdir $s)_gt_fPIC.o,\
$(GT_OBJ_DIR)/$(notdir $s)_fPIC.o,\
$(GT_OBJ_DIR)/$(notdir $s)_fPIC.o,\
$(GT_CXX),\
$(GT_OPTL),\
$(GT_SWITCHES),\
Expand All @@ -321,7 +332,7 @@ $(foreach s,$(SOURCE),\
$(eval $(call FPIC_COMPILE_RULE,\
$s,\
$(LOCAL_OBJ_DIR)/$(notdir $s)_fPIC.o,\
$(BISECT_OBJ_DIR)/$(notdir $s)_fPIC.o,\
$(BISECT_OBJ_DIR)/$(notdir $s)_fPIC.o,\
$(TROUBLE_CXX),\
$(TROUBLE_OPTL),\
$(TROUBLE_SWITCHES),\
Expand Down Expand Up @@ -350,6 +361,7 @@ $$(LOCAL_OBJ_DIR)/$1_gt_split_$$(NUMBER).o: $$(LOCAL_OBJ_DIR)/$1_gt_fPIC.o
$$(LOCAL_OBJ_DIR)/$1_gt_split_$$(NUMBER).o: $$(LOCAL_OBJ_DIR)/$1_trouble_symbols_$$(NUMBER).txt
$$(LOCAL_OBJ_DIR)/$1_gt_split_$$(NUMBER).o: $$(MAKEFILE)
$$(LOCAL_OBJ_DIR)/$1_gt_split_$$(NUMBER).o: | $$(LOCAL_OBJ_DIR)
@$$(call color_out,CYAN, $$(LOCAL_OBJ_DIR)/$1_gt_fPIC.o -> $1_gt_split_$$(NUMBER).o)
if [ -s "$$(LOCAL_OBJ_DIR)/$1_trouble_symbols_$$(NUMBER).txt" ]; then \
objcopy \
--weaken-symbols=$$(LOCAL_OBJ_DIR)/$1_trouble_symbols_$$(NUMBER).txt \
Expand All @@ -365,6 +377,7 @@ $$(LOCAL_OBJ_DIR)/$1_trouble_split_$$(NUMBER).o: $$(LOCAL_OBJ_DIR)/$1_fPIC.o
$$(LOCAL_OBJ_DIR)/$1_trouble_split_$$(NUMBER).o: $$(MAKEFILE)
$$(LOCAL_OBJ_DIR)/$1_trouble_split_$$(NUMBER).o: $$(LOCAL_OBJ_DIR)/$1_gt_symbols_$$(NUMBER).txt
$$(LOCAL_OBJ_DIR)/$1_trouble_split_$$(NUMBER).o: | $$(LOCAL_OBJ_DIR)
@$$(call color_out,CYAN, $$(LOCAL_OBJ_DIR)/$1_fPIC.o -> $1_trouble_split_$$(NUMBER).o)
if [ -s "$$(LOCAL_OBJ_DIR)/$1_gt_symbols_$$(NUMBER).txt" ]; then \
objcopy \
--weaken-symbols=$$(LOCAL_OBJ_DIR)/$1_gt_symbols_$$(NUMBER).txt \
Expand Down
17 changes: 17 additions & 0 deletions documentation/flit-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ this manually, but this does a few things conveniently for you, such as
Again, you can do these things manually and have more control. But for most
users, this will be the most direct and convenient way to run locally.

If you use the `Makefile` directly, which is totally fine, then there are a few
things to know.

```bash
make help
```

will output help documentation on what targets are available and what they mean.

The output from the `Makefile` will be short by default. You can output all of
the details by defining `VERBOSE=1` or `VERBOSE=true` either as an argument to
`make` or as an environment variable.

```bash
make VERBOSE=1 ...
```

## flit import

Imports flit results into the database configured in `flit-config.toml`. It
Expand Down
3 changes: 3 additions & 0 deletions documentation/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ cd FLiT
make
```

_Note: if you want to see all of the compilation details, set `VERBOSE=1`,
e.g., `make VERBOSE=1`_

You can either use the flit command-line tool from the git repository or you
can install it. If you choose to install it, it is simply

Expand Down
20 changes: 10 additions & 10 deletions documentation/run-wrapper-and-hpc-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ echo "$@" >> test-execution.log
time "$@"
```

This will give you freedom to log, to time, or to even then run them in
parallel with Slurm (using `srun` or `sbatch`). You can also do things like
monitor memory usage or use an automated checker for memory leaks. Overall it
can be a useful feature to tie in your own custom functionality on top of the
test executables.

Note, it is not good to launch too many small jobs using srun, but the amount
of jobs that FLiT generates is only approximately 300 or so, depending on how
many compilers are found in your PATH. That may or may not be too many for
your needs.
It used to be this approach was used to integrate with Slurm. Instead, we
prefer you perform an `sbatch` or `salloc` before-hand, and within that
allocation, you run the FLiT tests. If you want parallelism in the FLiT tests
themselves, then call `flit_mpi_main()`. If your program has different
parallelism than MPI, this function can still be used with `srun` instead of
`mpirun`.

You can use this wrapper to do other things like monitor memory usage or use an
automated checker for memory leaks. Overall it can be a useful feature to tie
in your own custom functionality on top of the test executables.


[Prev](cuda-support.md)
Expand Down
4 changes: 4 additions & 0 deletions documentation/test-executable.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ update`.
- **distclean:** Remove everything including executables and results (but not
the results database).

The output from `make` is very brief by default. If you want to see all of the
compilation details, define `VERBOSE=1` or `VERBOSE=true` in as an argument to
`make` or as an environment variable (e.g., `make VERBOSE=1 ...`)

## Test Executable Details

The test executables that are generated all have the same command-line
Expand Down
6 changes: 5 additions & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ build: $(BUILD_TARGETS)

include color_out.mk

ifndef VERBOSE
.SILENT:
endif

check: run_tester_py $(CHECK_TARGETS)
@$(call color_out,GREEN,All tests pass)

Expand All @@ -31,7 +35,7 @@ clean: $(CLEAN_TARGETS)
run_tester_py: $(HARNESS_PY)
@$(call color_out_noline,BROWN, testing)
@echo " $(HARNESS_PY)"
@python3 -m doctest $(HARNESS_PY)
python3 -m doctest $(HARNESS_PY)

build__%:
@$(MAKE) build --directory $*
Expand Down
4 changes: 4 additions & 0 deletions tests/flit_cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ CHECK_TARGETS := $(addprefix check__,$(SUB_DIRS))
CLEAN_TARGETS := $(addprefix clean__,$(SUB_DIRS))
BUILD_TARGETS := $(addprefix build__,$(SUB_DIRS))

ifndef VERBOSE
.SILENT:
endif

.PHONY: build check help clean
build: $(BUILD_TARGETS)

Expand Down
8 changes: 6 additions & 2 deletions tests/flit_cli/flit_bisect/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ IS_PYELF := $(shell if python3 -c 'import elftools' 2>/dev/null; then \

include ../../color_out.mk

ifndef VERBOSE
.SILENT:
endif

.PHONY: check help clean build run_%
ifeq ($(IS_PYELF),true)
check: $(TARGETS) $(RUN_TARGETS)
else
check:
$(call color_out,RED,Warning: pyelftools is not found on your system;\
@$(call color_out,RED,Warning: pyelftools is not found on your system;\
skipping bisect tests)
endif

Expand All @@ -30,4 +34,4 @@ clean:
run_% : %.py
@$(call color_out_noline,BROWN, running)
@echo " $<"
@$(RUNNER) $<
$(RUNNER) $<
Loading