diff --git a/.clang-format b/.clang-format index 6a487f12..5f486f1a 100644 --- a/.clang-format +++ b/.clang-format @@ -1,3 +1,4 @@ BasedOnStyle: LLVM IndentWidth: 4 -SortIncludes: true \ No newline at end of file +SortIncludes: true +InsertNewlineAtEOF: true \ No newline at end of file diff --git a/.github/workflows/pull-request-benchmark-workflow.yaml b/.github/workflows/pull-request-benchmark-workflow.yaml index 368ebace..c342f261 100644 --- a/.github/workflows/pull-request-benchmark-workflow.yaml +++ b/.github/workflows/pull-request-benchmark-workflow.yaml @@ -27,7 +27,12 @@ jobs: with: python-version: '3.11' - run: | - python -u Scripts/CheckFormattingAll_c_h_cpp_hpp.py + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' + sudo add-apt-repository 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' + sudo apt update + sudo apt install -y clang-format-18 + python -u Scripts/CheckFormattingAll_c_h_cpp_hpp.py --ClangFormatVersion '-18' #======================================== # Target Ubuntu - Host Ubuntu @@ -57,10 +62,40 @@ jobs: host-platform: 'windows' target-platform: 'host' +#======================================== +# Target Mac(x86_64) - Host Mac(x86_64) +#======================================== + + target_macx8664_host_macx8664: + needs: check_formatting + permissions: + pull-requests: write + uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + with: + runner: 'macos-13' + host-platform: 'mac(x86_64)' + target-platform: 'host' + +#======================================== +# Target Mac(ARM) - Host Mac(ARM) +#======================================== + + target_macarm_host_macarm: + needs: check_formatting + permissions: + pull-requests: write + uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + with: + runner: 'macos-14' + host-platform: 'mac(ARM)' + target-platform: 'host' + + #======================================== # Target Zynq - Host Ubuntu #======================================== +# The cross-compiler can not be found in the Ubuntu runner, but it can be found when cross-compiling on a local Ubuntu desktop (VM) # build_target_zynq_host_ubuntu: # needs: check_formatting # permissions: @@ -85,3 +120,35 @@ jobs: runner: 'windows-2022' host-platform: 'windows' target-platform: 'zynq' + +# TODO: For the below two jobs, appropriate cross-compilers for Mac (x86_64 and ARM) need to be added in ZyboEmbeddedLinux\CrossCompilers\aach32 + +#======================================== +# Target Zynq - Host Mac(x86_64) +#======================================== + +# The cross-compiler is currently not compatible with Mac(x86_64) + # target_zynq_host_macx8664: + # needs: check_formatting + # permissions: + # pull-requests: write + # uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + # with: + # runner: 'macos-13' + # host-platform: 'mac(x86_64)' + # target-platform: 'zynq' + +#======================================== +# Target Zynq - Host Mac(ARM) +#======================================== + +# Expected to fail due to to cross-compiler not compiled for Mac(ARM) + # target_zynq_host_macarm: + # needs: check_formatting + # permissions: + # pull-requests: write + # uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + # with: + # runner: 'macos-14' + # host-platform: 'mac(ARM)' + # target-platform: 'zynq' diff --git a/.github/workflows/push-to-main-workflow.yml b/.github/workflows/push-to-main-workflow.yml index c66a3634..b08d888c 100644 --- a/.github/workflows/push-to-main-workflow.yml +++ b/.github/workflows/push-to-main-workflow.yml @@ -19,7 +19,12 @@ jobs: with: python-version: '3.11' - run: | - python -u Scripts/CheckFormattingAll_c_h_cpp_hpp.py + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' + sudo add-apt-repository 'deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main' + sudo apt update + sudo apt install -y clang-format-18 + python -u Scripts/CheckFormattingAll_c_h_cpp_hpp.py --ClangFormatVersion '-18' #======================================== # Target Ubuntu - Host Ubuntu @@ -49,10 +54,40 @@ jobs: host-platform: 'windows' target-platform: 'host' +#======================================== +# Target Mac(x86_64) - Host Mac(x86_64) +#======================================== + + target_macx8664_host_macx8664: + needs: check_formatting + permissions: + pull-requests: write + uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + with: + runner: 'macos-13' + host-platform: 'mac(x86_64)' + target-platform: 'host' + +#======================================== +# Target Mac(ARM) - Host Mac(ARM) +#======================================== + + target_macarm_host_macarm: + needs: check_formatting + permissions: + pull-requests: write + uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + with: + runner: 'macos-14' + host-platform: 'mac(ARM)' + target-platform: 'host' + + #======================================== # Target Zynq - Host Ubuntu #======================================== +# The cross-compiler can not be found in the Ubuntu runner, but it can be found when cross-compiling on a local Ubuntu desktop (VM) # build_target_zynq_host_ubuntu: # needs: check_formatting # permissions: @@ -77,3 +112,35 @@ jobs: runner: 'windows-2022' host-platform: 'windows' target-platform: 'zynq' + +# TODO: For the below two jobs, appropriate cross-compilers for Mac (x86_64 and ARM) need to be added in ZyboEmbeddedLinux\CrossCompilers\aach32 + +#======================================== +# Target Zynq - Host Mac(x86_64) +#======================================== + +# The cross-compiler is currently not compatible with Mac(x86_64) + # target_zynq_host_macx8664: + # needs: check_formatting + # permissions: + # pull-requests: write + # uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + # with: + # runner: 'macos-13' + # host-platform: 'mac(x86_64)' + # target-platform: 'zynq' + +#======================================== +# Target Zynq - Host Mac(ARM) +#======================================== + +# Expected to fail due to to cross-compiler not compiled for Mac(ARM) + # target_zynq_host_macarm: + # needs: check_formatting + # permissions: + # pull-requests: write + # uses: ./.github/workflows/build-test-run-reusable-workflow.yaml + # with: + # runner: 'macos-14' + # host-platform: 'mac(ARM)' + # target-platform: 'zynq' diff --git a/Benchmark/BenchmarkDeflateInflateTextFile.c b/Benchmark/BenchmarkDeflateInflateTextFile.c index 7a0fda3f..4b17cadd 100644 --- a/Benchmark/BenchmarkDeflateInflateTextFile.c +++ b/Benchmark/BenchmarkDeflateInflateTextFile.c @@ -75,4 +75,4 @@ int main(int argc, char **argv) { B63_RUN(argcForB63, &argv[1]); return 0; -} \ No newline at end of file +} diff --git a/CoDeLib/RaiiString/src/RaiiString.c b/CoDeLib/RaiiString/src/RaiiString.c index 479aee3a..89636471 100644 --- a/CoDeLib/RaiiString/src/RaiiString.c +++ b/CoDeLib/RaiiString/src/RaiiString.c @@ -42,4 +42,4 @@ void RaiiStringClean(RaiiString *pThis) { pThis->pString = NULL; } pThis->lengthWithTermination = 0; -} \ No newline at end of file +} diff --git a/CoDeLib/Test/Utility/FileUtils.c b/CoDeLib/Test/Utility/FileUtils.c index 092f33b3..d2e90b4c 100644 --- a/CoDeLib/Test/Utility/FileUtils.c +++ b/CoDeLib/Test/Utility/FileUtils.c @@ -82,4 +82,4 @@ bool FilesAreEqual(FILE *pFile1, FILE *pFile2) { } while (bytesRead1 > 0); return true; -} \ No newline at end of file +} diff --git a/CoDeLib/Test/src/TestDeflateInflateZlib.c b/CoDeLib/Test/src/TestDeflateInflateZlib.c index ad12dce0..fe902e59 100644 --- a/CoDeLib/Test/src/TestDeflateInflateZlib.c +++ b/CoDeLib/Test/src/TestDeflateInflateZlib.c @@ -55,4 +55,4 @@ TEST(TestDeflateInflateZlib, test_InflateZlibWorkWithDeflateZlib) { TEST_GROUP_RUNNER(TestDeflateInflateZlib) { RUN_TEST_CASE(TestDeflateInflateZlib, test_InflateZlibWorkWithDeflateZlib); -} \ No newline at end of file +} diff --git a/CoDeLib/Test/src/TestDeflateInflateZlib.h b/CoDeLib/Test/src/TestDeflateInflateZlib.h index 40ef1b53..02fe63f6 100644 --- a/CoDeLib/Test/src/TestDeflateInflateZlib.h +++ b/CoDeLib/Test/src/TestDeflateInflateZlib.h @@ -1,3 +1,3 @@ #pragma once -void SetupTestDeflateInflateZlib(char *pFullPathToBenchmarkTestFiles); \ No newline at end of file +void SetupTestDeflateInflateZlib(char *pFullPathToBenchmarkTestFiles); diff --git a/CoDeLib/Test/src/TestRaiiString.c b/CoDeLib/Test/src/TestRaiiString.c index 5bb464ee..dc717949 100644 --- a/CoDeLib/Test/src/TestRaiiString.c +++ b/CoDeLib/Test/src/TestRaiiString.c @@ -172,4 +172,4 @@ TEST_GROUP_RUNNER(TestRaiiString) { // RaiiStringClean() RUN_TEST_CASE(TestRaiiString, test_RaiiStringClean_SetsNullptrInObject); RUN_TEST_CASE(TestRaiiString, test_RaiiStringClean_SetsLengthZeroInObject); -} \ No newline at end of file +} diff --git a/CoDeLib/include/CoDeLib/Deflate_zlib/Deflate_zlib.h b/CoDeLib/include/CoDeLib/Deflate_zlib/Deflate_zlib.h index 0ef35f1a..1335b929 100644 --- a/CoDeLib/include/CoDeLib/Deflate_zlib/Deflate_zlib.h +++ b/CoDeLib/include/CoDeLib/Deflate_zlib/Deflate_zlib.h @@ -2,4 +2,4 @@ #include -extern const struct IDeflate deflate_zlib; \ No newline at end of file +extern const struct IDeflate deflate_zlib; diff --git a/CoDeLib/include/CoDeLib/IDeflate.h b/CoDeLib/include/CoDeLib/IDeflate.h index c3b935fc..4549a46b 100644 --- a/CoDeLib/include/CoDeLib/IDeflate.h +++ b/CoDeLib/include/CoDeLib/IDeflate.h @@ -16,4 +16,4 @@ struct IDeflate { * otherwise. */ DEFLATE_RETURN_CODES (*Deflate)(FILE *input, FILE *output, void *options); -}; \ No newline at end of file +}; diff --git a/CoDeLib/include/CoDeLib/IInflate.h b/CoDeLib/include/CoDeLib/IInflate.h index a1fac92c..89921ba6 100644 --- a/CoDeLib/include/CoDeLib/IInflate.h +++ b/CoDeLib/include/CoDeLib/IInflate.h @@ -16,4 +16,4 @@ struct IInflate { * otherwise. */ INFLATE_RETURN_CODES (*Inflate)(FILE *input, FILE *output, void *options); -}; \ No newline at end of file +}; diff --git a/CoDeLib/include/CoDeLib/Inflate_zlib/Inflate_zlib.h b/CoDeLib/include/CoDeLib/Inflate_zlib/Inflate_zlib.h index c2821fab..1702e818 100644 --- a/CoDeLib/include/CoDeLib/Inflate_zlib/Inflate_zlib.h +++ b/CoDeLib/include/CoDeLib/Inflate_zlib/Inflate_zlib.h @@ -2,4 +2,4 @@ #include -extern const struct IInflate inflate_zlib; \ No newline at end of file +extern const struct IInflate inflate_zlib; diff --git a/CoDeLib/include/CoDeLib/RaiiString/RaiiString.h b/CoDeLib/include/CoDeLib/RaiiString/RaiiString.h index d738362d..481ccf4f 100644 --- a/CoDeLib/include/CoDeLib/RaiiString/RaiiString.h +++ b/CoDeLib/include/CoDeLib/RaiiString/RaiiString.h @@ -21,4 +21,4 @@ static const size_t MAX_CSTRING_INCLUDING_TERMINATION_LENGTH = 1024; RaiiString RaiiStringCreate(size_t length); RaiiString RaiiStringCreateFromCString(const char *pCString); -void RaiiStringClean(RaiiString *pThis); \ No newline at end of file +void RaiiStringClean(RaiiString *pThis); diff --git a/CoDeLib/include/CoDeLib/Test/Utility/FileUtils.h b/CoDeLib/include/CoDeLib/Test/Utility/FileUtils.h index 086aafbc..6044b9a5 100644 --- a/CoDeLib/include/CoDeLib/Test/Utility/FileUtils.h +++ b/CoDeLib/include/CoDeLib/Test/Utility/FileUtils.h @@ -9,4 +9,4 @@ void CreateFullPathToFile(const RaiiString *pFullPath, const char *pBasePath, const char *pFileName); void OpenFile(FILE **pInFile, char *basePath, char *pFilename, char *pOpenMode); size_t GetFileSizeInBytes(FILE *pFile); -bool FilesAreEqual(FILE *pFile1, FILE *pFile2); \ No newline at end of file +bool FilesAreEqual(FILE *pFile1, FILE *pFile2); diff --git a/DevEnvSetup.md b/DevEnvSetup.md index f4dfaa60..fe4e04a2 100644 --- a/DevEnvSetup.md +++ b/DevEnvSetup.md @@ -1,7 +1,7 @@ # Formatting ## Formatter -Download `clang-format` as part of `LLVM`: https://releases.llvm.org/download.html. While installing LLVM make sure to check the box `Add LLVM to the system PATH for ...`. +Download `clang-format` as part of `LLVM`: https://releases.llvm.org/download.html. While installing LLVM make sure to check the box `Add LLVM to the system PATH for ...`. Make sure to install at least version `16` to have `InsertNewlineAtEOF` available. > Note that you may have to close and re-open viusal studio to get the updated PATH. diff --git a/Scripts/CheckFormattingAll_c_h_cpp_hpp.py b/Scripts/CheckFormattingAll_c_h_cpp_hpp.py index 6855352a..8c9818a2 100644 --- a/Scripts/CheckFormattingAll_c_h_cpp_hpp.py +++ b/Scripts/CheckFormattingAll_c_h_cpp_hpp.py @@ -2,6 +2,36 @@ from pathlib import Path import subprocess import glob +import argparse + + +parser = argparse.ArgumentParser( + description="Check and format all c, h, cpp, hpp files" +) + +formatInPlaceOptions = ["true", "false"] + +parser.add_argument( + "--FormatInPlace", + action="store", + dest="formatInPlace", + choices=formatInPlaceOptions, + default="false", + help="Selects if the files should be formatted in place or if the formatting should be checked only", +) + +# TODO: This method doesn't seem very safe due to the option to execute any executable that starts with 'clang-format'. +# Better argument checking should be implemented. +parser.add_argument( + "--ClangFormatVersion", + action="store", + dest="clangFormatVersion", + default="", + help="Clang format version to use. The provided version is appended after the clang-format command with and must start with a '-'. For example: --ClangFormatVersion=-18", +) + +args = parser.parse_args() + CurrentScriptPath = Path(os.path.dirname(os.path.abspath(__file__))) RepositoryRootPath = Path(CurrentScriptPath.parent) @@ -25,8 +55,18 @@ print("\t{}".format(file)) print() -ClangFormatCommand = "clang-format --dry-run -Werror -style=file {}".format( - " ".join([str(file) for file in FilesToFormat]) +clangFormatFormattingOptions: str = "" +if args.formatInPlace == "true": + clangFormatFormattingOptions = "-i" + print("Formatting files in place") +else: + clangFormatFormattingOptions = "--dry-run -Werror" + print("Checking formatting only") + +ClangFormatCommand = "clang-format{0} {1} -style=file {2}".format( + args.clangFormatVersion, + clangFormatFormattingOptions, + " ".join([str(file) for file in FilesToFormat]), ) subprocess.run( ClangFormatCommand,