Skip to content

Commit 85235ee

Browse files
authored
Merge pull request #3428 from jimklimov/issue-3108
CI: Optimize use of autoconf caching
2 parents a630434 + 3841ce2 commit 85235ee

28 files changed

Lines changed: 4887 additions & 3191 deletions

Makefile.am

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,22 @@ install-fanout-cleanup: install-recursive @dotMAKE@
136136
# Called from generated-sources-with-a-touch:
137137
touch-include-all-nut_version-generated.timestamp:
138138
@[ -s include/nut_version.h ]
139-
@touch -r include/nut_version.h -d '-10 seconds' include/.all.nut_version-generated.timestamp && exit ; \
139+
@touch -r include/nut_version.h -d '-10 seconds' include/.all.nut_version-generated.timestamp 2>/dev/null && exit ; \
140140
touch -d '1970-01-01T00:00:00' include/.all.nut_version-generated.timestamp && exit ; \
141141
touch include/.all.nut_version-generated.timestamp
142142

143143
touch-clients-all-libupsclient_version-generated.timestamp:
144144
@[ -s clients/libupsclient-version.h ]
145-
@touch -r clients/libupsclient-version.h -d '-10 seconds' clients/.all.libupsclient_version-generated.timestamp && exit ; \
145+
@touch -r clients/libupsclient-version.h -d '-10 seconds' clients/.all.libupsclient_version-generated.timestamp 2>/dev/null && exit ; \
146146
touch -d '1970-01-01T00:00:00' clients/.all.libupsclient_version-generated.timestamp && exit ; \
147147
touch clients/.all.libupsclient_version-generated.timestamp
148148

149149
touch-docs-man-all-linkman-generated.timestamp:
150150
@[ -s docs/man/linkman-driver-names.txt ] && [ -s docs/man/linkman-drivertool-names.txt ]
151151
@if test -n "`find docs/man/linkman-driver-names.txt -newer docs/man/linkman-drivertool-names.txt`" ; then \
152-
touch -r docs/man/linkman-drivertool-names.txt -d '-10 seconds' docs/man/.all.nut_linkman-generated.timestamp && exit ; \
152+
touch -r docs/man/linkman-drivertool-names.txt -d '-10 seconds' docs/man/.all.nut_linkman-generated.timestamp 2>/dev/null && exit ; \
153153
else \
154-
touch -r docs/man/linkman-driver-names.txt -d '-10 seconds' docs/man/.all.nut_linkman-generated.timestamp && exit ; \
154+
touch -r docs/man/linkman-driver-names.txt -d '-10 seconds' docs/man/.all.nut_linkman-generated.timestamp 2>/dev/null && exit ; \
155155
fi ; \
156156
touch -d '1970-01-01T00:00:00' docs/man/.all.nut_linkman-generated.timestamp && exit ; \
157157
touch docs/man/.all.nut_linkman-generated.timestamp

ci_build.adoc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,24 @@ It can be stored outside of the build area(s), under `${CI_CACHE_NUT_BASEDIR}`
106106
by caller (e.g. via `~/.profile` of a developer) or guessed from environment
107107
variables typical for CI runs.
108108
109+
Note there is also a separate `DO_USE_NUTCI_CACHE_DEBUG=yes` (or `...=first`)
110+
toggle, which aims to keep a copy of not only the `config.cache`, but also of
111+
`config.log` and `config.h` files, as well as a copy of the help text from
112+
`configure` script, from a first run with new cache hash for troubleshooting.
113+
114+
A further `DO_USE_NUTCI_CACHE_DEBUG=each` keeps such files time-stamped, from
115+
every run (primarily to help determine if re-runs do modify some detection
116+
results due to mis-interpretation of cached data -- i.e. to help fix the `m4`
117+
scripts and/or `configure.ac` source file).
118+
119+
WARNING: It is up to the caller (developer, CI) to ensure that third-party
120+
dependencies and tools (and their flags delivered by `pkg-config`, or module
121+
paths for interpreted languages, etc.) remain the same between cached runs.
122+
109123
If something acts up, or the build environment changes invisibly to the
110124
script, an `export DO_CLEAN_NUTCI_CACHE_BEFORE=yes` (or a more targeted
111-
`DO_CLEAN_AUTOCONF_CACHE_BEFORE`, since NIT uses similar logic and general
112-
toggle to retain generated test certificates) should fix that.
125+
`export DO_CLEAN_AUTOCONF_CACHE_BEFORE=yes`, since NIT uses similar logic
126+
and general toggle to retain generated test certificates) should fix that.
113127
114128
You can also always nuke the `${CI_CACHE_NUT_BASEDIR}` directory, or the
115129
`AUTOCONF_*` subdirectories and stale lock files under it.

