Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdaming committed Jul 15, 2024
1 parent 66d1a13 commit 8212deb
Show file tree
Hide file tree
Showing 23 changed files with 4,011 additions and 2,307 deletions.
5 changes: 2 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Prevents Maven wrapper from failing when launched from git bash on a Windows box
maven-wrapper.properties text eol=lf

*.sh text eol=lf
tcrw text eol=lf
5 changes: 5 additions & 0 deletions cpp/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmakew text eol=lf
ctestw text eol=lf
cpackw text eol=lf
*.sh text eol=lf

6 changes: 3 additions & 3 deletions cpp/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This setup script does the following:
- Create a build directory: ***Kata-MedianListOfLists/cpp/build***. All build-related files are generated under this directory.
- Download a copy of cmake compatible with your platform.
- Download the dependencies required to build and test the kata (such as GoogleTest).
- Generate the solution file ***Kata-MedianListOfLists.sln*** for **Visual Studio 2019** on Windows,
- Generate the solution file ***Kata-MedianListOfLists.sln*** for **Visual Studio 2022** on Windows,
or the project file ***Kata-MedianListOfLists.xcodeproj*** for **Xcode** on macOS.
- Run an initial build and test of the kata to ensure that everything is set up properly.

Expand Down Expand Up @@ -113,7 +113,7 @@ Refer to [Using TCR](#using-tcr) section for additional details about TCR and av
<a name="running-the-kata-from-visual-studio"/></a>
### Running the kata from Visual Studio

> ***Supported Versions***: Visual Studio 2019 or later
> ***Supported Versions***: Visual Studio 2022 or later
Open Visual Studio, choose `Open a project or solution`, navigate to
the location containing the cloned kata repository, and open the solution file:
Expand All @@ -133,7 +133,7 @@ TCR is provided as a command line utility running in a terminal.
You can run it from Visual Studio directly, through leveraging on its built-in terminal.

> ***Notes***
> - Supported Versions: Visual Studio 2019 or later
> - Supported Versions: Visual Studio 2022 or later
> - Visual Studio 2017 and earlier versions are not supported as they do not have a built-in terminal.
#### 1. Open the kata
Expand Down
3 changes: 3 additions & 0 deletions cpp/cmake/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version.txt text eol=lf
*.sh text eol=lf

226 changes: 226 additions & 0 deletions cpp/cmake/cmake-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 Murex
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set -u

base_dir="$(cd "$(dirname -- "$0")" && pwd)"
if [ -z "${CMAKEW_BASE_DIR+x}" ]; then CMAKEW_BASE_DIR="${base_dir}"; fi
if [ -z "${CMAKEW_CACHE_DIR+x}" ]; then CMAKEW_CACHE_DIR="$(dirname "${base_dir}")/.cmake"; fi
if [ -z "${CMAKEW_CMD+x}" ]; then CMAKEW_CMD="cmake"; fi

# ------------------------------------------------------------------------------
# cmake directory structure and information
# ------------------------------------------------------------------------------

CMAKEW_VERSION_FILE="${CMAKEW_BASE_DIR}/version.txt"

# ------------------------------------------------------------------------------
# Trace messages
# ------------------------------------------------------------------------------

print_info() {
message="$1"
printf "%b" "${message}\n" | while IFS= read -r line; do >&2 printf "%b" "\e[1;34m>>> ${line} \e[0m\n"; done
}

print_warning() {
message="$1"
printf "%b" "${message}\n" | while IFS= read -r line; do >&2 printf "%b" "\e[1;33m>>> ${line} \e[0m\n"; done
}

print_error() {
message="$1"
printf "%b" "${message}\n" | while IFS= read -r line; do >&2 printf "%b" "\e[1;31m>>> ${line} \e[0m\n"; done
}

print_horizontal_line() {
term_columns=$(tput cols)
repeated=$((term_columns - 5))
line=$(head -c "${repeated}" </dev/zero | tr '\0' '-')
print_info "$line"
}

# ------------------------------------------------------------------------------
# Download cmake from cmake website
# ------------------------------------------------------------------------------

download_cmake() {
version="$1"
os="$2"
arch="$3"
archive_extension="$4"
exe_path="$5"

# ----------------------------------------------------------------------------
# 1) create and enter cache directory
# ----------------------------------------------------------------------------

mkdir -p "${CMAKEW_CACHE_DIR}"
pushd "${CMAKEW_CACHE_DIR}" >/dev/null 2>/dev/null || return 1

# ----------------------------------------------------------------------------
# 2) download cmake archive
# ----------------------------------------------------------------------------

cmake_version="${version}"
cmake_expected_dir="cmake-${cmake_version}-${os}-${arch}"
cmake_expected_archive_file="${cmake_expected_dir}.${archive_extension}"
cmake_archive_url="http://github.com/Kitware/CMake/releases/download/v${cmake_version}/${cmake_expected_archive_file}"
cmake_home="cmake-${os}-${arch}"

if ! [ -f "${cmake_expected_archive_file}" ]
then
print_info "downloading ${cmake_expected_archive_file}"
if ! curl -f -# -L "${cmake_archive_url}" -o "${cmake_expected_archive_file}"; then
print_error "failed to download ${cmake_archive_url}"
return 1
fi
fi

# ----------------------------------------------------------------------------
# 3) expand cmake archive
# ----------------------------------------------------------------------------

print_info "extracting cmake ${cmake_version}"
case "${archive_extension}" in
zip)
if ! unzip -q -o "${cmake_expected_archive_file}"; then
print_error "failed to expand ${cmake_expected_archive_file}"
return 1
fi
;;
tar.gz)
if ! tar zxf "${cmake_expected_archive_file}"; then
print_error "failed to expand ${cmake_expected_archive_file}"
return 1
fi
;;
*)
print_error "archive format ${archive_extension} is currently not supported"
exit 1
;;
esac

