sonic-buildimage/rules/functions
lguohan 20260ceb1d
[build]: add SONIC_CONFIG_BUILD_LOG_TIMESTAMP to add timestamp in build log (#4269)
add timestamp in each job build log

example:

   [01:39:21] dh clean  --with autotools-dev
   [01:39:22]    dh_auto_clean
   [01:39:27]      make -j16 distclean

Signed-off-by: Guohan Lu <lguohan@gmail.com>
2020-03-21 14:21:26 -07:00

129 lines
3.7 KiB
Plaintext

###############################################################################
## FUNCTIONS
###############################################################################
###############################################################################
## Colored output
###############################################################################
# Enable colored output
ifeq ($(SONIC_CONFIG_ENABLE_COLORS),y)
ifeq ($(MAKE_TERMOUT),)
RED=\033[1;31m
PURPLE=\033[1;35m
CYAN=\033[1;36m
GREEN=\033[1;32m
GRAY=\033[0m
endif
endif
ifeq ($(SONIC_CONFIG_BUILD_LOG_TIMESTAMP),y)
PROCESS_LOG_OPTION = -t
endif
# Print red colored output
# call:
# log_red message
log_red = echo -e "$(RED)$(1)$(GRAY)"
# Print purple colored output
# call:
# log_purple message
log_purple = echo -e "$(PURPLE)$(1)$(GRAY)"
# Print blue colored output
# call:
# log_blue message
log_blue = echo -e "$(CYAN)$(1)$(GRAY)"
# Print green colored output
# call:
# log_green message
log_green = echo -e "$(GREEN)$(1)$(GRAY)"
###############################################################################
## Logging
###############################################################################
FLUSH_LOG = rm -f $@.log
LOG_SIMPLE = &>> $(PROJECT_ROOT)/$@.log || { [ $$? -eq 0 ] || pushd $(PROJECT_ROOT) > /dev/null ; ./update_screen.sh -e $@ ; popd > /dev/null ; false ; }
LOG = |& $(PROJECT_ROOT)/scripts/process_log.sh $(PROCESS_LOG_OPTION) &>> $(PROJECT_ROOT)/$@.log ; test $${PIPESTATUS[-2]} -eq 0 || { [ $$? -eq 0 ] || pushd $(PROJECT_ROOT) > /dev/null ; ./update_screen.sh -e $@ ; popd > /dev/null ; false ; }
###############################################################################
## Header and footer for each target
###############################################################################
# Dump targets taht current depends on
ifeq ($(SONIC_CONFIG_PRINT_DEPENDENCIES),y)
PRINT_DEPENDENCIES = echo Dependencies for $@ are $^ $(LOG)
endif
# header for each rule
define HEADER
@
$(PRINT_DEPENDENCIES)
$(FLUSH_LOG)
./update_screen.sh -a $@
endef
# footer for each rule
define FOOTER
./update_screen.sh -d $@
endef
###############################################################################
## Definition of derived target
###############################################################################
# call:
# add_derived_package some_deb.deb, some_derived_deb
define add_derived_package
$(2)_DEPENDS += $(1)
$(2)_RDEPENDS += $($(1)_RDEPENDS)
$(2)_MAIN_DEB = $(1)
$(1)_DERIVED_DEBS += $(2)
$(2)_URL = $($(1)_URL)
$(2)_SRC_PATH = $($(1)_SRC_PATH)
SONIC_DERIVED_DEBS += $(2)
endef
# call:
# add_extra_package some_deb.deb, some_extra_deb
define add_extra_package
$(2)_MAIN_DEB = $(1)
$(1)_EXTRA_DEBS += $(2)
SONIC_EXTRA_DEBS += $(2)
endef
# call:
# add_dbg_docker some_docker.gz, some-docker-dbg.gz
define add_dbg_docker
$(2)_PATH = $($(1)_PATH)
$(2)_DBG_DEPENDS += $($(1)_DBG_DEPENDS)
$(2)_DBG_IMAGE_PACKAGES += $($(1)_DBG_IMAGE_PACKAGES)
$(2)_PYTHON_WHEELS += $($(1)_PYTHON_WHEELS)
$(2)_LOAD_DOCKERS += $($(1)_LOAD_DOCKERS)
$(2)_CACHE_MODE += $($(1)_CACHE_MODE)
$(2)_DEP_FLAGS += $($(1)_DEP_FLAGS)
$(2)_DEP_FILES += $($(1)_DEP_FILES)
$(2)_SMDEP_FILES += $($(1)_SMDEP_FILES)
$(2)_SMDEP_PATHS += $($(1)_SMDEP_PATHS)
$(2)_DEPENDS += $($(1)_DEPENDS)
$(2)_RDEPENDS += $($(1)_RDEPENDS)
$(2)_MAIN_DOCKER = $(1)
$(1)_DBG_DOCKER += $(2)
SONIC_DBG_DOCKERS += $(2)
endef
###############################################################################
## Utility functions
###############################################################################
# Recursive wildcard function
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
expand = $(foreach d,$(1),$(call expand,$($(d)_$(2)),$(2))) $(1)