Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BasedOnStyle: LLVM
IndentWidth: 4
SortIncludes: true
SortIncludes: true
InsertNewlineAtEOF: true
69 changes: 68 additions & 1 deletion .github/workflows/pull-request-benchmark-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'
69 changes: 68 additions & 1 deletion .github/workflows/push-to-main-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'
2 changes: 1 addition & 1 deletion Benchmark/BenchmarkDeflateInflateTextFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ int main(int argc, char **argv) {
B63_RUN(argcForB63, &argv[1]);

return 0;
}
}
2 changes: 1 addition & 1 deletion CoDeLib/RaiiString/src/RaiiString.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ void RaiiStringClean(RaiiString *pThis) {
pThis->pString = NULL;
}
pThis->lengthWithTermination = 0;
}
}
2 changes: 1 addition & 1 deletion CoDeLib/Test/Utility/FileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ bool FilesAreEqual(FILE *pFile1, FILE *pFile2) {
} while (bytesRead1 > 0);

return true;
}
}
2 changes: 1 addition & 1 deletion CoDeLib/Test/src/TestDeflateInflateZlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ TEST(TestDeflateInflateZlib, test_InflateZlibWorkWithDeflateZlib) {

TEST_GROUP_RUNNER(TestDeflateInflateZlib) {
RUN_TEST_CASE(TestDeflateInflateZlib, test_InflateZlibWorkWithDeflateZlib);
}
}
2 changes: 1 addition & 1 deletion CoDeLib/Test/src/TestDeflateInflateZlib.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#pragma once

void SetupTestDeflateInflateZlib(char *pFullPathToBenchmarkTestFiles);
void SetupTestDeflateInflateZlib(char *pFullPathToBenchmarkTestFiles);
2 changes: 1 addition & 1 deletion CoDeLib/Test/src/TestRaiiString.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ TEST_GROUP_RUNNER(TestRaiiString) {
// RaiiStringClean()
RUN_TEST_CASE(TestRaiiString, test_RaiiStringClean_SetsNullptrInObject);
RUN_TEST_CASE(TestRaiiString, test_RaiiStringClean_SetsLengthZeroInObject);
}
}
2 changes: 1 addition & 1 deletion CoDeLib/include/CoDeLib/Deflate_zlib/Deflate_zlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include <CoDeLib/IDeflate.h>

extern const struct IDeflate deflate_zlib;
extern const struct IDeflate deflate_zlib;
2 changes: 1 addition & 1 deletion CoDeLib/include/CoDeLib/IDeflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ struct IDeflate {
* otherwise.
*/
DEFLATE_RETURN_CODES (*Deflate)(FILE *input, FILE *output, void *options);
};
};
2 changes: 1 addition & 1 deletion CoDeLib/include/CoDeLib/IInflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ struct IInflate {
* otherwise.
*/
INFLATE_RETURN_CODES (*Inflate)(FILE *input, FILE *output, void *options);
};
};
2 changes: 1 addition & 1 deletion CoDeLib/include/CoDeLib/Inflate_zlib/Inflate_zlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include <CoDeLib/IInflate.h>

extern const struct IInflate inflate_zlib;
extern const struct IInflate inflate_zlib;
2 changes: 1 addition & 1 deletion CoDeLib/include/CoDeLib/RaiiString/RaiiString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void RaiiStringClean(RaiiString *pThis);
2 changes: 1 addition & 1 deletion CoDeLib/include/CoDeLib/Test/Utility/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
bool FilesAreEqual(FILE *pFile1, FILE *pFile2);
2 changes: 1 addition & 1 deletion DevEnvSetup.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
44 changes: 42 additions & 2 deletions Scripts/CheckFormattingAll_c_h_cpp_hpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down