Skip to content

Commit 31cdc84

Browse files
committed
CI: Make download tool detection lazy
The download tool check was failing scripts that source common.sh but don't use download functions (like riscv-tests.sh). This changes to lazy initialization - only check for curl/wget when a download function is actually called. This prevents unnecessary failures in scripts that source common.sh for other utilities like PARALLEL or check_platform().
1 parent 91cd99c commit 31cdc84

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

.ci/common.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,28 @@ fi
2424
# Universal download utility with curl/wget compatibility
2525
# Provides consistent interface regardless of which tool is available
2626

27-
# Detect available download tool
28-
if command -v curl > /dev/null 2>&1; then
29-
DOWNLOAD_TOOL="curl"
30-
elif command -v wget > /dev/null 2>&1; then
31-
DOWNLOAD_TOOL="wget"
32-
else
33-
echo "Error: Neither curl nor wget is available" >&2
34-
exit 1
35-
fi
27+
# Detect available download tool (lazy initialization)
28+
detect_download_tool()
29+
{
30+
if [ -n "${DOWNLOAD_TOOL:-}" ]; then
31+
return 0
32+
fi
33+
34+
if command -v curl > /dev/null 2>&1; then
35+
DOWNLOAD_TOOL="curl"
36+
elif command -v wget > /dev/null 2>&1; then
37+
DOWNLOAD_TOOL="wget"
38+
else
39+
echo "Error: Neither curl nor wget is available" >&2
40+
return 1
41+
fi
42+
}
3643

3744
# Download to stdout
3845
# Usage: download_to_stdout <url>
3946
download_to_stdout()
4047
{
48+
detect_download_tool || return 1
4149
local url="$1"
4250
case "$DOWNLOAD_TOOL" in
4351
curl)
@@ -53,6 +61,7 @@ download_to_stdout()
5361
# Usage: download_to_file <url> <output_file>
5462
download_to_file()
5563
{
64+
detect_download_tool || return 1
5665
local url="$1"
5766
local output="$2"
5867
case "$DOWNLOAD_TOOL" in
@@ -69,6 +78,7 @@ download_to_file()
6978
# Usage: download_with_headers <url> <header1> <header2> ...
7079
download_with_headers()
7180
{
81+
detect_download_tool || return 1
7282
local url="$1"
7383
shift
7484
local headers=()
@@ -93,6 +103,7 @@ download_with_headers()
93103
# Usage: download_silent <url>
94104
download_silent()
95105
{
106+
detect_download_tool || return 1
96107
local url="$1"
97108
case "$DOWNLOAD_TOOL" in
98109
curl)
@@ -108,6 +119,7 @@ download_silent()
108119
# Usage: download_with_progress <url> <output_file>
109120
download_with_progress()
110121
{
122+
detect_download_tool || return 1
111123
local url="$1"
112124
local output="$2"
113125
case "$DOWNLOAD_TOOL" in
@@ -125,6 +137,7 @@ download_with_progress()
125137
# Returns: 0 if accessible, 1 otherwise
126138
check_url()
127139
{
140+
detect_download_tool || return 1
128141
local url="$1"
129142
case "$DOWNLOAD_TOOL" in
130143
curl)

0 commit comments

Comments
 (0)