Skip to content
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.30)
cmake_minimum_required(VERSION 3.20)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "MinSizeRel" CACHE STRING "Choose the type of build, options are: Debug, Release, RelWithDebInfo, or MinSizeRel." FORCE)
Expand Down
35 changes: 35 additions & 0 deletions scripts/clang-format-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: $0 <name> [working_directory]" >&2
echo "Example: $0 my_plugin plugins_source/plugins" >&2
exit 2
fi

name="$1"
workdir="${2:-.}"
file_list="clang-format-files"
results_file="clang-format-results.txt"

# Allow override via env; fall back to clang-format-18.
CLANG_FORMAT="${CLANG_FORMAT:-clang-format-18}"

print_results() {
if [[ -f "$results_file" ]]; then
cat "$results_file"
fi
}

trap print_results EXIT

cd "$workdir"

find "$name" -type d -name third_party -prune -false -o -name '*.cc' -o -name '*.hpp' -o -name '*.h' > "$file_list"

echo "Formatting files:"
cat "$file_list"

which "$CLANG_FORMAT"
"$CLANG_FORMAT" --version
"$CLANG_FORMAT" -n --Werror --files="$file_list" 2> "$results_file"
26 changes: 26 additions & 0 deletions scripts/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: $0 <name> [working_directory]" >&2
echo "Example: $0 my_plugin plugins_source/plugins" >&2
exit 2
fi

name="$1"
workdir="${2:-.}"
file_list="clang-format-files"

# Allow override via env; fall back to clang-format-18.
CLANG_FORMAT="${CLANG_FORMAT:-clang-format-18}"

cd "$workdir"

find "$name" -type d -name third_party -prune -false -o -name '*.cc' -o -name '*.hpp' -o -name '*.h' > "$file_list"

echo "Formatting files:"
cat "$file_list"

which "$CLANG_FORMAT"
"$CLANG_FORMAT" --version
"$CLANG_FORMAT" -i --files="$file_list"
78 changes: 78 additions & 0 deletions scripts/run-clang-tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

set -euo pipefail

MYPATH="$(readlink -f "${BASH_SOURCE[0]}")"
MYDIR="${MYPATH%/*}"
MYNAME="${MYPATH##*/}"

TARGET_PATH="${1:-}"
WORK_DIR="${2:-$(pwd)}"
BUILD_DIR="${3:-$(readlink -f "${WORK_DIR}/../../build")}"
LOG_FILE="tidy-results-log.txt"
FIX_FILE="tidy-results-suggested-fixes.txt"

print_results() {
[ -f "${WORK_DIR}/${LOG_FILE}" ] && cat "${WORK_DIR}/${LOG_FILE}"
[ -f "${WORK_DIR}/${FIX_FILE}" ] && cat "${WORK_DIR}/${FIX_FILE}"
}

trap print_results EXIT

if [ -z "${TARGET_PATH}" ]; then
echo "Usage: ${MYNAME} <target-path> [work-dir] [build-dir]"
echo "Example: ${MYNAME} plugin_a ./plugins_source/plugins ./build"
exit 1
fi

if ! command -v run-clang-tidy-18 >/dev/null 2>&1; then
echo "run-clang-tidy-18 not found in PATH"
exit 1
fi

if [ ! -d "${WORK_DIR}" ]; then
echo "work-dir does not exist: ${WORK_DIR}"
exit 1
fi

if [ ! -d "${BUILD_DIR}" ]; then
echo "build-dir does not exist: ${BUILD_DIR}"
exit 1
fi

pushd "${WORK_DIR}" >/dev/null

if [ ! -e "${TARGET_PATH}" ]; then
echo "target-path does not exist in work-dir: ${TARGET_PATH}"
popd >/dev/null
exit 1
fi

mapfile -t FILES < <(
find "${TARGET_PATH}" \
-type d -name third_party -prune -o \
-type f \( -name '*.cc' -o -name '*.hpp' -o -name '*.h' \) -print
)

if [ ${#FILES[@]} -eq 0 ]; then
echo "No files found for clang-tidy under: ${TARGET_PATH}"
popd >/dev/null
exit 0
fi

printf '%s\n' "${FILES[@]}"

run-clang-tidy-18 \
-warnings-as-errors='*,-bugprone-macro-parentheses' \
-export-fixes="${FIX_FILE}" \
-p "${BUILD_DIR}" \
"${FILES[@]}" \
2>/dev/null \
| tee "${LOG_FILE}"

if [ -f "${FIX_FILE}" ] && grep -q "Level: Error" "${FIX_FILE}"; then
popd >/dev/null
exit 1
fi

popd >/dev/null
3 changes: 2 additions & 1 deletion src/avahi/avahi_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "../proxy/org/freedesktop/Avahi/Server/server_proxy.h"
#include "../proxy/org/freedesktop/Avahi/Server2/server2_proxy.h"

#include "../utils/logging.h"
#include "../utils/utils.h"

class AvahiServer final
Expand All @@ -38,7 +39,7 @@ class AvahiServer final
std::int32_t state_{};

void onStateChanged(const int32_t& state, const std::string& error) override {
spdlog::info("onStateChanged: state={}, error={}", state, error);
LOG_INFO("onStateChanged: state={}, error={}", state, error);
state_ = state;
}
};
Expand Down
19 changes: 10 additions & 9 deletions src/avahi/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "avahi_server.h"

#include "../utils/logging.h"
#include "../utils/utils.h"

int main() {
Expand All @@ -23,15 +24,15 @@ int main() {
if (const auto names = Utils::ListNames(*connection);
Utils::isServicePresent(names, "org.freedesktop.Avahi")) {
AvahiServer server(*connection);
spdlog::info("API Version: {}", server.GetAPIVersion());
spdlog::info("Domain Name: {}", server.GetDomainName());
spdlog::info("Host Name: {}", server.GetHostName());
spdlog::info("FQDN: {}", server.GetHostNameFqdn());
spdlog::info("Local Service Cookie: {}", server.GetLocalServiceCookie());
spdlog::info("State: {}", server.GetState());
spdlog::info("Version: {}", server.GetVersionString());
spdlog::info("NSSS upport available: {}",
server.IsNSSSupportAvailable() ? "Yes" : "No");
LOG_INFO("API Version: {}", server.GetAPIVersion());
LOG_INFO("Domain Name: {}", server.GetDomainName());
LOG_INFO("Host Name: {}", server.GetHostName());
LOG_INFO("FQDN: {}", server.GetHostNameFqdn());
LOG_INFO("Local Service Cookie: {}", server.GetLocalServiceCookie());
LOG_INFO("State: {}", server.GetState());
LOG_INFO("Version: {}", server.GetVersionString());
LOG_INFO("NSSS upport available: {}",
server.IsNSSSupportAvailable() ? "Yes" : "No");
}

connection->leaveEventLoop();
Expand Down
Loading
Loading