authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-10-22 16:10:01+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-16 16:09:58-08:00
log4ace1f5a7ffeb569e97dc78807a1eacc5565a272
tree12d4f0d2a66da0aa121b341677e86c0727b9e221
parentfd43baa9ad37217a5715c1e3cfad2d2d78558d1f

Build: add namedWriteFiles to Build


1 files changed, 16 insertions(+), 0 deletions(-)

lib/std/Build.zig+16
...@@ -90,6 +90,8 @@ host: ResolvedTarget,...@@ -90,6 +90,8 @@ host: ResolvedTarget,
90dep_prefix: []const u8 = "",90dep_prefix: []const u8 = "",
9191
92modules: std.StringArrayHashMap(*Module),92modules: std.StringArrayHashMap(*Module),
93
94named_writefiles: std.StringArrayHashMap(*Step.WriteFile),
93/// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child95/// A map from build root dirs to the corresponding `*Dependency`. This is shared with all child
94/// `Build`s.96/// `Build`s.
95initialized_deps: *InitializedDepMap,97initialized_deps: *InitializedDepMap,
...@@ -273,6 +275,7 @@ pub fn create(...@@ -273,6 +275,7 @@ pub fn create(
273 .args = null,275 .args = null,
274 .host = host,276 .host = host,
275 .modules = std.StringArrayHashMap(*Module).init(allocator),277 .modules = std.StringArrayHashMap(*Module).init(allocator),
278 .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(allocator),
276 .initialized_deps = initialized_deps,279 .initialized_deps = initialized_deps,
277 .available_deps = available_deps,280 .available_deps = available_deps,
278 };281 };
...@@ -360,6 +363,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc...@@ -360,6 +363,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc
360 .host = parent.host,363 .host = parent.host,
361 .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),364 .dep_prefix = parent.fmt("{s}{s}.", .{ parent.dep_prefix, dep_name }),
362 .modules = std.StringArrayHashMap(*Module).init(allocator),365 .modules = std.StringArrayHashMap(*Module).init(allocator),
366 .named_writefiles = std.StringArrayHashMap(*Step.WriteFile).init(allocator),
363 .initialized_deps = parent.initialized_deps,367 .initialized_deps = parent.initialized_deps,
364 .available_deps = pkg_deps,368 .available_deps = pkg_deps,
365 };369 };
...@@ -981,6 +985,12 @@ pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step...@@ -981,6 +985,12 @@ pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step
981 return write_file_step;985 return write_file_step;
982}986}
983987
988pub fn addNamedWriteFiles(b: *Build, name: []const u8) *Step.WriteFile {
989 const wf = Step.WriteFile.create(b);
990 b.named_writefiles.put(b.dupe(name), wf) catch @panic("OOM");
991 return wf;
992}
993
984pub fn addWriteFiles(b: *Build) *Step.WriteFile {994pub fn addWriteFiles(b: *Build) *Step.WriteFile {
985 return Step.WriteFile.create(b);995 return Step.WriteFile.create(b);
986}996}
...@@ -1711,6 +1721,12 @@ pub const Dependency = struct {...@@ -1711,6 +1721,12 @@ pub const Dependency = struct {
1711 };1721 };
1712 }1722 }
17131723
1724 pub fn namedWriteFiles(d: *Dependency, name: []const u8) *Step.WriteFile {
1725 return d.builder.named_writefiles.get(name) orelse {
1726 panic("unable to find named writefiles '{s}'", .{name});
1727 };
1728 }
1729
1714 pub fn path(d: *Dependency, sub_path: []const u8) LazyPath {1730 pub fn path(d: *Dependency, sub_path: []const u8) LazyPath {
1715 return .{1731 return .{
1716 .dependency = .{1732 .dependency = .{