| ... | ... | @@ -17,28 +17,28 @@ const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootst |
| 17 | 17 | |
| 18 | 18 | pub fn execute(args: [][]u8) !void { |
| 19 | 19 | // |
| 20 | | const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" }); |
| 20 | const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" }); |
| 21 | 21 | const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update")); |
| 22 | 22 | |
| 23 | 23 | var options = common.CollectOptions{ |
| 24 | 24 | .log = should_update, |
| 25 | 25 | .update = should_update, |
| 26 | 26 | }; |
| 27 | | const top_module = try common.collect_deps_deep(dir, "zig.mod", &options); |
| 27 | const top_module = try common.collect_deps_deep(cachepath, "zig.mod", &options); |
| 28 | 28 | |
| 29 | 29 | var list = std.ArrayList(u.Module).init(gpa); |
| 30 | 30 | try common.collect_pkgs(top_module, &list); |
| 31 | 31 | |
| 32 | | try create_depszig(dir, top_module, &list); |
| 32 | try create_depszig(cachepath, top_module, &list); |
| 33 | 33 | |
| 34 | 34 | if (bootstrap) return; |
| 35 | 35 | |
| 36 | | try create_lockfile(&list, dir); |
| 36 | try create_lockfile(&list, cachepath); |
| 37 | 37 | |
| 38 | 38 | try diff_lockfile(); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | | pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u.Module)) !void { |
| 41 | pub fn create_depszig(cachepath: string, top_module: u.Module, list: *std.ArrayList(u.Module)) !void { |
| 42 | 42 | const f = try std.fs.cwd().createFile("deps.zig", .{}); |
| 43 | 43 | defer f.close(); |
| 44 | 44 | |
| ... | ... | @@ -47,7 +47,7 @@ pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u. |
| 47 | 47 | try w.writeAll("const Pkg = std.build.Pkg;\n"); |
| 48 | 48 | try w.writeAll("const string = []const u8;\n"); |
| 49 | 49 | try w.writeAll("\n"); |
| 50 | | try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(dir)}); |
| 50 | try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(cachepath)}); |
| 51 | 51 | try w.writeAll("\n"); |
| 52 | 52 | try w.print("{s}\n", .{ |
| 53 | 53 | \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void { |
| ... | ... | @@ -111,11 +111,11 @@ pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u. |
| 111 | 111 | try w.writeAll(";\n\n"); |
| 112 | 112 | |
| 113 | 113 | try w.writeAll("pub const imports = struct {\n"); |
| 114 | | try print_imports(w, top_module, dir); |
| 114 | try print_imports(w, top_module, cachepath); |
| 115 | 115 | try w.writeAll("};\n"); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | | fn create_lockfile(list: *std.ArrayList(u.Module), dir: string) !void { |
| 118 | fn create_lockfile(list: *std.ArrayList(u.Module), path: string) !void { |
| 119 | 119 | const fl = try std.fs.cwd().createFile("zigmod.lock", .{}); |
| 120 | 120 | defer fl.close(); |
| 121 | 121 | |
| ... | ... | @@ -127,7 +127,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: string) !void { |
| 127 | 127 | continue; |
| 128 | 128 | } |
| 129 | 129 | if (md.type == .system_lib) continue; |
| 130 | | const mpath = try std.fs.path.join(gpa, &.{ dir, m.clean_path }); |
| 130 | const mpath = try std.fs.path.join(gpa, &.{ path, m.clean_path }); |
| 131 | 131 | const version = try md.exact_version(mpath); |
| 132 | 132 | try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); |
| 133 | 133 | } |
| ... | ... | @@ -350,13 +350,13 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void { |
| 350 | 350 | try w.writeAll("}"); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | | fn print_imports(w: std.fs.File.Writer, m: u.Module, dir: string) !void { |
| 353 | fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void { |
| 354 | 354 | for (m.deps) |d| { |
| 355 | 355 | if (d.main.len == 0) { |
| 356 | 356 | continue; |
| 357 | 357 | } |
| 358 | 358 | const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_"); |
| 359 | 359 | const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_"); |
| 360 | | try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ r2, std.zig.fmtEscapes(dir), std.zig.fmtEscapes(d.clean_path), d.main }); |
| 360 | try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ r2, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main }); |
| 361 | 361 | } |
| 362 | 362 | } |