Repository: apache/arrow
File: ci/scripts/install_vcpkg.sh (Shell)

Code before:

if [ "$#" -lt 1 ]; then
  echo "Usage: $0 ``<target-directory> [<vcpkg-version> [<vcpkg-ports-patch>]]"
  exit 1
fi

arrow_dir=$(cd -- "$(dirname -- "$0")/../.." && pwd -P)
default_vcpkg_ports_patch="${arrow_dir}/ci/vcpkg/ports.patch"
vcpkg_patch="${arrow_dir}/ci/vcpkg/vcpkg.patch"

vcpkg_destination=$1
vcpkg_version=${2:-}
vcpkg_ports_patch=${3:-$default_vcpkg_ports_patch}

if [ -z "${vcpkg_version}" ]; then
  vcpkg_version=$(source "${arrow_dir}/.env" && echo "$VCPKG")
fi

# reduce the fetched data using a shallow clone
git clone --shallow-since=2021-04-01 https://github.com/microsoft/vcpkg "${vcpkg_destination}"

pushd "${vcpkg_destination}"

git checkout "${vcpkg_version}"

if [ -f "${vcpkg_patch}" ]; then
  git apply --verbose --ignore-whitespace "${vcpkg_patch}"
  echo "Patch successfully applied to the VCPKG files!"
fi

if [[ "${OSTYPE:-}" == "msys" ]]; then
  ./bootstrap-vcpkg.bat -disableMetrics
else
  ./bootstrap-vcpkg.sh -disableMetrics
fi

if [ -f "${vcpkg_ports_patch}" ]; then
  git apply --verbose --ignore-whitespace "${vcpkg_ports_patch}"
  echo "Patch successfully applied to the VCPKG port files!"
fi

if [ -n "${GITHUB_TOKEN:-}" ] && \
     [ -n "${GITHUB_REPOSITORY_OWNER:-}" ] && \
     [ "${VCPKG_BINARY_SOURCES:-}" = "clear;nuget,GitHub,readwrite" ] ; then
  if type dnf 2>/dev/null; then
    dnf install -y epel-release
    dnf install -y mono-complete
  fi
  if type mono 2>/dev/null; then
    curl \
      --location \

Review comment (bug):
Why `-f`? Is the file doesn't exist, then probably our script or CI configuration is buggy and we should fix it.

Code after:

if [ "$#" -lt 1 ]; then
  echo "Usage: $0 ``<target-directory> [<vcpkg-version> [<vcpkg-ports-patch>]]"
  exit 1
fi

arrow_dir=$(cd -- "$(dirname -- "$0")/../.." && pwd -P)
default_vcpkg_ports_patch="${arrow_dir}/ci/vcpkg/ports.patch"
vcpkg_patch="${arrow_dir}/ci/vcpkg/vcpkg.patch"

vcpkg_destination=$1
vcpkg_version=${2:-}
vcpkg_ports_patch=${3:-$default_vcpkg_ports_patch}

if [ -z "${vcpkg_version}" ]; then
  vcpkg_version=$(source "${arrow_dir}/.env" && echo "$VCPKG")
fi

# reduce the fetched data using a shallow clone
git clone --shallow-since=2021-04-01 https://github.com/microsoft/vcpkg "${vcpkg_destination}"

pushd "${vcpkg_destination}"

git checkout "${vcpkg_version}"

git apply --verbose --ignore-whitespace "${vcpkg_patch}"
echo "Patch successfully applied to the VCPKG files!"

if [[ "${OSTYPE:-}" == "msys" ]]; then
  ./bootstrap-vcpkg.bat -disableMetrics
else
  ./bootstrap-vcpkg.sh -disableMetrics
fi

if [ -f "${vcpkg_ports_patch}" ]; then
  git apply --verbose --ignore-whitespace "${vcpkg_ports_patch}"
  echo "Patch successfully applied to the VCPKG port files!"
fi

if [ -n "${GITHUB_TOKEN:-}" ] && \
     [ -n "${GITHUB_REPOSITORY_OWNER:-}" ] && \
     [ "${VCPKG_BINARY_SOURCES:-}" = "clear;nuget,GitHub,readwrite" ] ; then
  if type dnf 2>/dev/null; then
    dnf install -y epel-release
    dnf install -y mono-complete
  fi
  if type mono 2>/dev/null; then
    curl \
      --location \
      --output "${vcpkg_destination}/nuget" \
      https://dist.nuget.org/win-x86-commandline/latest/nuget.exe