feat: buildscript: add simple output option
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7338c0902a
commit
935ebd0539
2 changed files with 87 additions and 26 deletions
|
@ -20,7 +20,7 @@ steps:
|
||||||
- mv zig-linux*/* .
|
- mv zig-linux*/* .
|
||||||
- export PATH="$PATH:$(pwd)"
|
- export PATH="$PATH:$(pwd)"
|
||||||
- cd ..
|
- cd ..
|
||||||
- ./build.zig
|
- BUILD_SIMPLE_OUTPUT=1 ./build.zig
|
||||||
|
|
||||||
- name: publish
|
- name: publish
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
|
|
99
build.zig
99
build.zig
|
@ -11,6 +11,8 @@ const c = @cImport({
|
||||||
const settings = @import("settings.zig");
|
const settings = @import("settings.zig");
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
const simple_output = std.os.getenv("BUILD_SIMPLE_OUTPUT") != null;
|
||||||
|
|
||||||
// used to buffer whatever
|
// used to buffer whatever
|
||||||
var buf: [512]u8 = undefined;
|
var buf: [512]u8 = undefined;
|
||||||
try std.fs.cwd().deleteTree(settings.build_dir);
|
try std.fs.cwd().deleteTree(settings.build_dir);
|
||||||
|
@ -49,10 +51,17 @@ pub fn main() !void {
|
||||||
while (try walker.next()) |e| {
|
while (try walker.next()) |e| {
|
||||||
switch (e.kind) {
|
switch (e.kind) {
|
||||||
.Directory => {
|
.Directory => {
|
||||||
|
if (simple_output) {
|
||||||
|
stdout.print(
|
||||||
|
"Writing Directory\t{s}\n",
|
||||||
|
.{e.path},
|
||||||
|
) catch {};
|
||||||
|
} else {
|
||||||
stdout.print(
|
stdout.print(
|
||||||
"Writing Directory\t\x1b[34m{s}/\x1b[0m\n",
|
"Writing Directory\t\x1b[34m{s}/\x1b[0m\n",
|
||||||
.{e.path},
|
.{e.path},
|
||||||
) catch {};
|
) catch {};
|
||||||
|
}
|
||||||
const path = try std.mem.concatWithSentinel(
|
const path = try std.mem.concatWithSentinel(
|
||||||
std.heap.c_allocator,
|
std.heap.c_allocator,
|
||||||
u8,
|
u8,
|
||||||
|
@ -63,7 +72,11 @@ pub fn main() !void {
|
||||||
try archiveCreateDir(zip.?, entry.?, path.ptr);
|
try archiveCreateDir(zip.?, entry.?, path.ptr);
|
||||||
},
|
},
|
||||||
.File => {
|
.File => {
|
||||||
|
if (simple_output) {
|
||||||
|
stdout.print("Writing File\t\t{s}\n", .{e.path}) catch {};
|
||||||
|
} else {
|
||||||
stdout.print("Writing File\t\t\x1b[34m{s}\x1b[0m\n", .{e.path}) catch {};
|
stdout.print("Writing File\t\t\x1b[34m{s}\x1b[0m\n", .{e.path}) catch {};
|
||||||
|
}
|
||||||
const path = try std.mem.concatWithSentinel(
|
const path = try std.mem.concatWithSentinel(
|
||||||
std.heap.c_allocator,
|
std.heap.c_allocator,
|
||||||
u8,
|
u8,
|
||||||
|
@ -103,7 +116,7 @@ pub fn main() !void {
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
|
||||||
downloadMods(mods.items, zip.?, entry.?) catch |err| {
|
downloadMods(mods.items, zip.?, entry.?, simple_output) catch |err| {
|
||||||
std.log.err("Error downloading mods", .{});
|
std.log.err("Error downloading mods", .{});
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
@ -262,6 +275,57 @@ const CurlInfo = struct {
|
||||||
index: usize,
|
index: usize,
|
||||||
total: usize,
|
total: usize,
|
||||||
mod_number_width: usize,
|
mod_number_width: usize,
|
||||||
|
simple_output: bool,
|
||||||
|
|
||||||
|
fn logStart(self: *CurlInfo) !void {
|
||||||
|
if (!self.simple_output)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try std.io.getStdOut().writer().print(
|
||||||
|
"[{d:[3]}/{d}] {s} Downloading...\n",
|
||||||
|
.{ self.index, self.total, self.filename, self.mod_number_width },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn logProgress(self: *CurlInfo, percentage: u8) !void {
|
||||||
|
if (self.simple_output)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try std.io.getStdOut().writer().print(
|
||||||
|
"\r\x1b[34m[{d:[4]}/{d}] \x1b[97m{s} \x1b[32m{}%",
|
||||||
|
.{
|
||||||
|
self.index,
|
||||||
|
self.total,
|
||||||
|
self.filename,
|
||||||
|
percentage,
|
||||||
|
self.mod_number_width,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn logZipping(self: *CurlInfo) !void {
|
||||||
|
if (!self.simple_output) {
|
||||||
|
try std.io.getStdOut().writer().print(
|
||||||
|
"\r\x1b[34m[{d:[3]}/{d}] \x1b[97m{s} \x1b[31mZipping...",
|
||||||
|
.{ self.index, self.total, self.filename, self.mod_number_width },
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
try std.io.getStdOut().writer().print(
|
||||||
|
"[{d:[3]}/{d}] {s} Zipping...\n",
|
||||||
|
.{ self.index, self.total, self.filename, self.mod_number_width },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn logDone(self: *CurlInfo) !void {
|
||||||
|
if (self.simple_output)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std.io.getStdOut().writer().print(
|
||||||
|
"\x1b[2K\r\x1b[34m[{d:[3]}/{d}] \x1b[97m{s}\n",
|
||||||
|
.{ self.index, self.total, self.filename, self.mod_number_width },
|
||||||
|
) catch {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn curlInfoCallback(
|
fn curlInfoCallback(
|
||||||
|
@ -273,15 +337,8 @@ fn curlInfoCallback(
|
||||||
) callconv(.C) usize {
|
) callconv(.C) usize {
|
||||||
_ = ultotal;
|
_ = ultotal;
|
||||||
_ = ulnow;
|
_ = ulnow;
|
||||||
std.io.getStdOut().writer().print(
|
info.logProgress(
|
||||||
"\r\x1b[34m[{d:[4]}/{d}] \x1b[97m{s} \x1b[32m{}%",
|
@intCast(u8, if (dltotal != 0) @divTrunc(dlnow * 100, dltotal) else 0),
|
||||||
.{
|
|
||||||
info.index,
|
|
||||||
info.total,
|
|
||||||
info.filename,
|
|
||||||
if (dltotal != 0) @divTrunc(dlnow * 100, dltotal) else 0,
|
|
||||||
info.mod_number_width,
|
|
||||||
},
|
|
||||||
) catch {};
|
) catch {};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -290,6 +347,7 @@ fn downloadMods(
|
||||||
mods: []const []const u8,
|
mods: []const []const u8,
|
||||||
zip: *c.archive,
|
zip: *c.archive,
|
||||||
entry: *c.archive_entry,
|
entry: *c.archive_entry,
|
||||||
|
simple_output: bool,
|
||||||
) !void {
|
) !void {
|
||||||
var curl = c.curl_easy_init();
|
var curl = c.curl_easy_init();
|
||||||
if (curl == null)
|
if (curl == null)
|
||||||
|
@ -319,12 +377,18 @@ fn downloadMods(
|
||||||
.index = 0,
|
.index = 0,
|
||||||
.total = mods.len,
|
.total = mods.len,
|
||||||
.mod_number_width = mod_number_width,
|
.mod_number_width = mod_number_width,
|
||||||
|
.simple_output = simple_output,
|
||||||
};
|
};
|
||||||
try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_XFERINFODATA, &info));
|
try handleCurlErr(c.curl_easy_setopt(curl, c.CURLOPT_XFERINFODATA, &info));
|
||||||
// hide cursor
|
// hide cursor
|
||||||
|
if (!simple_output) {
|
||||||
std.io.getStdOut().writeAll("\x1b[?25l") catch {};
|
std.io.getStdOut().writeAll("\x1b[?25l") catch {};
|
||||||
|
}
|
||||||
// show cursor & reset
|
// show cursor & reset
|
||||||
defer std.io.getStdOut().writeAll("\x1b[?25h\x1b[0\n") catch {};
|
defer if (!simple_output) {
|
||||||
|
std.io.getStdOut().writeAll("\x1b[?25h\x1b[0\n") catch {};
|
||||||
|
};
|
||||||
|
|
||||||
for (mods) |mod| {
|
for (mods) |mod| {
|
||||||
info.index += 1;
|
info.index += 1;
|
||||||
|
|
||||||
|
@ -368,12 +432,12 @@ fn downloadMods(
|
||||||
c.CURLOPT_URL,
|
c.CURLOPT_URL,
|
||||||
mod_cstr.ptr,
|
mod_cstr.ptr,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
try info.logStart();
|
||||||
|
|
||||||
try handleCurlErr(c.curl_easy_perform(curl));
|
try handleCurlErr(c.curl_easy_perform(curl));
|
||||||
|
|
||||||
std.io.getStdOut().writer().print(
|
try info.logZipping();
|
||||||
"\r\x1b[34m[{d:[3]}/{d}] \x1b[97m{s} \x1b[31mZipping...",
|
|
||||||
.{ info.index, info.total, info.filename, mod_number_width },
|
|
||||||
) catch {};
|
|
||||||
|
|
||||||
var archive_path = try std.mem.concatWithSentinel(
|
var archive_path = try std.mem.concatWithSentinel(
|
||||||
std.heap.c_allocator,
|
std.heap.c_allocator,
|
||||||
|
@ -387,10 +451,7 @@ fn downloadMods(
|
||||||
c.archive_entry_set_size(entry, @intCast(i64, mod_buf.items.len));
|
c.archive_entry_set_size(entry, @intCast(i64, mod_buf.items.len));
|
||||||
try handleArchiveErr(c.archive_write_header(zip, entry), zip);
|
try handleArchiveErr(c.archive_write_header(zip, entry), zip);
|
||||||
try writer.writeAll(mod_buf.items);
|
try writer.writeAll(mod_buf.items);
|
||||||
std.io.getStdOut().writer().print(
|
try info.logDone();
|
||||||
"\x1b[2K\r\x1b[34m[{d:[3]}/{d}] \x1b[97m{s}\n",
|
|
||||||
.{ info.index, info.total, info.filename, mod_number_width },
|
|
||||||
) catch {};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue