Skip to content

Commit

Permalink
feat: set CMAKE_EXPORT_COMPILE_COMMANDS to On
Browse files Browse the repository at this point in the history
This PR enables default generation of a compilation database (compile_commands.json) that can be used by tools like clangd, clang-tidy and include-what-you-use to provide diagnostics.
  • Loading branch information
rjaegers committed Feb 16, 2024
1 parent ee51be1 commit 1dd1975
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ COPY .devcontainer/requirements.txt /tmp/requirements.txt
RUN python3 -m pip install --require-hashes --no-cache-dir -r /tmp/requirements.txt \
&& rm -rf /tmp/requirements.txt

# Set default generator for CMake to Ninja
# Set default environment options for CMake
ENV CMAKE_GENERATOR="Ninja"
ENV CMAKE_EXPORT_COMPILE_COMMANDS="On"

# Install clang toolchain
COPY .devcontainer/apt-requirements-clang.json /tmp/apt-requirements-clang.json
Expand Down Expand Up @@ -84,7 +85,8 @@ RUN batstmp="$(mktemp -d /tmp/bats-core-${BATS_VERSION}.XXXX)" \
&& bash "${batstmp}/bats-core-${BATS_VERSION}/install.sh" /usr/local \
&& rm -rf "${batstmp}" \
&& git -C /usr/local clone -b v0.3.0 https://github.com/bats-core/bats-support.git \
&& git -C /usr/local clone -b v2.1.0 https://github.com/bats-core/bats-assert.git
&& git -C /usr/local clone -b v2.1.0 https://github.com/bats-core/bats-assert.git \
&& git -C /usr/local clone -b v0.4.0 https://github.com/bats-core/bats-file

# Install xwin
RUN wget -qO - "https://github.com/Jake-Shadle/xwin/releases/download/${XWIN_VERSION}/xwin-${XWIN_VERSION}-$(uname -m)-unknown-linux-musl.tar.gz" | tar -xzv -C /usr/local/bin --strip-components=1 "xwin-${XWIN_VERSION}-$(uname -m)-unknown-linux-musl/xwin"
Expand Down
10 changes: 10 additions & 0 deletions test/testsuite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ teardown_file() {
setup() {
load '/usr/local/bats-support/load'
load '/usr/local/bats-assert/load'
load '/usr/local/bats-file/load'
}

teardown() {
Expand Down Expand Up @@ -67,6 +68,15 @@ teardown() {
assert_success
}

# bats test_tags=tc:20
@test "compilation database should be generated on CMake configure" {
run cmake --preset gcc
assert_file_exists build/gcc/compile_commands.json

run cmake --preset gcc-arm-none-eabi
assert_file_exists build/gcc-arm-none-eabi/compile_commands.json
}

# bats test_tags=tc:4
@test "invalid code input should result in failing build" {
run cmake --preset gcc
Expand Down

0 comments on commit 1dd1975

Please sign in to comment.