| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | | const gpa = std.heap.c_allocator; |
| 4 | 3 | |
| 5 | 4 | const u = @import("index.zig"); |
| 6 | 5 | |
| ... | ... | @@ -249,7 +248,7 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const |
| 249 | 248 | return input[f..t]; |
| 250 | 249 | } |
| 251 | 250 | |
| 252 | | pub fn detect_pkgname(override: string, dir: string) !string { |
| 251 | pub fn detect_pkgname(alloc: *std.mem.Allocator, override: string, dir: string) !string { |
| 253 | 252 | if (override.len > 0) { |
| 254 | 253 | return override; |
| 255 | 254 | } |
| ... | ... | @@ -257,15 +256,15 @@ pub fn detect_pkgname(override: string, dir: string) !string { |
| 257 | 256 | if (!(try does_file_exist(dirO, "build.zig"))) { |
| 258 | 257 | return error.NoBuildZig; |
| 259 | 258 | } |
| 260 | | const dpath = try std.fs.realpathAlloc(gpa, try std.mem.concat(gpa, u8, &.{ dir, "build.zig" })); |
| 261 | | const splitP = try split(gpa, dpath, std.fs.path.sep_str); |
| 259 | const dpath = try std.fs.realpathAlloc(alloc, try std.mem.concat(alloc, u8, &.{ dir, "build.zig" })); |
| 260 | const splitP = try split(alloc, dpath, std.fs.path.sep_str); |
| 262 | 261 | var name = splitP[splitP.len - 2]; |
| 263 | 262 | name = trim_prefix(name, "zig-"); |
| 264 | 263 | assert(name.len > 0, "package name must not be an empty string", .{}); |
| 265 | 264 | return name; |
| 266 | 265 | } |
| 267 | 266 | |
| 268 | | pub fn detct_mainfile(override: string, dir: ?std.fs.Dir, name: string) !string { |
| 267 | pub fn detct_mainfile(alloc: *std.mem.Allocator, override: string, dir: ?std.fs.Dir, name: string) !string { |
| 269 | 268 | if (override.len > 0) { |
| 270 | 269 | if (try does_file_exist(dir, override)) { |
| 271 | 270 | if (std.mem.endsWith(u8, override, ".zig")) { |
| ... | ... | @@ -273,14 +272,14 @@ pub fn detct_mainfile(override: string, dir: ?std.fs.Dir, name: string) !string |
| 273 | 272 | } |
| 274 | 273 | } |
| 275 | 274 | } |
| 276 | | const namedotzig = try std.mem.concat(gpa, u8, &.{ name, ".zig" }); |
| 275 | const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" }); |
| 277 | 276 | if (try does_file_exist(dir, namedotzig)) { |
| 278 | 277 | return namedotzig; |
| 279 | 278 | } |
| 280 | | if (try does_file_exist(dir, try std.fs.path.join(gpa, &.{ "src", "lib.zig" }))) { |
| 279 | if (try does_file_exist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { |
| 281 | 280 | return "src/lib.zig"; |
| 282 | 281 | } |
| 283 | | if (try does_file_exist(dir, try std.fs.path.join(gpa, &.{ "src", "main.zig" }))) { |
| 282 | if (try does_file_exist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { |
| 284 | 283 | return "src/main.zig"; |
| 285 | 284 | } |
| 286 | 285 | return error.CantFindMain; |