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
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ cmake_minimum_required(VERSION 3.16.3)
project(YSTDLIB_CPP LANGUAGES CXX)

set(YSTDLIB_CPP_VERSION "0.0.1" CACHE STRING "Project version.")

# Enable exporting compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
"Enable/Disable output of compile commands during generation."
FORCE
)

add_executable(dummy)
target_sources(dummy PRIVATE src/ystdlib/hello.cpp)
target_compile_features(dummy PRIVATE cxx_std_20)
2 changes: 2 additions & 0 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
clang-format>=19.1.6
clang-tidy>=19.1.0
colorama>=0.4.6
gersemi>=0.16.2
yamllint>=1.35.1
6 changes: 6 additions & 0 deletions src/ystdlib/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

[[nodiscard]] auto main() -> int {
std::cout << "Hello, world!" << '\n';
return 0;
}
15 changes: 15 additions & 0 deletions taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ includes:

vars:
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
G_CMAKE_CACHE: "{{.G_BUILD_DIR}}/CMakeCache.txt"
G_COMPILE_COMMANDS_DB: "{{.G_BUILD_DIR}}/compile_commands.json"
# Project-specific variables
G_YSTDLIB_CPP_SRC_DIR: "{{.ROOT_DIR}}/src/ystdlib"

tasks:
clean:
desc: "Removes the project build directory."
cmds:
- "rm -rf '{{.G_BUILD_DIR}}'"

config-cmake-project:
internal: true
sources:
- "CMakeLists.txt"
- "{{.TASKFILE}}"
generates:
- "{{.G_CMAKE_CACHE}}"
- "{{.G_COMPILE_COMMANDS_DB}}"
cmds:
- "cmake -S '{{.ROOT_DIR}}' -B '{{.G_BUILD_DIR}}'"

init:
internal: true
silent: true
Expand Down
92 changes: 92 additions & 0 deletions taskfiles/lint-cpp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
version: "3"

tasks:
cpp-check:
desc: "Runs the C++ linters."
cmds:
- task: "cpp-format-check"
- task: "cpp-static-check"

cpp-fix:
desc: "Runs the C++ linters to fix all formatting issues and perform static code analysis. "
cmds:
- task: "cpp-format-fix"
- task: "cpp-static-fix"

cpp-format-check:
desc: "Runs the C++ linters that identify formatting issues."
sources: &cpp_format_src_files
- "{{.G_LINT_VENV_CHECKSUM_FILE}}"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/**/*.cpp"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/**/*.h"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/**/*.hpp"
- "{{.ROOT_DIR}}/.clang-format"
- "{{.TASKFILE}}"
deps:
- "cpp-configs"
- "venv"
cmds:
- task: ":utils:clang-format"
vars:
FLAGS: "--dry-run"
SRC_PATHS:
ref: ".G_LINT_CPP_DIRS"
VENV_DIR: "{{.G_LINT_VENV_DIR}}"

cpp-format-fix:
desc: "Runs the C++ linters and fixes all formatting issues."
sources: *cpp_format_src_files
deps:
- "cpp-configs"
- "venv"
cmds:
- task: ":utils:clang-format"
vars:
FLAGS: "-i"
SRC_PATHS:
ref: ".G_LINT_CPP_DIRS"
VENV_DIR: "{{.G_LINT_VENV_DIR}}"

cpp-static-check:
# Alias task to `cpp-static-fix` since we don't currently support automatic fixes.
# NOTE: clang-tidy does have the ability to fix some errors, but the fixes can be inaccurate.
# When we eventually determine which errors can be safely fixed, we'll allow clang-tidy to
# fix them.
desc: "Runs the C++ static analyzers. Only checks for warnings and violations."
aliases:
- "cpp-static-fix"
sources:
- "{{.G_CMAKE_CACHE}}"
- "{{.G_COMPILE_COMMANDS_DB}}"
- "{{.G_LINT_VENV_CHECKSUM_FILE}}"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/**/*.cpp"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/**/*.h"
- "{{.G_YSTDLIB_CPP_SRC_DIR}}/**/*.hpp"
- "{{.ROOT_DIR}}/.clang-tidy"
- "{{.TASKFILE}}"
deps:
- ":config-cmake-project"
- "cpp-configs"
- "venv"
cmds:
- task: ":utils:clang-tidy"
vars:
FLAGS: >-
--config-file "{{.ROOT_DIR}}/.clang-tidy"
-p "{{.G_COMPILE_COMMANDS_DB}}"
SRC_PATHS:
ref: ".G_LINT_CPP_DIRS"
VENV_DIR: "{{.G_LINT_VENV_DIR}}"

cpp-configs:
internal: true
sources:
- "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/.clang-format"
- "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/.clang-tidy"
- "{{.TASKFILE}}"
generates:
- "{{.ROOT_DIR}}/.clang-format"
- "{{.ROOT_DIR}}/.clang-tidy"
dir: "{{.ROOT_DIR}}"
cmds:
- "tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh"
7 changes: 7 additions & 0 deletions taskfiles/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ includes:
cmake:
flatten: true
taskfile: "./lint-cmake.yaml"
cpp:
flatten: true
taskfile: "./lint-cpp.yaml"
yaml:
flatten: true
taskfile: "./lint-yaml.yaml"

vars:
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv"
G_LINT_VENV_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/lint#venv.md5"
G_LINT_CPP_DIRS:
- "{{.G_YSTDLIB_CPP_SRC_DIR}}"

tasks:
check:
desc: "Runs the full suite of linters to identify warnings and violations."
cmds:
- task: "cmake-check"
- task: "cpp-check"
- task: "yaml-check"

fix:
desc: "Runs the full suite of linters and fixes some violations."
cmds:
- task: "cmake-fix"
- task: "cpp-fix"
- task: "yaml-fix"

venv:
Expand Down
Loading