| ... | @@ -228,20 +228,21 @@ fn unpackSourcesInner(tar_bytes: []u8) !void { | ... | @@ -228,20 +228,21 @@ fn unpackSourcesInner(tar_bytes: []u8) !void { |
| 228 | if (std.mem.endsWith(u8, tar_file.name, ".zig")) { | 228 | if (std.mem.endsWith(u8, tar_file.name, ".zig")) { |
| 229 | log.debug("found file: '{s}'", .{tar_file.name}); | 229 | log.debug("found file: '{s}'", .{tar_file.name}); |
| 230 | const file_name = try gpa.dupe(u8, tar_file.name); | 230 | const file_name = try gpa.dupe(u8, tar_file.name); |
| 231 | if (std.mem.indexOfScalar(u8, file_name, '/')) |pkg_name_end| { | 231 | // This is a hack to guess modules from the tar file contents. To handle modules |
| 232 | const pkg_name = file_name[0..pkg_name_end]; | 232 | // properly, the build system will need to change the structure here to have one |
| 233 | const gop = try Walk.modules.getOrPut(gpa, pkg_name); | 233 | // directory per module. This in turn requires compiler enhancements to allow |
| 234 | const file: Walk.File.Index = @enumFromInt(Walk.files.entries.len); | 234 | // the build system to actually discover the required information. |
| 235 | if (!gop.found_existing or | 235 | const mod_name, const is_module_root = p: { |
| 236 | std.mem.eql(u8, file_name[pkg_name_end..], "/root.zig") or | 236 | if (std.mem.find(u8, file_name, "std/")) |i| break :p .{ "std", std.mem.eql(u8, file_name[i + 4 ..], "std.zig") }; |
| 237 | std.mem.eql(u8, file_name[pkg_name_end + 1 .. file_name.len - ".zig".len], pkg_name)) | 237 | if (std.mem.endsWith(u8, file_name, "/builtin.zig")) break :p .{ "builtin", true }; |
| 238 | { | 238 | break :p .{ "root", std.mem.endsWith(u8, file_name, "/root.zig") }; |
| 239 | gop.value_ptr.* = file; | 239 | }; |
| 240 | } | 240 | const gop = try Walk.modules.getOrPut(gpa, mod_name); |
| 241 | const file_bytes = tar_reader.take(@intCast(tar_file.size)) catch unreachable; | 241 | const file: Walk.File.Index = @enumFromInt(Walk.files.entries.len); |
| 242 | it.unread_file_bytes = 0; // we have read the whole thing | 242 | if (!gop.found_existing or is_module_root) gop.value_ptr.* = file; |
| 243 | assert(file == try Walk.add_file(file_name, file_bytes)); | 243 | const file_bytes = tar_reader.take(@intCast(tar_file.size)) catch unreachable; |
| 244 | } | 244 | it.unread_file_bytes = 0; // we have read the whole thing |
| | 245 | assert(file == try Walk.add_file(file_name, file_bytes)); |
| 245 | } else { | 246 | } else { |
| 246 | log.warn("skipping: '{s}' - the tar creation should have done that", .{tar_file.name}); | 247 | log.warn("skipping: '{s}' - the tar creation should have done that", .{tar_file.name}); |
| 247 | } | 248 | } |