| ... | @@ -10,6 +10,7 @@ const yaml = @import("./util/yaml.zig"); | ... | @@ -10,6 +10,7 @@ const yaml = @import("./util/yaml.zig"); |
| 10 | pub const CollectOptions = struct { | 10 | pub const CollectOptions = struct { |
| 11 | log: bool, | 11 | log: bool, |
| 12 | update: bool, | 12 | update: bool, |
| | 13 | lock: ?[]const [4][]const u8 = null, |
| 13 | }; | 14 | }; |
| 14 | | 15 | |
| 15 | pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOptions) !u.Module { | 16 | pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOptions) !u.Module { |
| ... | @@ -21,7 +22,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt | ... | @@ -21,7 +22,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt |
| 21 | try moduledeps.append(try add_files_package("root", m.root_files, m.name)); | 22 | try moduledeps.append(try add_files_package("root", m.root_files, m.name)); |
| 22 | } | 23 | } |
| 23 | try moduledeps.append(try collect_deps(dir, mpath, options)); | 24 | try moduledeps.append(try collect_deps(dir, mpath, options)); |
| 24 | for (m.devdeps) |d| { | 25 | for (m.devdeps) |*d| { |
| 25 | if (try get_module_from_dep(d, dir, m.name, options)) |founddep| { | 26 | if (try get_module_from_dep(d, dir, m.name, options)) |founddep| { |
| 26 | try moduledeps.append(founddep); | 27 | try moduledeps.append(founddep); |
| 27 | } | 28 | } |
| ... | @@ -31,13 +32,8 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt | ... | @@ -31,13 +32,8 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt |
| 31 | .id = "root", | 32 | .id = "root", |
| 32 | .name = "root", | 33 | .name = "root", |
| 33 | .main = m.main, | 34 | .main = m.main, |
| 34 | .c_include_dirs = &.{}, | | |
| 35 | .c_source_flags = &.{}, | | |
| 36 | .c_source_files = &.{}, | | |
| 37 | .deps = moduledeps.toOwnedSlice(), | 35 | .deps = moduledeps.toOwnedSlice(), |
| 38 | .clean_path = "", | 36 | .clean_path = "", |
| 39 | .only_os = &.{}, | | |
| 40 | .except_os = &.{}, | | |
| 41 | .yaml = m.yaml, | 37 | .yaml = m.yaml, |
| 42 | .dep = null, | 38 | .dep = null, |
| 43 | }; | 39 | }; |
| ... | @@ -50,7 +46,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) | ... | @@ -50,7 +46,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) |
| 50 | if (m.files.len > 0) { | 46 | if (m.files.len > 0) { |
| 51 | try moduledeps.append(try add_files_package(m.id, m.files, m.name)); | 47 | try moduledeps.append(try add_files_package(m.id, m.files, m.name)); |
| 52 | } | 48 | } |
| 53 | for (m.deps) |d| { | 49 | for (m.deps) |*d| { |
| 54 | if (try get_module_from_dep(d, dir, m.name, options)) |founddep| { | 50 | if (try get_module_from_dep(d, dir, m.name, options)) |founddep| { |
| 55 | try moduledeps.append(founddep); | 51 | try moduledeps.append(founddep); |
| 56 | } | 52 | } |
| ... | @@ -65,8 +61,6 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) | ... | @@ -65,8 +61,6 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) |
| 65 | .c_source_files = m.c_source_files, | 61 | .c_source_files = m.c_source_files, |
| 66 | .deps = moduledeps.toOwnedSlice(), | 62 | .deps = moduledeps.toOwnedSlice(), |
| 67 | .clean_path = "../..", | 63 | .clean_path = "../..", |
| 68 | .only_os = &.{}, | | |
| 69 | .except_os = &.{}, | | |
| 70 | .yaml = m.yaml, | 64 | .yaml = m.yaml, |
| 71 | .dep = null, | 65 | .dep = null, |
| 72 | }; | 66 | }; |
| ... | @@ -180,8 +174,18 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C | ... | @@ -180,8 +174,18 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C |
| 180 | } | 174 | } |
| 181 | } | 175 | } |
| 182 | | 176 | |
| 183 | pub fn get_module_from_dep(d: u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) anyerror!?u.Module { | 177 | pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) anyerror!?u.Module { |
| 184 | const moddir = try get_moddir(dir, d, parent_name, options); | 178 | if (options.lock) |lock| { |
| | 179 | for (lock) |item| { |
| | 180 | if (std.mem.eql(u8, item[0], try d.clean_path())) { |
| | 181 | d.type = std.meta.stringToEnum(u.DepType, item[1]).?; |
| | 182 | d.path = item[2]; |
| | 183 | d.version = item[3]; |
| | 184 | break; |
| | 185 | } |
| | 186 | } |
| | 187 | } |
| | 188 | const moddir = try get_moddir(dir, d.*, parent_name, options); |
| 185 | switch (d.type) { | 189 | switch (d.type) { |
| 186 | .system_lib => { | 190 | .system_lib => { |
| 187 | return u.Module{ | 191 | return u.Module{ |
| ... | @@ -191,20 +195,17 @@ pub fn get_module_from_dep(d: u.Dep, dir: []const u8, parent_name: []const u8, o | ... | @@ -191,20 +195,17 @@ pub fn get_module_from_dep(d: u.Dep, dir: []const u8, parent_name: []const u8, o |
| 191 | .only_os = d.only_os, | 195 | .only_os = d.only_os, |
| 192 | .except_os = d.except_os, | 196 | .except_os = d.except_os, |
| 193 | .main = "", | 197 | .main = "", |
| 194 | .c_include_dirs = &.{}, | | |
| 195 | .c_source_flags = &.{}, | | |
| 196 | .c_source_files = &.{}, | | |
| 197 | .deps = &[_]u.Module{}, | 198 | .deps = &[_]u.Module{}, |
| 198 | .clean_path = d.path, | 199 | .clean_path = d.path, |
| 199 | .yaml = null, | 200 | .yaml = null, |
| 200 | .dep = d, | 201 | .dep = d.*, |
| 201 | }; | 202 | }; |
| 202 | }, | 203 | }, |
| 203 | else => { | 204 | else => { |
| 204 | var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { | 205 | var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { |
| 205 | error.FileNotFound => { | 206 | error.FileNotFound => { |
| 206 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { | 207 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 207 | var mod_from = try u.Module.from(d, dir, options); | 208 | var mod_from = try u.Module.from(d.*, dir, options); |
| 208 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; | 209 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 209 | if (mod_from.is_for_this()) return mod_from; | 210 | if (mod_from.is_for_this()) return mod_from; |
| 210 | return null; | 211 | return null; |
| ... | @@ -213,7 +214,7 @@ pub fn get_module_from_dep(d: u.Dep, dir: []const u8, parent_name: []const u8, o | ... | @@ -213,7 +214,7 @@ pub fn get_module_from_dep(d: u.Dep, dir: []const u8, parent_name: []const u8, o |
| 213 | }, | 214 | }, |
| 214 | else => e, | 215 | else => e, |
| 215 | }; | 216 | }; |
| 216 | dd.dep = d; | 217 | dd.dep = d.*; |
| 217 | const save = dd; | 218 | const save = dd; |
| 218 | if (d.type != .local) dd.clean_path = u.trim_prefix(moddir, dir)[1..]; | 219 | if (d.type != .local) dd.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 219 | if (dd.id.len == 0) dd.id = try u.random_string(48); | 220 | if (dd.id.len == 0) dd.id = try u.random_string(48); |
| ... | @@ -274,23 +275,35 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_name | ... | @@ -274,23 +275,35 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_name |
| 274 | \\ | 275 | \\ |
| 275 | ); | 276 | ); |
| 276 | | 277 | |
| 277 | const d: u.Dep = .{ | 278 | var d: u.Dep = .{ |
| 278 | .type = .local, | 279 | .type = .local, |
| 279 | .path = "files", | 280 | .path = "files", |
| 280 | .id = "", | 281 | .id = "", |
| 281 | .name = "self/files", | 282 | .name = "self/files", |
| 282 | .main = fname, | 283 | .main = fname, |
| 283 | .version = "absolute", | 284 | .version = "absolute", |
| 284 | .c_include_dirs = &.{}, | | |
| 285 | .c_source_flags = &.{}, | | |
| 286 | .c_source_files = &.{}, | | |
| 287 | .only_os = &.{}, | | |
| 288 | .except_os = &.{}, | | |
| 289 | .yaml = null, | 285 | .yaml = null, |
| 290 | .deps = &.{}, | 286 | .deps = &.{}, |
| 291 | }; | 287 | }; |
| 292 | return (try get_module_from_dep(d, destination, parent_name, .{ | 288 | return (try get_module_from_dep(&d, destination, parent_name, .{ |
| 293 | .log = false, | 289 | .log = false, |
| 294 | .update = false, | 290 | .update = false, |
| 295 | })).?; | 291 | })).?; |
| 296 | } | 292 | } |
| | 293 | |
| | 294 | pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 { |
| | 295 | const list = &std.ArrayList([4][]const u8).init(gpa); |
| | 296 | const max = std.math.maxInt(usize); |
| | 297 | const f = try std.fs.cwd().openFile(path, .{}); |
| | 298 | const r = f.reader(); |
| | 299 | while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { |
| | 300 | var iter = std.mem.split(line, " "); |
| | 301 | try list.append([4][]const u8{ |
| | 302 | iter.next().?, |
| | 303 | iter.next().?, |
| | 304 | iter.next().?, |
| | 305 | iter.next().?, |
| | 306 | }); |
| | 307 | } |
| | 308 | return list.toOwnedSlice(); |
| | 309 | } |