authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-17 16:56:34 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-02-17 16:56:34 -08:00
logdde8fcf7cbba73e56b3961e03b85574c8a50beca
tree51b5250792c12739da28e1d28a46776631a315fd
parent0fb6aaebc209f3eadbb3f63301e08dd2b2d3bb40

make zigmod.yml a valid file alternative to zig.mod


3 files changed, 11 insertions(+), 9 deletions(-)

src/cmd/zpm/add.zig+1-1
...@@ -33,7 +33,7 @@ pub fn execute(args: [][]u8) !void {...@@ -33,7 +33,7 @@ pub fn execute(args: [][]u8) !void {
3333
34 u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{});34 u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{});
3535
36 const self_module = try zigmod.ModFile.init(gpa, "zig.mod");36 const self_module = try zigmod.ModFile.init(gpa);
37 for (self_module.deps) |dep| {37 for (self_module.deps) |dep| {
38 if (std.mem.eql(u8, dep.name, found.name)) {38 if (std.mem.eql(u8, dep.name, found.name)) {
39 std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name});39 std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name});
src/common.zig+1-1
...@@ -247,7 +247,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -247,7 +247,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
247 },247 },
248 else => {248 else => {
249 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {249 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {
250 error.FileNotFound => {250 error.ManifestNotFound => {
251 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {251 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
252 var mod_from = try zigmod.Module.from(options.alloc, d.*, modpath, options);252 var mod_from = try zigmod.Module.from(options.alloc, d.*, modpath, options);
253 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];253 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];
src/util/modfile.zig+9-7
...@@ -30,16 +30,18 @@ pub const ModFile = struct {...@@ -30,16 +30,18 @@ pub const ModFile = struct {
30 min_zig_version: ?std.SemanticVersion,30 min_zig_version: ?std.SemanticVersion,
31 vcpkg: bool,31 vcpkg: bool,
3232
33 pub fn init(alloc: std.mem.Allocator, mpath: string) !Self {33 pub fn init(alloc: std.mem.Allocator) !Self {
34 const file = try std.fs.cwd().openFile(mpath, .{});34 return try from_dir(alloc, std.fs.cwd());
35 defer file.close();
36 const input = try file.reader().readAllAlloc(alloc, mb);
37 const doc = try yaml.parse(alloc, input);
38 return from_mapping(alloc, doc.mapping);
39 }35 }
4036
41 pub fn from_dir(alloc: std.mem.Allocator, dir: std.fs.Dir) !Self {37 pub fn from_dir(alloc: std.mem.Allocator, dir: std.fs.Dir) !Self {
42 const file = try dir.openFile("zig.mod", .{});38 const file = dir.openFile("zig.mod", .{}) catch |err| switch (err) {
39 error.FileNotFound => dir.openFile("zigmod.yml", .{}) catch |err2| switch (err2) {
40 error.FileNotFound => return error.ManifestNotFound,
41 else => |e2| return e2,
42 },
43 else => |e| return e,
44 };
43 defer file.close();45 defer file.close();
44 const input = try file.reader().readAllAlloc(alloc, mb);46 const input = try file.reader().readAllAlloc(alloc, mb);
45 const doc = try yaml.parse(alloc, input);47 const doc = try yaml.parse(alloc, input);