Skip to content

Commit 9f49ada

Browse files
committed
maint/util ~ improve/refactor 'build-gnu' & 'run-gnu-test'
- add more logging for better fault tracking - generalize for use in either RELEASE or DEBUG build mode
1 parent eb577c9 commit 9f49ada

File tree

2 files changed

+83
-43
lines changed

2 files changed

+83
-43
lines changed

util/build-gnu.sh

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,74 @@
11
#!/bin/bash
2+
# `build-gnu.bash` ~ builds GNU coreutils (from supplied sources)
3+
#
4+
# BUILD_PROFILE == 'debug' | 'release' ## build profile for *uutils* build; may be supplied by caller, defaults to 'debug'
25

3-
# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall gnulib inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW baddecode ; (vars/env) BUILDDIR SRCDIR
6+
# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall gnulib inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW baddecode ; (vars/env) BUILD_DIR SRCDIR
47

58
set -e
6-
if test ! -d ../gnu; then
7-
echo "Could not find ../gnu"
8-
echo "git clone https://github.com/coreutils/coreutils.git gnu"
9+
10+
ME="${0}"
11+
ME_dir="$(dirname -- "$(readlink -fm -- "${ME}")")"
12+
REPO_main_dir="$(dirname -- "${ME_dir}")"
13+
14+
### * config (from environment with fallback defaults); note: GNU and GNULIB are expected to be sibling repo directories
15+
16+
path_UUTILS=${path_UUTILS:-${REPO_main_dir}}
17+
path_GNU="$(readlink -fm -- "${path_GNU:-${path_UUTILS}/../gnu}")"
18+
path_GNULIB="$(readlink -fm -- "${path_GNULIB:-${path_UUTILS}/../gnulib}")"
19+
20+
echo "path_UUTILS='${path_UUTILS}'"
21+
echo "path_GNU='${path_GNU}'"
22+
echo "path_GNULIB='${path_GNULIB}'"
23+
24+
###
25+
26+
if test ! -d "${path_GNU}"; then
27+
echo "Could not find GNU (expected at '${path_GNU}')"
28+
echo "git clone https://github.com/coreutils/coreutils.git \"${path_GNU}\""
929
exit 1
1030
fi
11-
if test ! -d ../gnulib; then
12-
echo "Could not find ../gnulib"
13-
echo "git clone https://github.com/coreutils/gnulib.git gnulib"
31+
if test ! -d "${path_GNULIB}"; then
32+
echo "Could not find GnuLib (expected at '${path_GNULIB}')"
33+
echo "git clone https://github.com/coreutils/gnulib.git \"${path_GNULIB}\""
1434
exit 1
1535
fi
1636

37+
BUILD_PROFILE=${BUILD_PROFILE:-release}
38+
echo "BUILD_PROFILE='${BUILD_PROFILE}'"
1739

18-
pushd "$PWD"
19-
make PROFILE=release
20-
BUILDDIR="$PWD/target/release/"
21-
cp "${BUILDDIR}/install" "${BUILDDIR}/ginstall" # The GNU tests rename this script before running, to avoid confusion with the make target
22-
# Create *sum binaries
23-
for sum in b2sum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum
24-
do
25-
sum_path="${BUILDDIR}/${sum}"
26-
test -f "${sum_path}" || cp "${BUILDDIR}/hashsum" "${sum_path}"
27-
done
28-
test -f "${BUILDDIR}/[" || cp "${BUILDDIR}/test" "${BUILDDIR}/["
29-
popd
30-
GNULIB_SRCDIR="$PWD/../gnulib"
31-
pushd ../gnu/
40+
BUILD_DIR="${PWD}/target/${BUILD_PROFILE}/"
41+
echo "BUILD_DIR='${BUILD_DIR}'"
42+
43+
(
44+
cd "${PWD}"
45+
make "PROFILE=${BUILD_PROFILE}"
46+
cp "${BUILD_DIR}/install" "${BUILD_DIR}/ginstall" # The GNU tests rename this script before running, to avoid confusion with the make target
47+
# Create *sum binaries
48+
for sum in b2sum md5sum sha1sum sha224sum sha256sum sha384sum sha512sum
49+
do
50+
sum_path="${BUILD_DIR}/${sum}"
51+
test -f "${sum_path}" || cp "${BUILD_DIR}/hashsum" "${sum_path}"
52+
done
53+
test -f "${BUILD_DIR}/[" || cp "${BUILD_DIR}/test" "${BUILD_DIR}/["
54+
)
55+
56+
##
3257

58+
cd "${path_GNU}"
3359
# Any binaries that aren't built become `false` so their tests fail
3460
for binary in $(./build-aux/gen-lists-of-programs.sh --list-progs)
3561
do
36-
bin_path="${BUILDDIR}/${binary}"
37-
test -f "${bin_path}" || { echo "'${binary}' was not built with uutils, using the 'false' program"; cp "${BUILDDIR}/false" "${bin_path}"; }
62+
bin_path="${BUILD_DIR}/${binary}"
63+
test -f "${bin_path}" || { echo "'${binary}' was not built with uutils, using the 'false' program"; cp "${BUILD_DIR}/false" "${bin_path}"; }
3864
done
3965

