authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 00:37:01 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 00:37:01 -08:00
logabbc5cece53a8a8bd1d5b214eefdaa137da8b316
treefac377266b240750264f26bdb22b38b24df94741
parent24019b6f88c1f3a036112e91b18e3305f8aa32cf

Dep- add `keep` override flag for external repos that have no Zig/C code


4 files changed, 10 insertions(+), 1 deletions(-)

docs/zig.mod.md+5
......@@ -99,5 +99,10 @@ This attribute specifies a way to filter when the dependency will be generated i
9999- Example: `linux`
100100This attribute specifies a way to filter when the dependency will be generated into the contents of `deps.zig`. `except_os` is an exlusive filter in which the dependency will only be in the output if the host target operating is \*not\* in the list specified or if the field is ommitted.
101101
102#### Dep `keep`
103- Type: `string`
104- Example: `true`|any
105This attribute is a manual override for having an external repo that contains no Zig or C code but other files be managed through Zigmod and `deps.zig`. `true` is the only value which will enable this flag.
106
102107#### Dep Overrides
103108There are a number of fields you can add to a `Dep` object that will override it's top-level value. This is most useful in the case where a project you want to use does not have a `zig.mod` manifest. You can then use overrides to define the values for them. The only top-level value you can not override is `dependencies`.
src/common.zig+3-1
......@@ -236,7 +236,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
236236 else => {
237237 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {
238238 error.FileNotFound => {
239 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
239 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
240240 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);
241241 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];
242242 if (mod_from.is_for_this()) return mod_from;
......@@ -329,6 +329,7 @@ pub fn add_files_package(alloc: *std.mem.Allocator, pkg_name: string, mdir: std.
329329 .version = "absolute",
330330 .yaml = null,
331331 .deps = &.{},
332 .keep = false,
332333 };
333334 var options = CollectOptions{
334335 .log = false,
......@@ -372,6 +373,7 @@ pub fn parse_lockfile(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]const [4]st
372373 .main = "",
373374 .yaml = null,
374375 .deps = &.{},
376 .keep = false,
375377 };
376378 try list.append([4]string{
377379 try asdep.clean_path(),
src/util/dep.zig+1
......@@ -26,6 +26,7 @@ pub const Dep = struct {
2626 except_os: []const string = &.{},
2727 yaml: ?yaml.Mapping,
2828 deps: []zigmod.Dep,
29 keep: bool,
2930
3031 pub fn clean_path(self: Dep) !string {
3132 if (self.type == .local) {
src/util/modfile.zig+1
......@@ -125,6 +125,7 @@ pub const ModFile = struct {
125125 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""),
126126 .yaml = item.mapping,
127127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),
128 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")),
128129 });
129130 }
130131 }