Skip to content

Commit 8cb7146

Browse files
committed
Squashed 'src/note-c/' content from commit 43420cd
git-subtree-dir: src/note-c git-subtree-split: 43420cdab1f490d6ee3380f0c71d01ed5626b564
0 parents  commit 8cb7146

File tree

145 files changed

+32705
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+32705
-0
lines changed

.devcontainer/devcontainer.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/docker-existing-dockerfile
3+
{
4+
"name": "Note-C Development Environment Dockerfile",
5+
6+
// Sets the run context to one level up instead of the .devcontainer folder.
7+
"context": "..",
8+
9+
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
10+
"image": "ghcr.io/blues/note_c_ci:latest",
11+
// "dockerFile": "../Dockerfile",
12+
13+
// Set *default* container specific settings.json values on container create.
14+
"settings": {},
15+
16+
// Add the IDs of extensions you want installed when the container is created.
17+
"extensions": [
18+
"ms-vscode.cpptools",
19+
"shardulm94.trailing-spaces",
20+
"twxs.cmake"
21+
],
22+
23+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
24+
// "forwardPorts": [],
25+
26+
// Uncomment the next line to run commands after the container is created - for example installing curl.
27+
// "postCreateCommand": "apt-get update && apt-get install -y curl",
28+
29+
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
30+
// "runArgs": [
31+
// "--device=/dev/bus/usb/"
32+
// ],
33+
34+
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
35+
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
36+
37+
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
38+
"remoteUser": "blues"
39+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: 'Load note-c CI Docker image'
2+
runs:
3+
using: 'composite'
4+
steps:
5+
- name: Set up Docker Buildx
6+
uses: docker/setup-buildx-action@v2
7+
8+
- name: Download image artifact
9+
uses: actions/download-artifact@v2
10+
with:
11+
name: note_c_ci_image
12+
path: /tmp
13+
14+
- name: Load Docker image
15+
shell: bash
16+
run: |
17+
docker load --input /tmp/note_c_ci_image.tar

.github/workflows/ci.yml

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: note-c CI Pipeline
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
check_dockerfile_changed:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
changed: ${{ steps.filter.outputs.changed }}
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
# TODO: This is a 3rd party GitHub action from some dude. Ideally, we'd
20+
# use something more "official".
21+
- name: Check if Dockerfile changed
22+
uses: dorny/paths-filter@v2
23+
id: filter
24+
with:
25+
base: 'master'
26+
filters: |
27+
changed:
28+
- 'Dockerfile'
29+
30+
build_ci_docker_image:
31+
runs-on: ubuntu-latest
32+
needs: [check_dockerfile_changed]
33+
if: ${{ needs.check_dockerfile_changed.outputs.changed == 'true' }}
34+
35+
steps:
36+
- name: Checkout code
37+
uses: actions/checkout@v3
38+
39+
- name: Login to GitHub Container Registry
40+
uses: docker/login-action@v2
41+
with:
42+
registry: ghcr.io
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v2
48+
49+
- name: Rebuild image
50+
uses: docker/build-push-action@v4
51+
with:
52+
context: .
53+
load: true
54+
tags: ghcr.io/blues/note_c_ci:latest
55+
outputs: type=docker,dest=/tmp/note_c_ci_image.tar
56+
57+
- name: Upload image artifact
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: note_c_ci_image
61+
path: /tmp/note_c_ci_image.tar
62+
63+
run_doxygen:
64+
runs-on: ubuntu-latest
65+
if: ${{ always() }}
66+
needs: [build_ci_docker_image]
67+
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v3
71+
72+
- name: Load CI Docker image
73+
# Only load the Docker image artifact if build_ci_docker_image actually
74+
# ran (e.g. it wasn't skipped and was successful).
75+
if: ${{ needs.build_ci_docker_image.result == 'success' }}
76+
uses: ./.github/actions/load-ci-image
77+
78+
- name: Run doxygen
79+
run: |
80+
docker run --rm --volume $(pwd):/note-c/ --workdir /note-c/ --entrypoint ./scripts/run_doxygen.sh ghcr.io/blues/note_c_ci:latest
81+
82+
run_unit_tests:
83+
runs-on: ubuntu-latest
84+
if: ${{ always() }}
85+
needs: [build_ci_docker_image]
86+
87+
steps:
88+
- name: Checkout code
89+
uses: actions/checkout@v3
90+
91+
- name: Load CI Docker image
92+
if: ${{ needs.build_ci_docker_image.result == 'success' }}
93+
uses: ./.github/actions/load-ci-image
94+
95+
- name: Run tests
96+
run: |
97+
docker run --rm --volume $(pwd):/note-c/ --workdir /note-c/ --entrypoint ./scripts/run_unit_tests.sh ghcr.io/blues/note_c_ci:latest --coverage --mem-check
98+
99+
- name: Adjust lcov source file paths for Coveralls
100+
run: sudo sed -i 's/\/note-c\///g' ./build/test/coverage/lcov.info
101+
102+
- name: Publish test coverage
103+
uses: coverallsapp/github-action@master
104+
with:
105+
github-token: ${{ secrets.GITHUB_TOKEN }}
106+
path-to-lcov: ./build/test/coverage/lcov.info
107+
108+
run_astyle:
109+
runs-on: ubuntu-latest
110+
if: ${{ always() }}
111+
needs: [build_ci_docker_image]
112+
113+
steps:
114+
- name: Checkout Code
115+
uses: actions/checkout@v3
116+
117+
- name: Load CI Docker image
118+
if: ${{ needs.build_ci_docker_image.result == 'success' }}
119+
uses: ./.github/actions/load-ci-image
120+
121+
- name: Run astyle
122+
run: |
123+
docker run --rm --volume $(pwd):/note-c/ --workdir /note-c/ --entrypoint ./scripts/run_astyle.sh ghcr.io/blues/note_c_ci:latest
124+
125+
publish_ci_image:
126+
runs-on: ubuntu-latest
127+
# Make sure unit tests unit tests passed before publishing.
128+
needs: [build_ci_docker_image, run_unit_tests]
129+
# Only publish the image if this is a push event and the Docker image was rebuilt
130+
if: ${{ github.event_name == 'push' && needs.build_ci_docker_image.result == 'success' }}
131+
132+
steps:
133+
- name: Login to GitHub Container Registry
134+
uses: docker/login-action@v2
135+
with:
136+
registry: ghcr.io
137+
username: ${{ github.actor }}
138+
password: ${{ secrets.GITHUB_TOKEN }}
139+
140+
- name: Set up Docker Buildx
141+
uses: docker/setup-buildx-action@v2
142+
143+
- name: Push image to registry
144+
uses: docker/build-push-action@v4
145+
with:
146+
push: true
147+
tags: ghcr.io/blues/note_c_ci:latest

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
Doxyfile.bak
3+
latex/
4+
html/
5+
6+
# VS Code workspace files
7+
*.code-workspace
8+
*.orig
9+
settings.json

.vscode/extensions.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"unwantedRecommendations": [
5+
"ms-vscode.cmake-tools",
6+
"ms-vscode.cpptools-extension-pack",
7+
"ms-azuretools.vscode-docker"
8+
]
9+
}

