Skip to content

Commit

Permalink
Miscellaneous updates and fixes (#4)
Browse files Browse the repository at this point in the history
- Remove submodules for CMocka and powershell scripts.
- Remove hard dependency on CRLF line endings.
- Update clang-format, clang-tidy, clangd, Docker file and other similar
files.
- Update Poetry lock file and Dockerfile image.
  • Loading branch information
dmg0345 authored Oct 30, 2023
2 parents c2d17fd + 63d7a6c commit cc8e491
Show file tree
Hide file tree
Showing 36 changed files with 515 additions and 329 deletions.
11 changes: 9 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Clang Format file, in YAML format, for reference regarding the options available refer to:
# > https://releases.llvm.org/15.0.0/tools/clang/docs/ClangFormatStyleOptions.html
#
# To check when upgrading to a new version of clang-format:
#
# TODO: No break for brace after do in do-while statements.
# TODO: Function parameters will wrap to the same line when surpassing line limit by just a few chars, should
# wrap to one line per parameter, except for the first parameter which remains on the same line.
# TODO: Review for C++17.

# BasedOnStyle
AccessModifierOffset: 0
Expand Down Expand Up @@ -59,7 +66,7 @@ CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: false
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
Expand Down Expand Up @@ -151,6 +158,6 @@ SpacesInSquareBrackets: false
# StatementMacros
TabWidth: 4
# TypenameMacros
UseCRLF: true
# UseCRLF: true
UseTab: Never
# WhitespaceSensitiveMacros
3 changes: 2 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Checks: >
readability-*,
-readability-identifier-length,
-readability-avoid-const-params-in-decls,
-readability-magic-numbers
-readability-magic-numbers,
-readability-redundant-declaration
WarningsAsErrors: >
bugprone-*,
clang-analyzer-*,
Expand Down
7 changes: 7 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
# For clang-tidy and clang-format related operations within clangd, the .clang-tidy and .clang-format files are used.

CompileFlags:
Add: [-D_CLANGD=1]
CompilationDatabase: .cmake_build
Diagnostics:
Suppress: [
# Supress unknown pragma due to the following issue, which causes diagnotic push / pop to be detected as errors:
# - https://github.com/clangd/clangd/issues/1167
"-Wunknown-pragmas"
]
Index:
Background: Build
StandardLibrary: No
Expand Down
42 changes: 20 additions & 22 deletions .devcontainer/DockerFile
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
# syntax=docker/dockerfile:1
# escape=\

# Use latest Debian available with Powershell.
# Use latest Debian available with PowerShell.
FROM mcr.microsoft.com/powershell:7.3-debian-bookworm

# Ensure working from a known working directory.
WORKDIR "/"
# Ensure the active shell is Powershell.
# Ensure the active shell is PowerShell.
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Use an optimized 'sources.list' for Debian 12.
RUN Set-Content -Path /etc/apt/sources.list -Value "$( \
)deb https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware$( \
)deb-src https://ftp.debian.org/debian/ bookworm contrib main non-free non-free-firmware$( \
)deb https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware$( \
)deb-src https://ftp.debian.org/debian/ bookworm-updates contrib main non-free non-free-firmware$( \
)deb https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware$( \
)deb-src https://ftp.debian.org/debian/ bookworm-proposed-updates contrib main non-free non-free-firmware$( \
)deb https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware$( \
)deb-src https://ftp.debian.org/debian/ bookworm-backports contrib main non-free non-free-firmware$( \
)deb https://security.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware$( \
)deb-src https://security.debian.org/debian-security/ bookworm-security contrib main non-free non-free-firmware";

# Update package sources, upgrade current installed packages and install new packages. For details refer to:
# - https://packages.debian.org/index
# - https://www.debian.org/doc/manuals/apt-guide/ch2.en.html
# - https://manpages.debian.org/stretch/apt/apt-get.8.en.html
# - https://docs.docker.com/develop/develop-images/dockerfile_best-practices/ (apt-get)
# - https://askubuntu.com/questions/875213/apt-get-to-retry-downloading (apt-get retries)
# It is possible that the Dockerfile breaks over time at this point as packages might be deprecated and not exist
# anymore when updates or upgrades are released, in this scenario, the package versions will need to be updated.
RUN 'Acquire::Retries "6";' > /etc/apt/apt.conf.d/80-retries; \
apt-get --assume-yes update; \
apt-get --assume-yes upgrade; \
apt-get --assume-yes dist-upgrade; \
apt-get --assume-yes --purge install \
## C/C++ ARM / Debuggers / Build Packages ##########################################################################
apt-get --assume-yes --show-progress install \
## C/C++ / Debuggers / Build Packages ##############################################################################
gcc=4:12.2.0-3 \
libc6-dev=2.36-9+deb12u1 \
libc6-dev=2.36-9+deb12u3 \
gdb-multiarch=13.1-3 \
make=4.3-4.1 \
ninja-build=1.11.1-1 \
Expand All @@ -56,8 +42,8 @@ RUN 'Acquire::Retries "6";' > /etc/apt/apt.conf.d/80-retries;
python3-venv=3.11.2-1+b1 \
\
## Other ###########################################################################################################
wget=1.21.3-1+b2 \
git=1:2.39.2-1.1 \
wget \
xz-utils \
locales; \
\
Expand All @@ -69,7 +55,7 @@ RUN 'Acquire::Retries "6";' > /etc/apt/apt.conf.d/80-retries;
RUN wget "https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb" -O "package.deb"; \
dpkg --install "./package.deb"; \
apt-get --assume-yes update; \
apt-get --assume-yes --purge install dotnet-runtime-7.0; \
apt-get --assume-yes --show-progress install dotnet-runtime-7.0; \
apt-get --assume-yes clean; \
apt-get --assume-yes autoremove; \
Remove-Item "./package.deb" -Force;
Expand All @@ -79,6 +65,18 @@ RUN wget "https://packages.microsoft.com/config/debian/12/packages-microsoft-pro
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

# Additional Git configurations, refer to:
# - https://linuxhint.com/git-handle-symbolic-links/#3
# - https://stackoverflow.com/questions/6842687/the-remote-end-hung-up-unexpectedly-while-git-cloning
# - https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key#telling-git-about-your-ssh-key
# This forces the signing of all commits, user must provide 'user.name', 'user.email' and 'user.signingkey'.
RUN git config --global core.symlinks true; \
git config --global http.postBuffer 500M; \
git config --global http.maxRequestBuffer 100M; \
git config --global core.compression 0; \
git config --global gpg.format ssh; \
git config --global commit.gpgsign true;

## Python Virtual Environment ##########################################################################################
# Copy 'pyproject.toml' file and 'poetry.lock' file, if it exists, to the virtual environments directory.
COPY "../pyproject.toml" "/usr/venvs/pyproject.toml"
Expand Down
26 changes: 22 additions & 4 deletions .devcontainer/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,42 @@ version: '3.9'
services:
vscode:
# The 'vscode' service is built from the Dockerfile.
image: bde_c_cpp_image:latest
container_name: bde_c_cpp_container
image: dmg00345/bde:latest
container_name: bde_container
build:
context: ..
# The path to the DockerFile, relative to the root folder of the workspace.
dockerfile: .devcontainer/DockerFile

volumes:
# Map root folder to workspace folder, this is 'workspaceFolder' in 'devcontainer.json' file.
- ..:/workspace:cached
# Map the volume repository to the workspace, this is 'workspaceFolder' in 'devcontainer.json' file.
# Set the consistency to 'cached' as that is more suitable for development (high I/O frequency).
- vscode:/workspace:cached

environment:
CPPCHECK_C_2012_MISRA_RULES: /run/secrets/cppcheck_c_2012_misra_rules

secrets:
- cppcheck_c_2012_misra_rules

env_file:
# Github environment variables such as username and email.
- ../../!local/other-files/github/github.env

# Override default command to an infinite loop, this causes things not to shut down when the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"

## Volumes #############################################################################################################
volumes:
# Volume with the repository contents.
vscode:

## Configs #############################################################################################################

## Secrets #############################################################################################################
secrets:
# Secret with the CppCheck C:2012 MISRA rules summaries.
cppcheck_c_2012_misra_rules:
file: ../../!local/other-files/misra-c-2012/cppcheck_c_2012_misra_rules.txt

## Networks ############################################################################################################
20 changes: 4 additions & 16 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
// Set the workspace folder to the mapped volume to the project root folder set in 'docker-compose' file.
"workspaceFolder": "/workspace",
// Set the name of the container in Visual Studio Code user interface, this is not the same as the container name.
"name": "bde_c_cpp",
"name": "bde",
// Apply customizations to tools in the container.
"customizations": {
// Visual Studio Code.
"vscode": {
// Extensions to use.
"extensions": [
Expand All @@ -28,6 +27,7 @@

// Other.
"[email protected]",
"[email protected]",
"[email protected]", // Mainly used for validation and intellisense.
"[email protected]",
"[email protected]",
Expand All @@ -39,7 +39,7 @@

// Set the settings.
"settings": {
// Define 'pwsh' profile for Linux enviroments, this ensures the use of Powershell in terminals.
// Define 'pwsh' profile for Linux enviroments, this ensures the use of PowerShell in terminals.
// Start it with the Python virtual environment already activated.
"terminal.integrated.profiles.linux": {
"pwsh": {
Expand All @@ -49,19 +49,7 @@
}
},
// Set the default profile to 'pwsh' in Linux enviroments.
"terminal.integrated.defaultProfile.linux": "pwsh",

// Define 'pwsh' profile for Windows enviroments, this ensures the use of Powershell in terminals.
// Start it with the Python virtual environment already activated.
"terminal.integrated.profiles.windows": {
"pwsh": {
"path": "pwsh",
"icon": "terminal-powershell",
"args": ["-NoExit", "-Command", "& /usr/venvs/development/bin/Activate.ps1"]
}
},
// Set the default profile to 'pwsh' in Windows enviroments.
"terminal.integrated.defaultProfile.windows": "pwsh"
"terminal.integrated.defaultProfile.linux": "pwsh"
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Set line endings on files.
*.c text eol=crlf
*.h text eol=crlf
*.hpp text eol=crlf
*.cpp text eol=crlf
*.rst text eol=crlf
# Set the default behaviour.
* text=auto

# Files to explicitly be normalized and converted to native line endings on checkout.
*.c text
*.h text
*.hpp text
*.cpp text
*.rst text

# Symbolic links, this must be last.
3 changes: 1 addition & 2 deletions .github/workflows/full-development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# This workflow triggers whenever there is a push on the 'develop' branch.
# The 'develop' branch should be configured to restrict direct commits.
# The deployment is performed on 'https://www.development-xxx.netlify.app' and reflects last commit on 'develop'.

on:
push:
Expand All @@ -11,7 +10,7 @@ on:
name: (Development) - Full
run-name: "#${{ github.run_number }}: ${{ github.event.head_commit.message }}"
jobs:
off-target:
full-development:
uses: dmg0345/bde/.github/workflows/reusable-full.yml@master
secrets:
netlify_pat: ${{ secrets.NETLIFY_PAT }}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/full-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#
# This workflow triggers whenever there is a push on the 'master' branch.
# The 'master' branch should be configured to restrict direct commits.
# The deployment is performed on 'https://www.xxx.netlify.app' and reflects last commit on 'master'.

on:
push:
on:
push:
branches: master

name: (Production) - Full
run-name: "#${{ github.run_number }}: ${{ github.event.head_commit.message }}"
jobs:
off-target:
full-production:
uses: dmg0345/bde/.github/workflows/reusable-full.yml@master
secrets:
netlify_pat: ${{ secrets.NETLIFY_PAT }}
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/full-staging.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# Production workflow
# Staging workflow
#
# This workflow triggers whenever a pull request is open, reopened or there are new commits on it.
# The deployment is performed on 'https://www.{head_commit_sha}-xxx.netlify.app' and reflects last commit on the pull request.

on: pull_request

permissions:
permissions:
contents: read
pull-requests: write

name: (Staging) - Full
run-name: "#${{ github.run_number }}: ${{ github.event.pull_request.title }}"
jobs:
off-target:
full-staging:
uses: dmg0345/bde/.github/workflows/reusable-full.yml@master
secrets:
netlify_pat: ${{ secrets.NETLIFY_PAT }}
netlify_site_id: ${{ secrets.NETLIFY_SITE_ID }}
with:
docker_base_image: dmg00345/bde:latest
deploy: staging
deploy_alias: ${{ github.event.pull_request.head.sha }}
deploy_alias: staging-${{ github.run_number }}
Loading

0 comments on commit cc8e491

Please sign in to comment.