113498266Sopenharmony_ci#!/usr/bin/env bash
213498266Sopenharmony_ci#***************************************************************************
313498266Sopenharmony_ci#                                  _   _ ____  _
413498266Sopenharmony_ci#  Project                     ___| | | |  _ \| |
513498266Sopenharmony_ci#                             / __| | | | |_) | |
613498266Sopenharmony_ci#                            | (__| |_| |  _ <| |___
713498266Sopenharmony_ci#                             \___|\___/|_| \_\_____|
813498266Sopenharmony_ci#
913498266Sopenharmony_ci# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
1013498266Sopenharmony_ci#
1113498266Sopenharmony_ci# This software is licensed as described in the file COPYING, which
1213498266Sopenharmony_ci# you should have received as part of this distribution. The terms
1313498266Sopenharmony_ci# are also available at https://curl.se/docs/copyright.html.
1413498266Sopenharmony_ci#
1513498266Sopenharmony_ci# You may opt to use, copy, modify, merge, publish, distribute and/or sell
1613498266Sopenharmony_ci# copies of the Software, and permit persons to whom the Software is
1713498266Sopenharmony_ci# furnished to do so, under the terms of the COPYING file.
1813498266Sopenharmony_ci#
1913498266Sopenharmony_ci# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
2013498266Sopenharmony_ci# KIND, either express or implied.
2113498266Sopenharmony_ci#
2213498266Sopenharmony_ci# SPDX-License-Identifier: curl
2313498266Sopenharmony_ci#
2413498266Sopenharmony_ci###########################################################################
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci# shellcheck disable=SC3040,SC2039
2713498266Sopenharmony_ciset -eux; [ -n "${BASH:-}${ZSH_NAME:-}" ] && set -o pipefail
2813498266Sopenharmony_ci
2913498266Sopenharmony_ci# build
3013498266Sopenharmony_ci
3113498266Sopenharmony_ciif [ "${APPVEYOR_BUILD_WORKER_IMAGE}" = 'Visual Studio 2022' ]; then
3213498266Sopenharmony_ci  openssl_root_win='C:/OpenSSL-v30-Win64'
3313498266Sopenharmony_cielse
3413498266Sopenharmony_ci  openssl_root_win='C:/OpenSSL-v111-Win64'
3513498266Sopenharmony_cifi
3613498266Sopenharmony_ciopenssl_root="$(cygpath -u "${openssl_root_win}")"
3713498266Sopenharmony_ci
3813498266Sopenharmony_ciif [ "${BUILD_SYSTEM}" = 'CMake' ]; then
3913498266Sopenharmony_ci  options=''
4013498266Sopenharmony_ci  [[ "${TARGET:-}" = *'ARM64'* ]] && SKIP_RUN='ARM64 architecture'
4113498266Sopenharmony_ci  [ "${OPENSSL}" = 'ON' ] && options+=" -DOPENSSL_ROOT_DIR=${openssl_root_win}"
4213498266Sopenharmony_ci  [ "${OPENSSL}" = 'ON' ] && options+=" -DOPENSSL_ROOT_DIR=${openssl_root_win}"
4313498266Sopenharmony_ci  [ "${PRJ_CFG}" = 'Debug' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG='
4413498266Sopenharmony_ci  [ "${PRJ_CFG}" = 'Release' ] && options+=' -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE='
4513498266Sopenharmony_ci  [[ "${PRJ_GEN}" = *'Visual Studio'* ]] && options+=' -DCMAKE_VS_GLOBALS=TrackFileAccess=false'
4613498266Sopenharmony_ci  # Fails to run without this run due to missing MSVCR90.dll
4713498266Sopenharmony_ci  [ "${PRJ_GEN}" = 'Visual Studio 9 2008' ] && options+=' -DCURL_STATIC_CRT=ON'
4813498266Sopenharmony_ci  # shellcheck disable=SC2086
4913498266Sopenharmony_ci  cmake -B _bld "-G${PRJ_GEN}" ${TARGET:-} ${options} \
5013498266Sopenharmony_ci    "-DCURL_USE_OPENSSL=${OPENSSL}" \
5113498266Sopenharmony_ci    "-DCURL_USE_SCHANNEL=${SCHANNEL}" \
5213498266Sopenharmony_ci    "-DHTTP_ONLY=${HTTP_ONLY}" \
5313498266Sopenharmony_ci    "-DBUILD_SHARED_LIBS=${SHARED}" \
5413498266Sopenharmony_ci    "-DBUILD_TESTING=${TESTING}" \
5513498266Sopenharmony_ci    "-DENABLE_WEBSOCKETS=${WEBSOCKETS:-}" \
5613498266Sopenharmony_ci    "-DCMAKE_UNITY_BUILD=${UNITY}" \
5713498266Sopenharmony_ci    '-DCURL_WERROR=ON' \
5813498266Sopenharmony_ci    "-DENABLE_DEBUG=${DEBUG}" \
5913498266Sopenharmony_ci    "-DENABLE_UNICODE=${ENABLE_UNICODE}" \
6013498266Sopenharmony_ci    '-DCMAKE_INSTALL_PREFIX=C:/CURL' \
6113498266Sopenharmony_ci    "-DCMAKE_BUILD_TYPE=${PRJ_CFG}"
6213498266Sopenharmony_ci  # shellcheck disable=SC2086
6313498266Sopenharmony_ci  cmake --build _bld --config "${PRJ_CFG}" --parallel 2 --clean-first -- ${BUILD_OPT:-}
6413498266Sopenharmony_ci  if [ "${SHARED}" = 'ON' ]; then
6513498266Sopenharmony_ci    cp -f -p _bld/lib/*.dll _bld/src/
6613498266Sopenharmony_ci  fi
6713498266Sopenharmony_ci  if [ "${OPENSSL}" = 'ON' ]; then
6813498266Sopenharmony_ci    cp -f -p "${openssl_root}"/*.dll _bld/src/
6913498266Sopenharmony_ci  fi
7013498266Sopenharmony_ci  curl='_bld/src/curl.exe'
7113498266Sopenharmony_cielif [ "${BUILD_SYSTEM}" = 'VisualStudioSolution' ]; then
7213498266Sopenharmony_ci  (
7313498266Sopenharmony_ci    cd projects
7413498266Sopenharmony_ci    ./generate.bat "${VC_VERSION}"
7513498266Sopenharmony_ci    msbuild.exe -maxcpucount "-property:Configuration=${PRJ_CFG}" "Windows/${VC_VERSION}/curl-all.sln"
7613498266Sopenharmony_ci  )
7713498266Sopenharmony_ci  curl="build/Win32/${VC_VERSION}/${PRJ_CFG}/curld.exe"
7813498266Sopenharmony_cielif [ "${BUILD_SYSTEM}" = 'winbuild_vs2015' ]; then
7913498266Sopenharmony_ci  ./buildconf.bat
8013498266Sopenharmony_ci  (
8113498266Sopenharmony_ci    cd winbuild
8213498266Sopenharmony_ci    cat << EOF > _make.bat
8313498266Sopenharmony_ci      call "C:/Program Files/Microsoft SDKs/Windows/v7.1/Bin/SetEnv.cmd" /x64
8413498266Sopenharmony_ci      call "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat" x86_amd64
8513498266Sopenharmony_ci      nmake -f Makefile.vc mode=dll VC=14 "SSL_PATH=${openssl_root_win}" WITH_SSL=dll MACHINE=x64 DEBUG=${DEBUG} ENABLE_UNICODE=${ENABLE_UNICODE}
8613498266Sopenharmony_ciEOF
8713498266Sopenharmony_ci    ./_make.bat
8813498266Sopenharmony_ci    rm _make.bat
8913498266Sopenharmony_ci  )
9013498266Sopenharmony_ci  curl="builds/libcurl-vc14-x64-${PATHPART}-dll-ssl-dll-ipv6-sspi/bin/curl.exe"
9113498266Sopenharmony_cielif [ "${BUILD_SYSTEM}" = 'winbuild_vs2017' ]; then
9213498266Sopenharmony_ci  ./buildconf.bat
9313498266Sopenharmony_ci  (
9413498266Sopenharmony_ci    cd winbuild
9513498266Sopenharmony_ci    cat << EOF > _make.bat
9613498266Sopenharmony_ci      call "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Auxiliary/Build/vcvars64.bat"
9713498266Sopenharmony_ci      nmake -f Makefile.vc mode=dll VC=14.10 "SSL_PATH=${openssl_root_win}" WITH_SSL=dll MACHINE=x64 DEBUG=${DEBUG} ENABLE_UNICODE=${ENABLE_UNICODE}
9813498266Sopenharmony_ciEOF
9913498266Sopenharmony_ci    ./_make.bat
10013498266Sopenharmony_ci    rm _make.bat
10113498266Sopenharmony_ci  )
10213498266Sopenharmony_ci  curl="builds/libcurl-vc14.10-x64-${PATHPART}-dll-ssl-dll-ipv6-sspi/bin/curl.exe"
10313498266Sopenharmony_cielif [ "${BUILD_SYSTEM}" = 'autotools' ]; then
10413498266Sopenharmony_ci  autoreconf -fi
10513498266Sopenharmony_ci  (
10613498266Sopenharmony_ci    mkdir _bld
10713498266Sopenharmony_ci    cd _bld
10813498266Sopenharmony_ci    # shellcheck disable=SC2086
10913498266Sopenharmony_ci    ../configure ${CONFIG_ARGS:-}
11013498266Sopenharmony_ci    make -j2 V=1
11113498266Sopenharmony_ci    make -j2 V=1 examples
11213498266Sopenharmony_ci    cd tests
11313498266Sopenharmony_ci    make -j2 V=1
11413498266Sopenharmony_ci  )
11513498266Sopenharmony_ci  curl='_bld/src/curl.exe'
11613498266Sopenharmony_cifi
11713498266Sopenharmony_ci
11813498266Sopenharmony_cifind . -name '*.exe' -o -name '*.dll'
11913498266Sopenharmony_ciif [ -z "${SKIP_RUN:-}" ]; then
12013498266Sopenharmony_ci  "${curl}" --version
12113498266Sopenharmony_cielse
12213498266Sopenharmony_ci  echo "Skip running curl.exe. Reason: ${SKIP_RUN}"
12313498266Sopenharmony_cifi
12413498266Sopenharmony_ci
12513498266Sopenharmony_ciif false; then
12613498266Sopenharmony_ci  for log in CMakeFiles/CMakeConfigureLog.yaml CMakeFiles/CMakeOutput.log CMakeFiles/CMakeError.log; do
12713498266Sopenharmony_ci    [ -r "_bld/${log}" ] && cat "_bld/${log}"
12813498266Sopenharmony_ci  done
12913498266Sopenharmony_cifi
13013498266Sopenharmony_ci
13113498266Sopenharmony_ciif [ "${TESTING}" = 'ON' ] && [ "${BUILD_SYSTEM}" = 'CMake' ]; then
13213498266Sopenharmony_ci  cmake --build _bld --config "${PRJ_CFG}" --parallel 2 --target testdeps
13313498266Sopenharmony_cifi
13413498266Sopenharmony_ci
13513498266Sopenharmony_ci# test
13613498266Sopenharmony_ci
13713498266Sopenharmony_ciif [ "${TESTING}" = 'ON' ]; then
13813498266Sopenharmony_ci  export TFLAGS=''
13913498266Sopenharmony_ci  if [ -x "$(cygpath -u "${WINDIR}/System32/curl.exe")" ]; then
14013498266Sopenharmony_ci    TFLAGS+=" -ac $(cygpath -u "${WINDIR}/System32/curl.exe")"
14113498266Sopenharmony_ci  elif [ -x "$(cygpath -u "C:/msys64/usr/bin/curl.exe")" ]; then
14213498266Sopenharmony_ci    TFLAGS+=" -ac $(cygpath -u "C:/msys64/usr/bin/curl.exe")"
14313498266Sopenharmony_ci  fi
14413498266Sopenharmony_ci  TFLAGS+=" ${DISABLED_TESTS:-}"
14513498266Sopenharmony_ci  if [ "${BUILD_SYSTEM}" = 'CMake' ]; then
14613498266Sopenharmony_ci    ls _bld/lib/*.dll >/dev/null 2>&1 && cp -f -p _bld/lib/*.dll _bld/tests/libtest/
14713498266Sopenharmony_ci    cmake --build _bld --config "${PRJ_CFG}" --target test-ci
14813498266Sopenharmony_ci  elif [ "${BUILD_SYSTEM}" = 'autotools' ]; then
14913498266Sopenharmony_ci    (
15013498266Sopenharmony_ci      cd _bld
15113498266Sopenharmony_ci      make -j2 V=1 test-ci
15213498266Sopenharmony_ci    )
15313498266Sopenharmony_ci  else
15413498266Sopenharmony_ci    (
15513498266Sopenharmony_ci      TFLAGS="-a -p !flaky -r -rm ${TFLAGS}"
15613498266Sopenharmony_ci      cd _bld/tests
15713498266Sopenharmony_ci      ./runtests.pl
15813498266Sopenharmony_ci    )
15913498266Sopenharmony_ci  fi
16013498266Sopenharmony_cifi
161