| author | |
| committer | |
| log | 7a3c5144855c3dd5d6bdb3025357d576dfb589c4 |
| tree | 000ac4e2d2cee3c2103ccab175b8f996d64876a7 |
| parent | 66cfa409347fd6bf982dcc6831b788b969bfcaa5 |
5 files changed, 30 insertions(+), 2 deletions(-)
docs/zig.mod.md+3| ... | @@ -50,6 +50,7 @@ This is the object used in the top-level `dependencies` attribute and used to ad | ... | @@ -50,6 +50,7 @@ This is the object used in the top-level `dependencies` attribute and used to ad |
| 50 | This is the base attribute used to reference external code for use in your project. `type` is an enum and only allows certain values. `path` is the URL or other identifier used to locate the contents of this package based on the `type`. | 50 | This is the base attribute used to reference external code for use in your project. `type` is an enum and only allows certain values. `path` is the URL or other identifier used to locate the contents of this package based on the `type`. |
| 51 | 51 | ||
| 52 | The available `type`s are: | 52 | The available `type`s are: |
| 53 | - `local` | ||
| 53 | - `system_lib` | 54 | - `system_lib` |
| 54 | - `git` | 55 | - `git` |
| 55 | - `hg` | 56 | - `hg` |
| ... | @@ -57,6 +58,8 @@ The available `type`s are: | ... | @@ -57,6 +58,8 @@ The available `type`s are: |
| 57 | 58 | ||
| 58 | For the full details on `Dep` types, you can check out the source where the enum is defined: https://github.com/nektro/zigmod/blob/master/src/util/dep_type.zig. | 59 | For the full details on `Dep` types, you can check out the source where the enum is defined: https://github.com/nektro/zigmod/blob/master/src/util/dep_type.zig. |
| 59 | 60 | ||
| 61 | > Note: the `local` type modifies the input behavior to be shorthand for `<name> <main>` rather than `path version` since the latter fields don't make sense for local files. | ||
| 62 | |||
| 60 | #### Dep `version` | 63 | #### Dep `version` |
| 61 | - Type: `string-string` | 64 | - Type: `string-string` |
| 62 | - Example: `commit-2c21764` | 65 | - Example: `commit-2c21764` |
src/common.zig+7| ... | @@ -82,6 +82,9 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C | ... | @@ -82,6 +82,9 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C |
| 82 | u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path }); | 82 | u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path }); |
| 83 | } | 83 | } |
| 84 | switch (d.type) { | 84 | switch (d.type) { |
| 85 | .local => { | ||
| 86 | return d.path; | ||
| 87 | }, | ||
| 85 | .system_lib => { | 88 | .system_lib => { |
| 86 | // no op | 89 | // no op |
| 87 | return ""; | 90 | return ""; |
| ... | @@ -186,6 +189,10 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 | ... | @@ -186,6 +189,10 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 |
| 186 | }); | 189 | }); |
| 187 | }, | 190 | }, |
| 188 | else => { | 191 | else => { |
| 192 | if (d.type == .local) { | ||
| 193 | try list.append(try u.Module.from(d)); | ||
| 194 | return; | ||
| 195 | } | ||
| 189 | var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { | 196 | var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { |
| 190 | error.FileNotFound => { | 197 | error.FileNotFound => { |
| 191 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { | 198 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
src/util/dep.zig+3| ... | @@ -26,6 +26,9 @@ pub const Dep = struct { | ... | @@ -26,6 +26,9 @@ pub const Dep = struct { |
| 26 | yaml: ?yaml.Mapping, | 26 | yaml: ?yaml.Mapping, |
| 27 | 27 | ||
| 28 | pub fn clean_path(self: Dep) ![]const u8 { | 28 | pub fn clean_path(self: Dep) ![]const u8 { |
| 29 | if (self.type == .local) { | ||
| 30 | return if (self.path.len == 0) "../.." else self.path; | ||
| 31 | } | ||
| 29 | var p = self.path; | 32 | var p = self.path; |
| 30 | p = u.trim_prefix(p, "http://"); | 33 | p = u.trim_prefix(p, "http://"); |
| 31 | p = u.trim_prefix(p, "https://"); | 34 | p = u.trim_prefix(p, "https://"); |
src/util/dep_type.zig+3| ... | @@ -8,6 +8,7 @@ const u = @import("./index.zig"); | ... | @@ -8,6 +8,7 @@ const u = @import("./index.zig"); |
| 8 | 8 | ||
| 9 | // zig fmt: off | 9 | // zig fmt: off |
| 10 | pub const DepType = enum { | 10 | pub const DepType = enum { |
| 11 | local, // A 'package' derived from files in the same repository. | ||
| 11 | system_lib, // std.build.LibExeObjStep.linkSystemLibrary | 12 | system_lib, // std.build.LibExeObjStep.linkSystemLibrary |
| 12 | git, // https://git-scm.com/ | 13 | git, // https://git-scm.com/ |
| 13 | hg, // https://www.mercurial-scm.org/ | 14 | hg, // https://www.mercurial-scm.org/ |
| ... | @@ -32,6 +33,7 @@ pub const DepType = enum { | ... | @@ -32,6 +33,7 @@ pub const DepType = enum { |
| 32 | 33 | ||
| 33 | pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void { | 34 | pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void { |
| 34 | switch (self) { | 35 | switch (self) { |
| 36 | .local => {}, | ||
| 35 | .system_lib => {}, | 37 | .system_lib => {}, |
| 36 | .git => { | 38 | .git => { |
| 37 | u.assert((try u.run_cmd(null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath })) == 0, "git clone {s} failed", .{rpath}); | 39 | u.assert((try u.run_cmd(null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath })) == 0, "git clone {s} failed", .{rpath}); |
| ... | @@ -55,6 +57,7 @@ pub const DepType = enum { | ... | @@ -55,6 +57,7 @@ pub const DepType = enum { |
| 55 | 57 | ||
| 56 | pub fn update(self: DepType, dpath: []const u8, rpath: []const u8) !void { | 58 | pub fn update(self: DepType, dpath: []const u8, rpath: []const u8) !void { |
| 57 | switch (self) { | 59 | switch (self) { |
| 60 | .local => {}, | ||
| 58 | .system_lib => {}, | 61 | .system_lib => {}, |
| 59 | .git => { | 62 | .git => { |
| 60 | u.assert((try u.run_cmd(dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{}); | 63 | u.assert((try u.run_cmd(dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{}); |
src/util/modfile.zig+14-2| ... | @@ -70,6 +70,8 @@ pub const ModFile = struct { | ... | @@ -70,6 +70,8 @@ pub const ModFile = struct { |
| 70 | var dtype: []const u8 = undefined; | 70 | var dtype: []const u8 = undefined; |
| 71 | var path: []const u8 = undefined; | 71 | var path: []const u8 = undefined; |
| 72 | var version: ?[]const u8 = null; | 72 | var version: ?[]const u8 = null; |
| 73 | var name = item.mapping.get_string("name"); | ||
| 74 | var main = item.mapping.get_string("main"); | ||
| 73 | if (item.mapping.get("src")) |val| { | 75 | if (item.mapping.get("src")) |val| { |
| 74 | var src_iter = std.mem.tokenize(val.string, " "); | 76 | var src_iter = std.mem.tokenize(val.string, " "); |
| 75 | dtype = src_iter.next().?; | 77 | dtype = src_iter.next().?; |
| ... | @@ -88,13 +90,23 @@ pub const ModFile = struct { | ... | @@ -88,13 +90,23 @@ pub const ModFile = struct { |
| 88 | version = ""; | 90 | version = ""; |
| 89 | } | 91 | } |
| 90 | const dep_type = std.meta.stringToEnum(u.DepType, dtype).?; | 92 | const dep_type = std.meta.stringToEnum(u.DepType, dtype).?; |
| 93 | if (dep_type == .local) { | ||
| 94 | if (path.len > 0) { | ||
| 95 | name = path; | ||
| 96 | path = ""; | ||
| 97 | } | ||
| 98 | if (version.?.len > 0) { | ||
| 99 | main = version.?; | ||
| 100 | version = ""; | ||
| 101 | } | ||
| 102 | } | ||
| 91 | 103 | ||
| 92 | try dep_list.append(u.Dep{ | 104 | try dep_list.append(u.Dep{ |
| 93 | .type = dep_type, | 105 | .type = dep_type, |
| 94 | .path = path, | 106 | .path = path, |
| 95 | .id = item.mapping.get_string("id"), | 107 | .id = item.mapping.get_string("id"), |
| 96 | .name = item.mapping.get_string("name"), | 108 | .name = name, |
| 97 | .main = item.mapping.get_string("main"), | 109 | .main = main, |
| 98 | .version = version.?, | 110 | .version = version.?, |
| 99 | .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), | 111 | .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), |
| 100 | .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"), | 112 | .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"), |