Skip to content

Commit f666e71

Browse files
authored
Merge pull request #965 from yyuu/workaround-aria2c-stdout
`aria2c` doesn't support writing remote content to stdout
2 parents 1a37ab1 + 6baed1f commit f666e71

9 files changed

+112
-54
lines changed

Diff for: bin/ruby-build

+7-2
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,16 @@ http() {
313313
}
314314

315315
http_head_aria2c() {
316-
aria2c --dry-run ${ARIA2_OPTS} "$1" >&4 2>&1
316+
aria2c --dry-run --no-conf=true ${ARIA2_OPTS} "$1" >&4 2>&1
317317
}
318318

319319
http_get_aria2c() {
320-
aria2c -o "${2:--}" ${ARIA2_OPTS} "$1"
320+
local out="${2:-$(mktemp "out.XXXXXX")}"
321+
if aria2c --allow-overwrite=true --no-conf=true -o "${out}" ${ARIA2_OPTS} "$1" >&4; then
322+
[ -n "$2" ] || cat "${out}"
323+
else
324+
false
325+
fi
321326
}
322327

323328
http_head_curl() {

Diff for: test/build.bats

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ export CC=cc
88
export -n RUBY_CONFIGURE_OPTS
99

1010
setup() {
11+
ensure_not_found_in_path aria2c
1112
mkdir -p "$INSTALL_ROOT"
1213
stub md5 false
13-
stub aria2c false
14+
stub curl false
1415
}
1516

1617
executable() {

Diff for: test/cache.bats

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
load test_helper
44
export RUBY_BUILD_SKIP_MIRROR=1
55
export RUBY_BUILD_CACHE_PATH="$TMP/cache"
6-
export RUBY_BUILD_ARIA2_OPTS=
6+
export RUBY_BUILD_CURL_OPTS=
77

88
setup() {
9+
ensure_not_found_in_path aria2c
910
mkdir "$RUBY_BUILD_CACHE_PATH"
1011
}
1112

1213

1314
@test "packages are saved to download cache" {
14-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
15+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
1516

1617
install_fixture definitions/without-checksum
1718

1819
assert_success
1920
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
2021

21-
unstub aria2c
22+
unstub curl
2223
}
2324

2425

2526
@test "cached package without checksum" {
26-
stub aria2c
27+
stub curl
2728

2829
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
2930

@@ -32,13 +33,13 @@ setup() {
3233
assert_success
3334
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
3435

35-
unstub aria2c
36+
unstub curl
3637
}
3738

3839

3940
@test "cached package with valid checksum" {
4041
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
41-
stub aria2c
42+
stub curl
4243

4344
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
4445

@@ -48,7 +49,7 @@ setup() {
4849
assert [ -x "${INSTALL_ROOT}/bin/package" ]
4950
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
5051

51-
unstub aria2c
52+
unstub curl
5253
unstub shasum
5354
}
5455

@@ -58,8 +59,8 @@ setup() {
5859
local checksum="ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
5960

6061
stub shasum true "echo invalid" "echo $checksum"
61-
stub aria2c "--dry-run * : true" \
62-
"-o * https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$2"
62+
stub curl "-*I* : true" \
63+
"-q -o * -*S* https://?*/$checksum : cp $FIXTURE_ROOT/package-1.0.0.tar.gz \$3"
6364

6465
touch "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz"
6566

@@ -70,13 +71,13 @@ setup() {
7071
assert [ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
7172
assert diff -q "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" "${FIXTURE_ROOT}/package-1.0.0.tar.gz"
7273

73-
unstub aria2c
74+
unstub curl
7475
unstub shasum
7576
}
7677

7778

7879
@test "nonexistent cache directory is ignored" {
79-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
80+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
8081

8182
export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"
8283

@@ -86,5 +87,5 @@ setup() {
8687
assert [ -x "${INSTALL_ROOT}/bin/package" ]
8788
refute [ -d "$RUBY_BUILD_CACHE_PATH" ]
8889

89-
unstub aria2c
90+
unstub curl
9091
}

Diff for: test/checksum.bats

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,107 +3,107 @@
33
load test_helper
44
export RUBY_BUILD_SKIP_MIRROR=1
55
export RUBY_BUILD_CACHE_PATH=
6-
export RUBY_BUILD_ARIA2_OPTS=
6+
export RUBY_BUILD_CURL_OPTS=
77

88

99
@test "package URL without checksum" {
10-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
10+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
1111

1212
install_fixture definitions/without-checksum
1313

1414
assert_success
1515
assert [ -x "${INSTALL_ROOT}/bin/package" ]
1616

17-
unstub aria2c
17+
unstub curl
1818
}
1919

2020

2121
@test "package URL with valid checksum" {
2222
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
23-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
23+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
2424

2525
install_fixture definitions/with-checksum
2626

2727
assert_success
2828
assert [ -x "${INSTALL_ROOT}/bin/package" ]
2929

30-
unstub aria2c
30+
unstub curl
3131
unstub shasum
3232
}
3333

3434

3535
@test "package URL with invalid checksum" {
3636
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
37-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
37+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
3838

3939
install_fixture definitions/with-invalid-checksum
4040

4141
assert_failure
4242
refute [ -f "${INSTALL_ROOT}/bin/package" ]
4343

44-
unstub aria2c
44+
unstub curl
4545
unstub shasum
4646
}
4747

4848

4949
@test "package URL with checksum but no shasum support" {
5050
stub shasum false
51-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
51+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
5252

5353
install_fixture definitions/with-checksum
5454

5555
assert_success
5656
assert [ -x "${INSTALL_ROOT}/bin/package" ]
5757

58-
unstub aria2c
58+
unstub curl
5959
unstub shasum
6060
}
6161

6262

6363
@test "package URL with valid md5 checksum" {
6464
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
65-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
65+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
6666

6767
install_fixture definitions/with-md5-checksum
6868

6969
assert_success
7070
assert [ -x "${INSTALL_ROOT}/bin/package" ]
7171

72-
unstub aria2c
72+
unstub curl
7373
unstub md5
7474
}
7575

7676

7777
@test "package URL with md5 checksum but no md5 support" {
7878
stub md5 false
79-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
79+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
8080

8181
install_fixture definitions/with-md5-checksum
8282

8383
assert_success
8484
assert [ -x "${INSTALL_ROOT}/bin/package" ]
8585

86-
unstub aria2c
86+
unstub curl
8787
unstub md5
8888
}
8989

9090

9191
@test "package with invalid checksum" {
9292
stub shasum true "echo invalid"
93-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
93+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
9494

9595
install_fixture definitions/with-checksum
9696

9797
assert_failure
9898
refute [ -f "${INSTALL_ROOT}/bin/package" ]
9999

100-
unstub aria2c
100+
unstub curl
101101
unstub shasum
102102
}
103103

104104
@test "existing tarball in build location is reused" {
105105
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
106-
stub aria2c false
106+
stub curl false
107107
stub wget false
108108

109109
export -n RUBY_BUILD_CACHE_PATH
@@ -126,7 +126,7 @@ DEF
126126
stub shasum true \
127127
"echo invalid" \
128128
"echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
129-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
129+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
130130

131131
export -n RUBY_BUILD_CACHE_PATH
132132
export RUBY_BUILD_BUILD_PATH="${TMP}/build"
@@ -145,7 +145,7 @@ DEF
145145
}
146146

147147
@test "package URL with checksum of unexpected length" {
148-
stub aria2c "-o * http://example.com/* : cp $FIXTURE_ROOT/\${3##*/} \$2"
148+
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
149149

150150
run_inline_definition <<DEF
151151
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#checksum_of_unexpected_length" copy

Diff for: test/fetch.bats

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,37 @@
33
load test_helper
44
export RUBY_BUILD_SKIP_MIRROR=1
55
export RUBY_BUILD_CACHE_PATH=
6+
export RUBY_BUILD_ARIA2_OPTS=
67

78
setup() {
9+
ensure_not_found_in_path aria2c
810
export RUBY_BUILD_BUILD_PATH="${TMP}/source"
911
mkdir -p "${RUBY_BUILD_BUILD_PATH}"
1012
}
1113

1214
@test "failed download displays error message" {
13-
stub aria2c false
15+
stub curl false
1416

1517
install_fixture definitions/without-checksum
1618
assert_failure
1719
assert_output_contains "> http://example.com/packages/package-1.0.0.tar.gz"
1820
assert_output_contains "error: failed to download package-1.0.0.tar.gz"
1921
}
2022

23+
@test "using aria2c if available" {
24+
stub aria2c "--allow-overwrite=true --no-conf=true -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"
25+
26+
install_fixture definitions/without-checksum
27+
assert_success
28+
assert_output <<OUT
29+
Downloading package-1.0.0.tar.gz...
30+
-> http://example.com/packages/package-1.0.0.tar.gz
31+
Installing package-1.0.0...
32+
Installed package-1.0.0 to ${TMP}/install
33+
OUT
34+
unstub aria2c
35+
}
36+
2137
@test "fetching from git repository" {
2238
stub git "clone --depth 1 --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"
2339

Diff for: test/hooks.bats

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load test_helper
44

55
setup() {
6+
ensure_not_found_in_path aria2c
67
export RBENV_ROOT="${TMP}/rbenv"
78
export HOOK_PATH="${TMP}/i has hooks"
89
mkdir -p "$HOOK_PATH"

0 commit comments

Comments
 (0)