Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const ztk_dep = b.dependency("ztk", .{ .target = target, .optimize = optimize });
const ztcl_dep = ztk_dep.builder.dependency("ztcl", .{ .target = target, .optimize = optimize });
const ztk_mod = ztk_dep.module("ztk");
// The ztcl module of ztk: ztk gives ztcl its own options (`drop`), so a
// new dependency on ztcl here makes a second module of the same files.
const ztcl_mod = ztk_mod.import_table.get("ztcl") orelse @panic("ztk imports no ztcl module");
const imports: []const std.Build.Module.Import = &.{
.{ .name = "ztk", .module = ztk_dep.module("ztk") },
.{ .name = "ztcl", .module = ztcl_dep.module("ztcl") },
.{ .name = "ztk", .module = ztk_mod },
.{ .name = "ztcl", .module = ztcl_mod },
};
const use_lld = target.result.ofmt != .macho;
const root = b.createModule(.{
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
.minimum_zig_version = "0.17.0",
.dependencies = .{
.ztk = .{
.url = "git+https://github.com/beetlebugorg/ztk#31af992759944de373c46b4b96e07c5d0b125614",
.hash = "ztk-0.2.0-beta-pPTF2DxZUgC2z60gPx72clYhUBqeCvLgfzPB2Ou0neIE",
.url = "git+https://github.com/beetlebugorg/ztk#dd1046663dd6b29ca452547b5cf25f00027354d8",
.hash = "ztk-1.0.0-beta.1-pPTF2G4wVADy5CJyXdQMxvFs2EamImrt5xD2d3POyNGq",
},
},
.paths = .{ "build.zig", "build.zig.zon", "src" },
Expand Down
8 changes: 7 additions & 1 deletion src/app/apps.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ fn programName(a: std.mem.Allocator, target: []const u8, name: []const u8) ![]co
/// `lib/ztk/runtime` next to the folder of this program.
pub var runtime_root: ?[]const u8 = null;

/// The environment of the process for `ztk bundle`, which reads the
/// folders of the build tools from it. `main` sets it; with null (the
/// tests), the bundle gets an empty environment.
pub var environ: ?*const std.process.Environ.Map = null;

/// The path of the ztk program of a target.
fn runtimePath(a: std.mem.Allocator, target: []const u8) ![]const u8 {
const root = runtime_root orelse try std.fs.path.join(a, &.{ try std.process.executableDirPathAlloc(the_io, a), "..", "lib", "ztk", "runtime" });
Expand Down Expand Up @@ -155,7 +160,8 @@ fn build(a: std.mem.Allocator, target: []const u8) !BuildResult {
}
for (try appFiles(a, project)) |f| try args.append(a, try a.dupeSentinel(u8, f, 0));
var log: Io.Writer.Allocating = .init(a);
const status = try ztk.bundle.run(the_io, a, args.items, &log.writer);
var empty: std.process.Environ.Map = .init(a);
const status = try ztk.bundle.run(the_io, a, environ orelse &empty, args.items, &log.writer);
return .{ .status = status, .log = log.written(), .path = try std.fmt.allocPrint(a, "/build/{s}/{s}", .{ target, file }) };
}

Expand Down
1 change: 1 addition & 0 deletions src/app/crash.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn install(arena: std.mem.Allocator, io: Io, env: *const std.process.Environ
}
const last = prune(arena, io, dir);
if (it) |interp| {
_ = interp.eval("namespace eval ::dockyard::crash {}") catch {};
interp.setVar("::dockyard::crash::last", .{ .str = last orelse "" }) catch {};
interp.register("::dockyard::crash::open", cmdOpen) catch {};
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ pub fn shellOf(map: *const std.process.Environ.Map) []const u8 {

/// Sets the variables of `dockyard.tcl`.
pub fn setVars(it: *ztcl.Interp, s: Setup) !void {
// The namespace of the variables: ztcl fails a set in a namespace that does not exist, as Tcl does.
_ = try it.eval("namespace eval ::dockyard {}");
try it.setVar("::dockyard::project", .{ .str = s.project });
try it.setVar("::dockyard::agent", .{ .str = s.agent orelse "" });
try it.setVar("::dockyard::agent_name", .{ .str = s.agent_name });
Expand Down
2 changes: 1 addition & 1 deletion src/audit/audit.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ test "the audit log chains, indexes, and filters the records" {
// terminal view of monitor.tcl gives each record a line.
try it.allow(@backingInt(ztcl.interp.Capability.event) | @backingInt(ztcl.interp.Capability.clock));
it.event_host = .{ .now = testTicks, .sleep = testSleep };
_ = try it.eval("set ::dockyard::project /p; set ::dockyard::tui 1");
_ = try it.eval("namespace eval ::dockyard {}; set ::dockyard::project /p; set ::dockyard::tui 1");
_ = try it.eval(@embedFile("audit.tcl"));
_ = it.eval(
\\::dockyard::audit::start 1 {claude}
Expand Down
3 changes: 3 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub fn main(init: std.process.Init) !void {
try host.allowPreview(&it, std.fs.path.dirname(f) orelse "/");
} else {
try host.allow(&it, folder, env);
apps.environ = init.environ_map;
try apps.register(&it, io, folder);
try proxy.register(&it);
try host.setVars(&it, .{
Expand All @@ -226,6 +227,7 @@ pub fn main(init: std.process.Init) !void {
.headless = headless,
.dark = dark,
});
_ = try it.eval("namespace eval ::dockyard {}");
try it.setVar("::dockyard::view", .{ .str = view });
try it.setVar("::dockyard::audit_import", .{ .str = audit_import });
const sandbox_abs = if (sandbox_dir) |d| try std.fs.path.resolve(arena, &.{ cwd, d }) else null;
Expand All @@ -240,6 +242,7 @@ pub fn main(init: std.process.Init) !void {
try monitor.register(&it, try host.controlPath(arena, host.Dirs.fromMap(init.environ_map), folder));
// Windows has no audit log yet: the writer uses POSIX files.
if (comptime @import("builtin").os.tag != .windows) if (audit_dir.len > 0) try audit.register(&it, audit_dir);
_ = try it.eval("namespace eval ::dockyard {}");
try it.setVar("::dockyard::tui", .{ .str = if (tui) "1" else "0" });
}

Expand Down
2 changes: 2 additions & 0 deletions src/sandbox/guest_release.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub fn prepare(a: std.mem.Allocator, io: std.Io, project: []const u8, dir: []con

pub fn setVars(it: *ztcl.Interp, r: ?Release) !void {
var buf: [24]u8 = undefined;
// The namespace of the variables: ztcl fails a set in a namespace that does not exist, as Tcl does.
_ = try it.eval("namespace eval ::dockyard {}");
try it.setVar("::dockyard::sandbox_image", .{ .str = if (r) |x| x.name else "" });
try it.setVar("::dockyard::sandbox_counter", .{ .str = if (r) |x| try std.fmt.bufPrint(&buf, "{d}", .{x.counter}) else "" });
}
Expand Down
2 changes: 2 additions & 0 deletions src/sandbox/sandbox.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub fn prepare(a: std.mem.Allocator, io: Io, project: []const u8, dir: []const u
}

pub fn setVars(it: *ztcl.Interp, g: ?Guest, argv: []const u8, allow: []const u8) !void {
// The namespace of the variables: ztcl fails a set in a namespace that does not exist, as Tcl does.
_ = try it.eval("namespace eval ::dockyard {}");
try it.setVar("::dockyard::sandbox", .{ .str = if (g != null) jail_dir else "" });
try it.setVar("::dockyard::sandbox_kernel", .{ .str = if (g) |x| x.kernel else "" });
try it.setVar("::dockyard::sandbox_argv", .{ .str = argv });
Expand Down
Loading