Skip to content

Commit

Permalink
Consolidate helper functions for pretty messages
Browse files Browse the repository at this point in the history
This commit provides variants of 'notice' function:
  - notice(x) : colored as green
  - warn(x) : colored as yellow

The suffix 'x' indicates the use as function calls in Makefile.
  • Loading branch information
jserv committed Feb 12, 2025
1 parent bdfa187 commit 099d3ba
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,18 @@ endif
endif

clean:
$(RM) $(BIN) $(OBJS) $(DEV_OBJS) $(BUILD_DTB) $(BUILD_DTB2C) $(HIST_BIN) $(HIST_OBJS) $(deps) $(WEB_FILES) $(CACHE_OUT) src/rv32_jit.c
-$(RM) $(SOFTFLOAT_LIB)
$(VECHO) "Cleaning... "
$(Q)$(RM) $(BIN) $(OBJS) $(DEV_OBJS) $(BUILD_DTB) $(BUILD_DTB2C) $(HIST_BIN) $(HIST_OBJS) $(deps) $(WEB_FILES) $(CACHE_OUT) src/rv32_jit.c
$(Q)$-$(RM) $(SOFTFLOAT_LIB)
$(Q)$(call notice, [OK])
distclean: clean
$(RM) -r $(OUT)/id1
$(RM) -r $(DEMO_DIR)
$(RM) *.zip
$(RM) -r $(OUT)/mini-gdbstub
-$(RM) $(OUT)/.config
-$(RM) -r $(SOFTFLOAT_DUMMY_PLAT) $(OUT)/softfloat
$(VECHO) "Deleting all generated files... "
$(Q)$(RM) -r $(OUT)/id1
$(Q)$(RM) -r $(DEMO_DIR)
$(Q)$(RM) *.zip
$(Q)$(RM) -r $(OUT)/mini-gdbstub
$(Q)-$(RM) $(OUT)/.config
$(Q)-$(RM) -r $(SOFTFLOAT_DUMMY_PLAT) $(OUT)/softfloat
$(Q)$(call notice, [OK])

