Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cmake format script #9723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ repos:
args: ['-fallback-style=none']
- id: cmake-format
name: cmake-format
entry: bash cpp/scripts/run-cmake-format.sh cmake-format
entry: ./cpp/scripts/run-cmake-format.sh cmake-format
language: python
types: [cmake]
# Note that pre-commit autoupdate does not update the versions
Expand All @@ -81,7 +81,7 @@ repos:
- cmake-format==0.6.11
- id: cmake-lint
name: cmake-lint
entry: bash cpp/scripts/run-cmake-format.sh cmake-lint
entry: ./cpp/scripts/run-cmake-format.sh cmake-lint
language: python
types: [cmake]
# Note that pre-commit autoupdate does not update the versions
Expand Down
32 changes: 23 additions & 9 deletions cpp/scripts/run-cmake-format.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# This script is a pre-commit hook that wraps cmakelang's cmake linters. The
# This script is a wrapper for cmakelang that may be used with pre-commit. The
# wrapping is necessary because RAPIDS libraries split configuration for
# cmakelang linters between a local config file and a second config file that's
# shared across all of RAPIDS via rapids-cmake. In order to keep it up to date
Expand All @@ -16,19 +16,33 @@
# config file at a nonstandard location, they may do so by setting the
# environment variable RAPIDS_CMAKE_FORMAT_FILE.
#
# While this script can be invoked directly (but only from the repo root since
# all paths are relative to that), it is advisable to instead use the
# pre-commit hooks via
# `pre-commit run (cmake-format)|(cmake-format)`.
# This script can be invoked directly anywhere within the project repository.
# Alternatively, it may be invoked as a pre-commit hook via
# `pre-commit run (cmake-format)|(cmake-lint)`.
#
# Usage:
# bash run-cmake-format.sh {cmake-format,cmake-lint} infile [infile ...]

# Note that pre-commit always runs from the root of the repository, so relative
# paths are automatically relative to the repo root.
status=0
if [ -z ${CUDF_ROOT:+PLACEHOLDER} ]; then
CUDF_BUILD_DIR=$(git rev-parse --show-toplevel 2>&1)/cpp/build
status=$?
else
CUDF_BUILD_DIR=${CUDF_ROOT}
fi

if ! [ ${status} -eq 0 ]; then
if [[ ${CUDF_BUILD_DIR} == *"not a git repository"* ]]; then
echo "This script must be run inside the cudf repository, or the CUDF_ROOT environment variable must be set."
else
echo "Script failed with unknown error attempting to determine project root:"
echo ${CUDF_BUILD_DIR}
fi
exit 1
fi

DEFAULT_FORMAT_FILE_LOCATIONS=(
"cpp/build/_deps/rapids-cmake-src/cmake-format-rapids-cmake.json"
"${CUDF_ROOT:-${HOME}}/_deps/rapids-cmake-src/cmake-format-rapids-cmake.json"
"${CUDF_BUILD_DIR:-${HOME}}/_deps/rapids-cmake-src/cmake-format-rapids-cmake.json"
"cpp/libcudf_kafka/build/_deps/rapids-cmake-src/cmake-format-rapids-cmake.json"
)

Expand Down