authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-25 00:24:36 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-25 00:24:36 -07:00
logd259477fa8d3aa2dfbeca252d3d8667f48881811
tree6b0be7052f59d13229122960daa49bbc30680a6c
parent310002b87289c3f9c8a0c1178dcafcb32132ebe5

cmd/fetch- allow `.` in pacakge names, fixes #22

sorry for the merge conflict @digitalcreature

1 files changed, 12 insertions(+), 6 deletions(-)

src/cmd/fetch.zig+12-6
...@@ -344,9 +344,8 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {...@@ -344,9 +344,8 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {
344 if (d.main.len == 0) {344 if (d.main.len == 0) {
345 continue;345 continue;
346 }346 }
347 const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_");347 const ident = try zig_name_from_pkg_name(d.name);
348 const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_");348 try w.print(" pub const {s} = package_data._{s};\n", .{ ident, d.id[0..12] });
349 try w.print(" pub const {s} = package_data._{s};\n", .{ r2, d.id[0..12] });
350 }349 }
351 try w.writeAll("}");350 try w.writeAll("}");
352}351}
...@@ -356,8 +355,15 @@ fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void {...@@ -356,8 +355,15 @@ fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void {
356 if (d.main.len == 0) {355 if (d.main.len == 0) {
357 continue;356 continue;
358 }357 }
359 const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_");358 const ident = try zig_name_from_pkg_name(d.name);
360 const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_");359 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main });
361 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ r2, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main });
362 }360 }
363}361}
362
363fn zig_name_from_pkg_name(name: []const u8) ![]const u8 {
364 var legal = name;
365 legal = try std.mem.replaceOwned(u8, gpa, legal, "-", "_");
366 legal = try std.mem.replaceOwned(u8, gpa, legal, "/", "_");
367 legal = try std.mem.replaceOwned(u8, gpa, legal, ".", "_");
368 return legal;
369}