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

[CI] Upgrade to clang-format-18 #8

Merged
merged 3 commits into from
May 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions cpp_format_tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ARG BUILDIFIER_VERSION=3.5.0
ARG CLANG_VERSION=17.0.5-r0
ARG CLANG_VERSION=18
ARG CMAKE_FORMAT_VERSION=0.6.13

FROM alpine:3.19
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} \
clang17-extra-tools=${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 --break-system-packages cmake_format==${CMAKE_FORMAT_VERSION}
Expand All @@ -18,4 +18,4 @@ RUN curl -L -o /usr/local/bin/buildifier https://github.com/bazelbuild/buildtool
RUN chmod +x /usr/local/bin/buildifier

COPY format.sh /
ENTRYPOINT ["sh", "/format.sh"]
ENTRYPOINT ["bash", "/format.sh"]
64 changes: 50 additions & 14 deletions cpp_format_tools/format.sh
Original file line number Diff line number Diff line change
@@ -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-18 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