Skip to content

Commit fdea4c4

Browse files
authored
Merge pull request #1826 from larsewi/install-dependencies
ENT-13041: install-dependencies: documented and refactored script
2 parents 7e379b6 + c884121 commit fdea4c4

File tree

1 file changed

+117
-81
lines changed

1 file changed

+117
-81
lines changed

build-scripts/install-dependencies

Lines changed: 117 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
#!/bin/sh
22

3-
. `dirname "$0"`/functions
3+
#
4+
# This script installs the dependencies to be bundled with CFEngine.
5+
# The dependencies are built into you working directory.
6+
#
7+
# The script expects the following repositories to exist side by side:
8+
# .
9+
# ├── buildscripts
10+
# ├── core
11+
# ├── enterprise
12+
# ├── nova
13+
# └── masterfiles
14+
#
15+
# ^ When building community you won't need enterprise, nova.
16+
#
17+
# The script can be run as follows:
18+
# ```
19+
# $ PROJECT=[enterprise|community] EXPLICIT_ROLE=[hub|agent] BUILD_TYPE=[DEBUG|RELEASE] ./buildscripts/build-scripts/install-dependencies
20+
# ```
21+
#
22+
23+
. "$(dirname "$0")"/functions
424
. detect-environment
525
. compile-options
626

727
# We use packaging scripts
828
PATH=$PATH:$BASEDIR/buildscripts/deps-packaging
929

10-
# Not all dependencies support building in parallel.
11-
# TODO: Investigate if this is still the case or disable parallel jobs for only
12-
# the dependencies that not support it. (ENT-13041)
13-
MAKEFLAGS=-j1
14-
15-
set -x
16-
1730
# This should be already set from sourcing "functions" at the top, but
1831
# make sure, because we don't want build-artifacts-cache to have bogus
1932
# packages.
2033
set -e
2134

22-
2335
install_pkg_files()
2436
{
25-
retry_wrapper pkg-install-$DEP_PACKAGING "$@"
37+
retry_wrapper "pkg-install-$DEP_PACKAGING" "$@"
2638
}
2739

