Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ci/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ if [ -f /etc/os-release ]; then
fi
fi

# ci/dependencies.sh builds a newer pcre2 into /opt/pcre2 where the system one is too old (rhel-8)
if [ -d /opt/pcre2 ]; then
OPTS="$OPTS --with-pcre2=/opt/pcre2"
fi

if [ -n "$TERMUX_VERSION" ] || [ "$ID" = "alpine" ]; then
OPTS="$OPTS --without-pam"
fi
Expand Down
51 changes: 50 additions & 1 deletion ci/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ build_lmdb() {
git clone --recursive --depth 1 https://github.com/LMDB/lmdb
cd lmdb/libraries/liblmdb
make
$GAINROOT make install prefix=/usr
# lmdb's Makefile defaults to /usr/lib which is not in the runtime linker path on lib64 distributions (rhel, suse)
libdir=/usr/lib
if [ -d /usr/lib64 ]; then
libdir=/usr/lib64
fi
$GAINROOT make install prefix=/usr libdir="$libdir"
)
}

Expand All @@ -40,6 +45,49 @@ build_librsync() {
)
}

# Build pcre2 into /opt/pcre2, away from the system pcre2, and ci/configure.sh will use it from there.
# Use the same pcre2 release and checksum as the CFEngine packages, from buildscripts deps-packaging.
build_pcre2() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If libntech needs a particular version of pcre2 then libntech should specify that and we should use that specification here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just move this to buildscripts/ci/setup-cfengine-build-host.sh so we have the version there if we need to use it.

if [ -f /opt/pcre2/include/pcre2.h ]; then
echo pcre2 already installed in /opt/pcre2, no-op.
return
fi
deps_url=https://raw.githubusercontent.com/cfengine/buildscripts/master/deps-packaging/pcre2
tmpdir="$(mktemp -d)"
echo building pcre2 in "$tmpdir"
(
cd "$tmpdir"
curl --fail --location --silent --show-error --output source "$deps_url"/source
curl --fail --location --silent --show-error --output distfiles "$deps_url"/distfiles
tarball="$(awk '{print $2}' distfiles)"
curl --fail --location --silent --show-error --output "$tarball" "$(cat source)$tarball"
sha256sum --check distfiles
tar --extract --gzip --file "$tarball"
cd "${tarball%.tar.gz}"
./configure --prefix=/opt/pcre2 --libdir=/opt/pcre2/lib
make
$GAINROOT make install
)
}

# libntech's configure.ac lists the pcre2 declarations it needs (AC_CHECK_DECLS([PCRE2_...])).
# Build a newer pcre2 when the system one lacks any of them (rhel-8 has 10.32).
ensure_pcre2() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think any "guard" code should live in buildscripts/ci/setup-cfengine-build-host.sh and not here.

Here in core/ci/dependencies.sh we should just let things roll and fail if they will.

decls="$(sed -n 's/^ *AC_CHECK_DECLS(\[\(PCRE2_[^]]*\)\].*/\1/p' "$(dirname "$0")"/../libntech/configure.ac | tr ',' ' ')"
if [ -z "$decls" ]; then
echo "AC_CHECK_DECLS([PCRE2_...]) not found in libntech/configure.ac"
exit 1
fi
system_macros="$(printf '#define PCRE2_CODE_UNIT_WIDTH 8\n#include <pcre2.h>\n' | gcc -E -dM -)"
for decl in $decls; do
if ! echo "$system_macros" | grep --quiet --word-regexp "#define $decl"; then
echo "system pcre2 $(pcre2-config --version) lacks $decl required by libntech"
build_pcre2
return
fi
done
}

# limited support here, focused on rhel-like on aarch64 which has no previous CFEngine version to leverage: ENT-13016
if [ -f /etc/os-release ]; then
source /etc/os-release
Expand Down Expand Up @@ -68,6 +116,7 @@ if [ -f /etc/os-release ]; then
build_lmdb
build_librsync
fi
ensure_pcre2
else
echo "Unsupported version of redhat for $0"
exit 1
Expand Down
Loading