feat: port to master
This commit is contained in:
parent
d01f244f92
commit
91e5c5619c
5 changed files with 17 additions and 63 deletions
3
.gitattributes
vendored
3
.gitattributes
vendored
|
@ -1,3 +0,0 @@
|
|||
* text=auto
|
||||
*.zig text eol=lf
|
||||
zigmod.* text eol=lf
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,2 @@
|
|||
kcov-output/
|
||||
zig-cache/
|
||||
zig-out/
|
||||
.zigmod
|
||||
deps.zig
|
||||
|
|
58
build.zig
58
build.zig
|
@ -1,53 +1,19 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.build.Builder) !void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const lib = b.addStaticLibrary("globlin", "src/glob.zig");
|
||||
lib.setBuildMode(mode);
|
||||
lib.install();
|
||||
_ = b.addModule("globlin", .{
|
||||
.source_file = .{ .path = "src/glob.zig" },
|
||||
});
|
||||
|
||||
const main_tests = b.addTest("src/glob.zig");
|
||||
main_tests.setBuildMode(mode);
|
||||
const test_exe = b.addTest(.{
|
||||
.root_source_file = .{ .path = "src/glob.zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const coverage = b.option(bool, "kcov", "Generate test coverage with kcov") orelse false;
|
||||
if (coverage) {
|
||||
main_tests.setExecCmd(&[_]?[]const u8{
|
||||
"kcov",
|
||||
"--exclude-pattern=zig/lib",
|
||||
"kcov-output",
|
||||
null,
|
||||
});
|
||||
}
|
||||
|
||||
const test_step = b.step("test", "Run library tests");
|
||||
test_step.dependOn(&main_tests.step);
|
||||
|
||||
const fuzz_lib = b.addStaticLibrary("fuzz-lib", "src/fuzz.zig");
|
||||
fuzz_lib.setBuildMode(.Debug);
|
||||
fuzz_lib.want_lto = true;
|
||||
fuzz_lib.bundle_compiler_rt = true;
|
||||
|
||||
const fuzz_executable_name = "fuzz";
|
||||
const fuzz_exe_path = try std.fs.path.join(
|
||||
b.allocator,
|
||||
&.{ b.cache_root, fuzz_executable_name },
|
||||
);
|
||||
|
||||
const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o", fuzz_exe_path });
|
||||
fuzz_compile.addArtifactArg(fuzz_lib);
|
||||
const fuzz_install = b.addInstallBinFile(.{ .path = fuzz_exe_path }, fuzz_executable_name);
|
||||
const fuzz_compile_run = b.step(
|
||||
"fuzz",
|
||||
"Build executable for fuzz testing using afl-clang-lto",
|
||||
);
|
||||
fuzz_compile_run.dependOn(&fuzz_compile.step);
|
||||
fuzz_compile_run.dependOn(&fuzz_install.step);
|
||||
|
||||
// Compile a companion exe for debugging crashes
|
||||
const fuzz_debug_exe = b.addExecutable("fuzz-debug", "src/fuzz.zig");
|
||||
fuzz_debug_exe.setBuildMode(.Debug);
|
||||
// Only install fuzz-debug when the fuzz step is run
|
||||
const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe);
|
||||
fuzz_compile_run.dependOn(&install_fuzz_debug_exe.step);
|
||||
const test_step = b.step("test", "run tests");
|
||||
test_step.dependOn(&b.addRunArtifact(test_exe).step);
|
||||
}
|
||||
|
|
10
src/glob.zig
10
src/glob.zig
|
@ -142,8 +142,8 @@ pub fn match(glob: []const u8, path: []const u8) bool {
|
|||
state.glob_index = skipGlobstars(glob, &index) - 2;
|
||||
}
|
||||
|
||||
state.wildcard.glob_index = @intCast(u32, state.glob_index);
|
||||
state.wildcard.path_index = @intCast(u32, state.path_index + 1);
|
||||
state.wildcard.glob_index = @intCast(state.glob_index);
|
||||
state.wildcard.path_index = @intCast(state.path_index + 1);
|
||||
|
||||
// ** allows path separators, whereas * does not.
|
||||
// However, ** must be a full path component, i.e. a/**/b not a**b.
|
||||
|
@ -266,7 +266,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
|
|||
'}' => if (brace_stack.len > 0) {
|
||||
// If we hit the end of the braces, we matched the last option.
|
||||
brace_stack.longest_brace_match =
|
||||
math.max(brace_stack.longest_brace_match, @intCast(u32, state.path_index));
|
||||
@max(brace_stack.longest_brace_match, @as(u32, @intCast(state.path_index)));
|
||||
state.glob_index += 1;
|
||||
state = brace_stack.pop(&state);
|
||||
continue;
|
||||
|
@ -275,7 +275,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
|
|||
// If we hit a comma, we matched one of the options!
|
||||
// But we still need to check the others in case there is a longer match.
|
||||
brace_stack.longest_brace_match =
|
||||
math.max(brace_stack.longest_brace_match, @intCast(u32, state.path_index));
|
||||
@max(brace_stack.longest_brace_match, @as(u32, @intCast(state.path_index)));
|
||||
state.path_index = brace_stack.last().path_index;
|
||||
state.glob_index += 1;
|
||||
state.wildcard = Wildcard{};
|
||||
|
@ -298,7 +298,7 @@ pub fn match(glob: []const u8, path: []const u8) bool {
|
|||
state.glob_index > 0 and
|
||||
glob[state.glob_index - 1] == '}')
|
||||
{
|
||||
brace_stack.longest_brace_match = @intCast(u32, state.path_index);
|
||||
brace_stack.longest_brace_match = @intCast(state.path_index);
|
||||
state = brace_stack.pop(&state);
|
||||
}
|
||||
state.glob_index += 1;
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
id: n4uxgs54o2rnnx16sobuaar9tq7zbarpxlo35nadzho9p9r5
|
||||
name: globlin
|
||||
main: src/glob.zig
|
||||
license: MIT
|
||||
description: A fast pathname matcher
|
||||
dependencies:
|
Loading…
Reference in a new issue