From 7aca1f932ab72ddea6ae2b0ea0288f6ebfcdb578 Mon Sep 17 00:00:00 2001 From: Laurent Cheylus Date: Mon, 1 Jan 2024 20:31:47 +0100 Subject: [PATCH] build-gnu.sh: modify script to be compatible with BSD OS - Define variables for GNU version of make, nproc, readlink and sed and use them on BSD. - In specific cases (option -z not available on BSD and with command /c), use GNU sed instead of BSD sed. - For xargs, --no-run-if-empty option is a GNU extension. Replace it by -r to be compatible with FreeBSD and OpenBSD xargs command. Signed-off-by: Laurent Cheylus --- util/build-gnu.sh | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/util/build-gnu.sh b/util/build-gnu.sh index c8bd908b0..5f851a9e2 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -2,12 +2,28 @@ # `build-gnu.bash` ~ builds GNU coreutils (from supplied sources) # -# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW baddecode submodules ; (vars/env) SRCDIR vdir rcexp xpart dired +# spell-checker:ignore (paths) abmon deref discrim eacces getlimits getopt ginstall inacc infloop inotify reflink ; (misc) INT_OFLOW OFLOW baddecode submodules ; (vars/env) SRCDIR vdir rcexp xpart dired OSTYPE ; (utils) gnproc greadlink gsed set -e +# Use GNU version for make, nproc, readlink and sed on *BSD +case "$OSTYPE" in + *bsd*) + MAKE="gmake" + NPROC="gnproc" + READLINK="greadlink" + SED="gsed" + ;; + *) + MAKE="make" + NPROC="nproc" + READLINK="readlink" + SED="sed" + ;; +esac + ME="${0}" -ME_dir="$(dirname -- "$(readlink -fm -- "${ME}")")" +ME_dir="$(dirname -- "$("${READLINK}" -fm -- "${ME}")")" REPO_main_dir="$(dirname -- "${ME_dir}")" # Default profile is 'debug' @@ -26,7 +42,7 @@ echo "UU_MAKE_PROFILE='${UU_MAKE_PROFILE}'" ### * config (from environment with fallback defaults); note: GNU is expected to be a sibling repo directory path_UUTILS=${path_UUTILS:-${REPO_main_dir}} -path_GNU="$(readlink -fm -- "${path_GNU:-${path_UUTILS}/../gnu}")" +path_GNU="$("${READLINK}" -fm -- "${path_GNU:-${path_UUTILS}/../gnu}")" ### @@ -78,7 +94,7 @@ if [ "$(uname)" == "Linux" ]; then export SELINUX_ENABLED=1 fi -make PROFILE="${UU_MAKE_PROFILE}" +"${MAKE}" PROFILE="${UU_MAKE_PROFILE}" cp "${UU_BUILD_DIR}/install" "${UU_BUILD_DIR}/ginstall" # The GNU tests rename this script before running, to avoid confusion with the make target # Create *sum binaries @@ -115,7 +131,7 @@ else sed -i 's| tr | /usr/bin/tr |' tests/init.sh # Use a better diff sed -i 's|diff -c|diff -u|g' tests/Coreutils.pm - make -j "$(nproc)" + "${MAKE}" -j "$("${NPROC}")" touch gnu-built fi @@ -135,7 +151,7 @@ t_max=36 # done # ) # for i in ${seq}; do -# make "tests/factor/t${i}.sh" +# "${MAKE}" "tests/factor/t${i}.sh" # done # cat # sed -i -e 's|^seq |/usr/bin/seq |' -e 's|sha1sum |/usr/bin/sha1sum |' tests/factor/t*.sh @@ -194,8 +210,8 @@ sed -i 's|timeout |'"${SYSTEM_TIMEOUT}"' |' tests/tail/follow-stdin.sh sed -i 's|\(^\s*\)seq \$|\1'"${SYSTEM_TIMEOUT}"' 0.1 seq \$|' tests/seq/seq-precision.sh tests/seq/seq-long-double.sh # Remove dup of /usr/bin/ and /usr/local/bin/ when executed several times -grep -rlE '/usr/bin/\s?/usr/bin' init.cfg tests/* | xargs --no-run-if-empty sed -Ei 's|/usr/bin/\s?/usr/bin/|/usr/bin/|g' -grep -rlE '/usr/local/bin/\s?/usr/local/bin' init.cfg tests/* | xargs --no-run-if-empty sed -Ei 's|/usr/local/bin/\s?/usr/local/bin/|/usr/local/bin/|g' +grep -rlE '/usr/bin/\s?/usr/bin' init.cfg tests/* | xargs -r sed -Ei 's|/usr/bin/\s?/usr/bin/|/usr/bin/|g' +grep -rlE '/usr/local/bin/\s?/usr/local/bin' init.cfg tests/* | xargs -r sed -Ei 's|/usr/local/bin/\s?/usr/local/bin/|/usr/local/bin/|g' #### Adjust tests to make them work with Rust/coreutils # in some cases, what we are doing in rust/coreutils is good (or better) @@ -275,7 +291,8 @@ sed -i -e "s/ginstall: creating directory/install: creating directory/g" tests/i # GNU doesn't support padding < -LONG_MAX # disable this test case -sed -i -Ez "s/\n([^\n#]*pad-3\.2[^\n]*)\n([^\n]*)\n([^\n]*)/\n# uutils\/numfmt supports padding = LONG_MIN\n#\1\n#\2\n#\3/" tests/misc/numfmt.pl +# Use GNU sed because option -z is not available on BSD sed +"${SED}" -i -Ez "s/\n([^\n#]*pad-3\.2[^\n]*)\n([^\n]*)\n([^\n]*)/\n# uutils\/numfmt supports padding = LONG_MIN\n#\1\n#\2\n#\3/" tests/misc/numfmt.pl # Update the GNU error message to match the one generated by clap sed -i -e "s/\$prog: multiple field specifications/error: The argument '--field ' was provided more than once, but cannot be used multiple times\n\nUsage: numfmt [OPTION]... [NUMBER]...\n\n\nFor more information try '--help'/g" tests/misc/numfmt.pl @@ -300,7 +317,8 @@ awk 'BEGIN {count=0} /compare exp out2/ && count < 6 {sub(/compare exp out2/, "g sed -i -e "s|44 45|48 49|" tests/ls/stat-failed.sh # small difference in the error message -sed -i -e "/ls: invalid argument 'XX' for 'time style'/,/Try 'ls --help' for more information\./c\ +# Use GNU sed for /c command +"${SED}" -i -e "/ls: invalid argument 'XX' for 'time style'/,/Try 'ls --help' for more information\./c\ ls: invalid --time-style argument 'XX'\nPossible values are: [\"full-iso\", \"long-iso\", \"iso\", \"locale\", \"+FORMAT (e.g., +%H:%M) for a 'date'-style format\"]\n\nFor more information try --help" tests/ls/time-style-diag.sh # disable two kind of tests: @@ -309,7 +327,8 @@ ls: invalid --time-style argument 'XX'\nPossible values are: [\"full-iso\", \"lo sed -i -e "s/env \$prog \$BEFORE \$opt > out2/env \$prog \$BEFORE \$opt > out2 #/" -e "s/env \$prog \$BEFORE \$opt AFTER > out3/env \$prog \$BEFORE \$opt AFTER > out3 #/" -e "s/compare exp out2/compare exp out2 #/" -e "s/compare exp out3/compare exp out3 #/" tests/help/help-version-getopt.sh # Add debug info + we have less syscall then GNU's. Adjust our check. -sed -i -e '/test \$n_stat1 = \$n_stat2 \\/c\ +# Use GNU sed for /c command +"${SED}" -i -e '/test \$n_stat1 = \$n_stat2 \\/c\ echo "n_stat1 = \$n_stat1"\n\ echo "n_stat2 = \$n_stat2"\n\ test \$n_stat1 -ge \$n_stat2 \\' tests/ls/stat-free-color.sh