From 3ffb42eb7951baa4abd707a6455bcab5d250e268 Mon Sep 17 00:00:00 2001 From: Oblivion Date: Sat, 27 Apr 2024 11:55:41 +0000 Subject: [PATCH 1/2] [CI] Upgrade to clang-format-18 --- cpp_format_tools/Dockerfile | 13 ++++---- cpp_format_tools/format.sh | 64 +++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/cpp_format_tools/Dockerfile b/cpp_format_tools/Dockerfile index 13837aa..2d9a8ab 100644 --- a/cpp_format_tools/Dockerfile +++ b/cpp_format_tools/Dockerfile @@ -1,20 +1,21 @@ ARG BUILDIFIER_VERSION=3.5.0 -ARG CLANG_VERSION=10.0.1-r0 +ARG CLANG_VERSION=18 ARG CMAKE_FORMAT_VERSION=0.6.13 -FROM alpine:3.13 +FROM ubuntu:24.04 LABEL maintainer="The OpenTelemetry Authors" -RUN apk update +RUN apt update ARG CLANG_VERSION -RUN apk add --no-cache clang=${CLANG_VERSION} python3 py3-pip git curl +RUN apt install -y clang-format-${CLANG_VERSION} python3 python3-pip git curl \ + && ln /usr/bin/clang-format-${CLANG_VERSION} /usr/bin/clang-format ARG CMAKE_FORMAT_VERSION -RUN pip3 install cmake_format==${CMAKE_FORMAT_VERSION} +RUN pip3 install --break-system-packages cmake_format==${CMAKE_FORMAT_VERSION} ARG BUILDIFIER_VERSION RUN curl -L -o /usr/local/bin/buildifier https://github.com/bazelbuild/buildtools/releases/download/${BUILDIFIER_VERSION}/buildifier RUN chmod +x /usr/local/bin/buildifier COPY format.sh / -ENTRYPOINT ["sh", "/format.sh"] +ENTRYPOINT ["bash", "/format.sh"] diff --git a/cpp_format_tools/format.sh b/cpp_format_tools/format.sh index 29d2d8f..4d51385 100755 --- a/cpp_format_tools/format.sh +++ b/cpp_format_tools/format.sh @@ -1,23 +1,59 @@ #!/bin/bash +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + set -e -FIND="find /otel -name third_party -prune -o -name tools -prune -o -name .git -prune -o -name _deps -prune -o -name .build -prune -o -name out -prune -o -name .vs -prune -o" +FIND="find /otel -name third_party -prune -o -name tools -prune -o -name .git -prune -o -name _deps -prune -o -name .build -prune -o -name out -prune -o -name .vs -prune -o -name opentelemetry_logo.png -prune -o -name TraceLoggingDynamic.h -prune -o" + +# GNU syntax. +SED=(sed -i) +if [[ "$(uname)" = "Darwin" ]]; then + SED=(sed -i "") +fi -echo "Running sed: " -echo "-> Correct common miscapitalizations." -sed -i 's/Open[t]elemetry/OpenTelemetry/g' $($FIND -type f -print) -echo "-> No CRLF line endings, except Windows files." -sed -i 's/\r$//' $($FIND -name '*.ps1' -prune -o \ +# Correct common miscapitalizations. +"${SED[@]}" 's/Open[t]elemetry/OpenTelemetry/g' $($FIND -type f -print) +# No CRLF line endings, except Windows files. +"${SED[@]}" 's/\r$//' $($FIND -name '*.ps1' -prune -o \ -name '*.cmd' -prune -o -type f -print) -echo "-> No trailing spaces." -sed -i 's/ \+$//' $($FIND -type f -print) +# No trailing spaces. +"${SED[@]}" 's/ \+$//' $($FIND -type f -print) + +# If not overridden, try to use clang-format-10 or clang-format. +if [[ -z "$CLANG_FORMAT" ]]; then + CLANG_FORMAT=clang-format + if which clang-format-18 >/dev/null; then + CLANG_FORMAT=clang-format-18 + fi +fi -echo "Running clang-format $(clang-format --version 2>&1)." -clang-format -i -style=file $($FIND -name '*.cc' -print -o -name '*.h' -print) +$CLANG_FORMAT -version +$CLANG_FORMAT -i -style=file \ + $($FIND -name '*.cc' -print -o -name '*.h' -print) -echo "Running cmake-format $(cmake-format --version 2>&1)." -cmake-format -i $($FIND -name 'CMakeLists.txt' -print -name '*.cmake' -print -name '*.cmake.in' -print) +if which cmake-format >/dev/null; then + echo "Running cmake-format $(cmake-format --version 2>&1)." + cmake-format -i $($FIND -name 'CMakeLists.txt' -print -name '*.cmake' -print -name '*.cmake.in' -print) +else + echo "Can't find cmake-format. It can be installed with:" + echo " pip install --user cmake_format" + exit 1 +fi -echo "Running buildifier" -buildifier $($FIND -name WORKSPACE -print -o -name BUILD -print -o -name '*.BUILD' -o -name '*.bzl' -print) +if [[ -z "$BUILDIFIER" ]]; then + BUILDIFIER="$HOME/go/bin/buildifier" + if ! which "$BUILDIFIER" >/dev/null; then + BUILDIFIER=buildifier + fi +fi +if which "$BUILDIFIER" >/dev/null; then + echo "Running $BUILDIFIER" + "$BUILDIFIER" $($FIND -name WORKSPACE -print -o -name BUILD -print -o \ + -name '*.BUILD' -o -name '*.bzl' -print) +else + echo "Can't find buildifier. It can be installed with:" + echo " go get github.com/bazelbuild/buildtools/buildifier" + exit 1 +fi \ No newline at end of file From e9976edb05313ff6c20252257d0de9c40a1187b2 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Mon, 27 May 2024 10:28:15 +0200 Subject: [PATCH 2/2] Update cpp_format_tools/format.sh --- cpp_format_tools/format.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp_format_tools/format.sh b/cpp_format_tools/format.sh index 4d51385..5432a17 100755 --- a/cpp_format_tools/format.sh +++ b/cpp_format_tools/format.sh @@ -21,7 +21,7 @@ fi # No trailing spaces. "${SED[@]}" 's/ \+$//' $($FIND -type f -print) -# If not overridden, try to use clang-format-10 or clang-format. +# If not overridden, try to use clang-format-18 or clang-format. if [[ -z "$CLANG_FORMAT" ]]; then CLANG_FORMAT=clang-format if which clang-format-18 >/dev/null; then