diff --git a/docs/README.md b/docs/README.md index fff3460edb5049373c86871a2813c4634b8b38e1..7eaf55e53b6d21baca6f1c46698a7a5e11ba1e81 100644 --- a/docs/README.md +++ b/docs/README.md @@ -36,7 +36,7 @@ $ ./zig-out/bin/zigmod Check here for the [full command reference](./commands/). -Check here for the [`zig.mod` reference](./zig.mod.md). +Check here for the [`zigmod.yml` reference](./zig.mod.md). Check here for the [`deps.zig` reference](./deps.zig.md). diff --git a/docs/commands/aq_add.md b/docs/commands/aq_add.md index 66dcb97897cf6978e96038819d953316e788d285..a164fcee9df3c0947ec359c25e1249226dd3430b 100644 --- a/docs/commands/aq_add.md +++ b/docs/commands/aq_add.md @@ -3,8 +3,8 @@ zigmod aq add ``` -This command takes `` and adds its most recent version to your `zig.mod`. +This command takes `` and adds its most recent version to your `zigmod.yml`. If you're on the details page for a package, the string this command is expecting is the path of the url after the domain name. So for example for the package https://aquila.red/1/truemedian/zfetch, you would add it using `zigmod aq add 1/truemedian/zfetch`. -It will append the details to the end of your `zig.mod` file. If you're project is using both `dependencies` and `dev_dependencies` you may need to move the appended text up manually to the correct section. This step will be unnecessary in the next manifest format version. +It will append the details to the end of your `zigmod.yml` file. If you're project is using both `dependencies` and `dev_dependencies` you may need to move the appended text up manually to the correct section. This step will be unnecessary in the next manifest format version. diff --git a/docs/commands/ci.md b/docs/commands/ci.md index f6092cd5dde1cd99e68a782bd9ba05b188ab38ac..d8cf90ee2f179b949461746abb56dc6fd28af581 100644 --- a/docs/commands/ci.md +++ b/docs/commands/ci.md @@ -3,7 +3,7 @@ zigmod ci ``` -- This command takes no parameters and will do almost exactly the same thing as the [`fetch`](./fetch.md) command, except it will read version strings from your `zigmod.lock` file instead of from dependencies' `zig.mod` definitions. +- This command takes no parameters and will do almost exactly the same thing as the [`fetch`](./fetch.md) command, except it will read version strings from your `zigmod.lock` file instead of from dependencies' `zigmod.yml` definitions. - Inspired by the [`npm ci`](https://docs.npmjs.com/cli/ci.html) command. - Enables [Reproducible builds](https://reproducible-builds.org/). - Often used in Continuous Integration environments. diff --git a/docs/commands/init.md b/docs/commands/init.md index 9a7689172ac372e14e78951b7dbbdfa0928029e3..956a6afa8b91d260ccf31ad58a1dcf44834a4357 100644 --- a/docs/commands/init.md +++ b/docs/commands/init.md @@ -3,11 +3,11 @@ zigmod init ``` -This command will help you generate a `zig.mod` file and place it in the current directory. This is the main file that will define various pieces of metadata about your project and manage your dependencies. The command will guide you though a number of questions that help you setup supporting files as well such as `.gitignore` and `LICENSE`. +This command will help you generate a `zigmod.yml` file and place it in the current directory. This is the main file that will define various pieces of metadata about your project and manage your dependencies. The command will guide you though a number of questions that help you setup supporting files as well such as `.gitignore` and `LICENSE`. -Check out the [`zig.mod` reference](./../zig.mod.md) for more info. +Check out the [`zigmod.yml` reference](./../zig.mod.md) for more info. -Also check out `zigmod`'s own `zig.mod` for a useful example: https://github.com/nektro/zigmod/blob/master/zig.mod. +Also check out `zigmod`'s own `zigmod.yml` for a useful example: https://github.com/nektro/zigmod/blob/master/zig.mod. ## Screenshot ![image](https://user-images.githubusercontent.com/5464072/148404704-1082fd05-00fc-40ee-8cb7-17b538db3827.png) diff --git a/docs/commands/license_.md b/docs/commands/license_.md index fda72517a07cc0ef8608f4117f2230ab7a72f70b..f36bdb3e4d31f1e0ac5716a2ed641c6adc8626cd 100644 --- a/docs/commands/license_.md +++ b/docs/commands/license_.md @@ -3,9 +3,9 @@ zigmod license ``` -This will print a listing of all of your dependencies (deeply)' licenses. Any code is valid for the `license` field in `zig.mod` but should it match a valid SPDX identifier, a URL to learn more about the license will also be printed so the user can learn more about it. +This will print a listing of all of your dependencies (deeply)' licenses. Any code is valid for the `license` field in `zigmod.yml` but should it match a valid SPDX identifier, a URL to learn more about the license will also be printed so the user can learn more about it. -Should one of your dependencies not have a `license` field in their `zig.mod` manifest, an `Unspecified:` list will appear at the bottom of the output. +Should one of your dependencies not have a `license` field in their `zigmod.yml` manifest, an `Unspecified:` list will appear at the bottom of the output. Running this command on Zigmod itself (as of this writing) produces such output: ``` @@ -13,21 +13,22 @@ MIT: = https://spdx.org/licenses/MIT - This - git https://github.com/yaml/libyaml +- git https://github.com/nektro/iguanaTLS - git https://github.com/nektro/zig-ansi - git https://github.com/ziglibs/known-folders - git https://github.com/nektro/zig-licenses - git https://github.com/truemedian/zfetch - git https://github.com/truemedian/hzzp -- git https://github.com/alexnask/iguanaTLS - git https://github.com/MasterQ32/zig-network - git https://github.com/MasterQ32/zig-uri - git https://github.com/nektro/zig-json +- git https://github.com/nektro/zig-extras - git https://github.com/nektro/zig-range - git https://github.com/nektro/zig-detect-license - git https://github.com/nektro/zig-licenses-text - git https://github.com/nektro/zig-leven -- git https://github.com/nektro/zig-fs-check - git https://github.com/nektro/zig-inquirer - git https://github.com/arqv/ini +- git https://github.com/nektro/zig-time - git https://github.com/marlersoft/zigwin32 ``` diff --git a/docs/commands/zpm_add.md b/docs/commands/zpm_add.md index 8dcf59935bcf47a2e80ef6e1fa2dbd86026d66a8..d144e94efe179f7b4099879ee11003f66ff89d87 100644 --- a/docs/commands/zpm_add.md +++ b/docs/commands/zpm_add.md @@ -3,10 +3,10 @@ zigmod zpm add ``` -- `` is required and will pull the corresponding package from https://zpm.random-projects.net/ and add it to your `zig.mod`. -- Since zpm is not native to Zigmod is will also manually define the `name` and `main` attributes based on the zpm data. Normally, if the source you reference contains a `zig.mod` file in its root, those fields are not required to defined by the dependent. +- `` is required and will pull the corresponding package from https://zpm.random-projects.net/ and add it to your `zigmod.yml`. +- Since zpm is not native to Zigmod is will also manually define the `name` and `main` attributes based on the zpm data. Normally, if the source you reference contains a `zigmod.yml` file in its root, those fields are not required to defined by the dependent. -For example running `zigmod zpm add apple_pie` will append the following to your `zig.mod`: +For example running `zigmod zpm add apple_pie` will append the following to your `zigmod.yml`: ```yml - src: git https://github.com/Luukdegram/apple_pie name: apple_pie diff --git a/docs/tutorial.md b/docs/tutorial.md index 6451aaeaef58b5bc19034947629f62e8f882a786..1f533e2fd335134ccc65e805bf28b87cbeef985b 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -11,7 +11,7 @@ zig init-exe zigmod init ``` -Zigmod's init wizard will ask you if the current project is an application or a library and setup some initial properties in your `zig.mod`. However, if you do plan to have a project that is both a library to be used in other Zig projects and an application itself, don't fret. For Zigmod is able to support both of thses configurations simultaneously. +Zigmod's init wizard will ask you if the current project is an application or a library and setup some initial properties in your `zigmod.yml`. However, if you do plan to have a project that is both a library to be used in other Zig projects and an application itself, don't fret. For Zigmod is able to support both of thses configurations simultaneously. The wizard will also ask if you'd like it setup any additional metadata files such as `.gitignore` or `LICENSE` for you. @@ -19,7 +19,7 @@ The wizard will also ask if you'd like it setup any additional metadata files su --- ## Running `zigmod fetch` -This command will inspect your `zig.mod` and download any new dependencies as well as pulling updates for any ones already download. It will recursively do this for your entire tree until it is full constructed which will culminate in the generation of two output files: `deps.zig` and `zigmod.lock`. +This command will inspect your `zigmod.yml` and download any new dependencies as well as pulling updates for any ones already download. It will recursively do this for your entire tree until it is full constructed which will culminate in the generation of two output files: `deps.zig` and `zigmod.lock`. `deps.zig` we will use in the next step integrating with the [Zig Build System](https://ziglang.org/documentation/master/#Zig-Build-System). [Learn more](./deps.zig.md). @@ -58,7 +58,7 @@ The core of expandability, it is possible to add dependencies to your project. H - https://zig.pm/ is another supported pacakge index. You may add packages from ZPM with `zigmod zpm add `. - Other/Git - - Zigmod supports adding any Git repository as a dependency. This is done by manually editing your `zig.mod` and adding a line under either the `dependencies` or `dev_dependencies` keys. For example, adding a line with this contents would add `apple_pie` to your project: ` - src: git https://github.com/Luukdegram/apple_pie`. The URL field may be any valid Git url that you would pass to `git clone`. + - Zigmod supports adding any Git repository as a dependency. This is done by manually editing your `zigmod.yml` and adding a line under either the `dependencies` or `dev_dependencies` keys. For example, adding a line with this contents would add `apple_pie` to your project: ` - src: git https://github.com/Luukdegram/apple_pie`. The URL field may be any valid Git url that you would pass to `git clone`. - Other/System Library - System libraries are similar to Git dependencies, but instead of `git ` it is `system_lib `. diff --git a/docs/zig.mod.md b/docs/zig.mod.md index 49b548c33e0f0a4ecc7a468f8f7e5632f5594baa..f570a6aaf02e72ea6de27b192397f6f1922f5284 100644 --- a/docs/zig.mod.md +++ b/docs/zig.mod.md @@ -1,8 +1,8 @@ -## `zig.mod` Reference +## `zigmod.yml` Reference -`zig.mod` is the main manifest that Zigmod will read to learn all about your application or package. +`zigmod.yml` is the main manifest that Zigmod will read to learn all about your application or package. -`zigmod.yml` is a valid alternative if needed. +`zig.mod` is a valid legacy alternative. ### `id` - Type: `string` diff --git a/src/cmd/aquila/add.zig b/src/cmd/aquila/add.zig index fcb1ad7fce5b95a8c5c07e1856711df77cb77153..4a9a8002cbe0456315dc8501315b486399c52b6a 100644 --- a/src/cmd/aquila/add.zig +++ b/src/cmd/aquila/add.zig @@ -36,10 +36,7 @@ pub fn do(dir: std.fs.Dir, pkg_id: string) !string { } } - const file = dir.openFile("zig.mod", .{ .mode = .read_write }) catch |err| switch (err) { - error.FileNotFound => u.fail("error: zig.mod manifest not found! must run from project root.", .{}), - else => return err, - }; + const file = try zigmod.ModFile.openFile(std.fs.cwd(), .{ .mode = .read_write }); defer file.close(); try file.seekTo(try file.getEndPos()); diff --git a/src/cmd/aquila/install.zig b/src/cmd/aquila/install.zig index 6d2fe1787aa949df58b80d0765055b2ebc457bad..84bbcdd8aa921b01e4d8254047903c8cfc50aefe 100644 --- a/src/cmd/aquila/install.zig +++ b/src/cmd/aquila/install.zig @@ -12,15 +12,15 @@ pub fn execute(args: [][]u8) !void { const homepath = home.?; const homedir = try std.fs.cwd().openDir(homepath, .{}); - if (!(try u.does_file_exist(homedir, "zig.mod"))) { - const f = try homedir.createFile("zig.mod", .{}); + if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { + const f = try homedir.createFile("zigmod.yml", .{}); defer f.close(); const w = f.writer(); const init = @import("../init.zig"); try init.writeExeManifest(w, try u.random_string(gpa, 48), "zigmod_installation", null, null); } - // add to ~/zig.mod for later + // add to ~/zigmod.yml for later const aqadd = @import("./add.zig"); const pkgurl = aqadd.do(homedir, args[0]) catch |err| switch (err) { error.AquilaBadResponse => return, diff --git a/src/cmd/init.zig b/src/cmd/init.zig index 430edb6699ccf8fe7a639459601817a743fd23dd..13b1636f5e506a68e26934d6a15983db3e2fd8a9 100644 --- a/src/cmd/init.zig +++ b/src/cmd/init.zig @@ -15,7 +15,7 @@ const u = @import("./../util/index.zig"); pub fn execute(args: [][]u8) !void { _ = args; - std.debug.print("This utility will walk you through creating a zig.mod file.\n", .{}); + std.debug.print("This utility will walk you through creating a zigmod.yml file.\n", .{}); std.debug.print("That will give a good launching off point to get your next project started.\n", .{}); std.debug.print("Use `zigmod aq add ` to add a dependency from https://aquila.red/\n", .{}); std.debug.print("Press ^C at any time to quit.\n", .{}); @@ -46,7 +46,7 @@ pub fn execute(args: [][]u8) !void { const description = try inquirer.forString(stdout, stdin, "description:", gpa, null); std.debug.print("\n", .{}); - std.debug.print("About to write local zig.mod:\n", .{}); + std.debug.print("About to write local zigmod.yml:\n", .{}); std.debug.print("\n", .{}); switch (ptype) { @@ -61,7 +61,7 @@ pub fn execute(args: [][]u8) !void { return; }, true => { - const file = try cwd.createFile("zig.mod", .{}); + const file = try cwd.createFile("zigmod.yml", .{}); defer file.close(); const w = file.writer(); switch (ptype) { @@ -166,10 +166,7 @@ pub fn execute(args: [][]u8) !void { } if (!exists) try w.writeAll("* text=auto\n"); if (!exists) try w.writeAll("*.zig text eol=lf\n"); - try w.writeAll("zig.mod text eol=lf\n"); try w.writeAll("zigmod.* text eol=lf\n"); - try w.writeAll("zig.mod linguist-language=YAML\n"); - try w.writeAll("zig.mod gitlab-language=yaml\n"); } } } diff --git a/src/cmd/zpm/add.zig b/src/cmd/zpm/add.zig index 788e10f5e54e5e47980846dd6d5cc59503e796a8..3ef9aeec8bd64f0d64df164c47673e19ae3a4630 100644 --- a/src/cmd/zpm/add.zig +++ b/src/cmd/zpm/add.zig @@ -57,14 +57,22 @@ pub fn execute(args: [][]u8) !void { try _req.do(.GET, null, null); break :blk _req.status.code == 200; }; + const has_zigmodyml = blk: { + const _url = try std.mem.join(gpa, "/", &.{ found.git, "blob", "HEAD", "zigmod.yml" }); + const _req = try zfetch.Request.init(gpa, _url, null); + defer _req.deinit(); + try _req.do(.GET, null, null); + break :blk _req.status.code == 200; + }; - const file = try std.fs.cwd().openFile("zig.mod", .{ .mode = .read_write }); + const file = try zigmod.ModFile.openFile(std.fs.cwd(), .{ .mode = .read_write }); + defer file.close(); try file.seekTo(try file.getEndPos()); const file_w = file.writer(); try file_w.print("\n", .{}); try file_w.print(" - src: git {s}\n", .{u.trim_suffix(found.git, ".git")}); - if (!has_zigdotmod) { + if (!(has_zigdotmod or has_zigmodyml)) { try file_w.print(" name: {s}\n", .{found.name}); try file_w.print(" main: {s}\n", .{found.root_file.?[1..]}); } diff --git a/src/common.zig b/src/common.zig index 47421097b65ff3d3f534b0624fe3ad35b484c33e..a2925baaf903791a980a9352d6ce6849a7ff7923 100644 --- a/src/common.zig +++ b/src/common.zig @@ -268,7 +268,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO if (mod_from.is_for_this()) return mod_from; return null; } - u.fail("no zig.mod found and no override props defined. unable to use add this dependency!", .{}); + u.fail("no zig.mod or zigmod.yml found and no override props defined. unable to use add this dependency!", .{}); }, else => e, }; diff --git a/src/util/modfile.zig b/src/util/modfile.zig index c7353ac1538eae409c1a685ae6ddd9ec63e06d8b..03682c4bc8e5103ae98e4b0d2514e4b8b496dfb2 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -30,18 +30,22 @@ pub const ModFile = struct { min_zig_version: ?std.SemanticVersion, vcpkg: bool, - 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 = dir.openFile("zig.mod", .{}) catch |err| switch (err) { + pub fn openFile(dir: std.fs.Dir, ops: std.fs.File.OpenFlags) !std.fs.File { + return dir.openFile("zig.mod", ops) 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, }; + } + + 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 openFile(dir, .{}); defer file.close(); const input = try file.reader().readAllAlloc(alloc, mb); const doc = try yaml.parse(alloc, input);