Skip to content

Commit 8689abd

Browse files
committed
Adding changes as per review comment.
1 parent b9c9f3a commit 8689abd

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

src/cpp/.devcontainer/reinstall-gcc.sh

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ fetch_gcc() {
5858
exit 1
5959
}
6060

61+
# Function to robustly download files with retries
62+
robust_wget() {
63+
local url="$1"
64+
local output="$2"
65+
local retries=5
66+
local wait_seconds=5
67+
68+
for ((i=1; i<=retries; i++)); do
69+
if wget -O "$output" "$url"; then
70+
return 0
71+
else
72+
echo "Attempt $i failed for $url. Retrying in $wait_seconds seconds..."
73+
sleep "$wait_seconds"
74+
fi
75+
done
76+
77+
echo "Failed to download $url after $retries attempts."
78+
exit 1
79+
}
80+
81+
cleanup() {
82+
echo "Cleaning up temporary files..."
83+
rm -rf "${build_dir:-}" "${GCC_SRC_DIR:-}"
84+
sudo apt-get clean
85+
}
86+
87+
# Trap EXIT signal to ensure cleanup runs
88+
trap cleanup EXIT
89+
6190
# Download GCC source and signature
6291
fetch_gcc "gcc-${GCC_VERSION}.tar.xz"
6392
fetch_gcc "gcc-${GCC_VERSION}.tar.xz.sig"
@@ -79,7 +108,8 @@ rm "gcc-${GCC_VERSION}.tar.xz" "gcc-${GCC_VERSION}.tar.xz.sig"
79108
cd "${GCC_SRC_DIR}"
80109
./contrib/download_prerequisites
81110
for f in config.guess config.sub; do
82-
wget -O "$f" "https://git.savannah.gnu.org/cgit/config.git/plain/$f?id=7d3d27baf8107b630586c962c057e22149653deb"
111+
#wget -O "$f" "https://git.savannah.gnu.org/cgit/config.git/plain/$f?id=7d3d27baf8107b630586c962c057e22149653deb"
112+
robust_wget "https://git.savannah.gnu.org/cgit/config.git/plain/$f?id=7d3d27baf8107b630586c962c057e22149653deb" "$f"
83113
find -mindepth 2 -name "$f" -exec cp -v "$f" '{}' ';'
84114
done
85115

@@ -103,9 +133,6 @@ sudo update-alternatives --install /usr/bin/gcov gcov ${GCC_INSTALL_DIR}/bin/gco
103133
sudo update-alternatives --install /usr/bin/gcov-dump gcov-dump ${GCC_INSTALL_DIR}/bin/gcov-dump 999
104134
sudo update-alternatives --install /usr/bin/gcov-tool gcov-tool ${GCC_INSTALL_DIR}/bin/gcov-tool 999
105135

106-
# Cleanup
107-
rm -rf "$build_dir" "${GCC_SRC_DIR}"
108-
sudo apt-get clean
109136

110137
# Verify installation
111138
echo "Verifying GCC installation..."

0 commit comments

Comments
 (0)