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...@@ -99,5 +99,10 @@ This attribute specifies a way to filter when the dependency will be generated i
99- Example: `linux`99- Example: `linux`
100This 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.100This 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
102#### Dep Overrides107#### Dep Overrides
103There 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`.108There 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...@@ -236,7 +236,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
236 else => {236 else => {
237 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {237 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {
238 error.FileNotFound => {238 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) {
240 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);240 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);
241 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];241 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];
242 if (mod_from.is_for_this()) return mod_from;242 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....@@ -329,6 +329,7 @@ pub fn add_files_package(alloc: *std.mem.Allocator, pkg_name: string, mdir: std.
329 .version = "absolute",329 .version = "absolute",
330 .yaml = null,330 .yaml = null,
331 .deps = &.{},331 .deps = &.{},
332 .keep = false,
332 };333 };
333 var options = CollectOptions{334 var options = CollectOptions{
334 .log = false,335 .log = false,
...@@ -372,6 +373,7 @@ pub fn parse_lockfile(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]const [4]st...@@ -372,6 +373,7 @@ pub fn parse_lockfile(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]const [4]st
372 .main = "",373 .main = "",
373 .yaml = null,374 .yaml = null,
374 .deps = &.{},375 .deps = &.{},
376 .keep = false,
375 };377 };
376 try list.append([4]string{378 try list.append([4]string{
377 try asdep.clean_path(),379 try asdep.clean_path(),
src/util/dep.zig+1
...@@ -26,6 +26,7 @@ pub const Dep = struct {...@@ -26,6 +26,7 @@ pub const Dep = struct {
26 except_os: []const string = &.{},26 except_os: []const string = &.{},
27 yaml: ?yaml.Mapping,27 yaml: ?yaml.Mapping,
28 deps: []zigmod.Dep,28 deps: []zigmod.Dep,
29 keep: bool,
2930
30 pub fn clean_path(self: Dep) !string {31 pub fn clean_path(self: Dep) !string {
31 if (self.type == .local) {32 if (self.type == .local) {
src/util/modfile.zig+1
...@@ -125,6 +125,7 @@ pub const ModFile = struct {...@@ -125,6 +125,7 @@ pub const ModFile = struct {
125 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""),125 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""),
126 .yaml = item.mapping,126 .yaml = item.mapping,
127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),
128 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep")),
128 });129 });
129 }130 }
130 }131 }