Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Fossil dep type #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
try std.fs.deleteFileAbsolute(file_path);
return p;
},
.fossil => {
const dpath = if (d.version.len > 0) pv else p;
if (!try u.does_folder_exist(dpath)) {
try d.type.pull(options.alloc, d.path, dpath);
} else {
if (options.update) {
try d.type.update(options.alloc, dpath, d.path);
}
}
if (d.version.len > 0) {
u.assert((try u.run_cmd(options.alloc, dpath, &.{ "fossil", "checkout", d.version })) == 0, "can't fossil checkout version {s}", .{d.version});
}
return dpath;
},
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/util/dep_type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const DepType = enum {
git, // https://git-scm.com/
hg, // https://www.mercurial-scm.org/
http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
fossil, // https://fossil-scm.org/

// zig fmt: on
pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {
Expand All @@ -38,6 +39,10 @@ pub const DepType = enum {
u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});
}
},
.fossil => {
try std.fs.cwd().makePath(dpath);
u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "open", rpath })) == 0, "fossil open {s} failed", .{rpath});
},
}
}

Expand All @@ -58,6 +63,10 @@ pub const DepType = enum {
.http => {
//
},
.fossil => {
u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "pull" })) == 0, "fossil pull failed", .{});
u.assert((try u.run_cmd(alloc, dpath, &.{ "fossil", "update" })) == 0, "fossil update failed", .{});
},
}
}

Expand All @@ -71,6 +80,7 @@ pub const DepType = enum {
.git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
.hg => "",
.http => "",
.fossil => getFossilCheckout(alloc, mpath),
};
}

Expand All @@ -82,6 +92,7 @@ pub const DepType = enum {
.git => false,
.hg => false,
.http => false,
.fossil => false,
};
}

Expand All @@ -92,6 +103,7 @@ pub const DepType = enum {
git: Git,
hg: void,
http: void,
fossil: void,

pub const Git = enum {
branch,
Expand All @@ -108,3 +120,19 @@ pub const DepType = enum {
};
};
};

fn getFossilCheckout(alloc: std.mem.Allocator, mpath: []const u8) ![]const u8 {
const result = try u.run_cmd_raw(alloc, mpath, &.{ "fossil", "status" });
alloc.free(result.stderr);
defer alloc.free(result.stdout);

var iter = std.mem.tokenize(u8, result.stdout, " \n");
while (iter.next()) |tk| {
if (std.mem.eql(u8, tk, "checkout:")) {
const co = iter.next() orelse return "";
return try alloc.dupe(u8, co);
}
}

return "";
}