Added dependencies to plugin's (By name... for now ig, might wanna change so that it takes build function from plugin tho, safer)
This commit is contained in:
parent
5ab65e1b67
commit
3342f6ad6f
3 changed files with 51 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ const stage = @import("stage.zig");
|
|||
pub const plugin: App.plugin.Plugin = .{
|
||||
.name = "Simple",
|
||||
.description = "Simple plugin example",
|
||||
.dependencies = &.{},
|
||||
.build = build,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const Self = @This();
|
|||
|
||||
// --- ID ---
|
||||
name: []const u8,
|
||||
dependencies: []const []const u8 = &.{},
|
||||
description: []const u8 = "",
|
||||
version: [3]u8 = .{ 0, 0, 0 },
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,54 @@ pub fn build(
|
|||
self: *Self,
|
||||
ctx: Context,
|
||||
) !void {
|
||||
for (self.data.items) |*plugin| {
|
||||
try plugin.build(plugin, ctx);
|
||||
// --- # ---
|
||||
var built: std.StringHashMap(void) = .init(self.alloc);
|
||||
defer built.deinit();
|
||||
|
||||
// --- # ---
|
||||
var progress = true;
|
||||
while (progress) {
|
||||
progress = false;
|
||||
|
||||
for (self.data.items) |*plugin| {
|
||||
// --- SKIP SELF ---
|
||||
if (built.contains(plugin.name)) continue;
|
||||
|
||||
// --- CHECK IF DEP ARE [READY OR NOT]
|
||||
var ready: bool = true;
|
||||
for (plugin.dependencies) |dep| {
|
||||
if (!built.contains(dep)) {
|
||||
ready = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// --- IF YE, BUILD ---
|
||||
if (ready) {
|
||||
try plugin.build(plugin, ctx);
|
||||
try built.put(plugin.name, {});
|
||||
progress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- # ---
|
||||
var missing = false;
|
||||
for (self.data.items) |plugin| {
|
||||
if (!built.contains(plugin.name)) {
|
||||
std.debug.print("[PLUGIN] Failed to build \"{s}\". Missing dependencies:\n", .{plugin.name});
|
||||
|
||||
for (plugin.dependencies) |dep| {
|
||||
if (!built.contains(dep)) {
|
||||
std.debug.print(" - {s}\n", .{dep});
|
||||
}
|
||||
}
|
||||
missing = true;
|
||||
}
|
||||
}
|
||||
|
||||
// --- # ---
|
||||
if (missing) {
|
||||
return error.PluginDependencyError;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue