linters, some ast headers

This commit is contained in:
2024-12-18 22:34:22 +02:00
parent c2915d2eaa
commit 7361b6058d
8 changed files with 184 additions and 48 deletions

View File

@@ -1,5 +1,8 @@
const std = @import("std");
const c_lib = &[_][]const u8{ "tokenizer.c", "ast.c", "zig1.c" };
const all_c_files = c_lib ++ &[_][]const u8{"main.c"};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@@ -9,8 +12,8 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = target,
});
lib.addCSourceFile(.{
.file = b.path("tokenizer.c"),
lib.addCSourceFiles(.{
.files = c_lib,
.flags = &[_][]const u8{
"-std=c11",
"-Wall",
@@ -35,13 +38,44 @@ pub fn build(b: *std.Build) void {
lib.linkLibC();
const test_step = b.step("test", "Run unit tests");
const test_exe = b.addTest(.{
.root_source_file = b.path("test_all.zig"),
.optimize = optimize,
});
test_exe.linkLibrary(lib);
test_exe.addIncludePath(b.path("."));
test_step.dependOn(&b.addRunArtifact(test_exe).step);
const lint_step = b.step("lint", "Run linters");
const clang_format = b.addSystemCommand(&.{"clang-format"});
clang_format.addArgs(&.{ "--style=webkit", "-i" });
for (all_c_files) |cfile| clang_format.addFileArg(b.path(cfile));
lint_step.dependOn(&clang_format.step);
const clang_analyze = b.addSystemCommand(&.{"clang"});
clang_analyze.addArgs(&.{
"--analyze",
"--analyzer-output",
"text",
"-Wno-unused-command-line-argument",
"-Werror",
});
for (all_c_files) |cfile| clang_analyze.addFileArg(b.path(cfile));
lint_step.dependOn(&clang_analyze.step);
const gcc_analyze = b.addSystemCommand(&.{"gcc"});
gcc_analyze.addArgs(&.{ "--analyzer", "-Werror", "-o", "/dev/null" });
for (all_c_files) |cfile| gcc_analyze.addFileArg(b.path(cfile));
lint_step.dependOn(&gcc_analyze.step);
const cppcheck = b.addSystemCommand(&.{"cppcheck"});
cppcheck.addArgs(&.{
"--enable=all",
"--suppress=missingIncludeSystem",
"--suppress=checkersReport",
"--quiet",
"--suppress=unusedFunction", // TODO remove after plumbing is done
});
for (all_c_files) |cfile| cppcheck.addFileArg(b.path(cfile));
lint_step.dependOn(&cppcheck.step);
}