Skip to content

Commit

Permalink
Merge pull request #2256 from jimklimov/ccache-namespace
Browse files Browse the repository at this point in the history
CI: make use of `ccache` namespace support, where possible
  • Loading branch information
jimklimov authored Jan 3, 2024
2 parents 04ea8b4 + 7eb0255 commit b7e1247
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
# include directory for aclocal
ACLOCAL_AMFLAGS = -I m4

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# subdirectories to build and distribute. The order matters, as
# several subdirectories depend on stuff in "common" or tools being built first
SUBDIRS = include common clients conf data docs drivers tools \
Expand Down
2 changes: 1 addition & 1 deletion ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ fi
echo "Processing BUILD_TYPE='${BUILD_TYPE}' ..."

echo "Build host settings:"
set | grep -E '^(PATH|.*CCACHE.*|CI_.*|OS_.*|CANBUILD_.*|NODE_LABELS|MAKE|C.*FLAGS|LDFLAGS|ARCH.*|BITS.*|CC|CXX|CPP|DO_.*|BUILD_.*)=' || true
set | grep -E '^(PATH|[^ ]*CCACHE[^ ]*|CI_[^ ]*|OS_[^ ]*|CANBUILD_[^ ]*|NODE_LABELS|MAKE|C[^ ]*FLAGS|LDFLAGS|ARCH[^ ]*|BITS[^ ]*|CC|CXX|CPP|DO_[^ ]*|BUILD_[^ ]*)=' || true
uname -a
echo "LONG_BIT:`getconf LONG_BIT` WORD_BIT:`getconf WORD_BIT`" || true
if command -v xxd >/dev/null ; then xxd -c 1 -l 6 | tail -1; else if command -v od >/dev/null; then od -N 1 -j 5 -b | head -1 ; else hexdump -s 5 -n 1 -C | head -1; fi; fi < /bin/ls 2>/dev/null | awk '($2 == 1){print "Endianness: LE"}; ($2 == 2){print "Endianness: BE"}' || true
Expand Down
9 changes: 9 additions & 0 deletions clients/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Network UPS Tools: clients
EXTRA_DIST =

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# nutclient.cpp for some legacy reason (maybe initial detached development?)
# optionally includes "common.h" with the NUT build setup - and this option
# was never triggered in fact, not until pushed through command line like this:
Expand Down
9 changes: 9 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ EXTRA_DIST =
noinst_LTLIBRARIES = libparseconf.la libcommon.la libcommonclient.la
libparseconf_la_SOURCES = parseconf.c

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# do not hard depend on '../include/nut_version.h', since it blocks
# 'dist', and is only required for actual build, in which case
# BUILT_SOURCES (in ../include) will ensure nut_version.h will
Expand Down
68 changes: 68 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ dnl Use "./configure --enable-maintainer-mode" to keep Makefile.in and Makefile
dnl in sync after Git updates.
AM_MAINTAINER_MODE

dnl GNU and BSD make are okay with the syntax, but Sun make/dmake are not:
AC_MSG_CHECKING([whether this make implementation supports export VAR=VAL syntax])
dnl # using printf formatting for some funniner shells out there
nut_am_output="`printf 'export VAR=VAL\ntest:\n\t@echo "VAR=%s%sVAR%s"\n' '\$' '(' ')' | ${MAKE-make} -f - test`"
nut_am_result="$?"
AS_IF([test x"${nut_am_result}" = x0 -a x"${nut_am_output}" = x"VAR=VAL"], [
NUT_AM_MAKE_CAN_EXPORT=""
AC_MSG_RESULT(yes)
], [
NUT_AM_MAKE_CAN_EXPORT="#ThisMakeCanNotExport# "
AC_MSG_RESULT(no: got '${nut_am_output}')
])
AC_SUBST(NUT_AM_MAKE_CAN_EXPORT)

dnl Some systems have older autotools without direct macro support for PKG_CONF*
NUT_CHECK_PKGCONFIG

Expand Down Expand Up @@ -4575,6 +4589,60 @@ EOF])
])
AC_MSG_RESULT([done])

dnl # ccache versions 4.5 and newer support namespacing of the objects
dnl # to facilitate more targeted eviction with --evict-namespace and
dnl # perhaps --evict-older-than options. Here we bolt a namespace with
dnl # NUT as the project and CPU architecture for resulting binaries;
dnl # maybe we might use distro as well but some overlaps may be possible
dnl # that result in same objects for different-looking build roots.
dnl # Note this is enabled by default (explicit --without-... disables it).
dnl # Has practical effect if NUT_AM_MAKE_CAN_EXPORT test is successful.
AS_IF([test x"${CCACHE_NAMESPACE}" = x], [
CCACHE_NAMESPACE="nut"
dnl # Variables in this list are defined earlier in the script
for T in "${compiler_multiarch}" "${target_alias}" "${target}" "${target_cpu}-${target_os}" ; do
if test x"$T" != x -a x"$T" != x- ; then
CCACHE_NAMESPACE="${CCACHE_NAMESPACE}:${T}"
break
fi
done
unset T
])
AC_ARG_WITH(CCACHE_NAMESPACE,
AS_HELP_STRING([--with-CCACHE_NAMESPACE=namespace], [which ccache namespace to use for built binaries; typically nut:${autotools_target})]),
[
case "${withval}" in
no)
CCACHE_NAMESPACE=""
;;
yes) # Use user envvar or calculation above
;;
*)
CCACHE_NAMESPACE="${withval}"
;;
esac
], [])
NUT_REPORT_TARGET(CCACHE_NAMESPACE, "${CCACHE_NAMESPACE}", [ccache namespace tag (if ccache is used and new enough)])
AS_IF([test x"$CCACHE_NAMESPACE" != x -a x"$NUT_AM_MAKE_CAN_EXPORT" != x], [
AC_MSG_WARN([CCACHE_NAMESPACE setting may have no effect: this make implementation seems to not support "export VAR=VAL" syntax])
])

