authorgravatar for ellis@trisk-grove.comEllis Trisk-Grove <ellis@trisk-grove.com> 2021-05-15 17:34:42+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-11 20:24:56+03:00
logba7bfe949e7d3778fc4ca72ac73df60f4124b4da
treef2ec42bb0b7c6d04bede5f05a1cf29bf4cdf6939
parentb6277a4b1c2be27701d594bc1465ac72fc226260

std.build.InstallDir: make dupe() a public function

Co-authored-by: Veikka Tuominen <git@vexu.eu>

1 files changed, 7 insertions(+), 1 deletions(-)

lib/std/build.zig+7-1
......@@ -285,10 +285,12 @@ pub const Builder = struct {
285285 return run_step;
286286 }
287287
288 /// Allocator.dupe without the need to handle out of memory.
288289 pub fn dupe(self: *Builder, bytes: []const u8) []u8 {
289290 return self.allocator.dupe(u8, bytes) catch unreachable;
290291 }
291292
293 /// Duplicates an array of strings without the need to handle out of memory.
292294 pub fn dupeStrings(self: *Builder, strings: []const []const u8) [][]u8 {
293295 const array = self.allocator.alloc([]u8, strings.len) catch unreachable;
294296 for (strings) |s, i| {
......@@ -297,6 +299,7 @@ pub const Builder = struct {
297299 return array;
298300 }
299301
302 /// Duplicates a path and converts all slashes to the OS's canonical path separator.
300303 pub fn dupePath(self: *Builder, bytes: []const u8) []u8 {
301304 const the_copy = self.dupe(bytes);
302305 for (the_copy) |*byte| {
......@@ -308,6 +311,7 @@ pub const Builder = struct {
308311 return the_copy;
309312 }
310313
314 /// Duplicates a package recursively.
311315 pub fn dupePkg(self: *Builder, package: Pkg) Pkg {
312316 var the_copy = Pkg{
313317 .name = self.dupe(package.name),
......@@ -3121,7 +3125,8 @@ pub const InstallDir = union(enum) {
31213125 /// A path relative to the prefix
31223126 custom: []const u8,
31233127
3124 fn dupe(self: InstallDir, builder: *Builder) InstallDir {
3128 /// Duplicates the install directory including the path if set to custom.
3129 pub fn dupe(self: InstallDir, builder: *Builder) InstallDir {
31253130 if (self == .custom) {
31263131 // Written with this temporary to avoid RLS problems
31273132 const duped_path = builder.dupe(self.custom);
......@@ -3136,6 +3141,7 @@ pub const InstalledFile = struct {
31363141 dir: InstallDir,
31373142 path: []const u8,
31383143
3144 /// Duplicates the installed file path and directory.
31393145 pub fn dupe(self: InstalledFile, builder: *Builder) InstalledFile {
31403146 return .{
31413147 .dir = self.dir.dupe(builder),