| ... | @@ -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 | } |
| 287 | | 287 | |
| | 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 | } |
| 291 | | 292 | |
| | 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 | } |
| 299 | | 301 | |
| | 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 | } |
| 310 | | 313 | |
| | 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 prefix | 3125 | /// A path relative to the prefix |
| 3122 | custom: []const u8, | 3126 | custom: []const u8, |
| 3123 | | 3127 | |
| 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 problems | 3131 | // 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, |
| 3138 | | 3143 | |
| | 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), |