diff --git a/.github/format-check.sh b/.github/format-check.sh deleted file mode 100755 index e9bd2d677..000000000 --- a/.github/format-check.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -set -ex - -if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then - git fetch origin $GITHUB_BASE_REF:refs/remotes/origin/$GITHUB_BASE_REF - for f in $(git diff --diff-filter=AM --name-only origin/$GITHUB_BASE_REF 'vita3k/**.cpp' 'vita3k/**.h' 'tools/**.cpp' 'tools/**.h'); do - if [ "$(diff -u <(cat $f) <(clang-format $f))" != "" ] - then - echo "run format" - exit 1 - fi - done -fi \ No newline at end of file diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index ba0d75e99..103e42e19 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -15,13 +15,23 @@ env: jobs: format-check: + name: Format Check (${{ matrix.path }}) runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + path: + - vita3k + - tools steps: - name: Checkout uses: actions/checkout@v6 - name: Format check - run: .github/format-check.sh + uses: jidicula/clang-format-action@v4.18.0 + with: + clang-format-version: '22' + check-path: ${{ matrix.path }} build: name: Build (${{ matrix.os }}) diff --git a/format.bat b/format.bat index 96be90584..04eb24bb4 100644 --- a/format.bat +++ b/format.bat @@ -1,6 +1,7 @@ @echo off +if "%CLANG_FORMAT_BIN%"=="" set "CLANG_FORMAT_BIN=clang-format" cd vita3k -for /f %%f in ('dir *.cpp *.h /b/s') do clang-format -i %%f +for /f %%f in ('dir *.cpp *.h /b/s') do "%CLANG_FORMAT_BIN%" -i "%%f" cd ..\tools -for /f %%f in ('dir *.cpp *.h /b/s') do clang-format -i %%f +for /f %%f in ('dir *.cpp *.h /b/s') do "%CLANG_FORMAT_BIN%" -i "%%f" cd .. diff --git a/format.sh b/format.sh index e388cf637..10d6bb123 100755 --- a/format.sh +++ b/format.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash -set -ex +set -euo pipefail -find vita3k tools/gen-modules tools/native-tool \( -name *.cpp -o -name *.h \) | xargs clang-format -i +CLANG_FORMAT_BIN="${CLANG_FORMAT_BIN:-clang-format}" + +find vita3k tools/gen-modules tools/native-tool \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -0 "$CLANG_FORMAT_BIN" -i diff --git a/vita3k/gui-qt/src/controls_dialog.cpp b/vita3k/gui-qt/src/controls_dialog.cpp index ba65099cb..416305c6d 100644 --- a/vita3k/gui-qt/src/controls_dialog.cpp +++ b/vita3k/gui-qt/src/controls_dialog.cpp @@ -148,7 +148,7 @@ void style_mode_button(QToolButton *button) { " }" "QToolButton:hover { background-color: %1; }" "QToolButton:checked { background-color: %2; }") - .arg(hover.name(QColor::HexArgb), checked.name(QColor::HexArgb))); + .arg(hover.name(QColor::HexArgb), checked.name(QColor::HexArgb))); } void style_binding_button(QPushButton *button, bool capturing = false) { diff --git a/vita3k/gui-qt/src/ctrl_keyboard_filter.cpp b/vita3k/gui-qt/src/ctrl_keyboard_filter.cpp index 7b191b7c0..a172b0391 100644 --- a/vita3k/gui-qt/src/ctrl_keyboard_filter.cpp +++ b/vita3k/gui-qt/src/ctrl_keyboard_filter.cpp @@ -35,7 +35,7 @@ CtrlKeyboardFilter::CtrlKeyboardFilter(EmuEnvState &emuenv, QObject *parent) : QObject(parent) - , m_emuenv(emuenv){}; + , m_emuenv(emuenv) {}; bool CtrlKeyboardFilter::eventFilter(QObject *watched, QEvent *event) { switch (event->type()) { diff --git a/vita3k/gui-qt/src/debug_widget.cpp b/vita3k/gui-qt/src/debug_widget.cpp index 4b23d9984..58f223f02 100644 --- a/vita3k/gui-qt/src/debug_widget.cpp +++ b/vita3k/gui-qt/src/debug_widget.cpp @@ -375,8 +375,8 @@ void DebugWidget::on_thread_double_clicked(QTreeWidgetItem *item, int /*column*/ auto *dlg = new QDialog(this); dlg->setWindowTitle(tr("Thread: %1 (0x%2)") - .arg(QString::fromStdString(thread->name)) - .arg(thread_id, 8, 16, QLatin1Char('0'))); + .arg(QString::fromStdString(thread->name)) + .arg(thread_id, 8, 16, QLatin1Char('0'))); dlg->setAttribute(Qt::WA_DeleteOnClose); dlg->setMinimumSize(420, 480); diff --git a/vita3k/gui-qt/src/license_install_dialog.cpp b/vita3k/gui-qt/src/license_install_dialog.cpp index 39b495a56..9409ae2bd 100644 --- a/vita3k/gui-qt/src/license_install_dialog.cpp +++ b/vita3k/gui-qt/src/license_install_dialog.cpp @@ -73,8 +73,8 @@ void LicenseInstallDialog::install_from_file() { info.setWindowTitle(tr("License Installed")); info.setIcon(QMessageBox::Information); info.setText(tr("License installed successfully!\n\nContent ID: %1\nTitle ID: %2") - .arg(QString::fromStdString(m_emuenv.license_content_id), - QString::fromStdString(m_emuenv.license_title_id))); + .arg(QString::fromStdString(m_emuenv.license_content_id), + QString::fromStdString(m_emuenv.license_title_id))); info.exec(); accept(); } @@ -104,8 +104,8 @@ void LicenseInstallDialog::install_from_zrif() { info.setWindowTitle(tr("License Installed")); info.setIcon(QMessageBox::Information); info.setText(tr("License installed successfully!\n\nContent ID: %1\nTitle ID: %2") - .arg(QString::fromStdString(m_emuenv.license_content_id), - QString::fromStdString(m_emuenv.license_title_id))); + .arg(QString::fromStdString(m_emuenv.license_content_id), + QString::fromStdString(m_emuenv.license_title_id))); info.exec(); accept(); } diff --git a/vita3k/gui-qt/src/live_area_widget.cpp b/vita3k/gui-qt/src/live_area_widget.cpp index 855614309..abb4ff6df 100644 --- a/vita3k/gui-qt/src/live_area_widget.cpp +++ b/vita3k/gui-qt/src/live_area_widget.cpp @@ -120,7 +120,7 @@ static std::vector parse_text_entries(const pugi::xml_ static uint64_t current_time_secs() { return static_cast(std::chrono::duration_cast( std::chrono::steady_clock::now().time_since_epoch()) - .count()); + .count()); } static std::string strip_whitespace(const std::string &s) { diff --git a/vita3k/gui-qt/src/main_window.cpp b/vita3k/gui-qt/src/main_window.cpp index 861cf7a78..fb7c4d821 100644 --- a/vita3k/gui-qt/src/main_window.cpp +++ b/vita3k/gui-qt/src/main_window.cpp @@ -912,9 +912,9 @@ std::optional MainWindow::boot_game_once(const AppLaunchReques m_game_window = new GameWindow(emuenv, m_gui_settings, emuenv.backend_renderer, screen()); m_game_window->setTitle(tr("%1 | %2 (%3) | Loading...") - .arg(QString::fromStdString(window_title), - QString::fromStdString(emuenv.current_app_title), - QString::fromStdString(emuenv.io.title_id))); + .arg(QString::fromStdString(window_title), + QString::fromStdString(emuenv.current_app_title), + QString::fromStdString(emuenv.io.title_id))); m_game_window->setIcon(windowIcon()); if (m_live_area_widget) m_game_window->setGeometry(m_live_area_widget->geometry()); @@ -1068,9 +1068,9 @@ std::optional MainWindow::boot_game_once(const AppLaunchReques } m_game_window->setTitle(tr("%1 | %2 (%3) | Initializing...") - .arg(QString::fromStdString(window_title), - QString::fromStdString(emuenv.current_app_title), - QString::fromStdString(emuenv.io.title_id))); + .arg(QString::fromStdString(window_title), + QString::fromStdString(emuenv.current_app_title), + QString::fromStdString(emuenv.io.title_id))); if (!m_app_session.initialize_runtime()) { abort_boot(tr("Failed to initialize emulator state.")); @@ -1078,9 +1078,9 @@ std::optional MainWindow::boot_game_once(const AppLaunchReques } m_game_window->setTitle(tr("%1 | %2 (%3) | Loading modules...") - .arg(QString::fromStdString(window_title), - QString::fromStdString(emuenv.current_app_title), - QString::fromStdString(emuenv.io.title_id))); + .arg(QString::fromStdString(window_title), + QString::fromStdString(emuenv.current_app_title), + QString::fromStdString(emuenv.io.title_id))); if (!m_app_session.load_and_run()) { abort_boot(tr("Failed to start game threads.")); @@ -1114,9 +1114,9 @@ std::optional MainWindow::boot_game_once(const AppLaunchReques m_game_window->start_ui_updates(); m_game_window->setTitle(tr("%1 | %2 (%3) | Please wait, loading...") - .arg(QString::fromStdString(window_title), - QString::fromStdString(emuenv.current_app_title), - QString::fromStdString(emuenv.io.title_id))); + .arg(QString::fromStdString(window_title), + QString::fromStdString(emuenv.current_app_title), + QString::fromStdString(emuenv.io.title_id))); LOG_INFO("Game started: {} ({})", emuenv.current_app_title, launch_request.app_path); @@ -1272,9 +1272,9 @@ void MainWindow::show_live_area(const std::string &title_id) { m_game_container = m_live_area_widget; m_live_area_widget->setTitle(tr("%1 | %2 (%3)") - .arg(QString::fromStdString(window_title), - QString::fromStdString(emuenv.current_app_title), - QString::fromStdString(emuenv.io.title_id))); + .arg(QString::fromStdString(window_title), + QString::fromStdString(emuenv.current_app_title), + QString::fromStdString(emuenv.io.title_id))); m_live_area_widget->setIcon(windowIcon()); m_live_area_widget->installEventFilter(this); m_live_area_widget->show(); diff --git a/vita3k/gui-qt/src/trophy_collection_dialog.cpp b/vita3k/gui-qt/src/trophy_collection_dialog.cpp index d263d458f..5d5e4abe6 100644 --- a/vita3k/gui-qt/src/trophy_collection_dialog.cpp +++ b/vita3k/gui-qt/src/trophy_collection_dialog.cpp @@ -568,10 +568,10 @@ void TrophyCollectionDialog::update_summary_progress() { } const int pct = total_trophies > 0 ? (total_unlocked * 100 / total_trophies) : 0; m_progress_label->setText(tr("Total: %1% (%2/%3 trophies across %4 apps)") - .arg(pct) - .arg(total_unlocked) - .arg(total_trophies) - .arg(m_db.size())); + .arg(pct) + .arg(total_unlocked) + .arg(total_trophies) + .arg(m_db.size())); } void TrophyCollectionDialog::update_page_controls() { diff --git a/vita3k/util/include/util/byte_ring_buffer.h b/vita3k/util/include/util/byte_ring_buffer.h index acaca6e04..d892c76ac 100644 --- a/vita3k/util/include/util/byte_ring_buffer.h +++ b/vita3k/util/include/util/byte_ring_buffer.h @@ -9,7 +9,7 @@ class ByteRingBuffer { public: ByteRingBuffer(std::size_t size) : buffer(new char[size]) - , capacity(size){ + , capacity(size) { }; diff --git a/vita3k/util/include/util/obfuscate.h b/vita3k/util/include/util/obfuscate.h index 6be68419e..eb36c158f 100644 --- a/vita3k/util/include/util/obfuscate.h +++ b/vita3k/util/include/util/obfuscate.h @@ -179,7 +179,7 @@ constexpr auto make_obfuscator(const char (&data)[N]) { // functions for decrypting the string and is also implicitly convertable to a // char* #define AY_OBFUSCATE_KEY(data, key) \ - []() -> ay::obfuscated_data & { \ + []()->ay::obfuscated_data & { \ static_assert(sizeof(decltype(key)) == sizeof(ay::key_type), "key must be a 64 bit unsigned integer"); \ static_assert((key) >= (1ull << 56), "key must span all 8 bytes"); \ constexpr auto n = sizeof(data) / sizeof(data[0]); \ diff --git a/vita3k/util/include/util/quaternion.h b/vita3k/util/include/util/quaternion.h index 6011842af..33bcb8029 100644 --- a/vita3k/util/include/util/quaternion.h +++ b/vita3k/util/include/util/quaternion.h @@ -20,16 +20,16 @@ public: return { -xyz, w }; } - [[nodiscard]] Quaternion operator+(const Quaternion &other) const { + [[nodiscard]] Quaternion operator+(const Quaternion & other) const { return { xyz + other.xyz, w + other.w }; } - [[nodiscard]] Quaternion operator-(const Quaternion &other) const { + [[nodiscard]] Quaternion operator-(const Quaternion & other) const { return { xyz - other.xyz, w - other.w }; } [[nodiscard]] Quaternion operator*( - const Quaternion &other) const { + const Quaternion & other) const { return { xyz * other.w + other.xyz * w + Cross(xyz, other.xyz), w * other.w - Dot(xyz, other.xyz) }; } diff --git a/vita3k/util/include/util/vector_math.h b/vita3k/util/include/util/vector_math.h index 5e8714ed0..6aa597d3c 100644 --- a/vita3k/util/include/util/vector_math.h +++ b/vita3k/util/include/util/vector_math.h @@ -61,7 +61,7 @@ public: return Vec3(f, f, f); } - [[nodiscard]] constexpr Vec3 operator+(const Vec3 &other) const { + [[nodiscard]] constexpr Vec3 operator+(const Vec3 & other) const { return { x + other.x, y + other.y, z + other.z }; } @@ -72,7 +72,7 @@ public: return *this; } - [[nodiscard]] constexpr Vec3 operator-(const Vec3 &other) const { + [[nodiscard]] constexpr Vec3 operator-(const Vec3 & other) const { return { x - other.x, y - other.y, z - other.z }; } @@ -88,12 +88,12 @@ public: return { -x, -y, -z }; } - [[nodiscard]] constexpr Vec3 operator*(const Vec3 &other) const { + [[nodiscard]] constexpr Vec3 operator*(const Vec3 & other) const { return { x * other.x, y * other.y, z * other.z }; } template - [[nodiscard]] constexpr Vec3 operator*(const V &f) const { + [[nodiscard]] constexpr Vec3 operator*(const V & f) const { using TV = decltype(T{} * V{}); using C = std::common_type_t; @@ -110,7 +110,7 @@ public: return *this; } template - [[nodiscard]] constexpr Vec3 operator/(const V &f) const { + [[nodiscard]] constexpr Vec3 operator/(const V & f) const { using TV = decltype(T{} / V{}); using C = std::common_type_t; @@ -254,7 +254,7 @@ template // linear interpolation via SceFloat: 0.0=begin, 1.0=end template [[nodiscard]] constexpr decltype(X{} * SceFloat{} + X{} * SceFloat{}) -Lerp(const X &begin, const X &end, const SceFloat t) { + Lerp(const X &begin, const X &end, const SceFloat t) { return begin * (1.f - t) + end * t; } diff --git a/vita3k/util/include/util/warning.h b/vita3k/util/include/util/warning.h index 253c7b54c..9b827eff7 100644 --- a/vita3k/util/include/util/warning.h +++ b/vita3k/util/include/util/warning.h @@ -25,8 +25,7 @@ #elif defined(_MSC_VER) #define DISABLE_WARNING_PUSH __pragma(warning(push)) #define DISABLE_WARNING_POP __pragma(warning(pop)) -#define DISABLE_WARNING_NO_PUSH(warningNumber, warningName) __pragma(warning(disable \ - : warningNumber)) +#define DISABLE_WARNING_NO_PUSH(warningNumber, warningName) __pragma(warning(disable : warningNumber)) #else #define DISABLE_WARNING_PUSH #define DISABLE_WARNING_POP diff --git a/vita3k/util/src/instrset_detect.cpp b/vita3k/util/src/instrset_detect.cpp index 16acfd1bc..2d034ebe9 100644 --- a/vita3k/util/src/instrset_detect.cpp +++ b/vita3k/util/src/instrset_detect.cpp @@ -34,9 +34,9 @@ static inline void cpuid(int output[4], int functionnumber, int ecxleaf) { #elif defined(__GNUC__) || defined(__clang__) // use inline assembly, Gnu/AT&T syntax int a, b, c, d; __asm("cpuid" - : "=a"(a), "=b"(b), "=c"(c), "=d"(d) - : "a"(functionnumber), "c"(ecxleaf) - :); + : "=a"(a), "=b"(b), "=c"(c), "=d"(d) + : "a"(functionnumber), "c"(ecxleaf) + :); output[0] = a; output[1] = b; output[2] = c; @@ -72,9 +72,9 @@ static inline uint64_t xgetbv(int ctr) { uint32_t a, d; __asm("xgetbv" - : "=a"(a), "=d"(d) - : "c"(ctr) - :); + : "=a"(a), "=d"(d) + : "c"(ctr) + :); return a | (uint64_t(d) << 32); #else // #elif defined (_WIN32) // other compiler. try inline assembly with masm/intel/MS syntax