.vscode/tasks.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Note-C: Compile and Run ALL Tests",
6+
"type": "cppbuild",
7+
"command": "./scripts/run_unit_tests.sh",
8+
"args": [],
9+
"options": {
10+
"cwd": "${workspaceFolder}"
11+
},
12+
"problemMatcher": [
13+
"$gcc"
14+
],
15+
"group": {
16+
"kind": "build",
17+
"isDefault": true
18+
}
19+
},
20+
{
21+
"label": "Note-C: Compile and Run ALL Tests (with coverage and memory check)",
22+
"type": "cppbuild",
23+
"command": "./scripts/run_unit_tests.sh",
24+
"args": [
25+
"--coverage",
26+
"--mem-check"
27+
],
28+
"options": {
29+
"cwd": "${workspaceFolder}"
30+
},
31+
"problemMatcher": [
32+
"$gcc"
33+
],
34+
"group": {
35+
"kind": "build",
36+
"isDefault": false
37+
}
38+
},
39+
{
40+
"label": "Note-C: Run `astyle` Formatter",
41+
"type": "shell",
42+
"command": "./scripts/run_astyle.sh",
43+
"args": [],
44+
"options": {
45+
"cwd": "${workspaceFolder}",
46+
"env": {
47+
"LC_ALL":"C"
48+
}
49+
},
50+
"problemMatcher": [
51+
"$gcc"
52+
],
53+
"group": {
54+
"kind": "none"
55+
}
56+
}
57+
]
58+
}

