authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-09-18 11:06:01 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-09-18 11:06:01 -07:00
log5b580b86a3657415e5332119611b8eef56c98812
tree4034f1d37d4362c27bde26333f90deff5b053fee
parentef9721811ce58c5bc6af737642a67bc6b996218c

dry: u.trim_prefix -> extras.trimPrefix


6 files changed, 16 insertions(+), 18 deletions(-)

deps.zig+1-1
...@@ -249,7 +249,7 @@ pub const package_data = struct {...@@ -249,7 +249,7 @@ pub const package_data = struct {
249 pub var _89ujp8gq842x = Package{249 pub var _89ujp8gq842x = Package{
250 .name = "zigmod",250 .name = "zigmod",
251 .entry = "/../..//src/lib.zig",251 .entry = "/../..//src/lib.zig",
252 .deps = &[_]*Package{ &_g982zq6e8wsv, &_s84v9o48ucb0, &_2ta738wrqbaq, &_0npcrzfdlrvk, &_ejw82j2ipa0e, &_ocmr9rtohgcc, &_tnj3qf44tpeq, &_2ovav391ivak, &_c1xirp1ota5p, &_u7sysdckdymi, &_iecwp4b3bsfm },252 .deps = &[_]*Package{ &_g982zq6e8wsv, &_s84v9o48ucb0, &_2ta738wrqbaq, &_0npcrzfdlrvk, &_ejw82j2ipa0e, &_ocmr9rtohgcc, &_tnj3qf44tpeq, &_2ovav391ivak, &_c1xirp1ota5p, &_u7sysdckdymi, &_iecwp4b3bsfm, &_f7dubzb7cyqe },
253 };253 };
254 pub var _root = Package{254 pub var _root = Package{
255 };255 };
src/common.zig+5-4
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const ansi = @import("ansi");4const ansi = @import("ansi");
5const extras = @import("extras");
56
6const zigmod = @import("./lib.zig");7const zigmod = @import("./lib.zig");
7const u = @import("./util/index.zig");8const u = @import("./util/index.zig");
...@@ -243,7 +244,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -243,7 +244,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
243 error.ManifestNotFound => {244 error.ManifestNotFound => {
244 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {245 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
245 var mod_from = try zigmod.Module.from(options.alloc, d.*, modpath, options);246 var mod_from = try zigmod.Module.from(options.alloc, d.*, modpath, options);
246 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];247 if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
247 if (mod_from.is_for_this()) return mod_from;248 if (mod_from.is_for_this()) return mod_from;
248 return null;249 return null;
249 }250 }
...@@ -257,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -257,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
257 d.*.name = tryname;258 d.*.name = tryname;
258 d.*.main = trymain.?;259 d.*.main = trymain.?;
259 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);260 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);
260 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];261 if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
261 if (mod_from.is_for_this()) return mod_from;262 if (mod_from.is_for_this()) return mod_from;
262 return null;263 return null;
263 }264 }
...@@ -268,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -268,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
268 dd.dep = d.*;269 dd.dep = d.*;
269 dd.for_build = d.for_build;270 dd.for_build = d.for_build;
270 const save = dd;271 const save = dd;
271 if (d.type != .local) dd.clean_path = u.trim_prefix(modpath, cachepath)[1..];272 if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
272 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);273 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);
273 if (d.name.len > 0) dd.name = d.name;274 if (d.name.len > 0) dd.name = d.name;
274 if (d.main.len > 0) dd.main = d.main;275 if (d.main.len > 0) dd.main = d.main;
...@@ -306,7 +307,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name:...@@ -306,7 +307,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name:
306307
307 const cwdpath = try std.fs.cwd().realpathAlloc(alloc, ".");308 const cwdpath = try std.fs.cwd().realpathAlloc(alloc, ".");
308 const mpath = try mdir.realpathAlloc(alloc, ".");309 const mpath = try mdir.realpathAlloc(alloc, ".");
309 var fpath = u.trim_prefix(mpath, cwdpath);310 var fpath = extras.trimPrefix(mpath, cwdpath);
310 if (fpath.len == 0) fpath = std.fs.path.sep_str;311 if (fpath.len == 0) fpath = std.fs.path.sep_str;
311312
312 var cachedir = try std.fs.cwd().openDir(cachepath, .{});313 var cachedir = try std.fs.cwd().openDir(cachepath, .{});
src/util/dep.zig+4-3
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const yaml = @import("yaml");4const yaml = @import("yaml");
5const extras = @import("extras");
56
6const zigmod = @import("../lib.zig");7const zigmod = @import("../lib.zig");
7const u = @import("index.zig");8const u = @import("index.zig");
...@@ -36,9 +37,9 @@ pub const Dep = struct {...@@ -36,9 +37,9 @@ pub const Dep = struct {
36 return if (self.path.len == 0) "../.." else self.path;37 return if (self.path.len == 0) "../.." else self.path;
37 }38 }
38 var p = self.path;39 var p = self.path;
39 p = u.trim_prefix(p, "http://");40 p = extras.trimPrefix(p, "http://");
40 p = u.trim_prefix(p, "https://");41 p = extras.trimPrefix(p, "https://");
41 p = u.trim_prefix(p, "git://");42 p = extras.trimPrefix(p, "git://");
42 p = u.trim_suffix(p, ".git");43 p = u.trim_suffix(p, ".git");
43 p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p });44 p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p });
44 return p;45 return p;
src/util/funcs.zig+2-8
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("extras");
34
4const u = @import("index.zig");5const u = @import("index.zig");
56
...@@ -44,13 +45,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string {...@@ -44,13 +45,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string {
44 return list.toOwnedSlice();45 return list.toOwnedSlice();
45}46}
4647
47pub fn trim_prefix(in: string, prefix: string) string {
48 if (std.mem.startsWith(u8, in, prefix)) {
49 return in[prefix.len..];
50 }
51 return in;
52}
53
54pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool {48pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool {
55 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {49 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {
56 error.FileNotFound => return false,50 error.FileNotFound => return false,
...@@ -255,7 +249,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !...@@ -255,7 +249,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !
255 const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" }));249 const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" }));
256 const splitP = try split(alloc, dpath, std.fs.path.sep_str);250 const splitP = try split(alloc, dpath, std.fs.path.sep_str);
257 var name = splitP[splitP.len - 2];251 var name = splitP[splitP.len - 2];
258 name = trim_prefix(name, "zig-");252 name = extras.trimPrefix(name, "zig-");
259 assert(name.len > 0, "package name must not be an empty string", .{});253 assert(name.len > 0, "package name must not be an empty string", .{});
260 return name;254 return name;
261}255}
src/util/module.zig+3-2
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const yaml = @import("yaml");4const yaml = @import("yaml");
5const extras = @import("extras");
56
6const zigmod = @import("../lib.zig");7const zigmod = @import("../lib.zig");
7const u = @import("index.zig");8const u = @import("index.zig");
...@@ -67,8 +68,8 @@ pub const Module = struct {...@@ -67,8 +68,8 @@ pub const Module = struct {
67 var file_list_2 = std.ArrayList(string).init(alloc);68 var file_list_2 = std.ArrayList(string).init(alloc);
68 defer file_list_2.deinit();69 defer file_list_2.deinit();
69 for (file_list_1) |item| {70 for (file_list_1) |item| {
70 const _a = u.trim_prefix(item, cdpath);71 const _a = extras.trimPrefix(item, cdpath);
71 const _b = u.trim_prefix(_a, self.clean_path);72 const _b = extras.trimPrefix(_a, self.clean_path);
72 if (_b[0] == '.') continue;73 if (_b[0] == '.') continue;
73 try file_list_2.append(_b);74 try file_list_2.append(_b);
74 }75 }
zig.mod+1
...@@ -16,6 +16,7 @@ dependencies:...@@ -16,6 +16,7 @@ dependencies:
16 - src: git https://github.com/nektro/zig-inquirer16 - src: git https://github.com/nektro/zig-inquirer
17 - src: git https://github.com/nektro/arqv-ini17 - src: git https://github.com/nektro/arqv-ini
18 - src: git https://github.com/nektro/zig-time18 - src: git https://github.com/nektro/zig-time
19 - src: git https://github.com/nektro/zig-extras
1920
20root_dependencies:21root_dependencies:
21 - src: git https://github.com/marlersoft/zigwin3222 - src: git https://github.com/marlersoft/zigwin32