Skip to content
Merged
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
97 changes: 7 additions & 90 deletions util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,84 +11,6 @@ export PROFILE
path_UUTILS=${path_UUTILS:-${REPO_main_dir}}
path_GNU="${path_GNU:-${path_UUTILS}/../gnu}"

retry_attempts() {
local attempts="${GNU_TAR_SETUP_ATTEMPTS:-3}"
local delay="${GNU_TAR_SETUP_RETRY_DELAY:-30}"
local description="${1}"
shift
local attempt=1
local status=0

if [[ ! "${attempts}" =~ ^[1-9][0-9]*$ ]]; then
echo "GNU_TAR_SETUP_ATTEMPTS must be a positive integer, got: ${attempts}" >&2
return 1
fi

if [[ ! "${delay}" =~ ^[1-9][0-9]*$ ]]; then
echo "GNU_TAR_SETUP_RETRY_DELAY must be a positive integer, got: ${delay}" >&2
return 1
fi

while (( attempt <= attempts )); do
if "$@"; then
return 0
else
status=$?
fi

if (( attempt == attempts )); then
echo "Failed to ${description} after ${attempts} attempts." >&2
return "${status}"
fi

echo "Failed to ${description} (attempt ${attempt}/${attempts}); retrying in ${delay}s..." >&2
sleep "${delay}"
attempt=$(( attempt + 1 ))
delay=$(( delay * 2 ))
done
}

clone_gnu_tar() {
local attempts="${GNU_TAR_SETUP_ATTEMPTS:-3}"
local delay="${GNU_TAR_SETUP_RETRY_DELAY:-30}"
local attempt=1
local status=0

if [[ ! "${attempts}" =~ ^[1-9][0-9]*$ ]]; then
echo "GNU_TAR_SETUP_ATTEMPTS must be a positive integer, got: ${attempts}" >&2
return 1
fi

if [[ ! "${delay}" =~ ^[1-9][0-9]*$ ]]; then
echo "GNU_TAR_SETUP_RETRY_DELAY must be a positive integer, got: ${delay}" >&2
return 1
fi

if [[ -e "${path_GNU}" ]]; then
echo "Cannot clone GNU tar: ${path_GNU} exists but is not a git checkout." >&2
return 1
fi

while (( attempt <= attempts )); do
if git clone --recurse-submodules https://git.savannah.gnu.org/git/tar.git "${path_GNU}"; then
return 0
else
status=$?
fi

if (( attempt == attempts )); then
echo "Failed to clone GNU tar after ${attempts} attempts." >&2
return "${status}"
fi

echo "Failed to clone GNU tar (attempt ${attempt}/${attempts}); retrying in ${delay}s..." >&2
rm -rf -- "${path_GNU}"
sleep "${delay}"
attempt=$(( attempt + 1 ))
delay=$(( delay * 2 ))
done
}

echo "Building uutils tar..."
cd "${path_UUTILS}"
cargo build --profile="${PROFILE}" --bin tarapp
Expand All @@ -100,19 +22,14 @@ else
fi

# Symlink tarapp to tar so tests find it as 'tar'
ln -sf "${UU_BUILD_DIR}/tarapp" "${UU_BUILD_DIR}/tar"
echo "Created symlink ${UU_BUILD_DIR}/tar -> tarapp"
ln -svf "${UU_BUILD_DIR}/tarapp" "${UU_BUILD_DIR}/tar"

# Clone GNU tar if needed
if test ! -d "${path_GNU}/.git"; then
echo "Cloning GNU tar..."
clone_gnu_tar
# Extract GNU tar source if needed
if test ! -d "${path_GNU}/README"; then
echo "Extracting GNU tar..."
mkdir -p "${path_GNU}"
cd "${path_GNU}"
git checkout v1.35
retry_attempts "update GNU tar submodules" git submodule update --init --recursive

# Bootstrap requires gnulib and generates the configure script
./bootstrap --skip-po
curl -L https://ftpmirror.gnu.org/tar/tar-1.35.tar.xz | tar xJf - --strip-components=1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if we can upload a copy of the tarball do GitHub in our artifacts. It seems like we should cache this. Do you know if that's possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is possible. But I think we should have our own mirrors of all GPL projects and do that at there, not at this repo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://ftpmirror.gnu.org redirects to other mirror e.g. https://ftp.jaist.ac.jp/pub/GNU// . So I think load is not a problem.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For reliability I'd like to see us do that in another step. IT's also just good practice for supply chain security given the large number of mirrors, etc. (Not for this PR for sure, though)

This comment was marked as resolved.

fi

cd "${path_GNU}"
Expand All @@ -124,4 +41,4 @@ if [ ! -f Makefile ]; then
fi

echo "Building GNU tar (for test suite)..."
make -j"$(nproc)"
make -j"$(nproc 2>/dev/null || echo 2)"
Loading