From dde8fcf7cbba73e56b3961e03b85574c8a50beca Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 17 Feb 2022 16:56:34 -0800 Subject: [PATCH] make zigmod.yml a valid file alternative to zig.mod --- src/cmd/zpm/add.zig | 2 +- src/common.zig | 2 +- src/util/modfile.zig | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cmd/zpm/add.zig b/src/cmd/zpm/add.zig index ee36f6e64d1c14497bcfafb4d62b148cfa4bf779..788e10f5e54e5e47980846dd6d5cc59503e796a8 100644 --- a/src/cmd/zpm/add.zig +++ b/src/cmd/zpm/add.zig @@ -33,7 +33,7 @@ pub fn execute(args: [][]u8) !void { u.assert(found.root_file != null, "package must have an entry point to be able to be added to your dependencies", .{}); - const self_module = try zigmod.ModFile.init(gpa, "zig.mod"); + const self_module = try zigmod.ModFile.init(gpa); for (self_module.deps) |dep| { if (std.mem.eql(u8, dep.name, found.name)) { std.log.warn("dependency with name '{s}' already exists in your dependencies", .{found.name}); diff --git a/src/common.zig b/src/common.zig index 0f8613fa6fb8394fb8292c64e0bc73b2c0f345d2..47421097b65ff3d3f534b0624fe3ad35b484c33e 100644 --- a/src/common.zig +++ b/src/common.zig @@ -247,7 +247,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO }, else => { var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) { - error.FileNotFound => { + error.ManifestNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) { var mod_from = try zigmod.Module.from(options.alloc, d.*, modpath, options); if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; diff --git a/src/util/modfile.zig b/src/util/modfile.zig index aaf0b09258e9b6748ba4f4760d5b3a77cd470dcd..c7353ac1538eae409c1a685ae6ddd9ec63e06d8b 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -30,16 +30,18 @@ pub const ModFile = struct { min_zig_version: ?std.SemanticVersion, vcpkg: bool, - pub fn init(alloc: std.mem.Allocator, mpath: string) !Self { - const file = try std.fs.cwd().openFile(mpath, .{}); - defer file.close(); - const input = try file.reader().readAllAlloc(alloc, mb); - const doc = try yaml.parse(alloc, input); - return from_mapping(alloc, doc.mapping); + pub fn init(alloc: std.mem.Allocator) !Self { + return try from_dir(alloc, std.fs.cwd()); } pub fn from_dir(alloc: std.mem.Allocator, dir: std.fs.Dir) !Self { - const file = try dir.openFile("zig.mod", .{}); + const file = dir.openFile("zig.mod", .{}) catch |err| switch (err) { + error.FileNotFound => dir.openFile("zigmod.yml", .{}) catch |err2| switch (err2) { + error.FileNotFound => return error.ManifestNotFound, + else => |e2| return e2, + }, + else => |e| return e, + }; defer file.close(); const input = try file.reader().readAllAlloc(alloc, mb); const doc = try yaml.parse(alloc, input); -- 2.54.0