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>...@@ -56,6 +56,7 @@ zigmod add <type> <path>
56- `system_lib`56- `system_lib`
57- `git`57- `git`
58- `hg`58- `hg`
59- `http`
5960
60### `fetch` command61### `fetch` command
61```62```
...@@ -103,7 +104,7 @@ pub fn build(b: *Builder) void {...@@ -103,7 +104,7 @@ pub fn build(b: *Builder) void {
103#### Dep object104#### Dep object
104| Name | Type | Note | Description |105| Name | Type | Note | Description |
105|------|------|------|-------------|106|------|------|------|-------------|
106| `type` | `string` | required, enum | One of `system_lib`, `git`, `hg` |107| `type` | `string` | required, enum | One of `system_lib`, `git`, `hg`, `http` |
107| `path` | `string` | required | URL/path to this dependency. depends on the type |108| `path` | `string` | required | URL/path to this dependency. depends on the type |
108| `version` | `string` | only on some types | pin this dependency at a specific version |109| `version` | `string` | only on some types | pin this dependency at a specific version |
109| `only_os` | `string` | | comma separated list of OS names to add this Dep to |110| `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 {...@@ -130,6 +130,13 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
130 _ = try d.type.update(p, d.path);130 _ = try d.type.update(p, d.path);
131 }131 }
132 },132 },
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 },
133 }140 }
134 switch (d.type) {141 switch (d.type) {
135 .system_lib => {142 .system_lib => {
src/util/dep_type.zig+25
...@@ -1,3 +1,6 @@...@@ -1,3 +1,6 @@
1const std = @import("std");
2const gpa = std.heap.c_allocator;
3
1const u = @import("./index.zig");4const u = @import("./index.zig");
25
3//6//
...@@ -7,6 +10,7 @@ pub const DepType = enum {...@@ -7,6 +10,7 @@ pub const DepType = enum {
7 system_lib, // std.build.LibExeObjStep.linkSystemLibrary10 system_lib, // std.build.LibExeObjStep.linkSystemLibrary
8 git, // https://git-scm.com/11 git, // https://git-scm.com/
9 hg, // https://www.mercurial-scm.org/12 hg, // https://www.mercurial-scm.org/
13 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
1014
11 pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void {15 pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void {
12 switch (self) {16 switch (self) {
...@@ -18,6 +22,24 @@ pub const DepType = enum {...@@ -18,6 +22,24 @@ pub const DepType = enum {
18 .hg => {22 .hg => {
19 _ = try u.run_cmd(null, &[_][]const u8{"hg", "clone", rpath, dpath});23 _ = try u.run_cmd(null, &[_][]const u8{"hg", "clone", rpath, dpath});
20 },24 },
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 },
21 }43 }
22 }44 }
2345
...@@ -31,6 +53,9 @@ pub const DepType = enum {...@@ -31,6 +53,9 @@ pub const DepType = enum {
31 .hg => {53 .hg => {
32 _ = try u.run_cmd(dpath, &[_][]const u8{"hg", "pull"});54 _ = try u.run_cmd(dpath, &[_][]const u8{"hg", "pull"});
33 },55 },
56 .http => {
57 //
58 },
34 }59 }
35 }60 }
36};61};