ci_build.sh

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,13 @@ get_CI_CACHE_NUT_HASHDIR_CFG_OPT() {
12421242
fi
12431243
}
12441244
1245+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT_WITH_ENV() {
1246+
# Hash environment variables which we commonly use and that can impact
1247+
# the decisions of configure script as something that requires separate
1248+
# cache files, just in case.
1249+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT "$* CC='$CC' CXX='$CXX' CPP='$CPP' MAKE='$MAKE' SHELL='$SHELL' CONFIG_SHELL='$CONFIG_SHELL' PATH='$PATH' LD_LIBRARY_PATH='$LD_LIBRARY_PATH' PKG_CONFIG_PATH='$PKG_CONFIG_PATH' ARCH='$ARCH' BITS='$BITS' CFLAGS='$CFLAGS' CXXFLAGS='$CXXFLAGS' CPPFLAGS='$CPPFLAGS' LDFLAGS='$LDFLAGS'"
1250+
}
1251+
12451252
configure_CI_BUILDDIR() {
12461253
autogen_get_CONFIGURE_SCRIPT
12471254
@@ -1269,7 +1276,7 @@ configure_nut() {
12691276
# Help copy-pasting build setups from CI logs to terminal:
12701277
local CONFIG_OPTS_STR="`END=' \'; NUM=0; for F in \"${CONFIG_OPTS[@]}\" ; do NUM=$(($NUM + 1)); [ x\"$NUM\" = x\"${#CONFIG_OPTS[@]}\" ] && END=''; printf \"'%s'%s\n\" \"$F\" \"$END\" ; done`"
12711278
1272-
get_CI_CACHE_NUT_HASHDIR_CFG_OPT "${CONFIG_OPTS_STR} CC='$CC' CXX='$CXX' CPP='$CPP'"
1279+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT_WITH_ENV "${CONFIG_OPTS_STR}"
12731280
12741281
CI_CACHE_NUT_RETRIED=false
12751282
while : ; do # Note the CI_SHELL_IS_FLAKY=true support below
@@ -1292,14 +1299,39 @@ configure_nut() {
12921299
"${CONFIG_OPTS[@]}" \
12931300
&& echo "$0: configure phase complete (0)" >&2 \
12941301
&& {
1295-
if [ x"${DO_USE_AUTOCONF_CACHE}" = xyes ] && [ x"${DO_USE_AUTOCONF_CACHE_DEBUG}" = xyes ] && [ -n "${CI_CACHE_NUT_HASHDIR_CFG_OPT}" ] && [ -s "${CI_CACHE_NUT_HASHDIR_CFG}/config.cache" ] ; then
1296-
if [ x = x"`cat \"${CI_CACHE_NUT_HASHDIR_CFG}/config.log\" \"${CI_CACHE_NUT_HASHDIR_CFG}/config.h\"`" ] ; then
1297-
# Stash a copy to track evolution:
1298-
cp -pf "${CI_CACHE_NUT_HASHDIR_CFG}/config.cache" "${CI_CACHE_NUT_HASHDIR_CFG}/config.cache.orig"
1299-
# Populate on first run (may cost 1-2Mb):
1300-
cp -pf config.log "${CI_CACHE_NUT_HASHDIR_CFG}/"
1301-
cp -pf include/config.h "${CI_CACHE_NUT_HASHDIR_CFG}/"
1302-
fi
1302+
if [ x"${DO_USE_AUTOCONF_CACHE}" = xyes ] \
1303+
&& [ -n "${CI_CACHE_NUT_HASHDIR_CFG_OPT}" ] \
1304+
&& [ -s "${CI_CACHE_NUT_HASHDIR_CFG}/config.cache" ] \
1305+
; then
1306+
case x"${DO_USE_AUTOCONF_CACHE_DEBUG}" in
1307+
xyes|xfirst)
1308+
if [ x = x"`cat \"${CI_CACHE_NUT_HASHDIR_CFG}/config.log\" \"${CI_CACHE_NUT_HASHDIR_CFG}/config.h\"`" ] ; then
1309+
# Stash a copy to track evolution:
1310+
cp -pf "${CI_CACHE_NUT_HASHDIR_CFG}/config.cache" "${CI_CACHE_NUT_HASHDIR_CFG}/config.cache.orig"
1311+
# Populate on first run (may cost 1-2Mb):
1312+
cp -pf config.log "${CI_CACHE_NUT_HASHDIR_CFG}/"
1313+
cp -pf include/config.h "${CI_CACHE_NUT_HASHDIR_CFG}/"
1314+
fi
1315+
1316+
# Make sure all args are declared outside cached logic:
1317+
$CONFIGURE_SCRIPT --help > "${CI_CACHE_NUT_HASHDIR_CFG}/config.help" 2>&1
1318+
;;
1319+
xeach)
1320+
TS="`date '+%s'`" && [ -n "$TS" ] && [ "$TS" -gt 0 ] \
1321+
|| { TS="`date | tr -d ':' | tr -d ' '`" && [ -n "$TS" ] ; } \
1322+
|| TS=$$
1323+
1324+
for F in \
1325+
"${CI_CACHE_NUT_HASHDIR_CFG}/config.cache" \
1326+
config.log include/config.h \
1327+
; do
1328+
cp -pf "$F" "${CI_CACHE_NUT_HASHDIR_CFG}/`basename \"$F\"`.$TS"
1329+
done
1330+
1331+
# Make sure all args are declared outside cached logic:
1332+
$CONFIGURE_SCRIPT --help > "${CI_CACHE_NUT_HASHDIR_CFG}/config.help.$TS" 2>&1
1333+
;;
1334+
esac
13031335
fi
13041336
} && return 0 \
13051337
|| { RES_CFG=$?
@@ -1573,7 +1605,7 @@ optional_maintainer_clean_check() {
15731605
15741606
# If this exports CI_CACHE_NUT_HASHDIR_CFG_OPT, the `make distcheck`
15751607
# handlers in the stack of calls via Makefile.am should hear it
1576-
get_CI_CACHE_NUT_HASHDIR_CFG_OPT "${DISTCHECK_FLAGS} CC='$CC' CXX='$CXX' CPP='$CPP' DISTCHECK_TGT='maintainer-clean'"
1608+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT_WITH_ENV "${DISTCHECK_FLAGS} DISTCHECK_TGT='maintainer-clean'"
15771609
15781610
# Note: currently Makefile.am has just a dummy "distcleancheck" rule
15791611
MAKE_RES=0
@@ -1617,7 +1649,7 @@ optional_dist_clean_check() {
16171649
16181650
# If this exports CI_CACHE_NUT_HASHDIR_CFG_OPT, the `make distcheck`
16191651
# handlers in the stack of calls via Makefile.am should hear it
1620-
get_CI_CACHE_NUT_HASHDIR_CFG_OPT "${DISTCHECK_FLAGS} CC='$CC' CXX='$CXX' CPP='$CPP' DISTCHECK_TGT='distclean'"
1652+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT_WITH_ENV "${DISTCHECK_FLAGS} DISTCHECK_TGT='distclean'"
16211653
16221654
# Note: currently Makefile.am has just a dummy "distcleancheck" rule
16231655
MAKE_RES=0
@@ -2087,6 +2119,22 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-al
20872119
CONFIG_OPTS+=("CC=${CC}")
20882120
CONFIG_OPTS+=("CXX=${CXX}")
20892121
CONFIG_OPTS+=("CPP=${CPP}")
2122+
2123+
# Do not let autoconf-cached re-runs (re-running the configure script
2124+
# due to a `make` with changed *.m4, *.am or configure.ac sources)
2125+
# complain that CCACHE_* vars were not previously set. This hassle
2126+
# comes with use of AC_ARG_VAR to mark "precious" arguments:
2127+
CONFIG_OPTS+=("CCACHE_NAMESPACE=${CCACHE_NAMESPACE}")
2128+
CONFIG_OPTS+=("CCACHE_BASEDIR=${CCACHE_BASEDIR}")
2129+
CONFIG_OPTS+=("CCACHE_DIR=${CCACHE_DIR}")
2130+
CONFIG_OPTS+=("CCACHE_PATH=${CCACHE_PATH}")
2131+
else
2132+
# Still have them declared; the configure script will probably parse
2133+
# them as empty/undefined and re-evaluate if situation warrants that:
2134+
CONFIG_OPTS+=("CCACHE_NAMESPACE=")
2135+
CONFIG_OPTS+=("CCACHE_BASEDIR=")
2136+
CONFIG_OPTS+=("CCACHE_DIR=")
2137+
CONFIG_OPTS+=("CCACHE_PATH=")
20902138
fi
20912139
20922140
# Build and check this project; note that zprojects always have an autogen.sh
@@ -2198,7 +2246,7 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-al
21982246
21992247
# If this exports CI_CACHE_NUT_HASHDIR_CFG_OPT, the `make distcheck`
22002248
# handlers in the stack of calls via Makefile.am should hear it
2201-
get_CI_CACHE_NUT_HASHDIR_CFG_OPT "${DISTCHECK_FLAGS} CC='$CC' CXX='$CXX' CPP='$CPP' DISTCHECK_TGT='$BUILD_TGT'"
2249+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT_WITH_ENV "${DISTCHECK_FLAGS} DISTCHECK_TGT='$BUILD_TGT'"
22022250
22032251
# Tell the sub-makes (likely distcheck*) to hush down
22042252
# NOTE: Parameter pass-through was tested with:
@@ -2940,7 +2988,7 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-al
29402988
29412989
# If this exports CI_CACHE_NUT_HASHDIR_CFG_OPT, the `make distcheck`
29422990
# handlers in the stack of calls via Makefile.am should hear it
2943-
get_CI_CACHE_NUT_HASHDIR_CFG_OPT "${DISTCHECK_FLAGS} CC='$CC' CXX='$CXX' CPP='$CPP' DISTCHECK_TGT='$DISTCHECK_TGT'"
2991+
get_CI_CACHE_NUT_HASHDIR_CFG_OPT_WITH_ENV "${DISTCHECK_FLAGS} DISTCHECK_TGT='$DISTCHECK_TGT'"
29442992
29452993
# Tell the sub-makes (distcheck) to hush down
29462994
MAKEFLAGS="${MAKEFLAGS-} $MAKE_FLAGS_QUIET" \
@@ -3111,6 +3159,22 @@ bindings)
31113159
CONFIG_OPTS+=("CC=${CC}")
31123160
CONFIG_OPTS+=("CXX=${CXX}")
31133161
CONFIG_OPTS+=("CPP=${CPP}")
3162+
3163+
# Do not let autoconf-cached re-runs (re-running the configure script
3164+
# due to a `make` with changed *.m4, *.am or configure.ac sources)
3165+
# complain that CCACHE_* vars were not previously set. This hassle
3166+
# comes with use of AC_ARG_VAR to mark "precious" arguments:
3167+
CONFIG_OPTS+=("CCACHE_NAMESPACE=${CCACHE_NAMESPACE}")
3168+
CONFIG_OPTS+=("CCACHE_BASEDIR=${CCACHE_BASEDIR}")
3169+
CONFIG_OPTS+=("CCACHE_DIR=${CCACHE_DIR}")
3170+
CONFIG_OPTS+=("CCACHE_PATH=${CCACHE_PATH}")
3171+
else
3172+
# Still have them declared; the configure script will probably parse
3173+
# them as empty/undefined and re-evaluate if situation warrants that:
3174+
CONFIG_OPTS+=("CCACHE_NAMESPACE=")
3175+
CONFIG_OPTS+=("CCACHE_BASEDIR=")
3176+
CONFIG_OPTS+=("CCACHE_DIR=")
3177+
CONFIG_OPTS+=("CCACHE_PATH=")
31143178
fi
31153179
31163180
# If detect_platform_PKG_CONFIG_PATH_and_FLAGS() customized anything here,

common/common.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,12 +3183,17 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
31833183
* a reload action for Type=notify-reload; for more details see
31843184
* https://github.com/systemd/systemd/blob/main/src/core/service.c#L2618
31853185
*/
3186-
struct timespec monoclock_ts;
3187-
int got_monoclock = clock_gettime(CLOCK_MONOTONIC, &monoclock_ts);
3186+
struct timespec monoclock_ts;
3187+
int got_monoclock = clock_gettime(CLOCK_MONOTONIC, &monoclock_ts);
31883188
# endif /* HAVE_CLOCK_GETTIME && HAVE_CLOCK_MONOTONIC */
31893189
# endif /* HAVE_SD_NOTIFY */
31903190
#endif /* WITH_LIBSYSTEMD */
31913191

3192+
/* Some code paths (build configurations/goals) do not involve these,
3193+
* but easier to make-believe that we do than pepper code with ifdefs */
3194+
NUT_UNUSED_VARIABLE(buf);
3195+
NUT_UNUSED_VARIABLE(msglen);
3196+
31923197
/* Were we asked to be quiet on the console? */
31933198
if (upsnotify_report_verbosity < 0) {
31943199
char *quiet_init = getenv("NUT_QUIET_INIT_UPSNOTIFY");
@@ -3258,8 +3263,6 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
32583263

32593264
#if defined(WITH_LIBSYSTEMD) && (WITH_LIBSYSTEMD)
32603265
# if defined(WITHOUT_LIBSYSTEMD) && (WITHOUT_LIBSYSTEMD)
3261-
NUT_UNUSED_VARIABLE(buf);
3262-
NUT_UNUSED_VARIABLE(msglen);
32633266
if (!upsnotify_reported_disabled_systemd) {
32643267
upsdebugx(upsnotify_report_verbosity,
32653268
"%s: notify about state %s with libsystemd: "

configure.ac

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,33 @@ NUT_ARG_WITH([nss], [enable SSL support using Mozilla NSS], [auto])
28542854
NUT_ARG_WITH([openssl], [enable SSL support using OpenSSL], [auto])
28552855
NUT_ARG_WITH([ssl-client-validation], [enable SSL client certificate validation ability (currently requires NSS, beware issue #3329)], [auto])
28562856

2857+
dnl Optionally reset/initialize the cache values shared by several backends
2858+
dnl if the check methods below never ran for all active code paths (one or more):
2859+
AS_CASE([x${nut_cv_checked_libopenssl}${nut_cv_checked_libnss}x],
2860+
[xyesx], [],
2861+
[xyesyesx], [],
2862+
[
2863+
dnl Magic-format string to hold chosen SSL library version and its config-source
2864+
nut_cv_ssl_lib=""
2865+
2866+
nut_cv_LIBSSL_CFLAGS=""
2867+
nut_cv_LIBSSL_LIBS=""
2868+
nut_cv_LIBSSL_REQUIRES=""
2869+
nut_cv_LIBSSL_LDFLAGS_RPATH=""
2870+
nut_cv_LIBSSL_REQUIRES_SOURCE=""
2871+
nut_cv_LIBSSL_CFLAGS_SOURCE=""
2872+
nut_cv_LIBSSL_LIBS_SOURCE=""
2873+
2874+
dnl Start with what the build args said:
2875+
nut_cv_with_ssl="${nut_with_ssl}"
2876+
2877+
dnl Ensure re-evaluation if need be:
2878+
AS_UNSET([nut_cv_checked_libopenssl])
2879+
AS_UNSET([nut_noncv_checked_libopenssl_now])
2880+
AS_UNSET([nut_cv_checked_libnss])
2881+
AS_UNSET([nut_noncv_checked_libnss_now])
2882+
])
2883+
28572884
dnl ${nut_with_ssl}: any value except "yes" or "no" is treated as "auto".
28582885
if test "${nut_with_ssl}" != "no"; then
28592886
dnl check if either NSS or OpenSSL was explicitly requested
@@ -2889,6 +2916,17 @@ if test "${nut_with_ssl}" != "no"; then
28892916
fi
28902917
fi
28912918

2919+
dnl Summary for re-runs:
2920+
AS_IF([test "${nut_noncv_checked_libopenssl_now}" = no || test "${nut_noncv_checked_libnss_now}" = no], [
2921+
AC_MSG_NOTICE([Some LIBSSL (cached): ${nut_with_ssl} (${nut_ssl_lib})])
2922+
AC_MSG_NOTICE([Some LIBSSL (cached): cflags_source=${LIBSSL_CFLAGS_SOURCE} libs_source=${LIBSSL_LIBS_SOURCE}])
2923+
AC_MSG_NOTICE([Some LIBSSL (cached): LIBSSL_CFLAGS=${LIBSSL_CFLAGS}])
2924+
AC_MSG_NOTICE([Some LIBSSL (cached): LIBSSL_LIBS=${LIBSSL_LIBS}])
2925+
AC_MSG_NOTICE([Some LIBSSL (cached): LIBSSL_LDFLAGS_RPATH=${LIBSSL_LDFLAGS_RPATH}])
2926+
AC_MSG_NOTICE([Some LIBSSL (cached): requires_source=${LIBSSL_REQUIRES_SOURCE} LIBSSL_REQUIRES=${LIBSSL_REQUIRES}])
2927+
])
2928+
2929+
28922930
AM_CONDITIONAL(WITH_NSS, test "${nut_with_nss}" = "yes")
28932931
AM_CONDITIONAL(WITH_OPENSSL, test "${nut_with_openssl}" = "yes")
28942932

@@ -6331,6 +6369,10 @@ AC_SUBST(LIBSSL_LDFLAGS_RPATH)
63316369
AC_SUBST(LIBSSL_REQUIRES)
63326370
AC_SUBST(LIBGD_CFLAGS)
63336371
AC_SUBST(LIBGD_LDFLAGS)
6372+
AC_SUBST(LIBGLIB_CFLAGS)
6373+
AC_SUBST(LIBGLIB_LIBS)
6374+
AC_SUBST(LIBGIO_CFLAGS)
6375+
AC_SUBST(LIBGIO_LIBS)
63346376
AC_SUBST(LIBNETSNMP_CFLAGS)
63356377
AC_SUBST(LIBNETSNMP_LIBS)
63366378
AC_SUBST(LIBREGEX_LIBS)

0 commit comments

Comments
 (0)