| ... | @@ -6,6 +6,8 @@ const string = []const u8; | ... | @@ -6,6 +6,8 @@ const string = []const u8; |
| 6 | const u = @import("./../util/index.zig"); | 6 | const u = @import("./../util/index.zig"); |
| 7 | const common = @import("./../common.zig"); | 7 | const common = @import("./../common.zig"); |
| 8 | | 8 | |
| | 9 | const ansi = @import("ansi"); |
| | 10 | |
| 9 | const root = @import("root"); | 11 | const root = @import("root"); |
| 10 | const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {}; | 12 | const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {}; |
| 11 | const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false; | 13 | const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false; |
| ... | @@ -32,6 +34,8 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -32,6 +34,8 @@ pub fn execute(args: [][]u8) !void { |
| 32 | if (bootstrap) return; | 34 | if (bootstrap) return; |
| 33 | | 35 | |
| 34 | try create_lockfile(list, dir); | 36 | try create_lockfile(list, dir); |
| | 37 | |
| | 38 | try diff_lockfile(); |
| 35 | } | 39 | } |
| 36 | | 40 | |
| 37 | pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u.Module)) !void { | 41 | pub fn create_depszig(dir: string, top_module: u.Module, list: *std.ArrayList(u.Module)) !void { |
| ... | @@ -130,6 +134,94 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: string) !void { | ... | @@ -130,6 +134,94 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: string) !void { |
| 130 | } | 134 | } |
| 131 | } | 135 | } |
| 132 | | 136 | |
| | 137 | const DiffChange = struct { |
| | 138 | from: string, |
| | 139 | to: string, |
| | 140 | }; |
| | 141 | |
| | 142 | fn diff_lockfile() !void { |
| | 143 | const max = std.math.maxInt(usize); |
| | 144 | |
| | 145 | if (try u.does_folder_exist(".git")) { |
| | 146 | const result = try u.run_cmd_raw(null, &.{ "git", "diff", "zigmod.lock" }); |
| | 147 | const r = std.io.fixedBufferStream(result.stdout).reader(); |
| | 148 | while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { |
| | 149 | if (std.mem.startsWith(u8, line, "@@")) break; |
| | 150 | } |
| | 151 | |
| | 152 | const rems = &std.ArrayList(string).init(gpa); |
| | 153 | const adds = &std.ArrayList(string).init(gpa); |
| | 154 | while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { |
| | 155 | if (line[0] == ' ') continue; |
| | 156 | if (line[0] == '-') try rems.append(line[1..]); |
| | 157 | if (line[0] == '+') if (line[1] == '2') continue else try adds.append(line[1..]); |
| | 158 | } |
| | 159 | |
| | 160 | const changes = &std.StringHashMap(DiffChange).init(gpa); |
| | 161 | |
| | 162 | var i: usize = 0; |
| | 163 | while (i < rems.items.len) { |
| | 164 | const it = rems.items[i]; |
| | 165 | const sni = u.indexOfN(it, ' ', 2).?; |
| | 166 | |
| | 167 | var j: usize = 0; |
| | 168 | while (j < adds.items.len) { |
| | 169 | const jt = adds.items[j]; |
| | 170 | const snj = u.indexOfN(jt, ' ', 2).?; |
| | 171 | |
| | 172 | if (std.mem.eql(u8, it[0..sni], jt[0..snj])) { |
| | 173 | try changes.put(it[0..sni], .{ |
| | 174 | .from = it[u.indexOfAfter(it, '-', sni).? + 1 .. it.len], |
| | 175 | .to = jt[u.indexOfAfter(jt, '-', snj).? + 1 .. jt.len], |
| | 176 | }); |
| | 177 | _ = rems.orderedRemove(i); |
| | 178 | _ = adds.orderedRemove(j); |
| | 179 | break; |
| | 180 | } |
| | 181 | j += 1; |
| | 182 | } |
| | 183 | i += 1; |
| | 184 | } |
| | 185 | |
| | 186 | if (adds.items.len > 0) { |
| | 187 | std.debug.print(comptime ansi.color.Faint("Newly added packages:\n"), .{}); |
| | 188 | defer std.debug.print("\n", .{}); |
| | 189 | |
| | 190 | for (adds.items) |it| { |
| | 191 | std.debug.print("- {s}\n", .{it}); |
| | 192 | } |
| | 193 | } |
| | 194 | |
| | 195 | if (rems.items.len > 0) { |
| | 196 | std.debug.print(comptime ansi.color.Faint("Removed packages:\n"), .{}); |
| | 197 | defer std.debug.print("\n", .{}); |
| | 198 | |
| | 199 | for (rems.items) |it| { |
| | 200 | std.debug.print("- {s}\n", .{it}); |
| | 201 | } |
| | 202 | } |
| | 203 | |
| | 204 | if (changes.unmanaged.size > 0) std.debug.print(comptime ansi.color.Faint("Updated packages:\n"), .{}); |
| | 205 | var iter = changes.iterator(); |
| | 206 | while (iter.next()) |it| { |
| | 207 | if (diff_printchange("git https://github.com", "- {s}/compare/{s}...{s}\n", it)) continue; |
| | 208 | if (diff_printchange("git https://gitlab.com", "- {s}/-/compare/{s}...{s}\n", it)) continue; |
| | 209 | if (diff_printchange("git https://gitea.com", "- {s}/compare/{s}...{s}\n", it)) continue; |
| | 210 | |
| | 211 | std.debug.print("- {s}\n", .{it.key_ptr.*}); |
| | 212 | std.debug.print(" - {s} ... {s}\n", .{ it.value_ptr.from, it.value_ptr.to }); |
| | 213 | } |
| | 214 | } |
| | 215 | } |
| | 216 | |
| | 217 | fn diff_printchange(comptime testt: string, comptime replacement: string, item: std.StringHashMap(DiffChange).Entry) bool { |
| | 218 | if (std.mem.startsWith(u8, item.key_ptr.*, testt)) { |
| | 219 | std.debug.print(replacement, .{ item.key_ptr.*[4..], item.value_ptr.from, item.value_ptr.to }); |
| | 220 | return true; |
| | 221 | } |
| | 222 | return false; |
| | 223 | } |
| | 224 | |
| 133 | fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { | 225 | fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { |
| 134 | for (list) |mod| { | 226 | for (list) |mod| { |
| 135 | if (mod.is_sys_lib) continue; | 227 | if (mod.is_sys_lib) continue; |