Skip to content

Commit e1c7a86

Browse files
authored
Update to latest ZLS and Zig master (#135)
1 parent 68d1241 commit e1c7a86

File tree

16 files changed

+164
-113
lines changed

16 files changed

+164
-113
lines changed

RULES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Enforces that variable declaration names use consistent naming. For example,
7777

7878
* Exclude these declaration names from min and max declaration name checks.
7979

80-
* **Default:** `&.{ "x", "y", "z", "i", "b" }`
80+
* **Default:** `&.{ "x", "y", "z", "i", "b", "it", "ip", "c", }`
8181

8282
## `field_naming`
8383

build.zig

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub fn build(b: *std.Build) void {
192192
const optimize = b.standardOptimizeOption(.{});
193193
const test_coverage = b.option(bool, "coverage", "Generate a coverage report with kcov");
194194
const test_focus_on_rule = b.option([]const u8, "test_focus_on_rule", "Only run integration tests for this rule");
195+
const io = b.graph.io;
195196

196197
const zlinter_lib_module = b.addModule("zlinter", .{
197198
.root_source_file = b.path("src/lib/zlinter.zig"),
@@ -488,11 +489,11 @@ pub fn build(b: *std.Build) void {
488489
const rules_path = rules_lazy_path.getPath3(b, step);
489490
_ = step.addDirectoryWatchInput(rules_lazy_path) catch @panic("OOM");
490491

491-
var rules_dir = rules_path.root_dir.handle.openDir(rules_path.subPathOrDot(), .{ .iterate = true }) catch @panic("unable to open rules/ directory");
492-
defer rules_dir.close();
492+
var rules_dir = rules_path.root_dir.handle.openDir(io, rules_path.subPathOrDot(), .{ .iterate = true }) catch @panic("unable to open rules/ directory");
493+
defer rules_dir.close(io);
493494
{
494495
var it = rules_dir.walk(b.allocator) catch @panic("OOM");
495-
while (it.next() catch @panic("OOM")) |entry| {
496+
while (it.next(io) catch @panic("OOM")) |entry| {
496497
if (!std.mem.endsWith(u8, entry.basename, ".zig")) continue;
497498
doc_build_run.addFileArg(b.path(b.pathJoin(&.{ "src/rules", entry.path })));
498499
}
@@ -595,7 +596,9 @@ fn addWatchInput(
595596
) !void {
596597
const src_dir_path = file_or_dir.getPath3(b, step);
597598

599+
const io = b.graph.io;
598600
var src_dir = src_dir_path.root_dir.handle.openDir(
601+
io,
599602
src_dir_path.subPathOrDot(),
600603
.{ .iterate = true },
601604
) catch |e| switch (e) {
@@ -608,14 +611,14 @@ fn addWatchInput(
608611
.@"0.15", .@"0.16" => @panic(b.fmt("Unable to open directory '{f}': {t}", .{ src_dir_path, e })),
609612
},
610613
};
611-
defer src_dir.close();
614+
defer src_dir.close(io);
612615

613616
const needs_dir_derived = try step.addDirectoryWatchInput(file_or_dir);
614617

615618
var it = try src_dir.walk(b.allocator);
616619
defer it.deinit();
617620

618-
while (try it.next()) |entry| {
621+
while (try it.next(io)) |entry| {
619622
switch (entry.kind) {
620623
.directory => if (needs_dir_derived) {
621624
const entry_path = try src_dir_path.join(b.allocator, entry.path);
@@ -867,6 +870,7 @@ const ZlinterRun = struct {
867870
fn make(step: *std.Build.Step, _: std.Build.Step.MakeOptions) !void {
868871
const run: *ZlinterRun = @alignCast(@fieldParentPtr("step", step));
869872
const b = run.step.owner;
873+
const io = b.graph.io;
870874
const arena = b.allocator;
871875

872876
var cwd_buff: [std.fs.max_path_bytes]u8 = undefined;
@@ -1021,13 +1025,12 @@ const ZlinterRun = struct {
10211025

10221026
var timer = try std.time.Timer.start();
10231027

1024-
std.debug.lockStdErr();
1025-
defer std.debug.unlockStdErr();
1026-
1027-
child.spawn() catch |err| {
1028+
_ = std.debug.lockStderr(&.{});
1029+
defer std.debug.unlockStderr();
1030+
child.spawn(io) catch |err| {
10281031
return run.step.fail("Unable to spawn zlinter: {s}", .{@errorName(err)});
10291032
};
1030-
errdefer _ = child.kill() catch {};
1033+
errdefer _ = child.kill(io) catch {};
10311034

10321035
{
10331036
if (b.verbose)
@@ -1042,15 +1045,15 @@ const ZlinterRun = struct {
10421045
},
10431046
.@"0.15", .@"0.16" => {
10441047
var buffer: [1024]u8 = undefined;
1045-
var writer = stdin_file.writer(&buffer);
1048+
var writer = stdin_file.writer(io, &buffer);
10461049
writer.interface.writeInt(usize, build_info_zon_bytes.len, .little) catch @panic("stdin write failed");
10471050
writer.interface.writeAll(build_info_zon_bytes) catch @panic("stdin write failed");
10481051
writer.interface.flush() catch @panic("Flush failed");
10491052
},
10501053
}
10511054
}
10521055

1053-
const term = try child.wait();
1056+
const term = try child.wait(io);
10541057

10551058
step.result_duration_ns = timer.read();
10561059
step.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;
@@ -1092,8 +1095,9 @@ const ZlinterRun = struct {
10921095
fn readHtmlTemplate(b: *std.Build, path: std.Build.LazyPath) ![]const u8 {
10931096
const rules_path = path.getPath3(b, null);
10941097

1095-
var file = try rules_path.root_dir.handle.openFile(rules_path.subPathOrDot(), .{});
1096-
defer file.close();
1098+
const io = b.graph.io;
1099+
var file = try rules_path.root_dir.handle.openFile(io, rules_path.subPathOrDot(), .{});
1100+
defer file.close(io);
10971101

10981102
var file_buffer: [1024]u8 = undefined;
10991103
var file_reader = file.reader(b.graph.io, &file_buffer);
@@ -1146,11 +1150,11 @@ fn readHtmlTemplate(b: *std.Build, path: std.Build.LazyPath) ![]const u8 {
11461150
/// Normalised representation of the current working directory
11471151
const BuildCwd = struct {
11481152
path: []const u8,
1149-
dir: std.fs.Dir,
1153+
dir: std.Io.Dir,
11501154

11511155
pub fn init(buff: *[std.fs.max_path_bytes]u8) BuildCwd {
11521156
return .{
1153-
.dir = std.fs.cwd(),
1157+
.dir = std.Io.Dir.cwd(),
11541158
.path = std.process.getCwd(buff) catch unreachable,
11551159
};
11561160
}
@@ -1182,22 +1186,23 @@ const BuildCwd = struct {
11821186
};
11831187
errdefer b.allocator.free(relative);
11841188

1185-
if (relative.len != 0 and isReadable(&self.dir, relative)) {
1189+
if (relative.len != 0 and isReadable(b, &self.dir, relative)) {
11861190
return b.path(relative);
11871191
} else {
11881192
b.allocator.free(relative);
11891193
return null;
11901194
}
11911195
} else {
1192-
if (isReadable(&self.dir, to)) {
1196+
if (isReadable(b, &self.dir, to)) {
11931197
return b.path(b.dupe(to));
11941198
}
11951199
}
11961200
return null;
11971201
}
11981202

1199-
fn isReadable(from: *const std.fs.Dir, sub_path: []const u8) bool {
1203+
fn isReadable(b: *std.Build, from: *const std.Io.Dir, sub_path: []const u8) bool {
12001204
_ = from.access(
1205+
b.graph.io,
12011206
sub_path,
12021207
.{ .read = true },
12031208
) catch return false;

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
.zls = .{
88
// Update with `zig fetch --save git+https://github.com/zigtools/zls#master`
99
// IF changed THEN update .github/coverage.yml
10-
.url = "git+https://github.com/zigtools/zls?ref=master#d84c451fcea7b708e77a1e1e159c2d0633e39beb",
11-
.hash = "zls-0.16.0-dev-rmm5fjm_JADQFr8iimnZH4jeWpPlKC4CCfs6XYbUuiEm",
10+
.url = "git+https://github.com/zigtools/zls?ref=master#cbb6228417f2ddcac372808d4743960ba19f49a3",
11+
.hash = "zls-0.16.0-dev-rmm5fl7EJADZ3yTkAONy98Hx9PgTDKKIH0ZJtaR-rhtg",
1212
},
1313
},
1414
.paths = .{

build_docs.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ pub fn main() !void {
1313
defer std.process.argsFree(gpa, args);
1414

1515
const output_file_path = args[1];
16-
var output_file = std.fs.cwd().createFile(output_file_path, .{}) catch |err| {
16+
var output_file = std.Io.Dir.cwd().createFile(io, output_file_path, .{}) catch |err| {
1717
fatal("Unable to open '{s}': {s}", .{ output_file_path, @errorName(err) });
1818
};
19-
defer output_file.close();
19+
defer output_file.close(io);
2020

2121
var buffer: [1024]u8 = undefined;
22-
var writer = output_file.writer(&buffer);
22+
var writer = output_file.writer(io, &buffer);
2323

2424
try writer.interface.writeAll(
2525
\\# zlinter rules
@@ -46,8 +46,8 @@ pub fn main() !void {
4646
try writer.interface.writeAll(rule_name);
4747
try writer.interface.writeAll("`\n\n");
4848

49-
var file = try std.fs.cwd().openFile(file_name, .{});
50-
defer file.close();
49+
var file = try std.Io.Dir.cwd().openFile(io, file_name, .{});
50+
defer file.close(io);
5151

5252
var reader = file.readerStreaming(io, &file_buffer);
5353

@@ -61,7 +61,7 @@ pub fn main() !void {
6161

6262
try writer.interface.flush();
6363

64-
return std.process.cleanExit();
64+
return std.process.cleanExit(io);
6565
}
6666

6767
fn stringLessThan(_: void, lhs: []const u8, rhs: []const u8) bool {

build_rules.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ pub fn main() !void {
44
var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
55
defer if (debug_allocator.deinit() == .leak) @panic("Memory leak");
66

7+
var threaded: std.Io.Threaded = .init_single_threaded;
8+
const io = threaded.io();
9+
710
const gpa = debug_allocator.allocator();
811

912
const args = try std.process.argsAlloc(gpa);
@@ -12,15 +15,15 @@ pub fn main() !void {
1215
if (args.len < 2) fatal("Wrong number of arguments", .{});
1316

1417
const output_file_path = args[1];
15-
var output_file = std.fs.cwd().createFile(output_file_path, .{}) catch |err| {
18+
var output_file = std.Io.Dir.cwd().createFile(io, output_file_path, .{}) catch |err| {
1619
fatal("Unable to open '{s}': {s}", .{ output_file_path, @errorName(err) });
1720
};
18-
defer output_file.close();
21+
defer output_file.close(io);
1922

2023
const rule_names = args[2..];
2124

2225
var write_buffer: [2048]u8 = undefined;
23-
var output_file_writer = output_file.writer(&write_buffer);
26+
var output_file_writer = output_file.writer(io, &write_buffer);
2427

2528
try output_file_writer.interface.writeAll(
2629
\\const zlinter = @import("zlinter");
@@ -91,7 +94,7 @@ pub fn main() !void {
9194

9295
try output_file_writer.interface.flush();
9396

94-
return std.process.cleanExit();
97+
return std.process.cleanExit(io);
9598
}
9699

97100
fn fatal(comptime format: []const u8, args: anytype) noreturn {

integration_tests/build.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ const input_suffix = ".input.zig";
33
pub fn build(b: *std.Build) !void {
44
const target = b.standardTargetOptions(.{});
55
const optimize = b.standardOptimizeOption(.{});
6+
const io = b.graph.io;
67

78
const test_focus_on_rule = b.option([]const u8, "test_focus_on_rule", "Only run tests for this rule");
89
const test_step = b.step("test", "Run tests");
910

1011
const test_cases_path = b.path("test_cases/").getPath3(b, null).sub_path;
11-
var test_cases_dir = try std.fs.cwd().openDir(test_cases_path, .{ .iterate = true });
12-
defer test_cases_dir.close();
12+
var test_cases_dir = try std.Io.Dir.cwd().openDir(io, test_cases_path, .{ .iterate = true });
13+
defer test_cases_dir.close(io);
1314

1415
var walker = try test_cases_dir.walk(b.allocator);
1516
defer walker.deinit();
1617

17-
while (try walker.next()) |item| {
18+
while (try walker.next(io)) |item| {
1819
if (item.kind != .file) continue;
1920
if (!std.mem.endsWith(u8, item.path, input_suffix)) continue;
2021

@@ -114,7 +115,7 @@ pub fn build(b: *std.Build) !void {
114115
fn addFileArgIfExists(b: *std.Build, step: *std.Build.Step.Run, raw_path: []const u8) void {
115116
var path = b.path(raw_path);
116117
const relative_path = path.getPath3(b, &step.step).sub_path;
117-
const exists = if (std.fs.cwd().access(relative_path, .{})) true else |e| e != error.FileNotFound;
118+
const exists = if (std.Io.Dir.cwd().access(b.graph.io, relative_path, .{})) true else |e| e != error.FileNotFound;
118119
if (exists) {
119120
step.addFileArg(path);
120121
}

0 commit comments

Comments
 (0)