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 {...@@ -285,10 +285,12 @@ pub const Builder = struct {
285 return run_step;285 return run_step;
286 }286 }
287287
288 /// Allocator.dupe without the need to handle out of memory.
288 pub fn dupe(self: *Builder, bytes: []const u8) []u8 {289 pub fn dupe(self: *Builder, bytes: []const u8) []u8 {
289 return self.allocator.dupe(u8, bytes) catch unreachable;290 return self.allocator.dupe(u8, bytes) catch unreachable;
290 }291 }
291292
293 /// Duplicates an array of strings without the need to handle out of memory.
292 pub fn dupeStrings(self: *Builder, strings: []const []const u8) [][]u8 {294 pub fn dupeStrings(self: *Builder, strings: []const []const u8) [][]u8 {
293 const array = self.allocator.alloc([]u8, strings.len) catch unreachable;295 const array = self.allocator.alloc([]u8, strings.len) catch unreachable;
294 for (strings) |s, i| {296 for (strings) |s, i| {
...@@ -297,6 +299,7 @@ pub const Builder = struct {...@@ -297,6 +299,7 @@ pub const Builder = struct {
297 return array;299 return array;
298 }300 }
299301
302 /// Duplicates a path and converts all slashes to the OS's canonical path separator.
300 pub fn dupePath(self: *Builder, bytes: []const u8) []u8 {303 pub fn dupePath(self: *Builder, bytes: []const u8) []u8 {
301 const the_copy = self.dupe(bytes);304 const the_copy = self.dupe(bytes);
302 for (the_copy) |*byte| {305 for (the_copy) |*byte| {
...@@ -308,6 +311,7 @@ pub const Builder = struct {...@@ -308,6 +311,7 @@ pub const Builder = struct {
308 return the_copy;311 return the_copy;
309 }312 }
310313
314 /// Duplicates a package recursively.
311 pub fn dupePkg(self: *Builder, package: Pkg) Pkg {315 pub fn dupePkg(self: *Builder, package: Pkg) Pkg {
312 var the_copy = Pkg{316 var the_copy = Pkg{
313 .name = self.dupe(package.name),317 .name = self.dupe(package.name),
...@@ -3121,7 +3125,8 @@ pub const InstallDir = union(enum) {...@@ -3121,7 +3125,8 @@ pub const InstallDir = union(enum) {
3121 /// A path relative to the prefix3125 /// A path relative to the prefix
3122 custom: []const u8,3126 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 {
3125 if (self == .custom) {3130 if (self == .custom) {
3126 // Written with this temporary to avoid RLS problems3131 // Written with this temporary to avoid RLS problems
3127 const duped_path = builder.dupe(self.custom);3132 const duped_path = builder.dupe(self.custom);
...@@ -3136,6 +3141,7 @@ pub const InstalledFile = struct {...@@ -3136,6 +3141,7 @@ pub const InstalledFile = struct {
3136 dir: InstallDir,3141 dir: InstallDir,
3137 path: []const u8,3142 path: []const u8,
31383143
3144 /// Duplicates the installed file path and directory.
3139 pub fn dupe(self: InstalledFile, builder: *Builder) InstalledFile {3145 pub fn dupe(self: InstalledFile, builder: *Builder) InstalledFile {
3140 return .{3146 return .{
3141 .dir = self.dir.dupe(builder),3147 .dir = self.dir.dupe(builder),