CMakeLists.txt

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
4+
message(FATAL_ERROR "In-source builds are not allowed.
5+
Please create a build directory and use `cmake ..` inside it.
6+
NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*.
7+
You must delete them, or cmake will refuse to work.")
8+
endif()
9+
10+
project(note_c)
11+
12+
# Automatically ignore CMake build directory.
13+
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
14+
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
15+
endif()
16+
17+
option(NOTE_C_BUILD_TESTS "Build tests." OFF)
18+
option(NOTE_C_COVERAGE "Compile for test NOTE_C_COVERAGE reporting." OFF)
19+
option(NOTE_C_MEM_CHECK "Run tests with Valgrind." OFF)
20+
21+
set(NOTE_C_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
22+
add_library(note_c SHARED)
23+
target_sources(
24+
note_c
25+
PRIVATE
26+
${NOTE_C_SRC_DIR}/n_atof.c
27+
${NOTE_C_SRC_DIR}/n_b64.c
28+
${NOTE_C_SRC_DIR}/n_cjson.c
29+
${NOTE_C_SRC_DIR}/n_cjson_helpers.c
30+
${NOTE_C_SRC_DIR}/n_cobs.c
31+
${NOTE_C_SRC_DIR}/n_const.c
32+
${NOTE_C_SRC_DIR}/n_ftoa.c
33+
${NOTE_C_SRC_DIR}/n_helpers.c
34+
${NOTE_C_SRC_DIR}/n_hooks.c
35+
${NOTE_C_SRC_DIR}/n_i2c.c
36+
${NOTE_C_SRC_DIR}/n_md5.c
37+
${NOTE_C_SRC_DIR}/n_printf.c
38+
${NOTE_C_SRC_DIR}/n_request.c
39+
${NOTE_C_SRC_DIR}/n_serial.c
40+
${NOTE_C_SRC_DIR}/n_str.c
41+
${NOTE_C_SRC_DIR}/n_ua.c
42+
)
43+
target_compile_options(
44+
note_c
45+
PRIVATE
46+
-Wall
47+
-Wextra
48+
-Wpedantic
49+
-Werror
50+
-Og
51+
-ggdb
52+
)
53+
target_include_directories(
54+
note_c
55+
PUBLIC ${NOTE_C_SRC_DIR}
56+
)
57+
58+
if(NOTE_C_BUILD_TESTS)
59+
# Including CTest here rather than in test/CMakeLists.txt allows us to run
60+
# ctest from the root build directory (e.g. build/ instead of build/test/).
61+
# We also need to set MEMORYCHECK_COMMAND_OPTIONS before including this.
62+
# See: https://stackoverflow.com/a/60741757
63+
if(NOTE_C_MEM_CHECK)
64+
# Go ahead and make sure we can find valgrind while we're here.
65+
find_program(VALGRIND valgrind REQUIRED)
66+
message(STATUS "Found valgrind: ${VALGRIND}")
67+
set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
68+
endif(NOTE_C_MEM_CHECK)
69+
include(CTest)
70+
71+
target_compile_definitions(
72+
note_c
73+
PUBLIC NOTE_C_TEST
74+
)
75+
target_include_directories(
76+
note_c
77+
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/test/include
78+
)
79+
80+
add_subdirectory(test)
81+
endif(NOTE_C_BUILD_TESTS)

CODE_OF_CONDUCT.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Code of conduct
2+
3+
By participating in this project, you agree to abide by the
4+
[Blues Inc code of conduct][1].
5+
6+
[1]: https://blues.github.io/opensource/code-of-conduct
7+

0 commit comments

Comments
 (0)