From 8b21086e4059c666048a345dbbbbfe78b931aede Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Tue, 27 Jun 2023 08:48:32 -0700 Subject: [PATCH 1/3] format --- format.py | 17 ++- src/code/z_DLF.c | 100 +++++++++--------- src/code/z_actor.c | 10 +- src/code/z_effect_soft_sprite.c | 10 +- .../actors/ovl_En_Bigslime/z_en_bigslime.c | 8 +- 5 files changed, 79 insertions(+), 66 deletions(-) diff --git a/format.py b/format.py index 5e2c29febe..a9983cf5df 100755 --- a/format.py +++ b/format.py @@ -14,8 +14,8 @@ # clang-format, clang-tidy and clang-apply-replacements default version -# Version 11 is used when available for more consistency between contributors -CLANG_VER = 11 +# This specific version is used when available, for more consistency between contributors +CLANG_VER = 14 # Clang-Format options (see .clang-format for rules applied) FORMAT_OPTS = "-i -style=file" @@ -145,6 +145,12 @@ def format_files(src_files: List[str], extra_files: List[str], nb_jobs: int): def main(): parser = argparse.ArgumentParser(description="Format files in the codebase to enforce most style rules") parser.add_argument("files", metavar="file", nargs="*") + parser.add_argument( + "--show-paths", + dest="show_paths", + action="store_true", + help="Print the paths to the clang-* binaries used", + ) parser.add_argument( "-j", dest="jobs", @@ -155,6 +161,13 @@ def main(): ) args = parser.parse_args() + if args.show_paths: + import shutil + + print("CLANG_FORMAT ->", shutil.which(CLANG_FORMAT)) + print("CLANG_TIDY ->", shutil.which(CLANG_TIDY)) + print("CLANG_APPLY_REPLACEMENTS ->", shutil.which(CLANG_APPLY_REPLACEMENTS)) + nb_jobs = args.jobs or multiprocessing.cpu_count() if nb_jobs > 1: if CLANG_APPLY_REPLACEMENTS is None: diff --git a/src/code/z_DLF.c b/src/code/z_DLF.c index 036777d499..cb226b30c9 100644 --- a/src/code/z_DLF.c +++ b/src/code/z_DLF.c @@ -17,35 +17,35 @@ void Overlay_LoadGameState(GameStateOverlay* overlayEntry) { (uintptr_t)vramStart, (uintptr_t)overlayEntry->vramEnd); if (overlayEntry->loadedRamAddr != NULL) { - overlayEntry->unk_14 = (uintptr_t)( - (overlayEntry->unk_14 != NULL) - ? (void*)((uintptr_t)overlayEntry->unk_14 - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->unk_14 = (void*)(uintptr_t)((overlayEntry->unk_14 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_14 - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->init = (uintptr_t)( - (overlayEntry->init != NULL) - ? (void*)((uintptr_t)overlayEntry->init - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->init = (void*)(uintptr_t)((overlayEntry->init != NULL) + ? (void*)((uintptr_t)overlayEntry->init - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->destroy = (uintptr_t)( - (overlayEntry->destroy != NULL) - ? (void*)((uintptr_t)overlayEntry->destroy - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->destroy = (void*)(uintptr_t)((overlayEntry->destroy != NULL) + ? (void*)((uintptr_t)overlayEntry->destroy - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->unk_20 = (uintptr_t)( - (overlayEntry->unk_20 != NULL) - ? (void*)((uintptr_t)overlayEntry->unk_20 - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->unk_20 = (void*)(uintptr_t)((overlayEntry->unk_20 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_20 - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->unk_24 = (uintptr_t)( - (overlayEntry->unk_24 != NULL) - ? (void*)((uintptr_t)overlayEntry->unk_24 - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->unk_24 = (void*)(uintptr_t)((overlayEntry->unk_24 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_24 - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); overlayEntry->unk_28 = 0; } @@ -57,35 +57,35 @@ void Overlay_FreeGameState(GameStateOverlay* overlayEntry) { if (overlayEntry->loadedRamAddr != NULL) { var_v0 = (overlayEntry->unk_28 != 0) ? -1 : 0; if (var_v0 == 0) { - overlayEntry->unk_14 = (uintptr_t)( - (overlayEntry->unk_14 != NULL) - ? (void*)((uintptr_t)overlayEntry->unk_14 + - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->unk_14 = (void*)(uintptr_t)((overlayEntry->unk_14 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_14 + + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->init = (uintptr_t)( - (overlayEntry->init != NULL) - ? (void*)((uintptr_t)overlayEntry->init + - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->init = (void*)(uintptr_t)((overlayEntry->init != NULL) + ? (void*)((uintptr_t)overlayEntry->init + + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->destroy = (uintptr_t)( - (overlayEntry->destroy != NULL) - ? (void*)((uintptr_t)overlayEntry->destroy + - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->destroy = (uintptr_t)((overlayEntry->destroy != NULL) + ? (void*)((uintptr_t)overlayEntry->destroy + + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->unk_20 = (uintptr_t)( - (overlayEntry->unk_20 != NULL) - ? (void*)((uintptr_t)overlayEntry->unk_20 + - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->unk_20 = (void*)(uintptr_t)((overlayEntry->unk_20 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_20 + + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); - overlayEntry->unk_24 = (uintptr_t)( - (overlayEntry->unk_24 != NULL) - ? (void*)((uintptr_t)overlayEntry->unk_24 + - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + overlayEntry->unk_24 = (void*)(uintptr_t)((overlayEntry->unk_24 != NULL) + ? (void*)((uintptr_t)overlayEntry->unk_24 + + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); SystemArena_Free(overlayEntry->loadedRamAddr); overlayEntry->loadedRamAddr = NULL; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 7e6ea16627..b423825455 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -3185,11 +3185,11 @@ ActorInit* Actor_LoadOverlay(ActorContext* actorCtx, s16 index) { overlayEntry->numLoaded = 0; } - actorInit = (uintptr_t)( - (overlayEntry->initInfo != NULL) - ? (void*)((uintptr_t)overlayEntry->initInfo - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + actorInit = (void*)(uintptr_t)((overlayEntry->initInfo != NULL) + ? (void*)((uintptr_t)overlayEntry->initInfo - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); } return actorInit; diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c index 0c247998e9..870132a072 100644 --- a/src/code/z_effect_soft_sprite.c +++ b/src/code/z_effect_soft_sprite.c @@ -189,11 +189,11 @@ void EffectSs_Spawn(PlayState* play, s32 type, s32 priority, void* initData) { overlayEntry->loadedRamAddr); } - initInfo = (uintptr_t)( - (overlayEntry->initInfo != NULL) - ? (void*)((uintptr_t)overlayEntry->initInfo - - (intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr)) - : NULL); + initInfo = (void*)(uintptr_t)((overlayEntry->initInfo != NULL) + ? (void*)((uintptr_t)overlayEntry->initInfo - + (intptr_t)((uintptr_t)overlayEntry->vramStart - + (uintptr_t)overlayEntry->loadedRamAddr)) + : NULL); } if (initInfo->init != NULL) { diff --git a/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c b/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c index 946f1a03ab..4f87153c43 100644 --- a/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c +++ b/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c @@ -1740,10 +1740,10 @@ void EnBigslime_WindupThrowPlayer(EnBigslime* this, PlayState* play) { // loop over x, y, z for (j = 0; j < 3; j++) { // Linearly interpolate dynamicVtx --> staticVtx * (1 - scale * vtxSurfacePerturbation) - dynamicVtx->n.ob[j] += (s16)( - ((staticVtx->n.ob[j] - (s32)(scale * staticVtx->n.ob[j] * this->vtxSurfacePerturbation[i])) - - dynamicVtx->n.ob[j]) * - invWindupPunchTimer); + dynamicVtx->n.ob[j] += (s16)(((staticVtx->n.ob[j] - (s32)(scale * staticVtx->n.ob[j] * + this->vtxSurfacePerturbation[i])) - + dynamicVtx->n.ob[j]) * + invWindupPunchTimer); } } else { // loop over x, y, z From 2022a7780b653b8452737042b728845d321e6980 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sun, 16 Jul 2023 20:45:50 -0700 Subject: [PATCH 2/3] Update dockerfile and other documentation --- Dockerfile | 4 ++-- docs/BUILDING_MACOS.md | 4 ++-- docs/tools.md | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94b8cdfa2d..ac824113f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,8 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone & unzip \ vbindiff \ vim \ - clang-tidy-11 \ - clang-format-11 \ + clang-tidy-14 \ + clang-format-14 \ libpng-dev && \ apt clean && \ rm -rf /var/lib/apt/lists/* diff --git a/docs/BUILDING_MACOS.md b/docs/BUILDING_MACOS.md index 8a5aa20a3b..439916063c 100644 --- a/docs/BUILDING_MACOS.md +++ b/docs/BUILDING_MACOS.md @@ -11,13 +11,13 @@ For macOS, use Homebrew to install the following dependencies: * python3 * libpng * bash -* clang-format 11 +* clang-format-14 You can install them with the following commands: ```bash brew update -brew install coreutils make python3 libpng bash clang-format@11 +brew install coreutils make python3 libpng bash clang-format@14 ``` (The repository expects Homebrew-installed programs to be either linked correctly in `$PATH` etc. or in their default locations.) diff --git a/docs/tools.md b/docs/tools.md index e190fe0a38..ab17ecba08 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -198,26 +198,26 @@ Fixes line endings in the repo to Linux style (LF), which is required for the bu ### `format.py` -Formats all C files in the repo using `clang-format-11`, `clang-tidy`, and `clang-apply-replacements` (when multiprocessing). This will touch all files in the repo, so the next `make` will take longer. +Formats all C files in the repo using `clang-format-14`, `clang-tidy`, and `clang-apply-replacements` (when multiprocessing). This will touch all files in the repo, so the next `make` will take longer. You can specify how many threads you would like this to run with by adding the `-jN` flag. Where N is the number of threads. By default this will run using 1 thread (i.e. `-j1`). -`clang-11` is available in many native package managers, but if not try: +`clang-14` is available in many native package managers, but if not try: Linux: Download llvm's setup script, run it, than install normally ```bash wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh -sudo ./llvm.sh 11 +sudo ./llvm.sh 14 rm llvm.sh -sudo apt install clang-format-11 clang-tidy-11 clang-apply-replacements-11 +sudo apt install clang-format-14 clang-tidy-14 clang-apply-replacements-14 ``` Mac: Install with brew, than create symlinks for `clang-tidy` and `clang-apply-replacements` to use properly ```bash -brew install llvm clang-format-11 +brew install llvm clang-format-14 ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy" ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements" ``` From c456baf673e50a6cbb9514d6d153367c299fc998 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Wed, 26 Jul 2023 19:03:13 -0700 Subject: [PATCH 3/3] Update mac instructions --- docs/BUILDING_MACOS.md | 7 +++++-- docs/CONTRIBUTING.md | 2 +- docs/REVIEWING.md | 2 +- docs/tools.md | 10 ++++------ docs/tutorial/merging.md | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/BUILDING_MACOS.md b/docs/BUILDING_MACOS.md index 439916063c..cf93acbf25 100644 --- a/docs/BUILDING_MACOS.md +++ b/docs/BUILDING_MACOS.md @@ -11,17 +11,20 @@ For macOS, use Homebrew to install the following dependencies: * python3 * libpng * bash -* clang-format-14 You can install them with the following commands: ```bash brew update -brew install coreutils make python3 libpng bash clang-format@14 +brew install coreutils make python3 libpng bash ``` (The repository expects Homebrew-installed programs to be either linked correctly in `$PATH` etc. or in their default locations.) +Homebrew does not have clang-format-14 but MacPorts does + +(Have been unable to confirm actual commands with somone that has a Mac) + ## Building mips-linux-binutils The following instructions are written for MacOS users but should apply to any Unix-like system, with maybe some modifications at the end regarding the bash_profile. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 2f4c9854a6..2a5578e4ed 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -110,7 +110,7 @@ See the [Style Guide](STYLE.md) for more details on documentation style. Before opening a PR, walk through the following steps to ensure that your code conforms to the style guide and conventions. - `make` successfully builds a matching ROM. -- `./format.sh` was run to apply standard formatting. +- `./format.py` was run to apply standard formatting. - No new compiler warnings were introduced during the build process. - Can be verified locally by running `tools/warnings_count/check_new_warnings.sh` - New variables & functions should follow standard naming conventions. diff --git a/docs/REVIEWING.md b/docs/REVIEWING.md index 8b70f27114..b7f97bdea9 100644 --- a/docs/REVIEWING.md +++ b/docs/REVIEWING.md @@ -30,7 +30,7 @@ You should first famiiarise yourself with our [Contributing guide](CONTRIBUTING. - [ ] Jenkins build is successful. - [ ] `make` builds a matching ROM. - - [ ] `format.sh` was run. + - [ ] `format.py` was run. - [ ] `spec` contains correct relocation files. - [ ] Any new compiler warnings that were added are required for matching. Ensure there is good reason if the warnings files have changed. - [ ] Files with `NON_MATCHING` functions have equivalent behaviour. diff --git a/docs/tools.md b/docs/tools.md index ab17ecba08..c307382f9e 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -215,12 +215,10 @@ sudo apt install clang-format-14 clang-tidy-14 clang-apply-replacements-14 ``` Mac: -Install with brew, than create symlinks for `clang-tidy` and `clang-apply-replacements` to use properly -```bash -brew install llvm clang-format-14 -ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy" -ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements" -``` +Brew does not have clang-format-14, but MacPorts does. + +(Have been unable to confirm actual commands with somone that has a Mac) + ## External tools diff --git a/docs/tutorial/merging.md b/docs/tutorial/merging.md index b7745b5099..ba0d043f96 100644 --- a/docs/tutorial/merging.md +++ b/docs/tutorial/merging.md @@ -64,7 +64,7 @@ Ideally you should at least be able to get a function to have equivalent behavio ### Format -Run the formatting script `format.sh`, to format the C files in the standard way we use. If you have some arrays or struct definitions in your file, check that they have not been obnoxiously padded out: you can usually get a better format without a final comma for short things. +Run the formatting script `format.py`, to format the C files in the standard way we use. If you have some arrays or struct definitions in your file, check that they have not been obnoxiously padded out: you can usually get a better format without a final comma for short things. **N.B.** this is now essential: the CI will fail immediately if it detects files that change when formatted.