Skip to content

Commit 30fc5bc

Browse files
authored
feat(lint): Add tasks for linting C++ files with clang-tidy; Refactor tasks for linting C++ files (resolves #64). (#125)
1 parent 1f65436 commit 30fc5bc

File tree

13 files changed

+274
-280
lines changed

13 files changed

+274
-280
lines changed

.clang-format

Lines changed: 0 additions & 161 deletions
This file was deleted.

.github/workflows/build.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ jobs:
4747
shell: "bash"
4848
run: "npm install -g @go-task/cli"
4949

50+
- name: "Install uv"
51+
shell: "bash"
52+
run: |-
53+
curl \
54+
--fail \
55+
--location \
56+
--silent \
57+
--show-error \
58+
https://astral.sh/uv/0.8.4/install.sh \
59+
| sh
60+
5061
- name: "Build and run unit tests"
5162
run: "task test:run-${{matrix.build_type}}"
5263

.github/workflows/lint.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,25 @@ jobs:
3333
- name: "Install task"
3434
run: "npm install -g @go-task/cli"
3535

36+
- name: "Install uv"
37+
shell: "bash"
38+
run: |-
39+
curl \
40+
--fail \
41+
--location \
42+
--silent \
43+
--show-error \
44+
https://astral.sh/uv/0.8.4/install.sh \
45+
| sh
46+
47+
# We use clang for linting so CMake doesn't generate compile_commands.json with any gcc
48+
# specific flags that would confuse clang-tidy.
49+
- if: "matrix.os == 'ubuntu-24.04'"
50+
name: "Install clang."
51+
run: |-
52+
curl https://apt.llvm.org/llvm.sh | sudo bash -s -- 20
53+
sudo ln -s /usr/bin/clang-20 /usr/local/bin/cc
54+
sudo ln -s /usr/bin/clang++-20 /usr/local/bin/c++
55+
3656
- name: "Run lint task"
3757
run: "task lint:check"

README.md

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Requirements:
9090
* [fmt] >= 8.0.1
9191
* [GSL] >= 4.0.0
9292
* [Task] >= 3.38
93+
* [uv] >= 0.7.10
9394

9495
To build and install the project to `$HOME/.local`:
9596

@@ -153,45 +154,15 @@ is set to true and unit tests are built.
153154
Before submitting a PR, ensure you've run our linting tools and either fixed any violations or
154155
suppressed the warning.
155156

156-
### Requirements
157-
158-
We currently support running our linting tools on Linux and macOS. If you're developing on another
159-
OS, you can submit a [feature request][feature-req]. If you can't run the linting workflows
160-
locally, you can enable and run the [lint] workflow in your fork.
161-
162-
To run the linting tools, besides commonly installed tools like `tar`, you'll need:
163-
164-
* [clang-tidy]
165-
* `md5sum`
166-
* Python 3.8 or newer
167-
* python3-venv
168-
* [Task]
169-
170-
### Setup
171-
172-
```shell
173-
./tools/init.sh
174-
```
175-
176157
### Running the linters
177158

178-
Currently, `clang-tidy` has to be run manually:
179-
180-
```shell
181-
find src tests \
182-
-type f \
183-
\( -iname "*.cpp" -o -iname "*.hpp" \) \
184-
-print0 | \
185-
xargs -0 clang-tidy --config-file .clang-tidy -p build
186-
```
187-
188-
To report all errors run:
159+
To report all errors, run:
189160

190161
```shell
191162
task lint:check
192163
```
193164

194-
To fix cpp errors, and report yaml errors, run:
165+
To automatically fix any supported format or linting errors, run:
195166

196167
```shell
197168
task lint:fix
@@ -217,9 +188,8 @@ The following are issues we're aware of and working on:
217188

218189
[bug-report]: https://github.com/y-scope/log-surgeon/issues/new?assignees=&labels=bug&template=bug-report.yaml
219190
[Catch2]: https://github.com/catchorg/Catch2/tree/devel
220-
[clang-tidy]: https://clang.llvm.org/extra/clang-tidy/
221191
[feature-req]: https://github.com/y-scope/log-surgeon/issues/new?assignees=&labels=enhancement&template=feature-request.yaml
222192
[fmt]: https://github.com/fmtlib/fmt
223193
[GSL]: https://github.com/microsoft/GSL
224-
[lint]: https://github.com/y-scope/log-surgeon/blob/main/.github/workflows/lint.yaml
225194
[Task]: https://taskfile.dev/
195+
[uv]: https://docs.astral.sh/uv

examples/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
cmake_minimum_required(VERSION 3.22.1)
22
project(log-surgeon-examples)
33

4+
set(CMAKE_EXPORT_COMPILE_COMMANDS
5+
ON
6+
CACHE BOOL
7+
"Enable/Disable output of compile commands during generation."
8+
FORCE
9+
)
10+
411
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
512
set(default_build_type "Release")
613
message(STATUS "No build type specified. Setting to '${default_build_type}'.")

examples/buffer-parser.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using namespace std;
1515
using namespace log_surgeon;
1616

17-
auto process_logs(string& schema_path, string const& input_path) -> void {
17+
auto process_logs(string const& schema_path, string const& input_path) -> void {
1818
BufferParser parser{schema_path};
1919
optional<uint32_t> loglevel_id{parser.get_variable_id("loglevel")};
2020
if (false == loglevel_id.has_value()) {
@@ -91,11 +91,10 @@ auto process_logs(string& schema_path, string const& input_path) -> void {
9191
}
9292

9393
auto main(int argc, char* argv[]) -> int {
94-
if (int err{check_input(argc, argv)}; 0 != err) {
94+
std::vector<std::string> const args(argv + 1, argv + argc);
95+
if (int const err{check_input(args)}; 0 != err) {
9596
return err;
9697
}
97-
string schema_path{argv[1]};
98-
string input_path{argv[2]};
99-
process_logs(schema_path, input_path);
98+
process_logs(args[0], args[1]);
10099
return 0;
101100
}

examples/common.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#include "common.hpp"
22

3+
#include <cstdint>
34
#include <filesystem>
4-
#include <fstream>
55
#include <iostream>
66
#include <string>
77
#include <vector>
88

99
#include <log_surgeon/LogEvent.hpp>
10+
#include <log_surgeon/Token.hpp>
1011

1112
using namespace std;
1213
using namespace log_surgeon;
1314

14-
auto check_input(int argc, char* argv[]) -> int {
15+
auto check_input(std::vector<std::string> const& args) -> int {
1516
int ret{0};
16-
if (3 != argc) {
17+
if (2 != args.size()) {
1718
ret = 1;
18-
cout << "Not enough arguments." << endl;
19-
} else if (filesystem::path f{argv[1]}; false == filesystem::exists(f)) {
19+
cout << "Not enough arguments.\n";
20+
} else if (filesystem::path const f{args[0]}; false == filesystem::exists(f)) {
2021
ret = 2;
21-
cout << "Schema file does not exist." << endl;
22-
} else if (filesystem::path f{argv[2]}; false == filesystem::exists(f)) {
22+
cout << "Schema file does not exist.\n";
23+
} else if (filesystem::path const f{args[1]}; false == filesystem::exists(f)) {
2324
ret = 3;
24-
cout << "Input file does not exist." << endl;
25+
cout << "Input file does not exist.\n";
2526
}
2627
if (0 != ret) {
27-
cout << "usage: <path to schema file> <path to input log file>" << endl;
28+
cout << "usage: <path to schema file> <path to input log file>\n";
2829
}
2930
return ret;
3031
}
@@ -45,5 +46,5 @@ auto print_timestamp_loglevel(LogEventView const& event, uint32_t loglevel_id) -
4546
cout << ", loglevel:";
4647
cout << loglevel->to_string_view();
4748
}
48-
cout << endl;
49+
cout << "\n";
4950
}

examples/common.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#ifndef COMMON_HPP
22
#define COMMON_HPP
33

4+
#include <cstdint>
45
#include <string>
56
#include <vector>
67

78
#include <log_surgeon/LogEvent.hpp>
89

9-
auto check_input(int argc, char* argv[]) -> int;
10+
auto check_input(std::vector<std::string> const& args) -> int;
1011

1112
auto print_timestamp_loglevel(log_surgeon::LogEventView const& event, uint32_t loglevel_id) -> void;
1213

examples/reader-parser.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using namespace std;
1414
using namespace log_surgeon;
1515

16-
auto process_logs(string& schema_path, string const& input_path) -> void {
16+
auto process_logs(string const& schema_path, string const& input_path) -> void {
1717
ReaderParser parser{schema_path};
1818
optional<uint32_t> loglevel_id{parser.get_variable_id("loglevel")};
1919
if (false == loglevel_id.has_value()) {
@@ -60,11 +60,10 @@ auto process_logs(string& schema_path, string const& input_path) -> void {
6060
}
6161

6262
auto main(int argc, char* argv[]) -> int {
63-
if (int err{check_input(argc, argv)}; 0 != err) {
63+
std::vector<std::string> const args(argv + 1, argv + argc);
64+
if (int const err{check_input(args)}; 0 != err) {
6465
return err;
6566
}
66-
string schema_path{argv[1]};
67-
string input_path{argv[2]};
68-
process_logs(schema_path, input_path);
67+
process_logs(args[0], args[1]);
6968
return 0;
7069
}

0 commit comments

Comments
 (0)