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