From 7a2447ffa70880982f655d9e2ed49ff1f74fb83d Mon Sep 17 00:00:00 2001 From: James Xu Date: Sun, 18 Aug 2024 10:59:31 +0800 Subject: [PATCH] [GLUTEN-6900] Use clang-format-18 --- .github/workflows/code_style.yml | 4 +-- cpp/core/jni/JniCommon.h | 2 +- cpp/core/utils/ObjectStore.h | 2 +- cpp/core/utils/macros.h | 2 +- cpp/core/utils/qpl/qpl_codec.cc | 4 +-- .../operators/plannodes/RowVectorStream.h | 2 +- cpp/velox/tests/VeloxShuffleWriterTest.cc | 6 +--- dev/formatcppcode.sh | 30 +++++++++++++------ 8 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml index 8417264373a0..b08e06c0303a 100644 --- a/.github/workflows/code_style.yml +++ b/.github/workflows/code_style.yml @@ -36,9 +36,9 @@ jobs: steps: - uses: actions/checkout@v4 - name: Run clang-format style check for C/C++ - uses: jidicula/clang-format-action@v4.11.0 + uses: jidicula/clang-format-action@v4.13.0 with: - clang-format-version: '15' + clang-format-version: '18' check-path: ${{ matrix.path['check'] }} fallback-style: 'Google' # optional diff --git a/cpp/core/jni/JniCommon.h b/cpp/core/jni/JniCommon.h index 1d784f3a5eda..817624c8dcd1 100644 --- a/cpp/core/jni/JniCommon.h +++ b/cpp/core/jni/JniCommon.h @@ -237,7 +237,7 @@ class SafeNativeArray { private: SafeNativeArray(JNIEnv* env, JavaArrayType javaArray, JniNativeArrayType nativeArray) - : env_(env), javaArray_(javaArray), nativeArray_(nativeArray){}; + : env_(env), javaArray_(javaArray), nativeArray_(nativeArray) {}; JNIEnv* env_; JavaArrayType javaArray_; diff --git a/cpp/core/utils/ObjectStore.h b/cpp/core/utils/ObjectStore.h index 5a38a1af3331..1580035c8e1a 100644 --- a/cpp/core/utils/ObjectStore.h +++ b/cpp/core/utils/ObjectStore.h @@ -92,7 +92,7 @@ class ObjectStore { void release0(ResourceHandle handle); - ObjectStore(StoreHandle storeId) : storeId_(storeId){}; + ObjectStore(StoreHandle storeId) : storeId_(storeId) {}; StoreHandle storeId_; ResourceMap> store_; std::set aliveObjects_; diff --git a/cpp/core/utils/macros.h b/cpp/core/utils/macros.h index fef8ae1e75de..55a38ef600c1 100644 --- a/cpp/core/utils/macros.h +++ b/cpp/core/utils/macros.h @@ -105,4 +105,4 @@ #define TIME_NANO_TO_STRING(time) \ (time > 1e7 ? time / 1e6 : ((time > 1e4) ? time / 1e3 : time)) << (time > 1e7 ? "ms" : (time > 1e4 ? "us" : "ns")) -#define ROUND_TO_LINE(n, round) (((n) + (round)-1) & ~((round)-1)) +#define ROUND_TO_LINE(n, round) (((n) + (round) - 1) & ~((round) - 1)) diff --git a/cpp/core/utils/qpl/qpl_codec.cc b/cpp/core/utils/qpl/qpl_codec.cc index a1d6970b265c..39d626eb4eee 100644 --- a/cpp/core/utils/qpl/qpl_codec.cc +++ b/cpp/core/utils/qpl/qpl_codec.cc @@ -30,7 +30,7 @@ class HardwareCodecDeflateQpl { /// RET_ERROR stands for hardware codec fail,need fallback to software codec. static constexpr int64_t RET_ERROR = -1; - explicit HardwareCodecDeflateQpl(qpl_compression_levels compressionLevel) : compressionLevel_(compressionLevel){}; + explicit HardwareCodecDeflateQpl(qpl_compression_levels compressionLevel) : compressionLevel_(compressionLevel) {}; int64_t doCompressData(const uint8_t* source, uint32_t source_size, uint8_t* dest, uint32_t dest_size) const { uint32_t job_id; @@ -99,7 +99,7 @@ class HardwareCodecDeflateQpl { class SoftwareCodecDeflateQpl final { public: - explicit SoftwareCodecDeflateQpl(qpl_compression_levels compressionLevel) : compressionLevel_(compressionLevel){}; + explicit SoftwareCodecDeflateQpl(qpl_compression_levels compressionLevel) : compressionLevel_(compressionLevel) {}; ~SoftwareCodecDeflateQpl() { if (swJob) { diff --git a/cpp/velox/operators/plannodes/RowVectorStream.h b/cpp/velox/operators/plannodes/RowVectorStream.h index c72e9137f4a4..91a378e9780f 100644 --- a/cpp/velox/operators/plannodes/RowVectorStream.h +++ b/cpp/velox/operators/plannodes/RowVectorStream.h @@ -88,7 +88,7 @@ class ValueStreamNode final : public facebook::velox::core::PlanNode { } private: - void addDetails(std::stringstream& stream) const override{}; + void addDetails(std::stringstream& stream) const override {}; const facebook::velox::RowTypePtr outputType_; std::unique_ptr valueStream_; diff --git a/cpp/velox/tests/VeloxShuffleWriterTest.cc b/cpp/velox/tests/VeloxShuffleWriterTest.cc index 7cbfbcd79cc9..47b751dcea21 100644 --- a/cpp/velox/tests/VeloxShuffleWriterTest.cc +++ b/cpp/velox/tests/VeloxShuffleWriterTest.cc @@ -165,11 +165,7 @@ TEST_P(HashPartitioningShuffleWriter, hashPart1Vector) { makeFlatVector( 4, [](vector_size_t row) { return row % 2; }, nullEvery(5), DATE()), makeFlatVector( - 4, - [](vector_size_t row) { - return Timestamp{row % 2, 0}; - }, - nullEvery(5)), + 4, [](vector_size_t row) { return Timestamp{row % 2, 0}; }, nullEvery(5)), }); auto rowType = facebook::velox::asRowType(vector->type()); diff --git a/dev/formatcppcode.sh b/dev/formatcppcode.sh index 4ce4155f78b6..00b20b668e3c 100755 --- a/dev/formatcppcode.sh +++ b/dev/formatcppcode.sh @@ -1,13 +1,25 @@ cd `dirname $0` -# Check if clang-format-15 is installed -if ! command -v clang-format-15 &> /dev/null -then - echo "clang-format-15 could not be found" - echo "Installing clang-format-15..." - sudo apt update - sudo apt install clang-format-15 +CLANG_FORMAT_CMD="" +if [ "$(uname)" == "Darwin" ]; then + CLANG_FORMAT_CMD="clang-format" + if ! command -v $CLANG_FORMAT_CMD &> /dev/null + then + echo "$CLANG_FORMAT_CMD could not be found" + echo "Installing $CLANG_FORMAT_CMD..." + sudo brew install $CLANG_FORMAT_CMD + fi +else + CLANG_FORMAT_CMD="clang-format-18" + if ! command -v $CLANG_FORMAT_CMD &> /dev/null + then + echo "$CLANG_FORMAT_CMD could not be found" + echo "Installing $CLANG_FORMAT_CMD..." + sudo apt update + sudo apt install $CLANG_FORMAT_CMD + fi fi -find ../cpp/core -regex '.*\.\(cc\|hpp\|cu\|c\|h\)' -exec clang-format-15 -style=file -i {} \; -find ../cpp/velox -regex '.*\.\(cc\|hpp\|cu\|c\|h\)' -exec clang-format-15 -style=file -i {} \; \ No newline at end of file +echo "OS: $(uname), CLANG_FORMAT_CMD: ${CLANG_FORMAT_CMD}" +find ../cpp/core -type f \( -name "*.cc" -o -name "*.hpp" -o -name "*.cu" -o -name "*.c" -o -name "*.h" \) | xargs ${CLANG_FORMAT_CMD} -style=file -i +find ../cpp/velox -type f \( -name "*.cc" -o -name "*.hpp" -o -name "*.cu" -o -name "*.c" -o -name "*.h" \) | xargs ${CLANG_FORMAT_CMD} -style=file -i