dnl # Mark it as a "precious variable", for more details see
dnl # https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Setting-Output-Variables.html
AC_ARG_VAR(CCACHE_NAMESPACE)

dnl # Also list some other ccache options which ci_build.sh can fiddle with.
dnl # While that script "exports" them so it can call both configuration and
dnl # the build, their values may be unknown when a developer re-runs "make".
dnl # Normally most of the options would persist under $CCACHE_DIR/ccache.conf
dnl # and we would not pass them via envvars.
AC_ARG_VAR(CCACHE_BASEDIR)
AC_ARG_VAR(CCACHE_DIR)
AC_ARG_VAR(CCACHE_PATH)

PATH_DURING_CONFIGURE="$PATH"
AC_SUBST(PATH_DURING_CONFIGURE)

AC_MSG_NOTICE([Generating "data" files from templates, see below for executable scripts])
AC_CONFIG_FILES([
clients/Makefile
Expand Down
2 changes: 2 additions & 0 deletions docs/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Network UPS Tools: main docs

MAINTAINERCLEANFILES = Makefile.in .dirstamp
EXTRA_DIST =

Expand Down
2 changes: 2 additions & 0 deletions docs/cables/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Network UPS Tools: cable docs

CLEANFILES = *-spellchecked
MAINTAINERCLEANFILES = Makefile.in .dirstamp
2 changes: 1 addition & 1 deletion docs/man/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Network UPS Tools: man
# Network UPS Tools: man pages
#

# Notes:
Expand Down
9 changes: 9 additions & 0 deletions drivers/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Network UPS Tools: drivers

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# Make sure out-of-dir dependencies exist (especially when dev-building parts):
$(top_builddir)/common/libcommon.la \
$(top_builddir)/common/libparseconf.la \
Expand Down
11 changes: 11 additions & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Network UPS Tools: include

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

dist_noinst_HEADERS = attribute.h common.h extstate.h proto.h \
state.h str.h timehead.h upsconf.h nut_float.h nut_stdint.h nut_platform.h \
wincompat.h
Expand Down
10 changes: 10 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Network UPS Tools: lib

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

EXTRA_DIST = README.adoc

if WITH_DEV
Expand Down
2 changes: 2 additions & 0 deletions scripts/python/module/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Network UPS Tools: scripts/python/module (PyNUTClient)

# See also: .github/workflows/PyNUTClient.yml
# Note: this Makefile is focused on PyPI publication
# The usual autotools stuff including clean-up is in parent dir
Expand Down
9 changes: 9 additions & 0 deletions server/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Network UPS Tools: server

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# Make sure out-of-dir dependencies exist (especially when dev-building parts):
$(top_builddir)/common/libcommon.la \
$(top_builddir)/common/libparseconf.la: dummy
Expand Down
9 changes: 9 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Network UPS Tools: tests

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

SUBDIRS = . NIT

all: $(TESTS)
Expand Down
11 changes: 11 additions & 0 deletions tests/NIT/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Network UPS Tools: NUT Integration Tests (NIT)

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

EXTRA_DIST = nit.sh README.adoc

if WITH_CHECK_NIT
Expand Down
11 changes: 11 additions & 0 deletions tools/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Network UPS Tools: generators and other tools

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# SUBDIRS are explicitly a listing of all the directories that make
# must recurse into BEFORE processing the current directory.
#
Expand Down
11 changes: 11 additions & 0 deletions tools/nut-scanner/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Network UPS Tools: nut-scanner

# Export certain values for ccache which NUT ci_build.sh can customize,
# to facilitate developer iteration re-runs of "make" later.
# At least GNU and BSD make implementations are okay with this syntax.
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_NAMESPACE=@CCACHE_NAMESPACE@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_BASEDIR=@CCACHE_BASEDIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_DIR=@CCACHE_DIR@
@NUT_AM_MAKE_CAN_EXPORT@export CCACHE_PATH=@CCACHE_PATH@
@NUT_AM_MAKE_CAN_EXPORT@export PATH=@PATH_DURING_CONFIGURE@

# Generally, list headers and/or sources which are re-generated
# for nut-scanner in the parent dir
NUT_SCANNER_DEPS_H = nutscan-usb.h nutscan-snmp.h
Expand Down

0 comments on commit b7e1247

Please sign in to comment.