# ----------------------------------------------------------------------------
# 4) make the expanded archive the current version in cache
# ----------------------------------------------------------------------------

[ -d "${cmake_home}" ] && rm -Rf "${cmake_home}"
mv "${cmake_expected_dir}" "${cmake_home}"

popd >/dev/null 2>/dev/null || return 1
}

# ------------------------------------------------------------------------------
# Return expected cmake version
# ------------------------------------------------------------------------------

retrieve_expected_cmake_version() {
if [ -f "${CMAKEW_VERSION_FILE}" ]; then
expected_version=$(awk '{ print $2 }' < "${CMAKEW_VERSION_FILE}")
# print_info "expected cmake version: ${expected_version}"
echo "${expected_version}"
return 0
else
print_error "version file not found: ${CMAKEW_VERSION_FILE}"
return 1
fi
}

# ------------------------------------------------------------------------------
# Return current cmake version
# ------------------------------------------------------------------------------

retrieve_current_cmake_version() {
exe_path="$1"
current_version=$("${exe_path}" --version | head -1 | awk '{ print $3 }')
# print_info "current cmake version: ${current_version}"
echo "${current_version}"
return 0
}

# ------------------------------------------------------------------------------
# Retrieve the path to the cmake command to be launched
# depending on local machine's OS and architecture
# ------------------------------------------------------------------------------

retrieve_command_path() {
case $(uname -s) in
Darwin)
os="macos"
arch="universal"
archive_extension="tar.gz"
cmake_bin_dir="CMake.app/Contents/bin"
cmd="${CMAKEW_CMD}"
;;
Linux)
os="linux"
arch="x86_64"
archive_extension="tar.gz"
cmake_bin_dir="bin"
cmd="${CMAKEW_CMD}"
;;
MINGW64_NT-*)
os="windows"
arch="x86_64"
archive_extension="zip"
cmake_bin_dir="bin"
cmd="${CMAKEW_CMD}.exe"
;;
*)
print_error "os $(uname -s) is currently not supported"
exit 1
;;
esac

# Expected cmake version
expected_version=$(retrieve_expected_cmake_version) || return 1

cmake_home="cmake-${os}-${arch}"
cmake_bin_path="${CMAKEW_CACHE_DIR}/${cmake_home}/${cmake_bin_dir}"
cmake_exe_path="${cmake_bin_path}/${cmd}"

file_missing=$(type "${cmake_exe_path}" >/dev/null 2>/dev/null; echo $?)
# If the file already exists, check its current version
version_mismatch=0
if [ "${file_missing}" -eq 0 ]; then
current_version=$(retrieve_current_cmake_version "${cmake_exe_path}")
version_mismatch="$( [ "${current_version}" = "${expected_version}" ]; echo $? )"
fi
# If the file does not exist or if versions do not match, download it from CMAKE GitHub repository
if [ "${file_missing}" -ne 0 ] || [ "${version_mismatch}" -ne 0 ]; then
download_cmake "${expected_version}" "${os}" "${arch}" "${archive_extension}" "${cmake_bin_path}" || return 1
fi

echo "${cmake_exe_path}"
return 0
}

# ------------------------------------------------------------------------------
# Main
# ------------------------------------------------------------------------------

cmd_path="$(retrieve_command_path)"
# shellcheck disable=SC2181
[ $? -ne 0 ] && print_error "aborting" && exit 1
# shellcheck disable=SC2086
"${cmd_path}" "$@"
14 changes: 14 additions & 0 deletions cpp/cmake/set-options.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

CMAKE_BUILD_DIR="./build"
CMAKE_CONFIG="Debug"
case $(uname -s) in
Darwin) CMAKE_GENERATOR='Xcode';;
Linux) CMAKE_GENERATOR='Unix Makefiles';;
MINGW64_NT-*) CMAKE_GENERATOR='Visual Studio 17 2022';;
*) echo "os $(uname -s) not supported." && exit 1;;
esac

export CMAKE_BUILD_DIR
export CMAKE_CONFIG
export CMAKE_GENERATOR
1 change: 1 addition & 0 deletions cpp/cmake/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake 3.30.0
28 changes: 28 additions & 0 deletions cpp/cmakew
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
#
# Copyright (c) 2024 Murex
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

base_dir="$(cd "$(dirname -- "$0")" && pwd)"
CMAKEW_BASE_DIR="${base_dir}/cmake"
CMAKEW_CACHE_DIR="${base_dir}/.cmake"
CMAKEW_CMD="$(basename "$0" | sed -e 's/w$//g')"

. "${CMAKEW_BASE_DIR}/cmake-wrapper.sh"
Loading

0 comments on commit 8212deb

Please sign in to comment.