40-
./bootstrap --gnulib-srcdir="$GNULIB_SRCDIR"
66+
./bootstrap --gnulib-srcdir="${path_GNULIB}"
4167
./configure --quiet --disable-gcc-warnings
4268
#Add timeout to to protect against hangs
4369
sed -i 's|^"\$@|/usr/bin/timeout 600 "\$@|' build-aux/test-driver
4470
# Change the PATH in the Makefile to test the uutils coreutils instead of the GNU coreutils
45-
sed -i "s/^[[:blank:]]*PATH=.*/ PATH='${BUILDDIR//\//\\/}\$(PATH_SEPARATOR)'\"\$\$PATH\" \\\/" Makefile
71+
sed -i "s/^[[:blank:]]*PATH=.*/ PATH='${BUILD_DIR//\//\\/}\$(PATH_SEPARATOR)'\"\$\$PATH\" \\\/" Makefile
4672
sed -i 's| tr | /usr/bin/tr |' tests/init.sh
4773
make -j "$(nproc)"
4874
# Generate the factor tests, so they can be fixed
@@ -117,7 +143,7 @@ sed -i -e "s|rm: cannot remove 'a/1'|rm: cannot remove 'a'|g" tests/rm/rm2.sh
117143

118144
sed -i -e "s|removed directory 'a/'|removed directory 'a'|g" tests/rm/v-slash.sh
119145

120-
test -f "${BUILDDIR}/getlimits" || cp src/getlimits "${BUILDDIR}"
146+
test -f "${BUILD_DIR}/getlimits" || cp src/getlimits "${BUILD_DIR}"
121147

122148
# When decoding an invalid base32/64 string, gnu writes everything it was able to decode until
123149
# it hit the decode error, while we don't write anything if the input is invalid.

util/run-gnu-test.sh

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,49 @@
1-
#!/bin/bash
2-
# `$0 [TEST]`
1+
#!/bin/sh
2+
# `run-gnu-test.bash [TEST]`
33
# run GNU test (or all tests if TEST is missing/null)
4+
#
5+
# BUILD_PROFILE == 'debug' | 'release' ## build profile used for *uutils* build; may be supplied by caller, defaults to 'debug'
6+
47
# spell-checker:ignore (env/vars) GNULIB SUBDIRS ; (utils) shellcheck
58

69
ME_dir="$(dirname -- "$(readlink -fm -- "$0")")"
710
REPO_main_dir="$(dirname -- "${ME_dir}")"
811

912
set -e
1013

11-
### * config (from environment with fallback defaults)
14+
BUILD_PROFILE=${BUILD_PROFILE:-release}
15+
echo "BUILD_PROFILE='${BUILD_PROFILE}'"
16+
17+
### * config (from environment with fallback defaults); note: GNU and GNULIB are expected to be sibling repo directories
1218

1319
path_UUTILS=${path_UUTILS:-${REPO_main_dir}}
14-
path_GNU=${path_GNU:-${path_UUTILS}/../gnu}
15-
path_GNULIB=${path_GNULIB:-${path_UUTILS}/../gnulib}
20+
path_GNU="$(readlink -fm -- "${path_GNU:-${path_UUTILS}/../gnu}")"
21+
path_GNULIB="$(readlink -fm -- "${path_GNULIB:-${path_UUTILS}/../gnulib}")"
22+
23+
echo "path_UUTILS='${path_UUTILS}'"
24+
echo "path_GNU='${path_GNU}'"
25+
echo "path_GNULIB='${path_GNULIB}'"
1626

1727
###
1828

19-
BUILD_DIR="$(realpath -- "${path_UUTILS}/target/release")"
20-
GNULIB_DIR="$(realpath -- "${path_GNULIB}")"
29+
BUILD_DIR="$(readlink -fm -- "${path_UUTILS}/target/${BUILD_PROFILE}")"
30+
GNULIB_DIR="$(readlink -fm -- "${path_GNULIB}")"
31+
32+
echo "BUILD_DIR='${BUILD_DIR}'"
33+
echo "GNULIB_DIR='${GNULIB_DIR}'"
2134

22-
export BUILD_DIR
23-
export GNULIB_DIR
35+
export BUILD_DIR GNULIB_DIR
2436

25-
pushd "$(realpath -- "${path_GNU}")"
37+
(
38+
cd "${path_GNU}"
2639

27-
export RUST_BACKTRACE=1
40+
export RUST_BACKTRACE=1
2841

29-
if test -n "$1"; then
30-
# if set, run only the test passed
31-
export RUN_TEST="TESTS=$1"
32-
fi
42+
if test -n "$1"; then
43+
# if set, run only the test passed
44+
export RUN_TEST="TESTS=$1"
45+
fi
3346

34-
#shellcheck disable=SC2086
35-
timeout -sKILL 2h make -j "$(nproc)" check $RUN_TEST SUBDIRS=. RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes VERBOSE=no || : # Kill after 4 hours in case something gets stuck in make
47+
#shellcheck disable=SC2086
48+
timeout -sKILL 2h make -j "$(nproc)" check $RUN_TEST SUBDIRS=. RUN_EXPENSIVE_TESTS=yes RUN_VERY_EXPENSIVE_TESTS=yes VERBOSE=no || : # Kill after 4 hours in case something gets stuck in make
49+
)

0 commit comments

Comments
 (0)