-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathDirectoryFileInput.zig
More file actions
79 lines (68 loc) · 2.64 KB
/
DirectoryFileInput.zig
File metadata and controls
79 lines (68 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! DirectoryFileInput adds files within a directory to the dependencies of the given Step.Run command
//! This is required so that generated directories will work.
const std = @import("std");
const androidbuild = @import("androidbuild.zig");
const builtin = @import("builtin");
const Build = std.Build;
const Step = Build.Step;
const Run = Build.Step.Run;
const LazyPath = Build.LazyPath;
const fs = std.fs;
const mem = std.mem;
const assert = std.debug.assert;
step: Step,
/// Runner to update
run: *Build.Step.Run,
/// The directory that will contain the files to glob
dir: LazyPath,
pub fn create(owner: *std.Build, run: *Run, dir: LazyPath) void {
const self = owner.allocator.create(DirectoryFileInput) catch @panic("OOM");
self.* = .{
.step = Step.init(.{
.id = .custom,
.name = androidbuild.runNameContext("directory-file-input"),
.owner = owner,
.makeFn = make,
}),
.run = run,
.dir = dir,
};
// Run step relies on DirectoryFileInput finishing
run.step.dependOn(&self.step);
// If dir is generated then this will wait for that dir to generate
dir.addStepDependencies(&self.step);
}
fn make(step: *Step, _: Build.Step.MakeOptions) !void {
const b = step.owner;
const arena = b.allocator;
const self: *DirectoryFileInput = @fieldParentPtr("step", step);
const run = self.run;
const dir_path = if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
self.dir.getPath3(b, step)
else
try self.dir.getPath4(b, step);
// NOTE(jae): 2025-07-23
// As of Zig 0.15.0-dev.1092+d772c0627, package_name_path.openDir("") is not possible as it assumes you're appending a sub-path
var dir = if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
try dir_path.root_dir.handle.openDir(dir_path.sub_path, .{ .iterate = true })
else
try dir_path.root_dir.handle.openDir(b.graph.io, dir_path.sub_path, .{ .iterate = true });
defer if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
dir.close()
else
dir.close(b.graph.io);
var walker = try dir.walk(arena);
defer walker.deinit();
while (if (builtin.zig_version.major == 0 and builtin.zig_version.minor <= 15)
try walker.next()
else
try walker.next(b.graph.io)) |entry|
{
if (entry.kind != .file) continue;
// Add file as dependency to run command
run.addFileInput(LazyPath{
.cwd_relative = try dir_path.root_dir.join(b.allocator, &.{ dir_path.sub_path, entry.path }),
});
}
}
const DirectoryFileInput = @This();