Commit f666e716 authored by Mislav Marohnić's avatar Mislav Marohnić Committed by GitHub
Browse files

Merge pull request #965 from yyuu/workaround-aria2c-stdout

`aria2c` doesn't support writing remote content to stdout
parents 1a37ab18 6baed1ff
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -313,11 +313,16 @@ http() {
}

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

http_get_aria2c() {
  aria2c -o "${2:--}" ${ARIA2_OPTS} "$1"
  local out="${2:-$(mktemp "out.XXXXXX")}"
  if aria2c --allow-overwrite=true --no-conf=true -o "${out}" ${ARIA2_OPTS} "$1" >&4; then
    [ -n "$2" ] || cat "${out}"
  else
    false
  fi
}

http_head_curl() {
+2 −1
Original line number Diff line number Diff line
@@ -8,9 +8,10 @@ export CC=cc
export -n RUBY_CONFIGURE_OPTS

setup() {
  ensure_not_found_in_path aria2c
  mkdir -p "$INSTALL_ROOT"
  stub md5 false
  stub aria2c false
  stub curl false
}

executable() {
+13 −12
Original line number Diff line number Diff line
@@ -3,27 +3,28 @@
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH="$TMP/cache"
export RUBY_BUILD_ARIA2_OPTS=
export RUBY_BUILD_CURL_OPTS=

setup() {
  ensure_not_found_in_path aria2c
  mkdir "$RUBY_BUILD_CACHE_PATH"
}


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

  install_fixture definitions/without-checksum

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

  unstub aria2c
  unstub curl
}


@test "cached package without checksum" {
  stub aria2c
  stub curl

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

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

  unstub aria2c
  unstub curl
}


@test "cached package with valid checksum" {
  stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
  stub aria2c
  stub curl

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

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

  unstub aria2c
  unstub curl
  unstub shasum
}

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

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

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

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

  unstub aria2c
  unstub curl
  unstub shasum
}


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

  export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"

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

  unstub aria2c
  unstub curl
}
+18 −18
Original line number Diff line number Diff line
@@ -3,107 +3,107 @@
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=
export RUBY_BUILD_ARIA2_OPTS=
export RUBY_BUILD_CURL_OPTS=


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

  install_fixture definitions/without-checksum

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

  unstub aria2c
  unstub curl
}


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

  install_fixture definitions/with-checksum

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

  unstub aria2c
  unstub curl
  unstub shasum
}


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

  install_fixture definitions/with-invalid-checksum

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

  unstub aria2c
  unstub curl
  unstub shasum
}


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

  install_fixture definitions/with-checksum

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

  unstub aria2c
  unstub curl
  unstub shasum
}


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

  install_fixture definitions/with-md5-checksum

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

  unstub aria2c
  unstub curl
  unstub md5
}


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

  install_fixture definitions/with-md5-checksum

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

  unstub aria2c
  unstub curl
  unstub md5
}


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

  install_fixture definitions/with-checksum

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

  unstub aria2c
  unstub curl
  unstub shasum
}

@test "existing tarball in build location is reused" {
  stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
  stub aria2c false
  stub curl false
  stub wget false

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

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

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

  run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#checksum_of_unexpected_length" copy
+17 −1
Original line number Diff line number Diff line
@@ -3,14 +3,16 @@
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=
export RUBY_BUILD_ARIA2_OPTS=

setup() {
  ensure_not_found_in_path aria2c
  export RUBY_BUILD_BUILD_PATH="${TMP}/source"
  mkdir -p "${RUBY_BUILD_BUILD_PATH}"
}

@test "failed download displays error message" {
  stub aria2c false
  stub curl false

  install_fixture definitions/without-checksum
  assert_failure
@@ -18,6 +20,20 @@ setup() {
  assert_output_contains "error: failed to download package-1.0.0.tar.gz"
}

@test "using aria2c if available" {
  stub aria2c "--allow-overwrite=true --no-conf=true -o * http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$4"

  install_fixture definitions/without-checksum
  assert_success
  assert_output <<OUT
Downloading package-1.0.0.tar.gz...
-> http://example.com/packages/package-1.0.0.tar.gz
Installing package-1.0.0...
Installed package-1.0.0 to ${TMP}/install
OUT
  unstub aria2c
}

@test "fetching from git repository" {
  stub git "clone --depth 1 --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"

Loading