diff --git a/docs/zig.mod.md b/docs/zig.mod.md index 7b8fb47cff5a8d26b749b88db0a60a05c7148a61..d94a5145bd8571a968c77c4ee2963c135f25aa26 100644 --- a/docs/zig.mod.md +++ b/docs/zig.mod.md @@ -50,6 +50,7 @@ This is the object used in the top-level `dependencies` attribute and used to ad 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`. The available `type`s are: +- `local` - `system_lib` - `git` - `hg` @@ -57,6 +58,8 @@ The available `type`s are: 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. +> Note: the `local` type modifies the input behavior to be shorthand for `
` rather than `path version` since the latter fields don't make sense for local files. + #### Dep `version` - Type: `string-string` - Example: `commit-2c21764` diff --git a/src/common.zig b/src/common.zig index beeb0e92eb557c2444fbc6b9e1b1b0111565bdf3..9950545e96b710b35b738ac3db56639b308b2255 100644 --- a/src/common.zig +++ b/src/common.zig @@ -82,6 +82,9 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path }); } switch (d.type) { + .local => { + return d.path; + }, .system_lib => { // no op return ""; @@ -186,6 +189,10 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 }); }, else => { + if (d.type == .local) { + try list.append(try u.Module.from(d)); + return; + } var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { error.FileNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { diff --git a/src/util/dep.zig b/src/util/dep.zig index 223234ecda4223219a2ae7423500b504e94057b9..65371463b04203507cce8f5b1fd053aaab3cac59 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -26,6 +26,9 @@ pub const Dep = struct { yaml: ?yaml.Mapping, pub fn clean_path(self: Dep) ![]const u8 { + if (self.type == .local) { + return if (self.path.len == 0) "../.." else self.path; + } var p = self.path; p = u.trim_prefix(p, "http://"); p = u.trim_prefix(p, "https://"); diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index 74c07338e51a9d90dc59b9e6f96b68ed5e432704..3243f6de71ead921fc1b82b8df65b41ef8a829f5 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -8,6 +8,7 @@ const u = @import("./index.zig"); // zig fmt: off pub const DepType = enum { + local, // A 'package' derived from files in the same repository. system_lib, // std.build.LibExeObjStep.linkSystemLibrary git, // https://git-scm.com/ hg, // https://www.mercurial-scm.org/ @@ -32,6 +33,7 @@ pub const DepType = enum { pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void { switch (self) { + .local => {}, .system_lib => {}, .git => { 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 { pub fn update(self: DepType, dpath: []const u8, rpath: []const u8) !void { switch (self) { + .local => {}, .system_lib => {}, .git => { u.assert((try u.run_cmd(dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{}); diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 2188b4076e2140377c3ae262960fc7adb1936fca..9f516a40f3c40239fe51efec68f07aa58e050550 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -70,6 +70,8 @@ pub const ModFile = struct { var dtype: []const u8 = undefined; var path: []const u8 = undefined; var version: ?[]const u8 = null; + var name = item.mapping.get_string("name"); + var main = item.mapping.get_string("main"); if (item.mapping.get("src")) |val| { var src_iter = std.mem.tokenize(val.string, " "); dtype = src_iter.next().?; @@ -88,13 +90,23 @@ pub const ModFile = struct { version = ""; } const dep_type = std.meta.stringToEnum(u.DepType, dtype).?; + if (dep_type == .local) { + if (path.len > 0) { + name = path; + path = ""; + } + if (version.?.len > 0) { + main = version.?; + version = ""; + } + } try dep_list.append(u.Dep{ .type = dep_type, .path = path, .id = item.mapping.get_string("id"), - .name = item.mapping.get_string("name"), - .main = item.mapping.get_string("main"), + .name = name, + .main = main, .version = version.?, .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"), .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"),