From c2a2904cf0402fe0e8d342b8e07c9c39bf69363b Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 21 Apr 2025 16:04:21 +0200 Subject: [PATCH 01/13] ci: add meson checks --- .github/workflows/meson.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/meson.yml diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml new file mode 100644 index 00000000..0bd47702 --- /dev/null +++ b/.github/workflows/meson.yml @@ -0,0 +1,30 @@ +name: Meson Checks CI + +on: + push: + branches: ['main'] + pull_request: + workflow_dispatch: + +jobs: + meson_format: + name: Run Meson Format Checks + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: '0' + + # NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything! + - name: Setup meson + run: | + pip install meson --break-system-packages + + - name: Check Files + run: git ls-files --exclude='meson.build' --exclude='meson.options' --exclude='meson_options.txt' --exclude='*.wrap' --ignored -c -z | xargs -0r meson format -i -c ./meson.format + + ## TODO: use mesonlint from + ## https://github.com/JCWasmx86/mesonlsp + ## once it is maitained again + # meson_lint: + # name: Run Meson Lint Checks From 65cb46882d9a6248779676d2957b0e2a28db75d9 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 21 Apr 2025 18:19:46 +0200 Subject: [PATCH 02/13] feat: add meson format configuration --- meson.format | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 meson.format diff --git a/meson.format b/meson.format new file mode 100644 index 00000000..33b50963 --- /dev/null +++ b/meson.format @@ -0,0 +1,6 @@ +max_line_length = 100 +end_of_line = 'lf' +insert_final_newline = true +sort_files = true +kwargs_force_multiline = true +no_single_comma_function = true From b2a856377bc50cd27d7ded14d7a11cf80a993758 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 21 Apr 2025 18:24:16 +0200 Subject: [PATCH 03/13] ci: add meson format checks --- .github/workflows/meson.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 0bd47702..726bdce3 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -21,7 +21,15 @@ jobs: pip install meson --break-system-packages - name: Check Files - run: git ls-files --exclude='meson.build' --exclude='meson.options' --exclude='meson_options.txt' --exclude='*.wrap' --ignored -c -z | xargs -0r meson format -i -c ./meson.format + run: > + git ls-files + --exclude='meson.build' + --exclude='meson.options' + --exclude='meson_options.txt' + --ignored -c -z | xargs -0r + meson format --check-only -c ./meson.format + || echo "Not all meson files are formatted correctly" + && echo "All meson files are formatted correctly" ## TODO: use mesonlint from ## https://github.com/JCWasmx86/mesonlsp From 25ae300121f329d62e81ff37f82368b9e123dbda Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 21 Apr 2025 18:24:31 +0200 Subject: [PATCH 04/13] fix: format all meson files accordingly --- src/executables/game/meson.build | 8 +- src/executables/meson.build | 36 ++-- src/executables/platforms/3ds/meson.build | 34 +-- src/executables/platforms/switch/meson.build | 13 +- src/executables/platforms/windows/meson.build | 24 +-- src/executables/utility/meson.build | 5 +- src/libs/core/game/meson.build | 13 +- src/libs/core/hash-library/meson.build | 8 +- src/libs/core/meson.build | 4 +- src/libs/recordings/meson.build | 4 +- src/lobby/credentials/meson.build | 7 +- src/lobby/meson.build | 22 +- src/meson.build | 7 +- src/scenes/about_page/meson.build | 5 +- src/scenes/loading_screen/meson.build | 5 +- src/scenes/logo/meson.build | 5 +- src/scenes/main_menu/meson.build | 5 +- src/scenes/multiplayer_menu/meson.build | 5 +- src/scenes/online_lobby/meson.build | 5 +- src/scenes/play_select_menu/meson.build | 5 +- src/scenes/recording_selector/meson.build | 5 +- src/scenes/replay_game/meson.build | 5 +- src/ui/meson.build | 8 +- .../discord_social_sdk/meson.build | 20 +- subprojects/packagefiles/keyutils/meson.build | 7 +- tests/graphics/meson.build | 5 +- tests/utils/meson.build | 7 +- tools/dependencies/meson.build | 193 +++++++++--------- tools/install/meson.build | 17 +- tools/options/meson.build | 80 +++++--- 30 files changed, 243 insertions(+), 324 deletions(-) diff --git a/src/executables/game/meson.build b/src/executables/game/meson.build index 90b4c0b2..ec78e3cd 100644 --- a/src/executables/game/meson.build +++ b/src/executables/game/meson.build @@ -1,7 +1 @@ -main_files += files( - 'application.cpp', - 'application.hpp', - 'main.cpp', - 'parser.cpp', - 'parser.hpp', -) +main_files += files('application.cpp', 'application.hpp', 'main.cpp', 'parser.cpp', 'parser.hpp') diff --git a/src/executables/meson.build b/src/executables/meson.build index bda24c0d..7ef21e1f 100644 --- a/src/executables/meson.build +++ b/src/executables/meson.build @@ -46,11 +46,8 @@ if build_application endif if not fs.exists(APP_ROMFS) - error( - 'APP_ROMFS should exist, but doesn\'t: \'' - + APP_ROMFS - + '\'', - ) + error('APP_ROMFS should exist, but doesn\'t: \'' + + APP_ROMFS + '\'') endif if not APP_ROMFS.endswith('/') @@ -58,9 +55,11 @@ if build_application endif emscripten_link_args += [ - '--preload-file', APP_ROMFS + '@/assets/', + '--preload-file', + APP_ROMFS + '@/assets/', # based on: https://github.com/emscripten-core/emscripten/blob/main/src/shell_minimal.html - '--shell-file', meson.project_source_root() / 'platforms' / 'emscripten' / 'shell_file.html', + '--shell-file', + meson.project_source_root() / 'platforms' / 'emscripten' / 'shell_file.html', ] endif @@ -85,7 +84,9 @@ if build_application oopetris_html = executable( emscripten_name, - objects: oopetris_js.extract_all_objects(recursive: true), + objects: oopetris_js.extract_all_objects( + recursive: true + ), dependencies: emscripten_deps, link_args: emscripten_link_args, override_options: emscripten_options, @@ -94,12 +95,15 @@ if build_application link_depends: [oopetris_js], ) - python3 = find_program('python3', required: false) + python3 = find_program( + 'python3', + required: false, + ) if python3.found() server_py = files( - meson.project_source_root() / 'platforms' / 'emscripten' / 'server.py', + meson.project_source_root() / 'platforms' / 'emscripten' / 'server.py' ) dest_path = meson.project_build_root() / 'src' / 'executables' @@ -112,7 +116,10 @@ if build_application endif - wasm_validate_exe = find_program('wasm-validate', required: false) + wasm_validate_exe = find_program( + 'wasm-validate', + required: false, + ) if wasm_validate_exe.found() @@ -123,7 +130,6 @@ if build_application wasm_validate_exe, args: ['--enable-threads', wasm_file], depends: [oopetris_js, oopetris_html], - ) endif @@ -170,7 +176,7 @@ if build_application makensis = find_program('makensis') nsis_script = files( - meson.project_source_root() / 'tools' / 'installer' / 'setup.nsi', + meson.project_source_root() / 'tools' / 'installer' / 'setup.nsi' ) run_target( @@ -184,9 +190,7 @@ if build_application + meson.project_source_root(), '-DPROJECT_BUILD_DIR=' + meson.project_build_root(), '-DDYNAMIC_LIBRARIES_DIR=' - + ( - meson.project_build_root() / 'dynamic_libraries' / get_option('bindir') - ), + + (meson.project_build_root() / 'dynamic_libraries' / get_option('bindir')), nsis_script, ], depends: [oopetris_exe, oopetris_recordings_utility_exe], diff --git a/src/executables/platforms/3ds/meson.build b/src/executables/platforms/3ds/meson.build index f8524f36..fac72363 100644 --- a/src/executables/platforms/3ds/meson.build +++ b/src/executables/platforms/3ds/meson.build @@ -6,26 +6,9 @@ _3ds_deps = _3ds_options[2] # libraries -_3ds_dependencies = [ - 'flac', - 'freetype2', - 'ogg', - 'ogg', - 'opus', - 'opusfile', - 'vorbisidec', - 'zlib', -] - -_3ds_dependencies_native = [ - 'bz2', - 'ctru', - 'mad', - 'mikmod', - 'modplug', - 'png16', - 'SDL2main', -] +_3ds_dependencies = ['flac', 'freetype2', 'ogg', 'ogg', 'opus', 'opusfile', 'vorbisidec', 'zlib'] + +_3ds_dependencies_native = ['bz2', 'ctru', 'mad', 'mikmod', 'modplug', 'png16', 'SDL2main'] _3ds_library_dirs = meson.get_external_property('library_dirs', ['']) if _3ds_library_dirs.length() == 0 @@ -64,9 +47,7 @@ _3ds_elf_file = build_target( target_type: 'executable', ) -use_smdh = ['true', 'True', '1', true].contains( - meson.get_external_property('USE_SMDH', ''), -) +use_smdh = ['true', 'True', '1', true].contains(meson.get_external_property('USE_SMDH', '')) _3dsxtool = find_program('3dsxtool') @@ -125,11 +106,8 @@ if use_smdh endif if not fs.exists(APP_SMALL_ICON) - error( - 'APP_SMALL_ICON should exist, but doesn\'t: \'' - + APP_SMALL_ICON - + '\'', - ) + error('APP_SMALL_ICON should exist, but doesn\'t: \'' + + APP_SMALL_ICON + '\'') endif SMDH_FLAGS += APP_SMALL_ICON diff --git a/src/executables/platforms/switch/meson.build b/src/executables/platforms/switch/meson.build index 7017f9fe..26005afe 100644 --- a/src/executables/platforms/switch/meson.build +++ b/src/executables/platforms/switch/meson.build @@ -21,14 +21,7 @@ switch_dependencies = [ 'zlib', ] -switch_dependencies_native = [ - 'bz2', - 'drm_nouveau', - 'modplug', - 'nx', - 'png16', - 'SDL2main', -] +switch_dependencies_native = ['bz2', 'drm_nouveau', 'modplug', 'nx', 'png16', 'SDL2main'] foreach dep : switch_dependencies switch_deps += dependency( @@ -67,9 +60,7 @@ switch_elf_file = build_target( target_type: 'executable', ) -use_nacp = ['true', 'True', '1', true].contains( - meson.get_external_property('USE_NACP', ''), -) +use_nacp = ['true', 'True', '1', true].contains(meson.get_external_property('USE_NACP', '')) elf2nro = find_program('elf2nro') # executable input elf file, output nro file diff --git a/src/executables/platforms/windows/meson.build b/src/executables/platforms/windows/meson.build index 5a684a93..80c87601 100644 --- a/src/executables/platforms/windows/meson.build +++ b/src/executables/platforms/windows/meson.build @@ -6,21 +6,21 @@ minor_version = version_arr[1].to_int() patch_version = version_arr[2].to_int() rc_conf = configuration_data( - { - 'OOPETRIS_VERSION': meson.project_version(), - 'OOPETRIS_NAME': oopetris_name, - 'OOPETRIS_AUTHOR': oopetris_author, - 'OOPETRIS_MAJOR_VERSION': major_version, - 'OOPETRIS_MINOR_VERSION': minor_version, - 'OOPETRIS_PATCH_VERSION': patch_version, - 'PROJECT_SOURCE_DIR': meson.project_source_root().replace('\\', '/'), - }, + { + 'OOPETRIS_VERSION': meson.project_version(), + 'OOPETRIS_NAME': oopetris_name, + 'OOPETRIS_AUTHOR': oopetris_author, + 'OOPETRIS_MAJOR_VERSION': major_version, + 'OOPETRIS_MINOR_VERSION': minor_version, + 'OOPETRIS_PATCH_VERSION': patch_version, + 'PROJECT_SOURCE_DIR': meson.project_source_root().replace('\\', '/'), + } ) oopetris_win_rc = configure_file( - input: 'oopetris.rc.in', - output: 'oopetris.rc', - configuration: rc_conf, + input: 'oopetris.rc.in', + output: 'oopetris.rc', + configuration: rc_conf, ) oopetris_resource_windows = windows.compile_resources(oopetris_win_rc) diff --git a/src/executables/utility/meson.build b/src/executables/utility/meson.build index 997e8923..4730e799 100644 --- a/src/executables/utility/meson.build +++ b/src/executables/utility/meson.build @@ -1,4 +1 @@ -recordings_main_files += files( - 'command_line_arguments.hpp', - 'main.cpp', -) +recordings_main_files += files('command_line_arguments.hpp', 'main.cpp') diff --git a/src/libs/core/game/meson.build b/src/libs/core/game/meson.build index c5f6f48c..5a5dc0dc 100644 --- a/src/libs/core/game/meson.build +++ b/src/libs/core/game/meson.build @@ -1,15 +1,6 @@ -core_src_files += files( - 'mino.cpp', - 'mino_stack.cpp', - 'tetromino_type.cpp', -) +core_src_files += files('mino.cpp', 'mino_stack.cpp', 'tetromino_type.cpp') -_header_files = files( - 'grid_properties.hpp', - 'mino.hpp', - 'mino_stack.hpp', - 'tetromino_type.hpp', -) +_header_files = files('grid_properties.hpp', 'mino.hpp', 'mino_stack.hpp', 'tetromino_type.hpp') core_header_files += _header_files diff --git a/src/libs/core/hash-library/meson.build b/src/libs/core/hash-library/meson.build index df1ddcc6..5ecf3645 100644 --- a/src/libs/core/hash-library/meson.build +++ b/src/libs/core/hash-library/meson.build @@ -1,10 +1,6 @@ -core_src_files += files( - 'sha256.cpp', -) +core_src_files += files('sha256.cpp') -_header_files = files( - 'sha256.h', -) +_header_files = files('sha256.h') core_header_files += _header_files diff --git a/src/libs/core/meson.build b/src/libs/core/meson.build index 73478415..c4a4301f 100644 --- a/src/libs/core/meson.build +++ b/src/libs/core/meson.build @@ -9,7 +9,9 @@ subdir('helper') temp = core_lib.get('compile_args') temp += '-DOOPETRIS_LIBRARY_CORE_TYPE=' + (get_option('default_library') == 'static' ? '1' : '0') -core_lib += {'compile_args': temp} +core_lib += { + 'compile_args': temp, +} temp = 0 liboopetris_core = library( diff --git a/src/libs/recordings/meson.build b/src/libs/recordings/meson.build index 68a6444d..c5bb713e 100644 --- a/src/libs/recordings/meson.build +++ b/src/libs/recordings/meson.build @@ -7,7 +7,9 @@ subdir('utility') temp = recordings_lib.get('compile_args') temp += '-DOOPETRIS_LIBRARY_RECORDINGS_TYPE=' + (get_option('default_library') == 'static' ? '1' : '0') -recordings_lib += {'compile_args': temp} +recordings_lib += { + 'compile_args': temp, +} temp = 0 recordings_lib += { diff --git a/src/lobby/credentials/meson.build b/src/lobby/credentials/meson.build index 614c441b..dfa6da82 100644 --- a/src/lobby/credentials/meson.build +++ b/src/lobby/credentials/meson.build @@ -1,6 +1 @@ -graphics_src_files += files( - 'buffer.cpp', - 'buffer.hpp', - 'secret.cpp', - 'secret.hpp', -) +graphics_src_files += files('buffer.cpp', 'buffer.hpp', 'secret.cpp', 'secret.hpp') diff --git a/src/lobby/meson.build b/src/lobby/meson.build index 057eca85..6e26e1cc 100644 --- a/src/lobby/meson.build +++ b/src/lobby/meson.build @@ -1,24 +1,12 @@ if online_multiplayer_system == 'curl' - graphics_src_files += files( - 'curl_client.cpp', - 'curl_client.hpp', - ) + graphics_src_files += files('curl_client.cpp', 'curl_client.hpp') elif online_multiplayer_system == 'httplib' - graphics_src_files += files( - 'httplib_client.cpp', - 'httplib_client.hpp', - ) + graphics_src_files += files('httplib_client.cpp', 'httplib_client.hpp') elif online_multiplayer_system == 'web' - graphics_src_files += files( - 'web_client.cpp', - 'web_client.hpp', - ) + graphics_src_files += files('web_client.cpp', 'web_client.hpp') else - error( - 'Unhandled online_multiplayer_system: \'' - + online_multiplayer_system - + '\'', - ) + error('Unhandled online_multiplayer_system: \'' + + online_multiplayer_system + '\'') endif graphics_src_files += files( diff --git a/src/meson.build b/src/meson.build index c06d91f6..47b2ed75 100644 --- a/src/meson.build +++ b/src/meson.build @@ -20,11 +20,8 @@ if build_application graphics_lib += { 'deps': [graphics_lib.get('deps'), liboopetris_recordings_dep], 'inc_dirs': [graphics_lib.get('inc_dirs'), include_directories('.')], - 'compile_args': [ - graphics_lib.get('compile_args'), - '-DOOPETRIS_LIBRARY_GRAPHICS_TYPE=' - + (get_option('default_library') == 'static' ? '1' : '0'), - ], + 'compile_args': [graphics_lib.get('compile_args'), '-DOOPETRIS_LIBRARY_GRAPHICS_TYPE=' + + (get_option('default_library') == 'static' ? '1' : '0')], } liboopetris_graphics = library( diff --git a/src/scenes/about_page/meson.build b/src/scenes/about_page/meson.build index 08a18fe8..810e7ec1 100644 --- a/src/scenes/about_page/meson.build +++ b/src/scenes/about_page/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'about_page.cpp', - 'about_page.hpp', -) +graphics_src_files += files('about_page.cpp', 'about_page.hpp') diff --git a/src/scenes/loading_screen/meson.build b/src/scenes/loading_screen/meson.build index f21ea09a..9a0039ed 100644 --- a/src/scenes/loading_screen/meson.build +++ b/src/scenes/loading_screen/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'loading_screen.cpp', - 'loading_screen.hpp', -) +graphics_src_files += files('loading_screen.cpp', 'loading_screen.hpp') diff --git a/src/scenes/logo/meson.build b/src/scenes/logo/meson.build index 65358428..c9fe662a 100644 --- a/src/scenes/logo/meson.build +++ b/src/scenes/logo/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'logo.cpp', - 'logo.hpp', -) +graphics_src_files += files('logo.cpp', 'logo.hpp') diff --git a/src/scenes/main_menu/meson.build b/src/scenes/main_menu/meson.build index 08b3c734..430c2118 100644 --- a/src/scenes/main_menu/meson.build +++ b/src/scenes/main_menu/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'main_menu.cpp', - 'main_menu.hpp', -) +graphics_src_files += files('main_menu.cpp', 'main_menu.hpp') diff --git a/src/scenes/multiplayer_menu/meson.build b/src/scenes/multiplayer_menu/meson.build index 289b8c47..8fe549bd 100644 --- a/src/scenes/multiplayer_menu/meson.build +++ b/src/scenes/multiplayer_menu/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'multiplayer_menu.cpp', - 'multiplayer_menu.hpp', -) +graphics_src_files += files('multiplayer_menu.cpp', 'multiplayer_menu.hpp') diff --git a/src/scenes/online_lobby/meson.build b/src/scenes/online_lobby/meson.build index 84494318..32d2fb19 100644 --- a/src/scenes/online_lobby/meson.build +++ b/src/scenes/online_lobby/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'online_lobby.cpp', - 'online_lobby.hpp', -) +graphics_src_files += files('online_lobby.cpp', 'online_lobby.hpp') diff --git a/src/scenes/play_select_menu/meson.build b/src/scenes/play_select_menu/meson.build index cbb80ac6..3e5ce14a 100644 --- a/src/scenes/play_select_menu/meson.build +++ b/src/scenes/play_select_menu/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'play_select_menu.cpp', - 'play_select_menu.hpp', -) +graphics_src_files += files('play_select_menu.cpp', 'play_select_menu.hpp') diff --git a/src/scenes/recording_selector/meson.build b/src/scenes/recording_selector/meson.build index 8678059a..82e82662 100644 --- a/src/scenes/recording_selector/meson.build +++ b/src/scenes/recording_selector/meson.build @@ -6,8 +6,5 @@ graphics_src_files += files( ) if have_file_dialogs - graphics_src_files += files( - 'recording_chooser.cpp', - 'recording_chooser.hpp', - ) + graphics_src_files += files('recording_chooser.cpp', 'recording_chooser.hpp') endif diff --git a/src/scenes/replay_game/meson.build b/src/scenes/replay_game/meson.build index 1a336abc..7cfa633d 100644 --- a/src/scenes/replay_game/meson.build +++ b/src/scenes/replay_game/meson.build @@ -1,4 +1 @@ -graphics_src_files += files( - 'replay_game.cpp', - 'replay_game.hpp', -) +graphics_src_files += files('replay_game.cpp', 'replay_game.hpp') diff --git a/src/ui/meson.build b/src/ui/meson.build index 3c896191..f05dc328 100644 --- a/src/ui/meson.build +++ b/src/ui/meson.build @@ -1,10 +1,4 @@ -graphics_src_files += files( - 'focusable.hpp', - 'layout.cpp', - 'layout.hpp', - 'widget.cpp', - 'widget.hpp', -) +graphics_src_files += files('focusable.hpp', 'layout.cpp', 'layout.hpp', 'widget.cpp', 'widget.hpp') subdir('components') subdir('layouts') diff --git a/subprojects/packagefiles/discord_social_sdk/meson.build b/subprojects/packagefiles/discord_social_sdk/meson.build index 4ac396c9..5e31cf77 100644 --- a/subprojects/packagefiles/discord_social_sdk/meson.build +++ b/subprojects/packagefiles/discord_social_sdk/meson.build @@ -13,7 +13,10 @@ inc_dirs = include_directories('include') header_files = files('include' / 'cdiscord.h', 'include' / 'discordpp.h') -install_headers(header_files, subdir: 'discord') +install_headers( + header_files, + subdir: 'discord', +) lib_base_dir = '' @@ -21,9 +24,7 @@ if host_machine.system() == 'darwin' if host_machine.cpu_family() in ['aarch64', 'x86_64'] lib_base_dir = 'lib' else - error( - 'unsupported architecture for macos: ' + host_machine.cpu_family(), - ) + error('unsupported architecture for macos: ' + host_machine.cpu_family()) endif elif host_machine.system() == 'linux' @@ -58,24 +59,19 @@ elif host_machine.system() == 'linux' endif else - error( - 'unsupported architecture for linux: ' + host_machine.cpu_family(), - ) + error('unsupported architecture for linux: ' + host_machine.cpu_family()) endif elif host_machine.system() == 'windows' if host_machine.cpu_family() == 'x86_64' lib_base_dir = get_option('default_library') == 'static' ? 'bin' : 'lib' else - error( - 'unsupported architecture for windows: ' + host_machine.cpu_family(), - ) + error('unsupported architecture for windows: ' + host_machine.cpu_family()) endif else error('unsupported system: ' + host_machine.system()) endif -lib_dir = ( - lib_base_dir / (get_option('buildtype') == 'release' ? 'release' : 'debug') +lib_dir = (lib_base_dir / (get_option('buildtype') == 'release' ? 'release' : 'debug') ) c = meson.get_compiler('c') diff --git a/subprojects/packagefiles/keyutils/meson.build b/subprojects/packagefiles/keyutils/meson.build index 89d611c0..e2e0e04d 100644 --- a/subprojects/packagefiles/keyutils/meson.build +++ b/subprojects/packagefiles/keyutils/meson.build @@ -16,9 +16,7 @@ project( inc_dirs = include_directories('.') -src_files = files( - 'keyutils.c', -) +src_files = files('keyutils.c') API_VERSON = '1.10' @@ -26,7 +24,8 @@ sh = find_program('sh') current_date = run_command( sh, - '-c', 'date -u +%F', + '-c', + 'date -u +%F', check: true, ).stdout().strip() diff --git a/tests/graphics/meson.build b/tests/graphics/meson.build index dcb37735..081221b1 100644 --- a/tests/graphics/meson.build +++ b/tests/graphics/meson.build @@ -1,4 +1 @@ -graphics_test_src += files( - 'sdl_key.cpp', - 'tetrion_simulation.cpp', -) +graphics_test_src += files('sdl_key.cpp', 'tetrion_simulation.cpp') diff --git a/tests/utils/meson.build b/tests/utils/meson.build index adaf0f0e..95435d7f 100644 --- a/tests/utils/meson.build +++ b/tests/utils/meson.build @@ -1,6 +1 @@ -test_src += files( - 'files.cpp', - 'files.hpp', - 'helper.hpp', - 'printer.hpp', -) +test_src += files('files.cpp', 'files.hpp', 'helper.hpp', 'printer.hpp') diff --git a/tools/dependencies/meson.build b/tools/dependencies/meson.build index b3898630..647ac776 100644 --- a/tools/dependencies/meson.build +++ b/tools/dependencies/meson.build @@ -46,7 +46,7 @@ if meson.is_cross_build() int main() { return 0; } - ''', + ''' ) if not can_compile @@ -67,11 +67,13 @@ if meson.is_cross_build() foreach native_dependency_tuple : map_native_dependencies native_dep_lib_name = native_dependency_tuple[0] - native_dep_name = ( - native_dependency_tuple.length() == 2 ? native_dependency_tuple[1] : native_dep_lib_name - ) + native_dep_name = (native_dependency_tuple.length() == 2 ? native_dependency_tuple[1] : native_dep_lib_name +) - native_dep = cpp.find_library(native_dep_lib_name, required: true) + native_dep = cpp.find_library( + native_dep_lib_name, + required: true, + ) if native_dep_name == 'SDL2' @@ -79,37 +81,25 @@ if meson.is_cross_build() 'SDL_MAJOR_VERSION', prefix: '#include ', ).strip('"') - assert( - major_version != '', - 'failed to get major_version from SDL_version.h', - ) + assert(major_version != '', 'failed to get major_version from SDL_version.h') minor_version = cpp.get_define( 'SDL_MINOR_VERSION', prefix: '#include ', ).strip('"') - assert( - minor_version != '', - 'failed to get minor_version from SDL_version.h', - ) + assert(minor_version != '', 'failed to get minor_version from SDL_version.h') patch_version = cpp.get_define( 'SDL_PATCHLEVEL', prefix: '#include ', ).strip('"') - assert( - patch_version != '', - 'failed to get patch_version from SDL_version.h', - ) + assert(patch_version != '', 'failed to get patch_version from SDL_version.h') native_dep_with_version = declare_dependency( dependencies: native_dep, version: major_version + '.' + minor_version + '.' + patch_version, ) - meson.override_dependency( - native_dep_name, - native_dep_with_version, - ) + meson.override_dependency(native_dep_name, native_dep_with_version) else meson.override_dependency(native_dep_name, native_dep) @@ -131,7 +121,10 @@ if meson.is_cross_build() ] foreach native_dep_name : native_dep_names - native_deps += cpp.find_library(native_dep_name, required: true) + native_deps += cpp.find_library( + native_dep_name, + required: true, + ) endforeach graphics_lib += { @@ -145,10 +138,9 @@ endif fmt_use_header_only = false -if ( - meson.is_cross_build() - and (host_machine.system() == 'switch' - or host_machine.system() == '3ds') +if (meson.is_cross_build() +and (host_machine.system() == 'switch' +or host_machine.system() == '3ds') ) fmt_use_header_only = true endif @@ -162,16 +154,24 @@ if fmt_use_header_only meson.override_dependency('fmt', fmt_header_only_dep) fmt_dep = fmt_header_only_dep else - fmt_dep = dependency('fmt', required: true, allow_fallback: true) + fmt_dep = dependency( + 'fmt', + required: true, + allow_fallback: true, + ) endif -core_lib += {'deps': [core_lib.get('deps'), fmt_dep]} +core_lib += { + 'deps': [core_lib.get('deps'), fmt_dep], +} nlohmann_json_dep = dependency( 'nlohmann_json', required: true, ) -core_lib += {'deps': [core_lib.get('deps'), nlohmann_json_dep]} +core_lib += { + 'deps': [core_lib.get('deps'), nlohmann_json_dep], +} # check std::expected support have_std_expected = cpp.compiles( @@ -192,7 +192,10 @@ if not have_std_expected message('Compiler doesn\'t support std::expected, using fallback') - tl_exp_dep = dependency('tl-expected', required: true) + tl_exp_dep = dependency( + 'tl-expected', + required: true, + ) temp = core_lib.get('compile_args') temp += '-D_USE_TL_EXPECTED' @@ -222,16 +225,23 @@ endif magic_enum_dep = dependency( 'magic_enum', required: true, - default_options: {'test': false, 'hash': true}, + default_options: { + 'test': false, + 'hash': true, + }, ) -core_lib += {'deps': [core_lib.get('deps'), magic_enum_dep]} +core_lib += { + 'deps': [core_lib.get('deps'), magic_enum_dep], +} utf8cpp_dep = dependency( 'utf8cpp', required: true, version: '>=4.0.0', ) -graphics_lib += {'deps': [graphics_lib.get('deps'), utf8cpp_dep]} +graphics_lib += { + 'deps': [graphics_lib.get('deps'), utf8cpp_dep], +} icu_dep = dependency( 'icu-uc', @@ -240,10 +250,7 @@ icu_dep = dependency( if icu_dep.found() graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_HAVE_ICU_DEP', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-D_HAVE_ICU_DEP'], 'deps': [graphics_lib.get('deps'), icu_dep], } endif @@ -271,7 +278,9 @@ if build_application sdl2_dep = dependency( 'sdl2', required: true, - default_options: {'test': false}, + default_options: { + 'test': false, + }, version: '>=2.24.0', ) sdl2main_dep = dependency( @@ -314,15 +323,24 @@ if build_application allow_fallback: true, required: false, ) - sdl2_mixer_flags = {'flac': 'enabled'} + sdl2_mixer_flags = { + 'flac': 'enabled', + } sdl2_mixer_defines = ['-DAUDIO_WITH_FLAC_SUPPORT'] if mpg123_dep.found() - sdl2_mixer_flags += {'mpg123': 'enabled'} + sdl2_mixer_flags += { + 'mpg123': 'enabled', + } sdl2_mixer_defines += '-DAUDIO_WITH_MP3_SUPPORT' else - mpg123_dep = cpp.find_library('mpg123', required: false) + mpg123_dep = cpp.find_library( + 'mpg123', + required: false, + ) if mpg123_dep.found() - sdl2_mixer_flags += {'mpg123': 'enabled'} + sdl2_mixer_flags += { + 'mpg123': 'enabled', + } sdl2_mixer_defines += '-DAUDIO_WITH_MP3_SUPPORT' meson.override_dependency('mpg123', mpg123_dep) @@ -344,7 +362,9 @@ if build_application spdlog_dep = dependency( 'spdlog', required: true, - default_options: {'tests': 'disabled'}, + default_options: { + 'tests': 'disabled', + }, ) graphics_lib += { 'deps': [graphics_lib.get('deps'), spdlog_dep], @@ -352,10 +372,7 @@ if build_application if (meson.is_cross_build() and host_machine.system() == '3ds') graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-DSPDLOG_NO_TLS', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-DSPDLOG_NO_TLS'], } endif @@ -375,20 +392,14 @@ if build_application graphics_lib += { 'deps': [graphics_lib.get('deps'), cpp_httlib_dep], - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_OOPETRIS_ONLINE_SYSTEM=0', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-D_OOPETRIS_ONLINE_SYSTEM=0'], } elif meson.is_cross_build() and host_machine.system() == 'emscripten' online_multiplayer_system = 'web' graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_OOPETRIS_ONLINE_SYSTEM=1', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-D_OOPETRIS_ONLINE_SYSTEM=1'], } else @@ -404,30 +415,30 @@ if build_application graphics_lib += { 'deps': [graphics_lib.get('deps'), curl_cpp_wrapper], - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_OOPETRIS_ONLINE_SYSTEM=2', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-D_OOPETRIS_ONLINE_SYSTEM=2'], } endif - if ( - host_machine.system() == 'linux' - or (meson.is_cross_build() - and host_machine.system() == 'android') - ) + if (host_machine.system() == 'linux' +or (meson.is_cross_build() +and host_machine.system() == 'android') +) keyutils_dep = dependency( 'keyutils', required: true, allow_fallback: true, ) - graphics_lib += {'deps': [graphics_lib.get('deps'), keyutils_dep]} + graphics_lib += { + 'deps': [graphics_lib.get('deps'), keyutils_dep], + } elif host_machine.system() == 'windows' c = meson.get_compiler('c') ncrypt_dep = c.find_library('ncrypt') - graphics_lib += {'deps': [graphics_lib.get('deps'), ncrypt_dep]} + graphics_lib += { + 'deps': [graphics_lib.get('deps'), ncrypt_dep], + } endif build_installer = get_option('build_installer') @@ -438,8 +449,9 @@ if build_application if build_installer if get_option('buildtype') != 'release' error( - 'buildtype needs to be \'release\', when building the installer, but was: ' + - get_option('buildtype'), + 'buildtype needs to be \'release\', when building the installer, but was: ' + get_option( + 'buildtype' + ) ) endif @@ -447,23 +459,21 @@ if build_application if get_option('prefix') == '/app' is_flatpak_build = true else - error( - 'only support flatpak builds, when building the installer for linux', - ) + error('only support flatpak builds, when building the installer for linux') endif elif host_machine.system() == 'windows' message('Adding a windows installer target: \'windows_installer\'') else # TODO: create a proper installer for macOS : https://mesonbuild.com/Creating-OSX-packages.html - error( - 'unsupported system for building the installer: ' + host_machine.system(), - ) + error('unsupported system for building the installer: ' + host_machine.system()) endif temp = core_lib.get('compile_args') temp += '-DBUILD_INSTALLER' - core_lib += {'compile_args': temp} + core_lib += { + 'compile_args': temp, + } temp = 0 endif @@ -473,7 +483,9 @@ if build_application temp = core_lib.get('compile_args') temp += '-DFLATPAK_BUILD' - core_lib += {'compile_args': temp} + core_lib += { + 'compile_args': temp, + } temp = 0 endif @@ -491,25 +503,20 @@ if build_application if nfde_dep.found() have_file_dialogs = true graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_HAVE_FILE_DIALOGS', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-D_HAVE_FILE_DIALOGS'], 'deps': [graphics_lib.get('deps'), nfde_dep], } endif c = meson.get_compiler('c') - discord_dep_required = ( - not meson.is_cross_build() - and get_option('build_installer') - ) + discord_dep_required = (not meson.is_cross_build() +and get_option('build_installer') +) - if ( - host_machine.system() == 'linux' - and host_machine.cpu_family() == 'aarch64' - ) + if (host_machine.system() == 'linux' +and host_machine.cpu_family() == 'aarch64' +) # not supported on aarch64 linux :( discord_dep_required = false endif @@ -523,15 +530,15 @@ if build_application if discord_social_sdk_dep.found() have_discord_social_sdk = true graphics_lib += { - 'compile_args': [ - graphics_lib.get('compile_args'), - '-D_HAVE_DISCORD_SOCIAL_SDK', - ], + 'compile_args': [graphics_lib.get('compile_args'), '-D_HAVE_DISCORD_SOCIAL_SDK'], 'deps': [graphics_lib.get('deps'), discord_social_sdk_dep], } endif - argparse_dep = dependency('argparse', required: true) + argparse_dep = dependency( + 'argparse', + required: true, + ) graphic_application_deps += argparse_dep recordings_application_deps += argparse_dep diff --git a/tools/install/meson.build b/tools/install/meson.build index b141b05e..091e5c27 100644 --- a/tools/install/meson.build +++ b/tools/install/meson.build @@ -72,7 +72,10 @@ if build_application install_tag: 'other', ) - desktop_file_validate_exe = find_program('desktop-file-validate', required: require_checks) + desktop_file_validate_exe = find_program( + 'desktop-file-validate', + required: require_checks, + ) if desktop_file_validate_exe.found() test( @@ -97,18 +100,16 @@ if build_application install_tag: 'other', ) - ascli_exe = find_program('appstreamcli', required: require_checks) + ascli_exe = find_program( + 'appstreamcli', + required: require_checks, + ) if ascli_exe.found() test( 'validate metainfo file', ascli_exe, - args: [ - 'validate', - '--no-net', - '--explain', - '--pedantic', metainfo_file, - ], + args: ['validate', '--no-net', '--explain', '--pedantic', metainfo_file], ) endif diff --git a/tools/options/meson.build b/tools/options/meson.build index 43c26c1e..a1e40bf2 100644 --- a/tools/options/meson.build +++ b/tools/options/meson.build @@ -3,9 +3,7 @@ oopetris_name = 'OOPetris' core_lib = { 'inc_dirs': [], - 'compile_args': [ - '-DOOPETRIS_VERSION=' + meson.project_version(), - ], + 'compile_args': ['-DOOPETRIS_VERSION=' + meson.project_version()], 'deps': [], } @@ -27,12 +25,10 @@ graphics_lib = { if meson.is_cross_build() and host_machine.system() == 'serenity' temp = core_lib.get('compile_args') - temp += [ - '-D__SERENITY__', - '-DINSTALL_FILES', - '-DINSTALL_LOCATION=' + get_option('prefix'), - ] - core_lib += {'compile_args': temp} + temp += ['-D__SERENITY__', '-DINSTALL_FILES', '-DINSTALL_LOCATION=' + get_option('prefix')] + core_lib += { + 'compile_args': temp, + } temp = 0 elif meson.is_cross_build() and host_machine.system() == 'android' cpp = meson.get_compiler('cpp') @@ -42,10 +38,7 @@ elif meson.is_cross_build() and host_machine.system() == 'android' '__ANDROID_API__', prefix: '#include ', ).strip('"') - assert( - android_api != '', - 'failed to get android_api version', - ) + assert(android_api != '', 'failed to get android_api version') android_compile_args = [] android_link_args = [] @@ -63,11 +56,23 @@ elif meson.is_cross_build() and host_machine.system() == 'android' ] if not meson.is_subproject() - add_global_link_arguments(android_link_args, language: ['cpp']) - add_global_arguments(android_compile_args, language: ['cpp']) + add_global_link_arguments( + android_link_args, + language: ['cpp'], + ) + add_global_arguments( + android_compile_args, + language: ['cpp'], + ) else - add_project_link_arguments(android_link_args, language: ['cpp']) - add_project_arguments(android_compile_args, language: ['cpp']) + add_project_link_arguments( + android_link_args, + language: ['cpp'], + ) + add_project_arguments( + android_compile_args, + language: ['cpp'], + ) endif endif @@ -79,7 +84,10 @@ build_with_libcpp = false allow_tl_expected_fallback = false if cpp.get_id() == 'gcc' - add_project_arguments('-Wold-style-cast', language: ['cpp']) + add_project_arguments( + '-Wold-style-cast', + language: ['cpp'], + ) elif cpp.get_id() == 'clang' build_with_libcpp_option = get_option('clang_libcpp') @@ -91,8 +99,14 @@ elif cpp.get_id() == 'clang' build_with_libcpp = true else - cpp_lib = cpp.find_library('c++', required: false) - cppabi_lib = cpp.find_library('c++abi', required: false) + cpp_lib = cpp.find_library( + 'c++', + required: false, + ) + cppabi_lib = cpp.find_library( + 'c++abi', + required: false, + ) if cpp_lib.found() and cppabi_lib.found() build_with_libcpp = true @@ -109,20 +123,28 @@ elif cpp.get_id() == 'clang' core_lib += { 'compile_args': temp, - 'deps': [ - core_lib.get('deps'), - cpp.find_library('c++'), - cpp.find_library('c++abi'), - ], + 'deps': [core_lib.get('deps'), cpp.find_library('c++'), cpp.find_library('c++abi')], } temp = 0 if not meson.is_subproject() - add_global_link_arguments('-stdlib=libc++', language: ['cpp']) - add_global_arguments('-stdlib=libc++', language: ['cpp']) + add_global_link_arguments( + '-stdlib=libc++', + language: ['cpp'], + ) + add_global_arguments( + '-stdlib=libc++', + language: ['cpp'], + ) else - add_project_link_arguments('-stdlib=libc++', language: ['cpp']) - add_project_arguments('-stdlib=libc++', language: ['cpp']) + add_project_link_arguments( + '-stdlib=libc++', + language: ['cpp'], + ) + add_project_arguments( + '-stdlib=libc++', + language: ['cpp'], + ) endif From ae1487e75cfa6e114b971e5988d923e0f3802c8c Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 21 Apr 2025 18:37:32 +0200 Subject: [PATCH 05/13] fix: also exit with non-zero ecxit code in the failure case of the meson check action --- .github/workflows/meson.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 726bdce3..15c5f688 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -28,7 +28,7 @@ jobs: --exclude='meson_options.txt' --ignored -c -z | xargs -0r meson format --check-only -c ./meson.format - || echo "Not all meson files are formatted correctly" + || (echo "Not all meson files are formatted correctly" && exit 1) && echo "All meson files are formatted correctly" ## TODO: use mesonlint from From 5b35d13f6ddc316e29bd0bfb141f89ba52bd68cf Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 03:29:31 +0200 Subject: [PATCH 06/13] feat: add custom node action to check all meson files for correct formatting --- .../actions/meson-format-action/.gitignore | 1 + .../actions/meson-format-action/action.yml | 40 +++ .github/actions/meson-format-action/index.js | 255 ++++++++++++++++++ .../meson-format-action/package-lock.json | 83 ++++++ .../actions/meson-format-action/package.json | 13 + .github/workflows/meson.yml | 18 +- 6 files changed, 396 insertions(+), 14 deletions(-) create mode 100644 .github/actions/meson-format-action/.gitignore create mode 100644 .github/actions/meson-format-action/action.yml create mode 100644 .github/actions/meson-format-action/index.js create mode 100644 .github/actions/meson-format-action/package-lock.json create mode 100644 .github/actions/meson-format-action/package.json diff --git a/.github/actions/meson-format-action/.gitignore b/.github/actions/meson-format-action/.gitignore new file mode 100644 index 00000000..c2658d7d --- /dev/null +++ b/.github/actions/meson-format-action/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/.github/actions/meson-format-action/action.yml b/.github/actions/meson-format-action/action.yml new file mode 100644 index 00000000..adb780ae --- /dev/null +++ b/.github/actions/meson-format-action/action.yml @@ -0,0 +1,40 @@ +name: 'Meson Format Action' +author: Totto16 +description: 'Check if meson files are formatted correctly' +inputs: + format-file: + description: 'Path of format file' + required: false + default: '' + only-git-files: + description: 'Only check files, that are check into git' + required: false + default: 'true' +runs: + using: 'composite' + steps: + - name: Install Node.Js + uses: actions/setup-node@v4 + id: setup-js + with: + node-version: 22 + + - name: Install Node Dependencies + id: install-dependencies + shell: bash + run: | + cd "${{github.action_path}}" + npm ci + + # NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything! + - name: Setup meson + id: install-meson + shell: bash + run: | + pip install meson --break-system-packages + + - name: Run checker + shell: bash + id: meson-format-checker + run: | + node "${{github.action_path}}/index.js" diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js new file mode 100644 index 00000000..4056feed --- /dev/null +++ b/.github/actions/meson-format-action/index.js @@ -0,0 +1,255 @@ +const core = require('@actions/core') +const exec = require('@actions/exec') +const io = require('@actions/io') + +/** + * @callback ExecListenerCallback + * @param {Buffer} data + * @returns {void} + */ + +/** + * @typedef ExecListeners + * @type {object} + * @property {ExecListenerCallback} stdout + */ + +/** + * @typedef ExecOptions + * @type {object} + * @property {ExecListeners} listeners + * @property {boolean} failOnStdErr + * @property {boolean} ignoreReturnCode + */ + +/** + * @typedef AnnotationProperties + * @type {object} + * @property {string} title + * @property {string} file +/** + * + * @param {string} executable + * @param {string[]} arguments + * @async + * @returns {Promise} + */ +async function execAndGetStdout(executable, args) { + /** @type {string} */ + let output = '' + + /** @type {ExecOptions} */ + const options = { + failOnStdErr: true, + ignoreReturnCode: false, + } + + options.listeners = { + stdout: (data) => { + output += data.toString() + }, + } + + await io.which(executable, true) + + /** @type {number} */ + const exitCode = await exec.exec(executable, args, options) + + if (exitCode != 0) { + throw new Error(`${executable} exited with exit code ${exitCode}`) + } + + return output.split('\n') +} + +/** + * @param {boolean} onlyGitFiles + * @async + * @returns {Promise} + */ +async function getMesonFiles(onlyGitFiles) { + /** @type {string[]} */ + let files + + /** @type {string[]} */ + const mesonFiles = ['meson.build', 'meson.options', 'meson_options.txt'] + + if (onlyGitFiles) { + /** @type {string[]} */ + const gitFiles = mesonFiles.map((file) => `--exclude='${file}'`) + + files = await execAndGetStdout('git', [ + 'ls-files', + ...gitFiles, + '--ignored', + '-c', + ]) + } else { + /** @type {string[][]} */ + const findFiles = mesonFiles.map((file) => ['-name', file]) + + /** @type {string[]} */ + const finalFindFiles = findFiles.reduce((acc, elem, index) => { + if (index != 0) { + acc.push('-o') + } + + acc.push(...elem) + + return acc + }, []) + + files = await execAndGetStdout('find', [ + '.', + '(', + ...finalFindFiles, + ')', + ]) + } + + return files +} + +/** + * + * @param {string} file + * @param {string} formatFile + * @async + * @returns {Promise} + */ +async function checkFile(file, formatFile) { + /** @type {ExecOptions} */ + const options = { + ignoreReturnCode: true, + } + + /** @type {string[]} */ + const additionalArgs = formatFile == '' ? [] : ['-c', formatFile] + + /** @type {number} */ + const exitCode = await exec.exec( + 'meson', + ['format', '--check-only', ...additionalArgs, file], + options + ) + + return exitCode == 0 +} + +/** + * @async + * @returns {Promise} + */ +async function main() { + try { + /** @type {string} */ + const os = core.platform.platform + + if (os != 'linux') { + throw new Error( + `Action atm only supported on linux: but are on: ${os}` + ) + } + + /** @type {string} */ + const formatFile = core.getInput('format-file', { required: false }) + + /** @type {boolean} */ + const onlyGitFiles = core.getBooleanInput('only-git-files', { + required: false, + }) + + /** @type {string[]} */ + const files = await getMesonFiles(onlyGitFiles) + + await io.which('meson', true) + + /** @type {string[]} */ + const notFormattedFiles = [] + + core.startGroup('Check all files') + + //TODO: maybe parallelize this + for (const file of files) { + core.info(`Checking file: '${file}'`) + + /** @type {boolean} */ + const result = await checkFile(file, formatFile) + + core.info( + result + ? 'File is formatted correctly' + : 'File has formatting errors' + ) + core.info('') + + if (!result) { + notFormattedFiles.push(file) + + /** @type {AnnotationProperties} */ + const properties = { + file, + title: 'File not formatted correctly', + } + + core.error('File not formatted correctly', properties) + } + } + + core.endGroup() + + if (notFormattedFiles.length == 0) { + core.summary.clear() + + core.summary.addHeading('Result', 1) + core.summary.addRaw( + ':white_check_mark: All files are correctly formatted', + true + ) + + core.summary.write() + return + } + + core.summary.clear() + + core.summary.addList( + notFormattedFiles.map((file) => `\`${file}\``), + false + ) + + /** @type {string} */ + const fileList = core.summary.stringify() + core.summary.clear() + + core.summary.addHeading('Result', 1) + core.summary.addRaw(':x: Some files are not formatted correctly', true) + + core.summary.addDetails('Affected Files', fileList) + core.summary.addSeparator() + + core.summary.addRaw( + 'To format the files run the following command', + true + ) + + /** @type {string} */ + const additionalArgs = formatFile == '' ? [] : [`-c ${formatFile}`] + + /** @type {string} */ + const finalFileList = notFormattedFiles.join(' ') + + core.summary.addCodeBlock( + `meson format ${additionalArgs} -i ${finalFileList}`, + 'bash' + ) + + core.summary.write() + + throw new Error('Soem files are not formatted correctly') + } catch (error) { + core.setFailed(error) + } +} + +main() diff --git a/.github/actions/meson-format-action/package-lock.json b/.github/actions/meson-format-action/package-lock.json new file mode 100644 index 00000000..900287b0 --- /dev/null +++ b/.github/actions/meson-format-action/package-lock.json @@ -0,0 +1,83 @@ +{ + "name": "meson-format-action", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "meson-format-action", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "@actions/core": "^1.11.1", + "@actions/exec": "^1.1.1", + "@actions/io": "^1.1.3" + } + }, + "node_modules/@actions/core": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz", + "integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==", + "license": "MIT", + "dependencies": { + "@actions/exec": "^1.1.1", + "@actions/http-client": "^2.0.1" + } + }, + "node_modules/@actions/exec": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", + "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", + "license": "MIT", + "dependencies": { + "@actions/io": "^1.0.1" + } + }, + "node_modules/@actions/http-client": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz", + "integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^5.25.4" + } + }, + "node_modules/@actions/io": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", + "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==", + "license": "MIT" + }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/undici": { + "version": "5.29.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz", + "integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==", + "license": "MIT", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + } + } +} diff --git a/.github/actions/meson-format-action/package.json b/.github/actions/meson-format-action/package.json new file mode 100644 index 00000000..131cefff --- /dev/null +++ b/.github/actions/meson-format-action/package.json @@ -0,0 +1,13 @@ +{ + "name": "meson-format-action", + "version": "1.0.0", + "main": "index.js", + "author": "Totto16", + "license": "MIT", + "description": "", + "dependencies": { + "@actions/core": "^1.11.1", + "@actions/exec": "^1.1.1", + "@actions/io": "^1.1.3" + } +} diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 15c5f688..46afa388 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -15,21 +15,11 @@ jobs: with: fetch-depth: '0' - # NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything! - - name: Setup meson - run: | - pip install meson --break-system-packages - - name: Check Files - run: > - git ls-files - --exclude='meson.build' - --exclude='meson.options' - --exclude='meson_options.txt' - --ignored -c -z | xargs -0r - meson format --check-only -c ./meson.format - || (echo "Not all meson files are formatted correctly" && exit 1) - && echo "All meson files are formatted correctly" + uses: ./.github/actions/meson-format-action + with: + format-file: ./meson.format + only-git-files: true ## TODO: use mesonlint from ## https://github.com/JCWasmx86/mesonlsp From 1a165b929c3c7a6bb15d6b98930824e2ea9ee042 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 12:27:27 +0200 Subject: [PATCH 07/13] ci: fix the ci input paramaters to the final script - set env variables, that get than used as input correctly --- .github/actions/meson-format-action/action.yml | 3 +++ .github/actions/meson-format-action/index.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.github/actions/meson-format-action/action.yml b/.github/actions/meson-format-action/action.yml index adb780ae..a872a69c 100644 --- a/.github/actions/meson-format-action/action.yml +++ b/.github/actions/meson-format-action/action.yml @@ -36,5 +36,8 @@ runs: - name: Run checker shell: bash id: meson-format-checker + env: + INPUT_FORMAT-FILE: ${{ inputs.format-file }} + INPUT_ONLY-GIT-FILES: ${{ inputs.only-git-files }} run: | node "${{github.action_path}}/index.js" diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js index 4056feed..730e21ec 100644 --- a/.github/actions/meson-format-action/index.js +++ b/.github/actions/meson-format-action/index.js @@ -151,6 +151,10 @@ async function main() { ) } + //WIP + core.error(`file input is: ${core.getInput('format-file', { required: false })}`) + core.error(`git-file input is: ${core.getInput('only-git-files', { required: false })}`) + /** @type {string} */ const formatFile = core.getInput('format-file', { required: false }) From 2a53180008aa26fef57d1766a070e0295539a079 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 13:03:56 +0200 Subject: [PATCH 08/13] ci: fix meson format action fix the retrieval of the files with git --- .github/actions/meson-format-action/index.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js index 730e21ec..bbda52bc 100644 --- a/.github/actions/meson-format-action/index.js +++ b/.github/actions/meson-format-action/index.js @@ -59,7 +59,10 @@ async function execAndGetStdout(executable, args) { throw new Error(`${executable} exited with exit code ${exitCode}`) } - return output.split('\n') + /** @type {string[]} */ + const result = output === '' ? [] : output.split('\n') + + return result } /** @@ -76,7 +79,7 @@ async function getMesonFiles(onlyGitFiles) { if (onlyGitFiles) { /** @type {string[]} */ - const gitFiles = mesonFiles.map((file) => `--exclude='${file}'`) + const gitFiles = mesonFiles.flatMap((file) => ['--exclude', file]) files = await execAndGetStdout('git', [ 'ls-files', @@ -124,7 +127,7 @@ async function checkFile(file, formatFile) { } /** @type {string[]} */ - const additionalArgs = formatFile == '' ? [] : ['-c', formatFile] + const additionalArgs = formatFile === '' ? [] : ['-c', formatFile] /** @type {number} */ const exitCode = await exec.exec( @@ -133,7 +136,7 @@ async function checkFile(file, formatFile) { options ) - return exitCode == 0 + return exitCode === 0 } /** @@ -151,10 +154,6 @@ async function main() { ) } - //WIP - core.error(`file input is: ${core.getInput('format-file', { required: false })}`) - core.error(`git-file input is: ${core.getInput('only-git-files', { required: false })}`) - /** @type {string} */ const formatFile = core.getInput('format-file', { required: false }) @@ -202,7 +201,7 @@ async function main() { core.endGroup() - if (notFormattedFiles.length == 0) { + if (notFormattedFiles.length === 0) { core.summary.clear() core.summary.addHeading('Result', 1) @@ -238,7 +237,7 @@ async function main() { ) /** @type {string} */ - const additionalArgs = formatFile == '' ? [] : [`-c ${formatFile}`] + const additionalArgs = formatFile === '' ? [] : [`-c ${formatFile}`] /** @type {string} */ const finalFileList = notFormattedFiles.join(' ') From a82a15ef1968ca5141d46f1a3afe5734c6ffb99d Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 14:15:57 +0200 Subject: [PATCH 09/13] ci: fix meson format action fix markdown generation, make it better readable for the user --- .github/actions/meson-format-action/index.js | 26 +++++++++----------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js index bbda52bc..eedff5e7 100644 --- a/.github/actions/meson-format-action/index.js +++ b/.github/actions/meson-format-action/index.js @@ -210,23 +210,18 @@ async function main() { true ) - core.summary.write() + core.summary.write({ overwrite: true }) return } core.summary.clear() - core.summary.addList( - notFormattedFiles.map((file) => `\`${file}\``), - false - ) - - /** @type {string} */ - const fileList = core.summary.stringify() - core.summary.clear() - core.summary.addHeading('Result', 1) core.summary.addRaw(':x: Some files are not formatted correctly', true) + core.summary.addBreak() + + /** @type {string} */ + const fileList = notFormattedFiles.map((file) => `- \`${file}\``) core.summary.addDetails('Affected Files', fileList) core.summary.addSeparator() @@ -235,21 +230,24 @@ async function main() { 'To format the files run the following command', true ) + core.summary.addBreak() /** @type {string} */ - const additionalArgs = formatFile === '' ? [] : [`-c ${formatFile}`] + const additionalArgs = formatFile === '' ? [] : [`-c "${formatFile}"`] /** @type {string} */ - const finalFileList = notFormattedFiles.join(' ') + const finalFileList = notFormattedFiles + .map((file) => `"${file}"`) + .join(' ') core.summary.addCodeBlock( `meson format ${additionalArgs} -i ${finalFileList}`, 'bash' ) - core.summary.write() + core.summary.write({ overwrite: true }) - throw new Error('Soem files are not formatted correctly') + throw new Error('Some files are not formatted correctly') } catch (error) { core.setFailed(error) } From 75021a08b5e2b323e48b1713e1d6264ecbf27ac6 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 14:30:50 +0200 Subject: [PATCH 10/13] ci: fix meson format action fix markdown generation, use a proper list for the file entries --- .github/actions/meson-format-action/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js index eedff5e7..7e81cd23 100644 --- a/.github/actions/meson-format-action/index.js +++ b/.github/actions/meson-format-action/index.js @@ -139,6 +139,22 @@ async function checkFile(file, formatFile) { return exitCode === 0 } +/** + * + * @param {string[]} items + * @param {boolean} ordered + * @returns {string[]} + */ +function getMarkdownListOf(items, ordered) { + /** @type {string[]} */ + const items = items.map((item) => `
  • ${item}
  • `) + + /** @type {string} */ + const listType = ordered ? 'ol' : 'ul' + + return `<${listType}>${itemsContent}` +} + /** * @async * @returns {Promise} @@ -221,7 +237,7 @@ async function main() { core.summary.addBreak() /** @type {string} */ - const fileList = notFormattedFiles.map((file) => `- \`${file}\``) + const fileList = getMarkdownListOf(notFormattedFiles) core.summary.addDetails('Affected Files', fileList) core.summary.addSeparator() From 19f4286b517397918c05b7f3de2ee09caf43faec Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 14:30:54 +0200 Subject: [PATCH 11/13] ci: fix meson format action only install production files in the action --- .github/actions/meson-format-action/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/meson-format-action/action.yml b/.github/actions/meson-format-action/action.yml index a872a69c..566b31be 100644 --- a/.github/actions/meson-format-action/action.yml +++ b/.github/actions/meson-format-action/action.yml @@ -24,7 +24,7 @@ runs: shell: bash run: | cd "${{github.action_path}}" - npm ci + npm ci --production # NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything! - name: Setup meson From d2c9de15c71d49a24d7dd147d6ea5c95ca4e7942 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 14:43:06 +0200 Subject: [PATCH 12/13] ci: fix meson format action fix: add jsdoc type checking also check the types, and fix errors --- .github/actions/meson-format-action/index.js | 56 ++++++------------- .../actions/meson-format-action/jsconfig.json | 20 +++++++ .../meson-format-action/package-lock.json | 35 ++++++++++++ .../actions/meson-format-action/package.json | 7 +++ 4 files changed, 79 insertions(+), 39 deletions(-) create mode 100644 .github/actions/meson-format-action/jsconfig.json diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js index 7e81cd23..e9ad9ecd 100644 --- a/.github/actions/meson-format-action/index.js +++ b/.github/actions/meson-format-action/index.js @@ -2,35 +2,10 @@ const core = require('@actions/core') const exec = require('@actions/exec') const io = require('@actions/io') -/** - * @callback ExecListenerCallback - * @param {Buffer} data - * @returns {void} - */ - -/** - * @typedef ExecListeners - * @type {object} - * @property {ExecListenerCallback} stdout - */ - -/** - * @typedef ExecOptions - * @type {object} - * @property {ExecListeners} listeners - * @property {boolean} failOnStdErr - * @property {boolean} ignoreReturnCode - */ - -/** - * @typedef AnnotationProperties - * @type {object} - * @property {string} title - * @property {string} file /** * * @param {string} executable - * @param {string[]} arguments + * @param {string[]} args * @async * @returns {Promise} */ @@ -38,15 +13,14 @@ async function execAndGetStdout(executable, args) { /** @type {string} */ let output = '' - /** @type {ExecOptions} */ + /** @type {exec.ExecOptions} */ const options = { failOnStdErr: true, ignoreReturnCode: false, - } - - options.listeners = { - stdout: (data) => { - output += data.toString() + listeners: { + stdout: (data) => { + output += data.toString() + }, }, } @@ -121,7 +95,7 @@ async function getMesonFiles(onlyGitFiles) { * @returns {Promise} */ async function checkFile(file, formatFile) { - /** @type {ExecOptions} */ + /** @type {exec.ExecOptions} */ const options = { ignoreReturnCode: true, } @@ -143,11 +117,11 @@ async function checkFile(file, formatFile) { * * @param {string[]} items * @param {boolean} ordered - * @returns {string[]} + * @returns {string} */ function getMarkdownListOf(items, ordered) { /** @type {string[]} */ - const items = items.map((item) => `
  • ${item}
  • `) + const itemsContent = items.map((item) => `
  • ${item}
  • `) /** @type {string} */ const listType = ordered ? 'ol' : 'ul' @@ -205,7 +179,7 @@ async function main() { if (!result) { notFormattedFiles.push(file) - /** @type {AnnotationProperties} */ + /** @type {core.AnnotationProperties} */ const properties = { file, title: 'File not formatted correctly', @@ -237,7 +211,7 @@ async function main() { core.summary.addBreak() /** @type {string} */ - const fileList = getMarkdownListOf(notFormattedFiles) + const fileList = getMarkdownListOf(notFormattedFiles, false) core.summary.addDetails('Affected Files', fileList) core.summary.addSeparator() @@ -249,7 +223,7 @@ async function main() { core.summary.addBreak() /** @type {string} */ - const additionalArgs = formatFile === '' ? [] : [`-c "${formatFile}"`] + const additionalArgs = formatFile === '' ? '' : `-c "${formatFile}"` /** @type {string} */ const finalFileList = notFormattedFiles @@ -265,7 +239,11 @@ async function main() { throw new Error('Some files are not formatted correctly') } catch (error) { - core.setFailed(error) + if (error instanceof Error) { + core.setFailed(error) + } else { + core.setFailed(`Invalid error thrown: ${error}`) + } } } diff --git a/.github/actions/meson-format-action/jsconfig.json b/.github/actions/meson-format-action/jsconfig.json new file mode 100644 index 00000000..7b118202 --- /dev/null +++ b/.github/actions/meson-format-action/jsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "strict": true, + "noImplicitAny": true, + "strictFunctionTypes": true, + "strictPropertyInitialization": true, + "strictBindCallApply": true, + "strictNullChecks": true, + "noImplicitThis": true, + "noImplicitReturns": true, + "alwaysStrict": true, + "esModuleInterop": true, + "checkJs": true, + "allowJs": true, + "declaration": true, + "noEmit": true, + "exactOptionalPropertyTypes": true + }, + "files": ["index.js"] +} diff --git a/.github/actions/meson-format-action/package-lock.json b/.github/actions/meson-format-action/package-lock.json index 900287b0..54109bdf 100644 --- a/.github/actions/meson-format-action/package-lock.json +++ b/.github/actions/meson-format-action/package-lock.json @@ -12,6 +12,10 @@ "@actions/core": "^1.11.1", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.3" + }, + "devDependencies": { + "@types/node": "^22.14.1", + "typescript": "^5.8.3" } }, "node_modules/@actions/core": { @@ -58,6 +62,16 @@ "node": ">=14" } }, + "node_modules/@types/node": { + "version": "22.14.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz", + "integrity": "sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, "node_modules/tunnel": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", @@ -67,6 +81,20 @@ "node": ">=0.6.11 <=0.7.0 || >=0.7.3" } }, + "node_modules/typescript": { + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/undici": { "version": "5.29.0", "resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz", @@ -78,6 +106,13 @@ "engines": { "node": ">=14.0" } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" } } } diff --git a/.github/actions/meson-format-action/package.json b/.github/actions/meson-format-action/package.json index 131cefff..080cfbd4 100644 --- a/.github/actions/meson-format-action/package.json +++ b/.github/actions/meson-format-action/package.json @@ -9,5 +9,12 @@ "@actions/core": "^1.11.1", "@actions/exec": "^1.1.1", "@actions/io": "^1.1.3" + }, + "scripts": { + "check": "tsc --project ./jsconfig.json" + }, + "devDependencies": { + "@types/node": "^22.14.1", + "typescript": "^5.8.3" } } From cdea6c46a38d58da2b2b354cd504c00361131d29 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 22 Apr 2025 14:54:59 +0200 Subject: [PATCH 13/13] ci: fix meson format action migrate to seperate repo, that does the exact same, delete the local copy of that action --- .../actions/meson-format-action/.gitignore | 1 - .../actions/meson-format-action/action.yml | 43 --- .github/actions/meson-format-action/index.js | 250 ------------------ .../actions/meson-format-action/jsconfig.json | 20 -- .../meson-format-action/package-lock.json | 118 --------- .../actions/meson-format-action/package.json | 20 -- .github/workflows/meson.yml | 2 +- 7 files changed, 1 insertion(+), 453 deletions(-) delete mode 100644 .github/actions/meson-format-action/.gitignore delete mode 100644 .github/actions/meson-format-action/action.yml delete mode 100644 .github/actions/meson-format-action/index.js delete mode 100644 .github/actions/meson-format-action/jsconfig.json delete mode 100644 .github/actions/meson-format-action/package-lock.json delete mode 100644 .github/actions/meson-format-action/package.json diff --git a/.github/actions/meson-format-action/.gitignore b/.github/actions/meson-format-action/.gitignore deleted file mode 100644 index c2658d7d..00000000 --- a/.github/actions/meson-format-action/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/.github/actions/meson-format-action/action.yml b/.github/actions/meson-format-action/action.yml deleted file mode 100644 index 566b31be..00000000 --- a/.github/actions/meson-format-action/action.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: 'Meson Format Action' -author: Totto16 -description: 'Check if meson files are formatted correctly' -inputs: - format-file: - description: 'Path of format file' - required: false - default: '' - only-git-files: - description: 'Only check files, that are check into git' - required: false - default: 'true' -runs: - using: 'composite' - steps: - - name: Install Node.Js - uses: actions/setup-node@v4 - id: setup-js - with: - node-version: 22 - - - name: Install Node Dependencies - id: install-dependencies - shell: bash - run: | - cd "${{github.action_path}}" - npm ci --production - - # NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything! - - name: Setup meson - id: install-meson - shell: bash - run: | - pip install meson --break-system-packages - - - name: Run checker - shell: bash - id: meson-format-checker - env: - INPUT_FORMAT-FILE: ${{ inputs.format-file }} - INPUT_ONLY-GIT-FILES: ${{ inputs.only-git-files }} - run: | - node "${{github.action_path}}/index.js" diff --git a/.github/actions/meson-format-action/index.js b/.github/actions/meson-format-action/index.js deleted file mode 100644 index e9ad9ecd..00000000 --- a/.github/actions/meson-format-action/index.js +++ /dev/null @@ -1,250 +0,0 @@ -const core = require('@actions/core') -const exec = require('@actions/exec') -const io = require('@actions/io') - -/** - * - * @param {string} executable - * @param {string[]} args - * @async - * @returns {Promise} - */ -async function execAndGetStdout(executable, args) { - /** @type {string} */ - let output = '' - - /** @type {exec.ExecOptions} */ - const options = { - failOnStdErr: true, - ignoreReturnCode: false, - listeners: { - stdout: (data) => { - output += data.toString() - }, - }, - } - - await io.which(executable, true) - - /** @type {number} */ - const exitCode = await exec.exec(executable, args, options) - - if (exitCode != 0) { - throw new Error(`${executable} exited with exit code ${exitCode}`) - } - - /** @type {string[]} */ - const result = output === '' ? [] : output.split('\n') - - return result -} - -/** - * @param {boolean} onlyGitFiles - * @async - * @returns {Promise} - */ -async function getMesonFiles(onlyGitFiles) { - /** @type {string[]} */ - let files - - /** @type {string[]} */ - const mesonFiles = ['meson.build', 'meson.options', 'meson_options.txt'] - - if (onlyGitFiles) { - /** @type {string[]} */ - const gitFiles = mesonFiles.flatMap((file) => ['--exclude', file]) - - files = await execAndGetStdout('git', [ - 'ls-files', - ...gitFiles, - '--ignored', - '-c', - ]) - } else { - /** @type {string[][]} */ - const findFiles = mesonFiles.map((file) => ['-name', file]) - - /** @type {string[]} */ - const finalFindFiles = findFiles.reduce((acc, elem, index) => { - if (index != 0) { - acc.push('-o') - } - - acc.push(...elem) - - return acc - }, []) - - files = await execAndGetStdout('find', [ - '.', - '(', - ...finalFindFiles, - ')', - ]) - } - - return files -} - -/** - * - * @param {string} file - * @param {string} formatFile - * @async - * @returns {Promise} - */ -async function checkFile(file, formatFile) { - /** @type {exec.ExecOptions} */ - const options = { - ignoreReturnCode: true, - } - - /** @type {string[]} */ - const additionalArgs = formatFile === '' ? [] : ['-c', formatFile] - - /** @type {number} */ - const exitCode = await exec.exec( - 'meson', - ['format', '--check-only', ...additionalArgs, file], - options - ) - - return exitCode === 0 -} - -/** - * - * @param {string[]} items - * @param {boolean} ordered - * @returns {string} - */ -function getMarkdownListOf(items, ordered) { - /** @type {string[]} */ - const itemsContent = items.map((item) => `
  • ${item}
  • `) - - /** @type {string} */ - const listType = ordered ? 'ol' : 'ul' - - return `<${listType}>${itemsContent}` -} - -/** - * @async - * @returns {Promise} - */ -async function main() { - try { - /** @type {string} */ - const os = core.platform.platform - - if (os != 'linux') { - throw new Error( - `Action atm only supported on linux: but are on: ${os}` - ) - } - - /** @type {string} */ - const formatFile = core.getInput('format-file', { required: false }) - - /** @type {boolean} */ - const onlyGitFiles = core.getBooleanInput('only-git-files', { - required: false, - }) - - /** @type {string[]} */ - const files = await getMesonFiles(onlyGitFiles) - - await io.which('meson', true) - - /** @type {string[]} */ - const notFormattedFiles = [] - - core.startGroup('Check all files') - - //TODO: maybe parallelize this - for (const file of files) { - core.info(`Checking file: '${file}'`) - - /** @type {boolean} */ - const result = await checkFile(file, formatFile) - - core.info( - result - ? 'File is formatted correctly' - : 'File has formatting errors' - ) - core.info('') - - if (!result) { - notFormattedFiles.push(file) - - /** @type {core.AnnotationProperties} */ - const properties = { - file, - title: 'File not formatted correctly', - } - - core.error('File not formatted correctly', properties) - } - } - - core.endGroup() - - if (notFormattedFiles.length === 0) { - core.summary.clear() - - core.summary.addHeading('Result', 1) - core.summary.addRaw( - ':white_check_mark: All files are correctly formatted', - true - ) - - core.summary.write({ overwrite: true }) - return - } - - core.summary.clear() - - core.summary.addHeading('Result', 1) - core.summary.addRaw(':x: Some files are not formatted correctly', true) - core.summary.addBreak() - - /** @type {string} */ - const fileList = getMarkdownListOf(notFormattedFiles, false) - - core.summary.addDetails('Affected Files', fileList) - core.summary.addSeparator() - - core.summary.addRaw( - 'To format the files run the following command', - true - ) - core.summary.addBreak() - - /** @type {string} */ - const additionalArgs = formatFile === '' ? '' : `-c "${formatFile}"` - - /** @type {string} */ - const finalFileList = notFormattedFiles - .map((file) => `"${file}"`) - .join(' ') - - core.summary.addCodeBlock( - `meson format ${additionalArgs} -i ${finalFileList}`, - 'bash' - ) - - core.summary.write({ overwrite: true }) - - throw new Error('Some files are not formatted correctly') - } catch (error) { - if (error instanceof Error) { - core.setFailed(error) - } else { - core.setFailed(`Invalid error thrown: ${error}`) - } - } -} - -main() diff --git a/.github/actions/meson-format-action/jsconfig.json b/.github/actions/meson-format-action/jsconfig.json deleted file mode 100644 index 7b118202..00000000 --- a/.github/actions/meson-format-action/jsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "strict": true, - "noImplicitAny": true, - "strictFunctionTypes": true, - "strictPropertyInitialization": true, - "strictBindCallApply": true, - "strictNullChecks": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "alwaysStrict": true, - "esModuleInterop": true, - "checkJs": true, - "allowJs": true, - "declaration": true, - "noEmit": true, - "exactOptionalPropertyTypes": true - }, - "files": ["index.js"] -} diff --git a/.github/actions/meson-format-action/package-lock.json b/.github/actions/meson-format-action/package-lock.json deleted file mode 100644 index 54109bdf..00000000 --- a/.github/actions/meson-format-action/package-lock.json +++ /dev/null @@ -1,118 +0,0 @@ -{ - "name": "meson-format-action", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "meson-format-action", - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "@actions/core": "^1.11.1", - "@actions/exec": "^1.1.1", - "@actions/io": "^1.1.3" - }, - "devDependencies": { - "@types/node": "^22.14.1", - "typescript": "^5.8.3" - } - }, - "node_modules/@actions/core": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz", - "integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==", - "license": "MIT", - "dependencies": { - "@actions/exec": "^1.1.1", - "@actions/http-client": "^2.0.1" - } - }, - "node_modules/@actions/exec": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", - "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", - "license": "MIT", - "dependencies": { - "@actions/io": "^1.0.1" - } - }, - "node_modules/@actions/http-client": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz", - "integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==", - "license": "MIT", - "dependencies": { - "tunnel": "^0.0.6", - "undici": "^5.25.4" - } - }, - "node_modules/@actions/io": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", - "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==", - "license": "MIT" - }, - "node_modules/@fastify/busboy": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", - "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", - "license": "MIT", - "engines": { - "node": ">=14" - } - }, - "node_modules/@types/node": { - "version": "22.14.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.14.1.tgz", - "integrity": "sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw==", - "dev": true, - "license": "MIT", - "dependencies": { - "undici-types": "~6.21.0" - } - }, - "node_modules/tunnel": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", - "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", - "license": "MIT", - "engines": { - "node": ">=0.6.11 <=0.7.0 || >=0.7.3" - } - }, - "node_modules/typescript": { - "version": "5.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", - "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, - "node_modules/undici": { - "version": "5.29.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz", - "integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==", - "license": "MIT", - "dependencies": { - "@fastify/busboy": "^2.0.0" - }, - "engines": { - "node": ">=14.0" - } - }, - "node_modules/undici-types": { - "version": "6.21.0", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", - "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", - "dev": true, - "license": "MIT" - } - } -} diff --git a/.github/actions/meson-format-action/package.json b/.github/actions/meson-format-action/package.json deleted file mode 100644 index 080cfbd4..00000000 --- a/.github/actions/meson-format-action/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "meson-format-action", - "version": "1.0.0", - "main": "index.js", - "author": "Totto16", - "license": "MIT", - "description": "", - "dependencies": { - "@actions/core": "^1.11.1", - "@actions/exec": "^1.1.1", - "@actions/io": "^1.1.3" - }, - "scripts": { - "check": "tsc --project ./jsconfig.json" - }, - "devDependencies": { - "@types/node": "^22.14.1", - "typescript": "^5.8.3" - } -} diff --git a/.github/workflows/meson.yml b/.github/workflows/meson.yml index 46afa388..6c024402 100644 --- a/.github/workflows/meson.yml +++ b/.github/workflows/meson.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: '0' - name: Check Files - uses: ./.github/actions/meson-format-action + uses: Totto16/meson-format-action@1 with: format-file: ./meson.format only-git-files: true