2018-07-16 17:52:50 -07:00
|
|
|
const std = @import("std");
|
|
|
|
const mem = std.mem;
|
|
|
|
const assert = std.debug.assert;
|
2020-04-01 09:44:45 -07:00
|
|
|
const ArrayListSentineled = std.ArrayListSentineled;
|
2018-07-16 17:52:50 -07:00
|
|
|
|
2018-11-13 05:08:37 -08:00
|
|
|
pub const Package = struct {
|
2020-04-01 09:44:45 -07:00
|
|
|
root_src_dir: ArrayListSentineled(u8, 0),
|
|
|
|
root_src_path: ArrayListSentineled(u8, 0),
|
2018-07-16 17:52:50 -07:00
|
|
|
|
|
|
|
/// relative to root_src_dir
|
|
|
|
table: Table,
|
|
|
|
|
2019-09-03 14:53:05 -07:00
|
|
|
pub const Table = std.StringHashMap(*Package);
|
2018-07-16 17:52:50 -07:00
|
|
|
|
|
|
|
/// makes internal copies of root_src_dir and root_src_path
|
|
|
|
/// allocator should be an arena allocator because Package never frees anything
|
|
|
|
pub fn create(allocator: *mem.Allocator, root_src_dir: []const u8, root_src_path: []const u8) !*Package {
|
2019-02-03 13:13:28 -08:00
|
|
|
const ptr = try allocator.create(Package);
|
|
|
|
ptr.* = Package{
|
2020-04-01 09:44:45 -07:00
|
|
|
.root_src_dir = try ArrayListSentineled(u8, 0).init(allocator, root_src_dir),
|
|
|
|
.root_src_path = try ArrayListSentineled(u8, 0).init(allocator, root_src_path),
|
2018-07-16 17:52:50 -07:00
|
|
|
.table = Table.init(allocator),
|
2019-02-03 13:13:28 -08:00
|
|
|
};
|
|
|
|
return ptr;
|
2018-07-16 17:52:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(self: *Package, name: []const u8, package: *Package) !void {
|
|
|
|
const entry = try self.table.put(try mem.dupe(self.table.allocator, u8, name), package);
|
|
|
|
assert(entry == null);
|
|
|
|
}
|
|
|
|
};
|