28-
2940
# OpenSSL 1.1 requires Perl 5.10.0 and some modules existing only in 5.13.4 to
3041
# build and test properly, so we require 5.13.4 at least. See NOTES.PERL in
3142
# OpenSSL.
@@ -38,42 +49,42 @@ install_pkg_files()
3849
# perl-Module-Load-Conditional for RHELs).
3950
check_and_install_perl()
4051
{
41-
[ x"$PERL" = x ] && [ -x "$HOME/perl-my/bin/perl" ] \
52+
# Unless $PERL us already set:
53+
# - set it to $HOME/perl-my/bin/perl if it exists and is executable
54+
# - otherwise look for it elsewhere
55+
[ -z "$PERL" ] && [ -x "$HOME/perl-my/bin/perl" ] \
4256
&& PERL="$HOME/perl-my/bin/perl" \
43-
|| PERL=`func_whereis perl`
57+
|| PERL=$(func_whereis perl)
4458

4559
PERL_OK=yes
46-
PERL_MINOR_VERSION=`$PERL -e 'print "$]"."\n"' | cut -d. -f2`
47-
if [ "$PERL_MINOR_VERSION" -lt 013004 ]
48-
then
49-
echo "$PERL version is $PERL_MINOR_VERSION," \
50-
"too old"
60+
PERL_MINOR_VERSION=$($PERL -e 'print "$]"."\n"' | cut -d. -f2)
61+
if [ "$PERL_MINOR_VERSION" -lt 013004 ]; then
62+
log_debug "$PERL version is too old (minor version $PERL_MINOR_VERSION)"
5163
PERL_OK="no"
5264
fi
65+
5366
if ! $PERL -e 'use List::Util qw(pairs);'; then
54-
echo "$PERL has List::Util that does not export pairs. Needs to be at least version 1.29 for OpenSSL version 3.3.2."
67+
log_debug $PERL has List::Util that does not export pairs. Needs to be at least version 1.29 for OpenSSL version 3.3.2.
5568
PERL_OK="no"
5669
fi
70+
5771
if [ "$PERL_OK" != "yes" ]; then
58-
echo "$PERL is too old or modules are missing, building new one from source..."
72+
log_debug $PERL is too old or modules are missing, building new one from source...
5973

6074
# -fno-stack-protector: Ensure built perl will not depend on libssp.so
61-
if echo | gcc -E -fno-stack-protector - >/dev/null 2>&1
62-
then
75+
if echo | gcc -E -fno-stack-protector - >/dev/null 2>&1; then
6376
PERL_CFLAGS='-Accflags=-fno-stack-protector'
6477
fi
6578

6679
# Solaris 11 insists on having a dependency to libgcc_s.so which
6780
# resides in /opt/csw/lib. Unfortunately the following hack is not
6881
# working on other platforms so we have to hide it.
69-
if [ $OS = solaris ] && [ $OS_VERSION = 11 ]
70-
then
82+
if [ "$OS" = solaris ] && [ "$OS_VERSION" = 11 ]; then
7183
PERL_LDFLAGS='-Aldflags=-static-libgcc'
7284
PERL_LDDLFLAGS='-Alddlflags=-static-libgcc -Alddlflags=-shared'
7385
fi
7486

75-
if [ $OS = aix ] && [ $OS_VERSION != 5.3 ]
76-
then
87+
if [ "$OS" = aix ] && [ "$OS_VERSION" != 5.3 ]; then
7788
# AIX says it provides the nexttoward() 128bit floating point API,
7889
# but it actually doesn't provide the function. So let's make sure
7990
# the function is declared missing and not used.
@@ -85,15 +96,26 @@ check_and_install_perl()
8596
# from the perl dev team - they are only intended for development
8697
PERL_VERSION=5.40.1
8798
PERL_SHA256=02f8c45bb379ed0c3de7514fad48c714fd46be8f0b536bfd5320050165a1ee26
88-
wget https://www.cpan.org/src/5.0/perl-${PERL_VERSION}.tar.gz
89-
[ `func_sha256 perl-${PERL_VERSION}.tar.gz` != "${PERL_SHA256}" ] \
90-
&& fatal "perl checksum error"
99+
100+
log_debug Fetching perl tarball...
101+
run_and_print_on_failure wget https://www.cpan.org/src/5.0/perl-${PERL_VERSION}.tar.gz
102+
if [ "$(func_sha256 perl-${PERL_VERSION}.tar.gz)" != "${PERL_SHA256}" ]; then
103+
fatal "perl checksum error"
104+
fi
105+
106+
log_debug Extracting perl tarball...
91107
gzip -dc perl-${PERL_VERSION}.tar.gz | tar xf -
92108
cd perl-${PERL_VERSION}
93-
./Configure -des -Dprefix=$HOME/perl-my -Dcc=gcc -Dmake=$MAKE \
94-
$PERL_EXTRA_FLAGS $PERL_CFLAGS $PERL_LDFLAGS $PERL_LDDLFLAGS
95-
$MAKE
96-
$MAKE install
109+
110+
log_debug Running ./Configure on perl project...
111+
run_and_print_on_failure ./Configure -des -Dprefix="$HOME"/perl-my -Dcc=gcc -Dmake="$MAKE" \
112+
"$PERL_EXTRA_FLAGS" "$PERL_CFLAGS" "$PERL_LDFLAGS" "$PERL_LDDLFLAGS"
113+
114+
log_debug Running make on perl project...
115+
run_and_print_on_failure $MAKE
116+
117+
log_debug Running make install on perl project...
118+
run_and_print_on_failure $MAKE install
97119
PERL=$HOME/perl-my/bin/perl
98120
fi
99121

@@ -106,91 +128,105 @@ check_and_install_perl
106128

107129
# non-gnu exotics don't support sed -i,
108130
# and only hub or deb packages use files mentioned below
109-
if [ "$BUILDPREFIX" != "/var/cfengine" -a \( "$DEP_PACKAGING" = "deb" -o "$ROLE" = hub \) ]
110-
then
111-
# Apply necessary changes for alternate prefix
112-
sed -i "s:/var/cfengine:$BUILDPREFIX:" \
113-
$BASEDIR/buildscripts/deps-packaging/*/debian/*.install \
114-
$BASEDIR/buildscripts/deps-packaging/*/mingw/debian/*.install \
115-
$BASEDIR/buildscripts/deps-packaging/apache/httpd.conf
131+
if [ "$BUILDPREFIX" != /var/cfengine ]; then
132+
if [ "$DEP_PACKAGING" = deb ] || [ "$ROLE" = hub ]; then
133+
# Apply necessary changes for alternate prefix
134+
sed -i "s:/var/cfengine:$BUILDPREFIX:" \
135+
"$BASEDIR/buildscripts/deps-packaging/*/debian/*.install" \
136+
"$BASEDIR/buildscripts/deps-packaging/*/mingw/debian/*.install" \
137+
"$BASEDIR/buildscripts/deps-packaging/apache/httpd.conf"
138+
fi
116139
fi
117140

118141
# Override for manual testing
119-
if [ "x$1" != x ]
120-
then
121-
DEPS="$@"
142+
if [ -n "$1" ]; then
143+
log_debug "Overriding dependency list (manual testing)"
144+
DEPS="$*"
122145
fi
123146

124-
125147
for dep in $DEPS
126148
do
127149
case "$BUILD_TYPE" in
128-
DEBUG|CODE_COVERAGE)
129-
optimize=yes
130-
debugsym=no
131-
versuffix=+untested
132-
tests=no;;
133-
RELEASE)
134-
optimize=yes
135-
debugsym=no
136-
versuffix=+release
137-
tests=yes;;
138-
*)
139-
echo "Unknown build type: $BUILD_TYPE"
140-
exit 42;;
150+
DEBUG|CODE_COVERAGE)
151+
optimize=yes
152+
debugsym=no
153+
versuffix=+untested
154+
tests=no
155+
;;
156+
RELEASE)
157+
optimize=yes
158+
debugsym=no
159+
versuffix=+release
160+
tests=yes
161+
;;
162+
*)
163+
fatal "Unknown build type: $BUILD_TYPE"
164+
;;
141165
esac
142166

143167
case "$ARCH" in
144-
x86|x64)
145-
crossver=+mingw$ARCH
146-
cross=$ARCH;;
147-
*)
148-
crossver=
149-
cross=native;;
168+
x86|x64)
169+
crossver=+mingw$ARCH
170+
cross=$ARCH
171+
;;
172+
*)
173+
crossver=
174+
cross=native
175+
;;
150176
esac
151177

152-
revision=$(cat $BASEDIR/buildscripts/deps-packaging/revision)
153-
if [ "$BUILDPREFIX" != "/var/cfengine" ]
154-
then
178+
# Add $PREFIX to version of built dependencies so they get different package names and are distinguishable from each
179+
revision=$(cat "$BASEDIR"/buildscripts/deps-packaging/revision)
180+
if [ "$BUILDPREFIX" != "/var/cfengine" ]; then
155181
safe_prefix="+$(echo "$PREFIX" | sed 's:/::g')"
156182
fi
157183
version=0+$revision$versuffix$crossver$safe_prefix
158184

159185
# FETCH dependency packages if needed
160-
package_files=`pkg-cache listpkgfiles $dep-$version`
186+
package_files=$(pkg-cache listpkgfiles "$dep-$version")
161187

162188
# If package cache did not have the packages
163-
if [ x"$package_files" = x ]
164-
then
189+
if [ -z "$package_files" ]; then
190+
log_debug Building package $dep...
165191
# BUILD the packages
166192
if [ "$dep" = "lmdb" ] && [ "$BUILD_TYPE" != "RELEASE" ]; then
167-
# Always build LMDB with debug symbols in non-release builds
168-
$BASEDIR/buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING \
169-
$dep $tests $cross $optimize yes $version
193+
# Always build LMDB with debug symbols in non-release builds.
194+
# The reason is an ongoing issue where we fail to open database transactions.
195+
# See ENT-10777 for more info.
196+
"$BASEDIR/buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING" \
197+
"$dep" "$tests" "$cross" "$optimize" yes "$version"
170198
else
171-
$BASEDIR/buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING \
172-
$dep $tests $cross $optimize $debugsym $version
199+
"$BASEDIR/buildscripts/deps-packaging/pkg-build-$DEP_PACKAGING" \
200+
"$dep" "$tests" "$cross" "$optimize" "$debugsym" "$version"
173201
fi
174202

175-
package_files=`pkg-find-$DEP_PACKAGING $BASEDIR/$dep`
176-
177-
[ x"$package_files" = x ] && \
203+
# Make sure package is there after building it
204+
package_files=$("pkg-find-$DEP_PACKAGING" "$BASEDIR/$dep")
205+
if [ -z "$package_files" ]; then
178206
fatal "Empty output dir after building dependency: $dep"
207+
fi
179208

180209
# CACHE the newly built package
181-
pkg-cache putpkg $dep-$version $package_files
210+
# shellcheck disable=SC2086
211+
log_debug Caching package $dep...
212+
pkg-cache putpkg "$dep-$version" $package_files
182213

183214
# CLEAN UP
215+
# shellcheck disable=SC2086
216+
log_debug Removing package files for $dep...
184217
rm -f $package_files
185218

186219
# Now the package should be in the local cache
187-
package_files=`pkg-cache listpkgfiles $dep-$version`
188-
[ x"$package_files" = x ] && \
220+
package_files=$(pkg-cache listpkgfiles "$dep-$version")
221+
if [ -z "$package_files" ]; then
189222
fatal "Cache did not find package after putpkg"
223+
fi
190224
fi
191225

192226
# INSTALL the packages
193-
install_pkg_files $package_files
227+
# shellcheck disable=SC2086
228+
log_debug Installing package files for $dep...
229+
install_pkg_files $package_files
194230

195231
# keep 50 most recent packages to preserve disk space
196232
pkg-cache keep_newest 50

0 commit comments

Comments
 (0)