diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 57be86fdea1f40440dd2ea52bf96a65f8dc7fbd2..58cca45d631846a08d38b430f6e41938c704e640 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -83,7 +83,7 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis try w.writeAll("pub const package_data = struct {\n"); const duped = &std.ArrayList(u.Module).init(gpa); for (list.items) |mod| { - if (std.mem.eql(u8, mod.id, "root")) { + if (mod.is_sys_lib) { continue; } try duped.append(mod); @@ -115,6 +115,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void { if (md.type == .local) { continue; } + if (md.type == .system_lib) continue; const mpath = try std.fs.path.join(gpa, &.{ dir, m.clean_path }); const version = if (md.version.len > 0) md.version else (try md.type.exact_version(mpath)); try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); @@ -124,10 +125,12 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void { fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { for (list) |mod| { + if (mod.is_sys_lib) continue; if (std.mem.eql(u8, mod.id, "root")) { + try w.print(" pub const _root = \"\";\n", .{}); continue; } - try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.id[0..12], std.zig.fmtEscapes(mod.clean_path) }); + try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) }); } } @@ -151,14 +154,14 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d \\ pub const _{s} = Package{{ \\ , .{ - mod.id[0..12], + mod.short_id(), }); - if (mod.main.len > 0) { + if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) { try w.print( \\ .pkg = Pkg{{ .name = "{s}", .path = .{{ .path = dirs._{s} ++ "/{s}" }}, .dependencies = , .{ mod.name, - mod.id[0..12], + mod.short_id(), mod.main, }); if (mod.has_no_zig_deps()) { @@ -200,7 +203,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d if (mod.has_syslib_deps()) { try w.writeAll(" .system_libs = &.{"); for (mod.deps) |item, j| { - if (!mod.is_sys_lib) continue; + if (!item.is_sys_lib) continue; try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)}); if (j != mod.deps.len - 1) try w.writeAll(","); } diff --git a/src/cmd/sum.zig b/src/cmd/sum.zig index 1d9421589dbf0b233bc58f873a23f5f5aae73c53..6a25ddb8de4f5429e72ada47ace17bc3fb2958a5 100644 --- a/src/cmd/sum.zig +++ b/src/cmd/sum.zig @@ -36,6 +36,7 @@ pub fn execute(args: [][]u8) !void { if (std.mem.eql(u8, m.clean_path, "../..")) { continue; } + if (m.is_sys_lib) continue; const hash = try m.get_hash(dir); try w.print("{s} {s}\n", .{ hash, m.clean_path }); } diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 23171219976ca5bf769e796fa71b283ed248f5ad..fe814321c639ac5a43da637c785adc4a014071f4 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -259,3 +259,9 @@ pub fn git_rev_HEAD(alloc: *std.mem.Allocator, path: []const u8) ![]const u8 { const r = std.mem.trim(u8, try dirg.readFileAlloc(alloc, h[5..], max), "\n"); return r; } + +pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const T { + const f = std.math.max(from, 0); + const t = std.math.min(to, input.len); + return input[f..t]; +} diff --git a/src/util/module.zig b/src/util/module.zig index 1336868add47e12af9c37bf7eda02c02d99c699f..70302031aec366b5fbb8e3783e13db8f5333bfce 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -116,4 +116,8 @@ pub const Module = struct { } return false; } + + pub fn short_id(self: Module) []const u8 { + return u.slice(u8, self.id, 0, 12); + } };