From 2722fd1f247a5db7f6371dbaa778fa0d59510b9b Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 7 Mar 2022 21:20:52 -0800 Subject: [PATCH] add DepType.isLocal --- src/cmd/fetch.zig | 5 +---- src/common.zig | 4 ++-- src/util/dep_type.zig | 10 ++++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 6972c45c16364eeb09aa4cbe42cad26f41684679..8f300d126327aa42c0726b183f34755b0c2c0649 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -138,10 +138,7 @@ fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module) try wl.writeAll("2\n"); for (list.items) |m| { if (m.dep) |md| { - if (md.type == .local) { - continue; - } - if (md.type == .system_lib) continue; + if (md.type.isLocal()) continue; const mpath = try std.fs.path.join(alloc, &.{ path, m.clean_path }); const version = try md.exact_version(mpath); try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); diff --git a/src/common.zig b/src/common.zig index 4458ff1b0abb6209a50ed94e1c7b9c2565a071a9..0472779470e8a17ec9503dacdf6b8ad74fa983cb 100644 --- a/src/common.zig +++ b/src/common.zig @@ -108,7 +108,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path() }); const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v() }); - const nocache = d.type == .local or d.type == .system_lib; + const nocache = d.type.isLocal(); if (!nocache and u.list_contains(options.already_fetched.items, p)) return p; if (!nocache and u.list_contains(options.already_fetched.items, pv)) return pv; @@ -223,7 +223,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO const modpath = try get_modpath(cachepath, d.*, options); const moddir = if (std.mem.eql(u8, modpath, "files") or modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); - const nocache = d.type == .local or d.type == .system_lib; + const nocache = d.type.isLocal(); if (!nocache) try options.already_fetched.append(modpath); switch (d.type) { diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index d30dbe6d64f116533c8ae964651474d128d6fe13..60699a51c288eb7b0acba50f8a0c6c54fac49918 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -89,6 +89,16 @@ pub const DepType = enum { }; } + pub fn isLocal(self: DepType) bool { + return switch (self) { + .local => true, + .system_lib => true, + .git => false, + .hg => false, + .http => false, + }; + } + pub const GitVersion = enum { branch, tag, -- 2.54.0