-include $(deps)
16 changes: 9 additions & 7 deletions mk/artifact.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SHELL_HACK := $(shell mkdir -p $(BIN_DIR)/linux-x86-softfp $(BIN_DIR)/riscv32 $(
# $(3): name showing in terminal
define fetch-releases-tag
$(if $(wildcard $(BIN_DIR)/$(2)), \
$(info $(3) is found. Skipping downloading.), \
$(info $(call warnx, $(3) is found. Skipping downloading.)), \
$(eval LATEST_RELEASE := $(shell wget -q https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- \
| grep '"tag_name"' \
| grep "$(1)" \
Expand All @@ -59,7 +59,7 @@ ifeq ($(call has, PREBUILT), 1)
else ifeq ($(call has, ARCH_TEST), 1)
$(call fetch-releases-tag,sail,rv32emu-prebuilt-sail-$(HOST_PLATFORM),Sail model)
else
$(call fetch-releases-tag,ELF,rv32emu-prebuilt.tar.gz,Prebuilt benchmark)
$(call fetch-releases-tag,ELF,rv32emu-prebuilt.tar.gz,Prebuilt blob)
endif

PREBUILT_BLOB_URL = https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)
Expand Down Expand Up @@ -112,14 +112,16 @@ endif

ifeq ($(call has, ARCH_TEST), 1)
$(Q)if [ "$(RES)" = "1" ]; then \
$(PRINTF) "\n$(YELLOW)SHA-1 verification failed! Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n$(NO_COLOR)"; \
$(call warn, "SHA-1 verification failed!"); \
$(PRINTF) "Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n"; \
wget -q --show-progress $(PREBUILT_BLOB_URL)/$(RV32EMU_PREBUILT_TARBALL) -O build/$(RV32EMU_PREBUILT_TARBALL); \
else \
$(call notice, [OK]); \
fi
else
$(Q)if [ "$(RES)" = "1" ]; then \
$(PRINTF) "\n$(YELLOW)SHA-1 verification failed! Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n$(NO_COLOR)"; \
$(call warn, "SHA-1 verification failed!"); \
$(PRINTF) "Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n"; \
wget -q --show-progress $(PREBUILT_BLOB_URL)/$(RV32EMU_PREBUILT_TARBALL) -O build/$(RV32EMU_PREBUILT_TARBALL); \
tar --strip-components=1 -zxf build/$(RV32EMU_PREBUILT_TARBALL) -C build; \
else \
Expand Down Expand Up @@ -172,22 +174,22 @@ ifeq ($(call has, SYSTEM), 1)
$(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-image $(PREBUILT_BLOB_URL)/sha1sum-linux-image
$(Q)$(call notice, [OK])
else
$(Q)$(PRINTF) "Skipped\n"
$(Q)$(call warn, skipped)
endif
else ifeq ($(call has, ARCH_TEST), 1)
ifeq ($(wildcard $(BIN_DIR)/rv32emu-prebuilt-sail-$(HOST_PLATFORM)),)
$(Q)wget -q -O $(BIN_DIR)/rv32emu-prebuilt-sail-$(HOST_PLATFORM).sha $(PREBUILT_BLOB_URL)/rv32emu-prebuilt-sail-$(HOST_PLATFORM).sha
$(Q)$(call notice, [OK])
else
$(Q)$(PRINTF) "Skipped\n"
$(Q)$(call warn, skipped)
endif
else
ifeq ($(wildcard $(BIN_DIR)/rv32emu-prebuilt.tar.gz),)
$(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-x86-softfp $(PREBUILT_BLOB_URL)/sha1sum-linux-x86-softfp
$(Q)wget -q -O $(BIN_DIR)/sha1sum-riscv32 $(PREBUILT_BLOB_URL)/sha1sum-riscv32
$(Q)$(call notice, [OK])
else
$(Q)$(PRINTF) "Skipped\n"
$(Q)$(call warn , skipped)
endif
endif
endif
Expand Down
8 changes: 5 additions & 3 deletions mk/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ $(eval CFLAGS += -D RV32_FEATURE_$(strip $1)=$(call has, $1))
endef

# Test suite
PASS_COLOR = \e[32;01m
NO_COLOR = \e[0m
GREEN = \033[32m
YELLOW = \033[33m
NC = \033[0m

notice = $(PRINTF) "$(PASS_COLOR)$(strip $1)$(NO_COLOR)\n"
notice = $(PRINTF) "$(GREEN)$(strip $1)$(NC)\n"
noticex = $(shell echo "$(GREEN)$(strip $1)$(NC)\n")
warn = $(PRINTF) "$(YELLOW)$(strip $1)$(NC)\n"
# Used inside $(warning) or $(error)
warnx = $(shell echo "$(YELLOW)$(strip $1)$(NC)\n")

# File utilities
SHA1SUM = sha1sum
Expand Down
12 changes: 6 additions & 6 deletions mk/wasm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ FIREFOX_MAJOR := $(shell $(FIREFOX_MAJOR_VERSION_CHECK_CMD))

# Chrome
ifeq ($(shell echo $(CHROME_MAJOR)\>=$(CHROME_SUPPORT_TCO_AT_MAJOR) | bc), 1)
$(info $(shell echo "$(GREEN)$(CHROME_SUPPORT_TCO_INFO)$(NC)"))
$(info $(call noticex, "$(CHROME_SUPPORT_TCO_INFO)"))
else
$(warning $(shell echo "$(YELLOW)$(CHROME_NO_SUPPORT_TCO_WARNING)$(NC)"))
$(warning $(call warnx, "$(CHROME_NO_SUPPORT_TCO_WARNING)"))
endif

# Firefox
ifeq ($(shell echo $(FIREFOX_MAJOR)\>=$(FIREFOX_SUPPORT_TCO_AT_MAJOR) | bc), 1)
$(info $(shell echo "$(GREEN)$(FIREFOX_SUPPORT_TCO_INFO)$(NC)"))
$(info $(call noticex, "$(FIREFOX_SUPPORT_TCO_INFO)"))
else
$(warning $(shell echo "$(YELLOW)$(FIREFOX_NO_SUPPORT_TCO_WARNING)$(NC)"))
$(warning $(call warnx, "$(FIREFOX_NO_SUPPORT_TCO_WARNING)"))
endif

# Safari
Expand All @@ -100,9 +100,9 @@ SAFARI_VERSION := $(shell $(SAFARI_VERSION_CHECK_CMD))
SAFARI_MAJOR := $(shell echo $(SAFARI_VERSION) | cut -f1 -d.)
SAFARI_MINOR := $(shell echo $(SAFARI_VERSION) | cut -f2 -d.)
ifeq ($(shell echo "$(SAFARI_MAJOR).$(SAFARI_MINOR)>=$(SAFARI_SUPPORT_TCO_AT_MAJOR_MINOR)" | bc), 1)
$(info $(shell echo "$(GREEN)$(SAFARI_SUPPORT_TCO_INFO)$(NC)"))
$(info $(call noticex, "$(SAFARI_SUPPORT_TCO_INFO)"))
else
$(warning $(shell echo "$(YELLOW)$(SAFARI_NO_SUPPORT_TCO_WARNING)$(NC)"))
$(warning $(call warnx, "$(SAFARI_NO_SUPPORT_TCO_WARNING)"))
endif
endif

Expand Down

0 comments on commit 099d3ba

Please sign in to comment.