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 {
249249 pub var _89ujp8gq842x = Package{
250250 .name = "zigmod",
251251 .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 },
253253 };
254254 pub var _root = Package{
255255 };
src/common.zig+5-4
......@@ -2,6 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const builtin = @import("builtin");
44const ansi = @import("ansi");
5const extras = @import("extras");
56
67const zigmod = @import("./lib.zig");
78const u = @import("./util/index.zig");
......@@ -243,7 +244,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
243244 error.ManifestNotFound => {
244245 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
245246 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..];
247248 if (mod_from.is_for_this()) return mod_from;
248249 return null;
249250 }
......@@ -257,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
257258 d.*.name = tryname;
258259 d.*.main = trymain.?;
259260 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..];
261262 if (mod_from.is_for_this()) return mod_from;
262263 return null;
263264 }
......@@ -268,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
268269 dd.dep = d.*;
269270 dd.for_build = d.for_build;
270271 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..];
272273 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);
273274 if (d.name.len > 0) dd.name = d.name;
274275 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:
306307
307308 const cwdpath = try std.fs.cwd().realpathAlloc(alloc, ".");
308309 const mpath = try mdir.realpathAlloc(alloc, ".");
309 var fpath = u.trim_prefix(mpath, cwdpath);
310 var fpath = extras.trimPrefix(mpath, cwdpath);
310311 if (fpath.len == 0) fpath = std.fs.path.sep_str;
311312
312313 var cachedir = try std.fs.cwd().openDir(cachepath, .{});
src/util/dep.zig+4-3
......@@ -2,6 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const builtin = @import("builtin");
44const yaml = @import("yaml");
5const extras = @import("extras");
56
67const zigmod = @import("../lib.zig");
78const u = @import("index.zig");
......@@ -36,9 +37,9 @@ pub const Dep = struct {
3637 return if (self.path.len == 0) "../.." else self.path;
3738 }
3839 var p = self.path;
39 p = u.trim_prefix(p, "http://");
40 p = u.trim_prefix(p, "https://");
41 p = u.trim_prefix(p, "git://");
40 p = extras.trimPrefix(p, "http://");
41 p = extras.trimPrefix(p, "https://");
42 p = extras.trimPrefix(p, "git://");
4243 p = u.trim_suffix(p, ".git");
4344 p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p });
4445 return p;
src/util/funcs.zig+2-8
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const string = []const u8;
3const extras = @import("extras");
34
45const u = @import("index.zig");
56
......@@ -44,13 +45,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string {
4445 return list.toOwnedSlice();
4546}
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
5448pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool {
5549 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {
5650 error.FileNotFound => return false,
......@@ -255,7 +249,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !
255249 const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" }));
256250 const splitP = try split(alloc, dpath, std.fs.path.sep_str);
257251 var name = splitP[splitP.len - 2];
258 name = trim_prefix(name, "zig-");
252 name = extras.trimPrefix(name, "zig-");
259253 assert(name.len > 0, "package name must not be an empty string", .{});
260254 return name;
261255}
src/util/module.zig+3-2
......@@ -2,6 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const builtin = @import("builtin");
44const yaml = @import("yaml");
5const extras = @import("extras");
56
67const zigmod = @import("../lib.zig");
78const u = @import("index.zig");
......@@ -67,8 +68,8 @@ pub const Module = struct {
6768 var file_list_2 = std.ArrayList(string).init(alloc);
6869 defer file_list_2.deinit();
6970 for (file_list_1) |item| {
70 const _a = u.trim_prefix(item, cdpath);
71 const _b = u.trim_prefix(_a, self.clean_path);
71 const _a = extras.trimPrefix(item, cdpath);
72 const _b = extras.trimPrefix(_a, self.clean_path);
7273 if (_b[0] == '.') continue;
7374 try file_list_2.append(_b);
7475 }
zig.mod+1
......@@ -16,6 +16,7 @@ dependencies:
1616 - src: git https://github.com/nektro/zig-inquirer
1717 - src: git https://github.com/nektro/arqv-ini
1818 - src: git https://github.com/nektro/zig-time
19 - src: git https://github.com/nektro/zig-extras
1920
2021root_dependencies:
2122 - src: git https://github.com/marlersoft/zigwin32