Skip to content

Commit

Permalink
Merge pull request #2778 from jimklimov/fix-appveyor-libmodbus
Browse files Browse the repository at this point in the history
Fix Appveyor CI to use NUT libmodbus fork
  • Loading branch information
jimklimov authored Jan 23, 2025
2 parents 9066236 + 8c851c8 commit 4c00520
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 55 deletions.
17 changes: 9 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ platform: x64
# https://www.appveyor.com/docs/build-cache/
environment:
APPVEYOR_SAVE_CACHE_ON_ERROR: true
APPVEYOR_CACHE_ENTRY_ZIP_ARGS: -t7z -m0=lzma -mx=9
APPVEYOR_CACHE_ENTRY_ZIP_ARGS: -t7z -m0=lzma -mx=6
CCACHE_DIR: /home/appveyor/.ccache

# https://github.com/networkupstools/nut/blob/Windows-v2.8.0-1/docs/config-prereqs.txt#L951
Expand All @@ -47,7 +47,8 @@ install:
C:\msys64\usr\bin\bash -lc "date -u; pacman --noconfirm -Syuu"
- cmd: |
REM Prerequisites for NUT per https://github.com/networkupstools/nut/blob/master/docs/config-prereqs.txt :
C:\msys64\usr\bin\bash -lc "date -u; pacman --noconfirm -S --needed base-devel mingw-w64-x86_64-toolchain autoconf-wrapper automake-wrapper libtool mingw-w64-x86_64-libltdl gcc ccache mingw-w64-x86_64-ccache git aspell aspell-en python mingw-w64-x86_64-python-pygments mingw-w64-x86_64-winpthreads-git mingw-w64-x86_64-libusb mingw-w64-x86_64-libusb-compat-git mingw-w64-x86_64-neon libneon-devel mingw-w64-x86_64-libmodbus-git mingw-w64-x86_64-libgd mingw-w64-x86_64-cppunit"
C:\msys64\usr\bin\bash -lc "date -u; pacman --noconfirm -S --needed base-devel mingw-w64-x86_64-toolchain autoconf-wrapper automake-wrapper libtool mingw-w64-x86_64-libltdl gcc ccache mingw-w64-x86_64-ccache git aspell aspell-en python mingw-w64-x86_64-python-pygments mingw-w64-x86_64-winpthreads-git mingw-w64-x86_64-libusb mingw-w64-x86_64-libusb-compat-git mingw-w64-x86_64-neon libneon-devel mingw-w64-x86_64-libgd mingw-w64-x86_64-cppunit"
REM SKIP mingw-w64-x86_64-libmodbus-git : we custom-build one with USB support
- cmd: |
REM Assorted stats after package processing:
C:\msys64\usr\bin\bash -lc "date -u; ls -la / ; du -ksx / ; date -u; du -ks /var/cache/pacman/pkg; date -u"
Expand All @@ -68,7 +69,7 @@ before_build:
set CHERE_INVOKING=yes
REM Start a 64 bit Mingw environment:
set MSYSTEM=MINGW64
C:\msys64\usr\bin\bash -lc "date -u; export MSYS2_PATH ; bash ./scripts/Windows/build-mingw-prereqs.sh"
C:\msys64\usr\bin\bash -lc 'date -u; export MSYS2_PATH ; PATH="/mingw64/lib/ccache/bin:/mingw64/bin:$PATH" bash ./scripts/Windows/build-mingw-prereqs.sh'
build_script:
Expand All @@ -77,7 +78,7 @@ build_script:
set CHERE_INVOKING=yes
REM Start a 64 bit Mingw environment:
set MSYSTEM=MINGW64
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/bin:$PATH" CI_SKIP_CHECK=true ./ci_build.sh'
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/bin:$PATH" CI_SKIP_CHECK=true CANBUILD_WITH_LIBMODBUS_USB=yes ./ci_build.sh'
after_build:
Expand All @@ -96,9 +97,9 @@ test_script:
REM Start a 64 bit Mingw environment:
set MSYSTEM=MINGW64
REM Start Mingw-based integration and unit checks:
C:\msys64\usr\bin\bash -lc 'date -u; NUT_STATEPATH="C:\\Users\\appveyor\\AppData\\Local\\Temp\\nut-test"; mkdir -p "${NUT_STATEPATH}"; export NUT_STATEPATH; PATH="/mingw64/bin:$PATH" make -s check || bash -lc "for F in tests/*.log tests/*.trs ; do echo \"===---=== $F :\"; cat \"$F\"; done; exit 1;" '
REM Start a Mingw-based documentation spellcheck:
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/bin:$PATH" make -s -j 4 spellcheck'
C:\msys64\usr\bin\bash -lc 'date -u; NUT_STATEPATH="C:\\Users\\appveyor\\AppData\\Local\\Temp\\nut-test"; mkdir -p "${NUT_STATEPATH}"; export NUT_STATEPATH; PATH="/mingw64/lib/ccache/bin:/mingw64/bin:$PATH" make -s check || bash -lc "for F in tests/*.log tests/*.trs ; do echo \"===---=== $F :\"; cat \"$F\"; done; exit 1;" '
REM Start a Mingw-based documentation spellcheck (note that "make check" above could cover some documents in path of artifact delivery, but maybe not all that we have):
C:\msys64\usr\bin\bash -lc 'date -u; PATH="/mingw64/lib/ccache/bin:/mingw64/bin:$PATH" make -s -j 8 spellcheck'
after_test:
Expand All @@ -109,7 +110,7 @@ after_test:
set MSYSTEM=MINGW64
REM Oh the joys of shell scripting with strings passed through CMD:
REM Note: currently Python installation path with MSYS is buggy [#1584]
C:\msys64\usr\bin\bash -lc 'date -u; if ! rm -rf ".inst" ; then echo "WARNING: Failed to clean away .inst" ; fi ; PATH="/mingw64/bin:$PATH" make -s install-win-bundle DESTDIR="`pwd`/.inst/NUT-for-Windows-x86_64-SNAPSHOT-%APPVEYOR_BUILD_VERSION%" ; ln -fs "NUT-for-Windows-x86_64-SNAPSHOT-%APPVEYOR_BUILD_VERSION%" ./.inst/NUT-for-Windows-x86_64-SNAPSHOT ; ( cd .inst/NUT-for-Windows-x86_64-SNAPSHOT ; find . -ls ; )'
C:\msys64\usr\bin\bash -lc 'date -u; set -e ; if ! rm -rf ".inst" ; then echo "WARNING: Failed to clean away .inst" ; fi ; PATH="/mingw64/lib/ccache/bin:/mingw64/bin:$PATH" make -s install-win-bundle DESTDIR="`pwd`/.inst/NUT-for-Windows-x86_64-SNAPSHOT-%APPVEYOR_BUILD_VERSION%" ; ln -fs "NUT-for-Windows-x86_64-SNAPSHOT-%APPVEYOR_BUILD_VERSION%" ./.inst/NUT-for-Windows-x86_64-SNAPSHOT ; ( cd .inst/NUT-for-Windows-x86_64-SNAPSHOT ; find . -ls ; ) ; date -u'
cd .inst
7z a ../NUT-for-Windows-x86_64-SNAPSHOT-%APPVEYOR_BUILD_VERSION%.7z NUT*
- cmd: |
Expand Down
16 changes: 14 additions & 2 deletions ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,12 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp
CONFIG_OPTS+=("--with-nut_monitor=force")
CONFIG_OPTS+=("--with-pynut=auto")

# Primarily here to ensure libusb-1.0 use on MSYS2/mingw
# when 0.1 is available too
if [ "${CANBUILD_WITH_LIBMODBUS_USB-}" = yes ] ; then
CONFIG_OPTS+=("--with-modbus+usb=yes")
fi

# Similarly for nut-scanner which requires libltdl which
# is not ubiquitous on CI workers. So unless agent labels
# declare it should be capable, err on the safe side:
Expand Down Expand Up @@ -1532,7 +1538,7 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp
# below depending on scenario
autogen_get_CONFIGURE_SCRIPT

if [ "$NO_PKG_CONFIG" == "true" ] && [ "$CI_OS_NAME" = "linux" ] && (command -v dpkg) ; then
if [ "$NO_PKG_CONFIG" = "true" ] && [ "$CI_OS_NAME" = "linux" ] && (command -v dpkg) ; then
# This should be done in scratch containers...
echo "NO_PKG_CONFIG==true : BUTCHER pkg-config package for this test case" >&2
sudo dpkg -r --force all pkg-config
Expand Down Expand Up @@ -2059,7 +2065,7 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp
[ -n "$CI_TIME" ] && echo "`date`: listing files installed into the custom DESTDIR..." && \
find "$INST_PREFIX" -ls || true

if [ "$DO_DISTCHECK" == "no" ] ; then
if [ "$DO_DISTCHECK" = "no" ] ; then
echo "Skipping distcheck (doc generation is disabled, it would fail)"
else
[ -z "$CI_TIME" ] || echo "`date`: Starting distcheck of currently tested project..."
Expand Down Expand Up @@ -2132,6 +2138,12 @@ bindings)
--disable-force-nut-version-header \
--enable-check-NIT --enable-maintainer-mode)

