Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kbd

kbd/console Secret

Created March 1, 2021 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbd/791687547f2271f85bf272b091d64fbd to your computer and use it in GitHub Desktop.
Save kbd/791687547f2271f85bf272b091d64fbd to your computer and use it in GitHub Desktop.
$ zig build-exe evented_test_case.zig
broken LLVM module found: Basic Block in function 'std.child_process.ChildProcess.spawnPosix' does not have terminator!
label %OkResume
Instruction does not dominate all uses!
%28 = load { %std.child_process.Term, i16 }*, { %std.child_process.Term, i16 }** %6, align 8, !dbg !6264
%41 = bitcast { %std.child_process.Term, i16 }* %28 to i8*, !dbg !6264
This is a bug in the Zig compiler.
Unable to dump stack trace: debug info stripped
zsh: abort zig build-exe evented_test_case.zig
const std = @import("std");
const stdout = std.io.getStdOut().writer();
const print = stdout.print;
const Allocator = std.mem.Allocator;
const Str = []const u8;
pub var A: *Allocator = undefined;
pub const io_mode = .evented;
const GitStatus = struct {
// state: Str,
branch: Str,
status: Str,
// stash: Table[Str, int]
};
fn run(argv: []const Str) !std.ChildProcess.ExecResult {
return try std.ChildProcess.exec(.{
.allocator = A,
.argv = argv,
});
}
fn concatStringArray(lists: []const []Str) ![]Str {
return try std.mem.concat(A, Str, lists);
}
fn gitCmd(args: []Str, workingdir: Str) !std.ChildProcess.ExecResult {
var gitcmd = [_]Str{"git", "-C", workingdir};
var cmd_parts = [_][]Str{ &gitcmd, args };
var cmd = try concatStringArray(&cmd_parts);
return try run(cmd);
}
fn getBranch(dir: Str) !Str {
var cmd1 = [_]Str{"symbolic-ref", "HEAD", "--short"};
var result = try gitCmd(&cmd1, dir);
if (result.term.Exited == 0)
return result.stdout;
var cmd2 = [_]Str{"describe", "--all", "--contains", "--always", "HEAD"};
result = try gitCmd(&cmd2, dir);
return result.stdout;
}
fn getStatus(dir: Str) !Str {
// get and parse status codes
var cmd = [_]Str{"status", "-zb"};
var result = try gitCmd(&cmd, dir);
if (result.term.Exited != 0)
return error.GitStatusFailed;
return result.stdout;
}
fn getFullRepoStatus(dir: Str) !GitStatus {
var branch = async getBranch(dir);
var status = async getStatus(dir);
return GitStatus{
// .state = getState(dir),
.branch = try await branch,
.status = try await status,
// .stash = getRepoStashCounts(dir),
};
}
pub fn main() !u8 {
// allocator setup
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
A = &arena.allocator;
var dir: Str = ".";
var status = try getFullRepoStatus(dir);
return 0;
}
@kbd
Copy link
Author

kbd commented Mar 1, 2021

Compiles and runs if you comment out:

pub const io_mode = .evented;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment