authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-05 10:06:59 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-05 10:06:59 -08:00
log3d01c20f3e759d4c7fb02af6aea88f59e736e7c8
tree6e8376a9b02b06a0ff324853a810429a886b9519
parenta425c075efb9dd9cf38cace488aa8ba8afa0a6c6

add the http dep type


3 files changed, 34 insertions(+), 1 deletions(-)

README.md+2-1
......@@ -56,6 +56,7 @@ zigmod add <type> <path>
5656- `system_lib`
5757- `git`
5858- `hg`
59- `http`
5960
6061### `fetch` command
6162```
......@@ -103,7 +104,7 @@ pub fn build(b: *Builder) void {
103104#### Dep object
104105| Name | Type | Note | Description |
105106|------|------|------|-------------|
106| `type` | `string` | required, enum | One of `system_lib`, `git`, `hg` |
107| `type` | `string` | required, enum | One of `system_lib`, `git`, `hg`, `http` |
107108| `path` | `string` | required | URL/path to this dependency. depends on the type |
108109| `version` | `string` | only on some types | pin this dependency at a specific version |
109110| `only_os` | `string` | | comma separated list of OS names to add this Dep to |
src/cmd_fetch.zig+7
......@@ -130,6 +130,13 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
130130 _ = try d.type.update(p, d.path);
131131 }
132132 },
133 .http => {
134 const file_name = try u.last(try u.split(d.path, "/"));
135 if (try u.does_file_exist(p)) {
136 try u.rm_recv(p);
137 }
138 _ = try d.type.pull(d.path, p);
139 },
133140 }
134141 switch (d.type) {
135142 .system_lib => {
src/util/dep_type.zig+25
......@@ -1,3 +1,6 @@
1const std = @import("std");
2const gpa = std.heap.c_allocator;
3
14const u = @import("./index.zig");
25
36//
......@@ -7,6 +10,7 @@ pub const DepType = enum {
710 system_lib, // std.build.LibExeObjStep.linkSystemLibrary
811 git, // https://git-scm.com/
912 hg, // https://www.mercurial-scm.org/
13 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
1014
1115 pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void {
1216 switch (self) {
......@@ -18,6 +22,24 @@ pub const DepType = enum {
1822 .hg => {
1923 _ = try u.run_cmd(null, &[_][]const u8{"hg", "clone", rpath, dpath});
2024 },
25 .http => {
26 try u.mkdir_all(dpath);
27 _ = try u.run_cmd(dpath, &[_][]const u8{"wget", rpath});
28 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];
29 if (std.mem.endsWith(u8, f, ".zip")) {
30 _ = try u.run_cmd(dpath, &[_][]const u8{"unzip", f, "-d", "."});
31 try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f}));
32 }
33 if (
34 std.mem.endsWith(u8, f, ".tar")
35 or std.mem.endsWith(u8, f, ".tar.gz")
36 or std.mem.endsWith(u8, f, ".tar.xz")
37 or std.mem.endsWith(u8, f, ".tar.zst")
38 ) {
39 _ = try u.run_cmd(dpath, &[_][]const u8{"tar", "-xf", f, "-C", "."});
40 try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f}));
41 }
42 },
2143 }
2244 }
2345
......@@ -31,6 +53,9 @@ pub const DepType = enum {
3153 .hg => {
3254 _ = try u.run_cmd(dpath, &[_][]const u8{"hg", "pull"});
3355 },
56 .http => {
57 //
58 },
3459 }
3560 }
3661};