# Primarily here to ensure libusb-1.0 use on MSYS2/mingw
# when 0.1 is available too
if [ "${CANBUILD_WITH_LIBMODBUS_USB-}" = yes ] ; then
CONFIG_OPTS+=("--with-modbus+usb=yes")
fi

# Not default for parameter-less build, to prevent "make check-NIT"
# from somehow interfering with the running daemons.
if [ x"${INPLACE_RUNTIME-}" = xtrue ] || [ x"${BUILD_TYPE-}" = xinplace ] ; then
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,7 @@ AS_IF([test "${nut_with_modbus}" != "no"], [
dnl detection method (if nut_have_libmodbus_usb=="yes")
NUT_REPORT_DRV([build Modbus drivers with RTU USB support], [${nut_have_libmodbus_usb}])
])
AM_CONDITIONAL(WITH_MODBUS_USB, [test "${nut_with_modbus}" = "yes" && test "${nut_have_libmodbus_usb}" = yes && test "${nut_with_usb}" = yes && test "${nut_with_modbus_and_usb}" != "no"])

dnl ----------------------------------------------------------------------
dnl Check for with-ipmi, and --with-freeipmi (or --with-openipmi)
Expand Down
2 changes: 1 addition & 1 deletion drivers/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ adelsystem_cbi_LDADD = $(LDADD_DRIVERS) $(LIBMODBUS_LIBS)
# for USB connections. Legacy versions work for Serial and TCP links.
apc_modbus_SOURCES = apc_modbus.c
apc_modbus_LDADD = $(LDADD_DRIVERS) $(LIBMODBUS_LIBS)
if WITH_USB
if WITH_MODBUS_USB
apc_modbus_SOURCES += $(LIBUSB_IMPL) hidparser.c usb-common.c
apc_modbus_LDADD += $(LIBUSB_LIBS)
endif
Expand Down
39 changes: 36 additions & 3 deletions m4/nut_check_libmodbus.m4
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,33 @@ if test -z "${nut_have_libmodbus_seen}"; then
CFLAGS="${CFLAGS_ORIG} ${depCFLAGS}"
LIBS="${LIBS_ORIG} ${depLIBS}"
AC_CHECK_HEADERS(modbus.h, [nut_have_libmodbus=yes], [nut_have_libmodbus=no], [AC_INCLUDES_DEFAULT])
AS_IF([test x"${nut_have_libmodbus}" = xyes ], [
AC_CHECK_FUNCS(modbus_new_tcp, [], [
nut_have_libmodbus=no
AC_REQUIRE([NUT_CHECK_SOCKETLIB])
AS_IF([test x"${NETLIBS-}" != x], [
AC_MSG_NOTICE([Retry detection of libmodbus TCP support with NETLIBS])
unset ac_cv_func_modbus_new_tcp
LIBS="${LIBS} ${NETLIBS}"
AC_CHECK_FUNCS(modbus_new_tcp, [
nut_have_libmodbus=yes
depLIBS="${depLIBS} ${NETLIBS}"
], [
AS_IF([test x"${NETLIBS_GETADDRS-}" != x], [
AC_MSG_NOTICE([Retry detection of libmodbus TCP support with NETLIBS and NETLIBS_GETADDRS])
unset ac_cv_func_modbus_new_tcp
LIBS="${LIBS} ${NETLIBS_GETADDRS}"
AC_CHECK_FUNCS(modbus_new_tcp, [
nut_have_libmodbus=yes
depLIBS="${depLIBS} ${NETLIBS} ${NETLIBS_GETADDRS}"
], [nut_have_libmodbus=no])
])
])
])
])
])
AS_IF([test x"${nut_have_libmodbus}" = xyes ], [
AC_CHECK_FUNCS(modbus_new_rtu, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_new_tcp, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_set_byte_timeout, [], [nut_have_libmodbus=no])
AC_CHECK_FUNCS(modbus_set_response_timeout, [], [nut_have_libmodbus=no])
])
Expand All @@ -88,12 +112,21 @@ if test -z "${nut_have_libmodbus_seen}"; then
dnl know we are not opposed to pulling it in.
dnl Static libmodbus builds do not refer to
dnl (shared) libusb for example.
dnl NOTE: Currently libusb-1.0 is required by
dnl libmodbus with rtu_usb additions. By our
dnl default, mingw/MSYS2 native builds prefer
dnl libusb-0.1(-compat) over libusb-1.0 if
dnl both are available - see nut_check_libusb.m4
AC_REQUIRE([NUT_CHECK_LIBUSB])
AC_MSG_NOTICE([Retry detection of libmodbus USB support])
AC_MSG_NOTICE([Retry detection of libmodbus USB support (may require libusb-1.0 specifically)])
CFLAGS="$CFLAGS $LIBUSB_CFLAGS"
LIBS="$LIBS $LIBUSB_LIBS"
unset ac_cv_func_modbus_new_rtu_usb
AC_CHECK_FUNCS(modbus_new_rtu_usb, [nut_have_libmodbus_usb=yes], [
AC_CHECK_FUNCS(modbus_new_rtu_usb, [
nut_have_libmodbus_usb=yes
depCFLAGS="${depCFLAGS} ${LIBUSB_CFLAGS}"
depLIBS="${depLIBS} ${LIBUSB_LIBS}"
], [
AS_IF([test x"${nut_with_usb}" = xyes && test x"${nut_with_modbus}" = xyes && test x"${nut_have_libmodbus}" = xyes ], [
AC_MSG_WARN([Both --with-modbus and --with-usb were requested, and a libmodbus was found, but it seems to not support USB. You may require a custom build per https://github.com/networkupstools/nut/wiki/APC-UPS-with-Modbus-protocol])
])
Expand Down
14 changes: 10 additions & 4 deletions m4/nut_check_libusb.m4
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,20 @@ if test -z "${nut_have_libusb_seen}"; then
nut_usb_lib="(libusb-1.0)"
dnl ...except on Windows, where we support libusb-0.1(-compat)
dnl better so far (allow manual specification though, to let
dnl someone finally develop the on-par support):
dnl someone finally develop the on-par support), see also
dnl https://github.com/networkupstools/nut/issues/1507
dnl Note this may upset detection of libmodbus RTU USB support.
AS_IF([test x"${LIBUSB_0_1_VERSION}" != xnone], [
AS_CASE(["${target_os}"],
[*mingw*], [
AS_IF([test x"$build" = x"$host"], [
AC_MSG_NOTICE([mingw/MSYS2 native builds prefer libusb-0.1(-compat) over libusb-1.0 if both are available])
LIBUSB_VERSION="${LIBUSB_0_1_VERSION}"
nut_usb_lib="(libusb-0.1)"
AS_IF([test "${nut_with_modbus_and_usb}" = "yes"], [
AC_MSG_NOTICE(["Normally" mingw/MSYS2 native builds prefer libusb-0.1(-compat) over libusb-1.0 if both are available, but you requested --with-modbus+usb so preferring libusb-1.0 in this build])
], [
AC_MSG_NOTICE([mingw/MSYS2 native builds prefer libusb-0.1(-compat) over libusb-1.0 if both are available until https://github.com/networkupstools/nut/issues/1507 is solved])
LIBUSB_VERSION="${LIBUSB_0_1_VERSION}"
nut_usb_lib="(libusb-0.1)"
])
],[
AC_MSG_NOTICE([mingw cross-builds prefer libusb-1.0 over libusb-0.1(-compat) if both are available])
])
Expand Down
Loading

0 comments on commit 4c00520

Please sign in to comment.