Skip to content

Commit

Permalink
Merge pull request #2306 from jimklimov/fix-CI-std
Browse files Browse the repository at this point in the history
CI: Fix C/C++ standard customization
  • Loading branch information
jimklimov committed Feb 10, 2024
2 parents dcbb2ba + affa048 commit 636c3d8
Show file tree
Hide file tree
Showing 36 changed files with 264 additions and 142 deletions.
9 changes: 8 additions & 1 deletion Jenkinsfile-dynamatrix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import org.nut.dynamatrix.*;
dynacfgPipeline.disableSlowBuildCIBuild = false
dynacfgPipeline.disableSlowBuildCIBuildExperimental = false

// NOTE: Disabled by default because with -std=c* the compiler and linker
// (at least on environments NUT CI farm has) do not "see" many things,
// and do not even define WIN32, and this is unrelated to NUT codebase.
// This toggle aims to only disable 'c' builds in the scenario; but the
//'gnu' ones should still happen if it is enabled overall.
dynacfgPipeline.disableStrictCIBuild_CrossWindows = true

// At this time, GCC succeeds building C89/GNU89 mode for NUT
// while CLANG complains about things we can't fix easily.
dynacfgPipeline.axisCombos_COMPILER_GCC = [~/COMPILER=GCC/]
Expand Down Expand Up @@ -1221,7 +1228,7 @@ set | sort -n """
dynamatrixAxesVirtualLabelsMap: [
'BITS': [64, 32],
'CSTDVERSION_${KEY}': [ ['c': '99', 'cxx': '11'] ],
'CSTDVARIANT': ['c', 'gnu'],
'CSTDVARIANT': ['gnu'] + (dynacfgPipeline.disableStrictCIBuild_CrossWindows ? [] : ['c']),
],
dynamatrixAxesCommonEnv: [
['LANG=C','LC_ALL=C','TZ=UTC',
Expand Down
2 changes: 2 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ https://github.com/networkupstools/nut/milestone/10
application name. [#2205]
* Original recipe for `apc_modbus` strictly required USB support even if
building NUT without it. [#2262]
* Builds requested with a specific C/C++ language standard revision via
`CFLAGS` and `CXXFLAGS` should again be honoured. [PR #2306]

- nut-usbinfo.pl, nut-scanner and libnutscan:
* Library API version for `libnutscan` was bumped from 2.2.0 to 2.5.0
Expand Down
5 changes: 5 additions & 0 deletions UPGRADING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Changes from 2.8.2 to 2.8.3
Changes from 2.8.1 to 2.8.2
---------------------------

- Builds requested with a specific C/C++ language standard revision via
`CFLAGS` and `CXXFLAGS` should again be honoured. There was a mishap
with the `m4` scripting for `autoconf` which could have caused use of
C11/C++11 if compiler supported it, regardless of a request. [PR #2306]
- Added generation of FreeBSD/pfSense quirks for USB devices supported
by NUT (may get installed to `$datadir` e.g. `/usr/local/share/nut`
and need to be pasted into your `/boot/loader.conf.local`). [#2159]
Expand Down
2 changes: 1 addition & 1 deletion ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ bindings)
""|inplace)
echo "ERROR: No BUILD_TYPE was specified, doing a minimal default ritual without any required options" >&2
if [ -n "${BUILD_WARNOPT}${BUILD_WARNFATAL}" ]; then
echo "WARNING: BUILD_WARNOPT and BUILD_WARNFATAL settings are ignored in this mode" >&2
echo "WARNING: BUILD_WARNOPT and BUILD_WARNFATAL settings are ignored in this mode (warnings are always enabled and fatal for these developer-oriented builds)" >&2
sleep 5
fi
echo ""
Expand Down
4 changes: 3 additions & 1 deletion clients/cgilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "common.h"

#include <ctype.h>
#include <stdio.h>

#include "common.h"
#include "cgilib.h"
#include "parseconf.h"

Expand Down
2 changes: 1 addition & 1 deletion clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ static int parse_conf_arg(size_t numargs, char **arg)
/* DEBUG_MIN (NUM) */
/* debug_min (NUM) also acceptable, to be on par with ups.conf */
if (!strcasecmp(arg[0], "DEBUG_MIN")) {
int lvl = -1; // typeof common/common.c: int nut_debug_level
int lvl = -1; /* typeof common/common.c: int nut_debug_level */
if ( str_to_int (arg[1], &lvl, 10) && lvl >= 0 ) {
nut_debug_level_global = lvl;
} else {
Expand Down
3 changes: 2 additions & 1 deletion clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ static int sock_read(conn_t *conn)
* fit in the US_MAX_READ length limit - at worst we would
* "return 0", and continue with pconf_char() next round.
*/
size_t numarg;
#ifndef WIN32
errno = 0;
ret = read(conn->fd, &ch, 1);
Expand Down Expand Up @@ -768,7 +769,7 @@ static int sock_read(conn_t *conn)

/* try to use it, and complain about unknown commands */
upsdebugx(3, "Ending sock_read() on a good note: try to use command:");
for (size_t numarg = 0; numarg < conn->ctx.numargs; numarg++)
for (numarg = 0; numarg < conn->ctx.numargs; numarg++)
upsdebugx(3, "\targ %" PRIuSIZE ": %s", numarg, conn->ctx.arglist[numarg]);
if (!sock_arg(conn)) {
log_unknown(conn->ctx.numargs, conn->ctx.arglist);
Expand Down
3 changes: 2 additions & 1 deletion common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,8 @@ static char * get_libname_in_dir(const char* base_libname, size_t base_libname_l

# ifdef WIN32
if (!libname_path) {
for (char *p = current_test_path; *p != '\0' && (p - current_test_path) < LARGEBUF; p++) {
char *p;
for (p = current_test_path; *p != '\0' && (p - current_test_path) < LARGEBUF; p++) {
if (*p == '/') *p = '\\';
}
upsdebugx(3, "%s: WIN32: re-checking with %s", __func__, current_test_path);
Expand Down
54 changes: 31 additions & 23 deletions common/strptime.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/* Use NUT build configuration */
#include "config.h"

/*
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
Expand Down Expand Up @@ -77,13 +81,13 @@ static char gmt[] = { "GMT" };
static char utc[] = { "UTC" };
/* RFC-822/RFC-2822 */
static const char * const nast[5] = {
"EST", "CST", "MST", "PST", "\0\0\0"
"EST", "CST", "MST", "PST", "\0\0\0"
};
static const char * const nadt[5] = {
"EDT", "CDT", "MDT", "PDT", "\0\0\0"
"EDT", "CDT", "MDT", "PDT", "\0\0\0"
};
static const char * const am_pm[2] = {
"am", "pm"
"am", "pm"
};
static const char * const day[7] = {
"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"
Expand All @@ -107,7 +111,7 @@ static const u_char *find_string(const u_char *, int *, const char * const *,
static int
strncasecmp(const char *a, const char *b, size_t c)
{
return _strnicmp(a, b, c);
return _strnicmp(a, b, c);
}
#endif
*/
Expand Down Expand Up @@ -163,11 +167,11 @@ again: switch (c = *fmt++) {
/*
* "Complex" conversion rules, implemented through recursion.
*/
/* we do not need 'c'
case 'c': Date and time, using the locale's format.
/* // we do not need 'c':
case 'c': Date and time, using the locale's format.
new_fmt = _ctloc(d_t_fmt);
goto recurse;
*/
*/

case 'D': /* The date as "%m/%d/%y". */
new_fmt = "%m/%d/%y";
Expand All @@ -185,7 +189,7 @@ again: switch (c = *fmt++) {
goto recurse;

case 'r': /* The time in 12-hour clock representation. */
new_fmt = "%I:%M:S %p";//_ctloc(t_fmt_ampm);
new_fmt = "%I:%M:S %p";/*_ctloc(t_fmt_ampm); */
LEGAL_ALT(0);
goto recurse;

Expand All @@ -194,18 +198,20 @@ again: switch (c = *fmt++) {
LEGAL_ALT(0);
goto recurse;

/* we don't use 'X'
case 'X': The time, using the locale's format.
/* // we don't use 'X'
case 'X': The time, using the locale's format.
new_fmt =_ctloc(t_fmt);
goto recurse;
*/
*/

/* // we do not need 'x'
case 'x': The date, using the locale's format.
new_fmt =_ctloc(d_fmt);
*/

/* we do not need 'x'
case 'x': The date, using the locale's format.
new_fmt =_ctloc(d_fmt);*/
recurse:
bp = (const u_char *)strptime((const char *)bp,
new_fmt, tm);
new_fmt, tm);
LEGAL_ALT(ALT_E);
continue;

Expand Down Expand Up @@ -319,7 +325,7 @@ again: switch (c = *fmt++) {
}

tm = localtime(&sse);
if (tm == NULL)
if (tm == NULL)
bp = NULL;
}
continue;
Expand Down Expand Up @@ -356,9 +362,9 @@ again: switch (c = *fmt++) {
case 'G': /* The year corresponding to the ISO week
* number with century.
*/
do
do {
bp++;
while (isdigit(*bp));
} while (isdigit(*bp));
continue;

case 'V': /* The ISO 8601:1988 week number as decimal */
Expand Down Expand Up @@ -392,7 +398,8 @@ again: switch (c = *fmt++) {
case 'Z':
_tzset();
if (strncasecmp((const char *)bp, gmt, 3) == 0
|| strncasecmp((const char *)bp, utc, 3) == 0) {
|| strncasecmp((const char *)bp, utc, 3) == 0
) {
tm->tm_isdst = 0;
#ifdef TM_GMTOFF
tm->TM_GMTOFF = 0;
Expand All @@ -403,8 +410,8 @@ again: switch (c = *fmt++) {
bp += 3;
} else {
ep = find_string(bp, &i,
(const char * const *)tzname,
NULL, 2);
(const char * const *)tzname,
NULL, 2);
if (ep != NULL) {
tm->tm_isdst = i;
#ifdef TM_GMTOFF
Expand Down Expand Up @@ -490,12 +497,13 @@ again: switch (c = *fmt++) {
}

if ((*bp >= 'A' && *bp <= 'I') ||
(*bp >= 'L' && *bp <= 'Y')) {
(*bp >= 'L' && *bp <= 'Y')
) {
#ifdef TM_GMTOFF
/* Argh! No 'J'! */
if (*bp >= 'A' && *bp <= 'I')
tm->TM_GMTOFF =
('A' - 1) - (int)*bp;
('A' - 1) - (int)*bp;
else if (*bp >= 'L' && *bp <= 'M')
tm->TM_GMTOFF = 'A' - (int)*bp;
else if (*bp >= 'N' && *bp <= 'Y')
Expand Down
17 changes: 16 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ AC_CONFIG_HEADERS([include/config.h])
AC_PREFIX_DEFAULT(/usr/local/ups)
AM_INIT_AUTOMAKE([subdir-objects])

AS_CASE([${target_os}],
[*mingw*], [AS_CASE([${CFLAGS-}${CXXFLAGS-}],
[*"-std=c"*|*-ansi*], [
AC_MSG_NOTICE(
[-----------------------------------------------------------------------
WARNING: It seems you are building with MinGW and requested a strict C/C++
language mode. Per https://stackoverflow.com/a/76780217/4715872 MinGW may
not define WIN32 and other options needed for proper building and linking.
If this happens, please retry with GNU C/C++ language mode options instead.
-----------------------------------------------------------------------])
sleep 5
])]
)

dnl Default to `configure --enable-silent-rules` or `make V=1` for details?
dnl This feature seems to require automake-1.13 or newer (1.11+ by other info)
dnl On very old systems can comment it away with little loss (then automake-1.10
Expand Down Expand Up @@ -2832,6 +2846,7 @@ AS_IF([test "x$nut_cv_header_windows_h" = xyes],
[AM_CONDITIONAL([HAVE_WINDOWS], [false])]
)


dnl ----------------------------------------------------------------------

PREFIX="${prefix}"
Expand Down Expand Up @@ -3535,7 +3550,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[${CPLUSPLUS_DECL}]], [[${CPLUSPLUS_MAIN}]])
[AC_MSG_RESULT([yes, out of the box])
have_cxx11=yes],
[AS_CASE(["${CXXFLAGS}"],
[*"-std="*], [
[*"-std="*|*"-ansi"*], [
AC_MSG_RESULT([no, not with the standard already set in CXXFLAGS='${CXXFLAGS}'])
have_cxx11=no
],[
Expand Down
29 changes: 24 additions & 5 deletions docs/developers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,26 @@ Other hints
~~~~~~~~~~~

TIP: At this point NUT is expected to work correctly when built with a
C99 (or rather GNU99 on many systems) or newer standard.
"strict" C99 (or rather GNU99 on many systems) or newer standard.

The NUT codebase may build in a mode without warnings made fatal on C89
(GNU89), but the emitted warnings indicate that those binaries may crash.
By the end of 2021, NUT codebase has been revised to pass GNU and strict-C
mode builds with C89 standard with the GCC toolkit (and on systems that do
have the newer features in libraries, just hide them in standard headers);
however CLANG toolkit is more restrictive about the C99+ syntax used.
If somebody in the community requires to build and run NUT on systems
that old, pull requests to fix the offending coding issues are welcome.
That said, some systems refuse to expose methods or types available in
their system headers and binary libraries if strict-C mode is used alone,
without extra system-specific defines to enable more than the baseline.

It was also seen that cross-builds (e.g. NUT for Windows using mingw on
Linux) may be unable to define `WIN32` and/or find symbols for linking
when using a strict-C language standard.

The C++ support expects C++11 or newer (not really configured or tested
for older C++98 or C++03), modulo features that were deprecated in later
language revisions (C++14 onwards) as highlighted by warnings from newer
compilers.

Note also that the NUT codebase currently relies on certain features,
such as the printf format modifiers for `(s)size_t`, use of `long long`,
Expand All @@ -190,8 +200,16 @@ revisions). Many of the "offences" against the older standard actually
come from system and third-party header files.

That said, the NUT CI farm does run non-regression builds with GNU C89
and strict C89 standard revisions and minimal passing warnings level,
and "strict" C89 standard revisions and minimal passing warnings level,
to ensure that codebase is and remains at least basically compliant.
We try to cover a few distributions from early 2000's for this, either
in regular CI builds or one-off local builds for community members with
a zoo of old systems.

If somebody in the community actually requires to build and run NUT on
systems that old, where newer compilers are not available, pull requests
to fix the offending coding issues in some way that does not break other
use-cases are welcome.

Continuous Integration and Automated Builds
-------------------------------------------
Expand Down Expand Up @@ -299,7 +317,8 @@ Jenkins CI
^^^^^^^^^^

Since mid-2021, the NUT CI farm is implemented by several virtual servers
courteously provided by http://fosshost.org
courteously provided by link:http://fosshost.org[Fosshost] and later by
link:https://www.digitalocean.com/?refcode=d2fbf2b9e082&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge[DigitalOcean].

These run various operating systems as build agents, and a Jenkins instance
to orchestrate the builds of NUT branches and pull requests on those agents.
Expand Down
3 changes: 2 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3443 utf-8
personal_ws-1.1 en 3444 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -2686,6 +2686,7 @@ ont
ontd
ontimedays
ontiniedays
onwards
ooce
openSUSE
opencollective
Expand Down

0 comments on commit 636c3d8

Please sign in to comment.