authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-22 18:10:05 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-22 18:10:05 -07:00
logf844b67f8110f601bf6a4ef0d573635dabd7f81d
treeb019839af8fde815068f2d85e7e96798d225b14b
parent6abac9b3f41b9e3490023d232a57548a71183c9c

alias `[]const u8` -> `string`

kept as lowercase so we know its still a 'primitive' type

17 files changed, 142 insertions(+), 130 deletions(-)

build.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const builtin = @import("builtin");3const builtin = @import("builtin");
3const deps = @import("./deps.zig");4const deps = @import("./deps.zig");
45
...@@ -19,7 +20,7 @@ pub fn build(b: *std.build.Builder) void {...@@ -19,7 +20,7 @@ pub fn build(b: *std.build.Builder) void {
1920
20 const exe_options = b.addOptions();21 const exe_options = b.addOptions();
21 exe.addOptions("build_options", exe_options);22 exe.addOptions("build_options", exe_options);
22 exe_options.addOption([]const u8, "version", b.option([]const u8, "tag", "") orelse "dev");23 exe_options.addOption(string, "version", b.option(string, "tag", "") orelse "dev");
23 exe_options.addOption(bool, "bootstrap", bootstrap != null);24 exe_options.addOption(bool, "bootstrap", bootstrap != null);
2425
25 if (bootstrap != null) {26 if (bootstrap != null) {
src/cmd/aq.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const zfetch = @import("zfetch");5const zfetch = @import("zfetch");
...@@ -42,7 +43,7 @@ pub fn execute(args: [][]u8) !void {...@@ -42,7 +43,7 @@ pub fn execute(args: [][]u8) !void {
42 u.fail("unknown command \"{s}\" for \"zigmod aq\"", .{args[0]});43 u.fail("unknown command \"{s}\" for \"zigmod aq\"", .{args[0]});
43}44}
4445
45pub fn server_fetch(url: []const u8) !json.Value {46pub fn server_fetch(url: string) !json.Value {
46 const req = try zfetch.Request.init(gpa, url, null);47 const req = try zfetch.Request.init(gpa, url, null);
47 defer req.deinit();48 defer req.deinit();
4849
src/cmd/aquila/add.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const u = @import("./../../util/index.zig");5const u = @import("./../../util/index.zig");
...@@ -13,7 +14,7 @@ pub fn execute(args: [][]u8) !void {...@@ -13,7 +14,7 @@ pub fn execute(args: [][]u8) !void {
13 std.log.info("Successfully added package {s}", .{pkg_id});14 std.log.info("Successfully added package {s}", .{pkg_id});
14}15}
1516
16pub fn do(dir: std.fs.Dir, pkg_id: []const u8) ![]const u8 {17pub fn do(dir: std.fs.Dir, pkg_id: string) !string {
17 const url = try std.mem.join(gpa, "/", &.{ aq.server_root, pkg_id });18 const url = try std.mem.join(gpa, "/", &.{ aq.server_root, pkg_id });
18 const val = try aq.server_fetch(url);19 const val = try aq.server_fetch(url);
1920
src/cmd/aquila/install.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const knownfolders = @import("known-folders");5const knownfolders = @import("known-folders");
...@@ -54,7 +55,7 @@ pub fn execute(args: [][]u8) !void {...@@ -54,7 +55,7 @@ pub fn execute(args: [][]u8) !void {
54 try ci.do(modpath, moddir);55 try ci.do(modpath, moddir);
5556
56 // zig build57 // zig build
57 const argv: []const []const u8 = &.{58 const argv: []const string = &.{
58 "zig", "build",59 "zig", "build",
59 "--prefix", try std.fs.path.join(gpa, &.{ homepath, ".zigmod" }),60 "--prefix", try std.fs.path.join(gpa, &.{ homepath, ".zigmod" }),
60 "--cache-dir", try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "zig" }),61 "--cache-dir", try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "zig" }),
src/cmd/ci.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const u = @import("./../util/index.zig");5const u = @import("./../util/index.zig");
...@@ -15,7 +16,7 @@ pub fn execute(args: [][]u8) !void {...@@ -15,7 +16,7 @@ pub fn execute(args: [][]u8) !void {
15 try do(cachepath, dir);16 try do(cachepath, dir);
16}17}
1718
18pub fn do(cachepath: []const u8, dir: std.fs.Dir) !void {19pub fn do(cachepath: string, dir: std.fs.Dir) !void {
19 var options = common.CollectOptions{20 var options = common.CollectOptions{
20 .log = true,21 .log = true,
21 .update = false,22 .update = false,
src/cmd/fetch.zig+2-3
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const gpa = std.heap.c_allocator;
3
4const string = []const u8;2const string = []const u8;
3const gpa = std.heap.c_allocator;
54
6const u = @import("./../util/index.zig");5const u = @import("./../util/index.zig");
7const common = @import("./../common.zig");6const common = @import("./../common.zig");
...@@ -360,7 +359,7 @@ fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void {...@@ -360,7 +359,7 @@ fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void {
360 }359 }
361}360}
362361
363fn zig_name_from_pkg_name(name: []const u8) ![]const u8 {362fn zig_name_from_pkg_name(name: string) !string {
364 var legal = name;363 var legal = name;
365 legal = try std.mem.replaceOwned(u8, gpa, legal, "-", "_");364 legal = try std.mem.replaceOwned(u8, gpa, legal, "-", "_");
366 legal = try std.mem.replaceOwned(u8, gpa, legal, "/", "_");365 legal = try std.mem.replaceOwned(u8, gpa, legal, "/", "_");
src/cmd/init.zig+8-7
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const inquirer = @import("inquirer");5const inquirer = @import("inquirer");
...@@ -25,18 +26,18 @@ pub fn execute(args: [][]u8) !void {...@@ -25,18 +26,18 @@ pub fn execute(args: [][]u8) !void {
25 const stdin = std.io.getStdIn().reader();26 const stdin = std.io.getStdIn().reader();
26 const cwd = std.fs.cwd();27 const cwd = std.fs.cwd();
2728
28 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", []const u8, "{s}", try u.random_string(48));29 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", try u.random_string(48));
2930
30 const ptype = try inquirer.forEnum(stdout, stdin, "Are you making an application or a library?", gpa, enum { exe, lib }, null);31 const ptype = try inquirer.forEnum(stdout, stdin, "Are you making an application or a library?", gpa, enum { exe, lib }, null);
3132
32 const name = try inquirer.forString(stdout, stdin, "package name:", gpa, u.detect_pkgname(u.try_index([]const u8, args, 0, ""), "") catch |err| switch (err) {33 const name = try inquirer.forString(stdout, stdin, "package name:", gpa, u.detect_pkgname(u.try_index(string, args, 0, ""), "") catch |err| switch (err) {
33 error.NoBuildZig => {34 error.NoBuildZig => {
34 u.fail("init requires a build.zig file", .{});35 u.fail("init requires a build.zig file", .{});
35 },36 },
36 else => return err,37 else => return err,
37 });38 });
3839
39 const entry = if (ptype == .lib) try inquirer.forString(stdout, stdin, "package entry point:", gpa, u.detct_mainfile(u.try_index([]const u8, args, 1, ""), null, name) catch |err| switch (err) {40 const entry = if (ptype == .lib) try inquirer.forString(stdout, stdin, "package entry point:", gpa, u.detct_mainfile(u.try_index(string, args, 1, ""), null, name) catch |err| switch (err) {
40 error.CantFindMain => null,41 error.CantFindMain => null,
41 else => return err,42 else => return err,
42 }) else null;43 }) else null;
...@@ -100,7 +101,7 @@ pub fn execute(args: [][]u8) !void {...@@ -100,7 +101,7 @@ pub fn execute(args: [][]u8) !void {
100 realtext = try std.mem.replaceOwned(u8, gpa, realtext, "<year>", try inquirer.answer(101 realtext = try std.mem.replaceOwned(u8, gpa, realtext, "<year>", try inquirer.answer(
101 stdout,102 stdout,
102 "year:",103 "year:",
103 []const u8,104 string,
104 "{s}",105 "{s}",
105 try std.fmt.allocPrint(gpa, "{d}", .{1970 + @divFloor(std.time.timestamp(), s_in_y)}),106 try std.fmt.allocPrint(gpa, "{d}", .{1970 + @divFloor(std.time.timestamp(), s_in_y)}),
106 ));107 ));
...@@ -121,7 +122,7 @@ pub fn execute(args: [][]u8) !void {...@@ -121,7 +122,7 @@ pub fn execute(args: [][]u8) !void {
121 }122 }
122}123}
123124
124pub fn writeExeManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8, license: ?[]const u8, description: ?[]const u8) !void {125pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {
125 try w.print("id: {s}\n", .{id});126 try w.print("id: {s}\n", .{id});
126 try w.print("name: {s}\n", .{name});127 try w.print("name: {s}\n", .{name});
127 if (license) |_| try w.print("license: {s}\n", .{license.?});128 if (license) |_| try w.print("license: {s}\n", .{license.?});
...@@ -129,7 +130,7 @@ pub fn writeExeManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8,...@@ -129,7 +130,7 @@ pub fn writeExeManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8,
129 try w.print("dev_dependencies:\n", .{});130 try w.print("dev_dependencies:\n", .{});
130}131}
131132
132pub fn writeLibManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8, entry: []const u8, license: []const u8, description: []const u8) !void {133pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry: string, license: string, description: string) !void {
133 try w.print("id: {s}\n", .{id});134 try w.print("id: {s}\n", .{id});
134 try w.print("name: {s}\n", .{name});135 try w.print("name: {s}\n", .{name});
135 try w.print("main: {s}\n", .{entry});136 try w.print("main: {s}\n", .{entry});
...@@ -138,7 +139,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8,...@@ -138,7 +139,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: []const u8, name: []const u8,
138 try w.print("dependencies:\n", .{});139 try w.print("dependencies:\n", .{});
139}140}
140141
141fn guessCopyrightName() !?[]const u8 {142fn guessCopyrightName() !?string {
142 const home = (try knownfolders.open(gpa, .home, .{})).?;143 const home = (try knownfolders.open(gpa, .home, .{})).?;
143 if (!(try u.does_file_exist(".gitconfig", home))) return null;144 if (!(try u.does_file_exist(".gitconfig", home))) return null;
144 const file = try home.openFile(".gitconfig", .{});145 const file = try home.openFile(".gitconfig", .{});
src/cmd/version.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
3const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
4const builtin = @import("builtin");3const builtin = @import("builtin");
54
src/cmd/zpm.zig+8-7
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const zfetch = @import("zfetch");5const zfetch = @import("zfetch");
...@@ -19,12 +20,12 @@ pub const commands = struct {...@@ -19,12 +20,12 @@ pub const commands = struct {
19pub const server_root = "https://zpm.random-projects.net/api";20pub const server_root = "https://zpm.random-projects.net/api";
2021
21pub const Package = struct {22pub const Package = struct {
22 author: []const u8,23 author: string,
23 name: []const u8,24 name: string,
24 tags: [][]const u8,25 tags: []string,
25 git: []const u8,26 git: string,
26 root_file: ?[]const u8,27 root_file: ?string,
27 description: []const u8,28 description: string,
28};29};
2930
30pub fn execute(args: [][]u8) !void {31pub fn execute(args: [][]u8) !void {
...@@ -53,7 +54,7 @@ pub fn execute(args: [][]u8) !void {...@@ -53,7 +54,7 @@ pub fn execute(args: [][]u8) !void {
53 u.fail("unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]});54 u.fail("unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]});
54}55}
5556
56pub fn server_fetch(url: []const u8) !json.Value {57pub fn server_fetch(url: string) !json.Value {
57 const req = try zfetch.Request.init(gpa, url, null);58 const req = try zfetch.Request.init(gpa, url, null);
58 defer req.deinit();59 defer req.deinit();
59 try req.do(.GET, null, null);60 try req.do(.GET, null, null);
src/common.zig+14-14
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const builtin = @import("builtin");3const builtin = @import("builtin");
3const gpa = std.heap.c_allocator;4const gpa = std.heap.c_allocator;
45
...@@ -6,7 +7,6 @@ const ansi = @import("ansi");...@@ -6,7 +7,6 @@ const ansi = @import("ansi");
67
7const u = @import("./util/index.zig");8const u = @import("./util/index.zig");
8const yaml = @import("./util/yaml.zig");9const yaml = @import("./util/yaml.zig");
9const string = []const u8;
1010
11const root = @import("root");11const root = @import("root");
12const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};12const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};
...@@ -18,7 +18,7 @@ const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootst...@@ -18,7 +18,7 @@ const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootst
18pub const CollectOptions = struct {18pub const CollectOptions = struct {
19 log: bool,19 log: bool,
20 update: bool,20 update: bool,
21 lock: ?[]const [4][]const u8 = null,21 lock: ?[]const [4]string = null,
22 alloc: *std.mem.Allocator = gpa,22 alloc: *std.mem.Allocator = gpa,
23 already_fetched: *std.ArrayList(string) = undefined,23 already_fetched: *std.ArrayList(string) = undefined,
2424
...@@ -28,7 +28,7 @@ pub const CollectOptions = struct {...@@ -28,7 +28,7 @@ pub const CollectOptions = struct {
28 }28 }
29};29};
3030
31pub fn collect_deps_deep(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOptions) !u.Module {31pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !u.Module {
32 const m = try u.ModFile.from_dir(gpa, mdir);32 const m = try u.ModFile.from_dir(gpa, mdir);
33 try options.init();33 try options.init();
34 var moduledeps = std.ArrayList(u.Module).init(gpa);34 var moduledeps = std.ArrayList(u.Module).init(gpa);
...@@ -55,7 +55,7 @@ pub fn collect_deps_deep(cachepath: []const u8, mdir: std.fs.Dir, options: *Coll...@@ -55,7 +55,7 @@ pub fn collect_deps_deep(cachepath: []const u8, mdir: std.fs.Dir, options: *Coll
55 };55 };
56}56}
5757
58pub fn collect_deps(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOptions) anyerror!u.Module {58pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!u.Module {
59 const m = try u.ModFile.from_dir(gpa, mdir);59 const m = try u.ModFile.from_dir(gpa, mdir);
60 var moduledeps = std.ArrayList(u.Module).init(gpa);60 var moduledeps = std.ArrayList(u.Module).init(gpa);
61 defer moduledeps.deinit();61 defer moduledeps.deinit();
...@@ -93,7 +93,7 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void...@@ -93,7 +93,7 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void
93 }93 }
94}94}
9595
96pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![]const u8 {96pub fn get_modpath(cachepath: string, d: u.Dep, options: *CollectOptions) !string {
97 const p = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path() });97 const p = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path() });
98 const pv = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path_v() });98 const pv = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path_v() });
9999
...@@ -197,7 +197,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![...@@ -197,7 +197,7 @@ pub fn get_modpath(cachepath: []const u8, d: u.Dep, options: *CollectOptions) ![
197 }197 }
198}198}
199199
200pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, options: *CollectOptions) anyerror!?u.Module {200pub fn get_module_from_dep(d: *u.Dep, cachepath: string, options: *CollectOptions) anyerror!?u.Module {
201 if (options.lock) |lock| {201 if (options.lock) |lock| {
202 for (lock) |item| {202 for (lock) |item| {
203 if (std.mem.eql(u8, item[0], try d.clean_path())) {203 if (std.mem.eql(u8, item[0], try d.clean_path())) {
...@@ -275,11 +275,11 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, options: *CollectOp...@@ -275,11 +275,11 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, options: *CollectOp
275 }275 }
276}276}
277277
278pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const []const u8) !u.Module {278pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !u.Module {
279 const destination = ".zigmod/deps/files";279 const destination = ".zigmod/deps/files";
280 const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" });280 const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" });
281281
282 const map = &std.StringHashMap([]const u8).init(gpa);282 const map = &std.StringHashMap(string).init(gpa);
283 defer map.deinit();283 defer map.deinit();
284284
285 for (dirs) |dir_path| {285 for (dirs) |dir_path| {
...@@ -310,7 +310,7 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [...@@ -310,7 +310,7 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [
310 );310 );
311 try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});311 try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});
312 try w.writeAll(312 try w.writeAll(
313 \\const files = std.ComptimeStringMap([]const u8, .{313 \\const files = std.ComptimeStringMap(string, .{
314 \\314 \\
315 );315 );
316 var iter = map.iterator();316 var iter = map.iterator();
...@@ -321,7 +321,7 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [...@@ -321,7 +321,7 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [
321 try w.writeAll(321 try w.writeAll(
322 \\});322 \\});
323 \\323 \\
324 \\pub fn open(comptime path: []const u8) ?[]const u8 {324 \\pub fn open(comptime path: string) ?string {
325 \\ if (path.len == 0) return null;325 \\ if (path.len == 0) return null;
326 \\ if (path[0] != '/') return null;326 \\ if (path[0] != '/') return null;
327 \\ return files.get(path);327 \\ return files.get(path);
...@@ -346,8 +346,8 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [...@@ -346,8 +346,8 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [
346 return (try get_module_from_dep(&d, destination, &options)).?;346 return (try get_module_from_dep(&d, destination, &options)).?;
347}347}
348348
349pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {349pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4]string {
350 var list = std.ArrayList([4][]const u8).init(gpa);350 var list = std.ArrayList([4]string).init(gpa);
351 const max = std.math.maxInt(usize);351 const max = std.math.maxInt(usize);
352 const f = try dir.openFile("zigmod.lock", .{});352 const f = try dir.openFile("zigmod.lock", .{});
353 const r = f.reader();353 const r = f.reader();
...@@ -361,7 +361,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {...@@ -361,7 +361,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {
361 switch (v) {361 switch (v) {
362 1 => {362 1 => {
363 var iter = std.mem.split(u8, line, " ");363 var iter = std.mem.split(u8, line, " ");
364 try list.append([4][]const u8{364 try list.append([4]string{
365 iter.next().?,365 iter.next().?,
366 iter.next().?,366 iter.next().?,
367 iter.next().?,367 iter.next().?,
...@@ -380,7 +380,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {...@@ -380,7 +380,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {
380 .yaml = null,380 .yaml = null,
381 .deps = &.{},381 .deps = &.{},
382 };382 };
383 try list.append([4][]const u8{383 try list.append([4]string{
384 try asdep.clean_path(),384 try asdep.clean_path(),
385 @tagName(asdep.type),385 @tagName(asdep.type),
386 asdep.path,386 asdep.path,
src/main.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const builtin = @import("builtin");3const builtin = @import("builtin");
34
4pub const build_options = @import("build_options");5pub const build_options = @import("build_options");
...@@ -55,7 +56,7 @@ pub fn main() !void {...@@ -55,7 +56,7 @@ pub fn main() !void {
55 }56 }
56 }57 }
5758
58 var sub_cmd_args = std.ArrayList([]const u8).init(gpa);59 var sub_cmd_args = std.ArrayList(string).init(gpa);
59 try sub_cmd_args.append(try std.fmt.allocPrint(gpa, "zigmod-{s}", .{args[0]}));60 try sub_cmd_args.append(try std.fmt.allocPrint(gpa, "zigmod-{s}", .{args[0]}));
60 for (args[1..]) |item| {61 for (args[1..]) |item| {
61 try sub_cmd_args.append(item);62 try sub_cmd_args.append(item);
src/util/dep.zig+14-13
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
3const builtin = std.builtin;4const builtin = std.builtin;
45
...@@ -12,21 +13,21 @@ pub const Dep = struct {...@@ -12,21 +13,21 @@ pub const Dep = struct {
12 const Self = @This();13 const Self = @This();
1314
14 type: u.DepType,15 type: u.DepType,
15 path: []const u8,16 path: string,
1617
17 id: []const u8,18 id: string,
18 name: []const u8,19 name: string,
19 main: []const u8,20 main: string,
20 version: []const u8,21 version: string,
21 c_include_dirs: []const []const u8 = &.{},22 c_include_dirs: []const string = &.{},
22 c_source_flags: []const []const u8 = &.{},23 c_source_flags: []const string = &.{},
23 c_source_files: []const []const u8 = &.{},24 c_source_files: []const string = &.{},
24 only_os: []const []const u8 = &.{},25 only_os: []const string = &.{},
25 except_os: []const []const u8 = &.{},26 except_os: []const string = &.{},
26 yaml: ?yaml.Mapping,27 yaml: ?yaml.Mapping,
27 deps: []u.Dep,28 deps: []u.Dep,
2829
29 pub fn clean_path(self: Dep) ![]const u8 {30 pub fn clean_path(self: Dep) !string {
30 if (self.type == .local) {31 if (self.type == .local) {
31 return if (self.path.len == 0) "../.." else self.path;32 return if (self.path.len == 0) "../.." else self.path;
32 }33 }
...@@ -39,7 +40,7 @@ pub const Dep = struct {...@@ -39,7 +40,7 @@ pub const Dep = struct {
39 return p;40 return p;
40 }41 }
4142
42 pub fn clean_path_v(self: Dep) ![]const u8 {43 pub fn clean_path_v(self: Dep) !string {
43 if (self.type == .http and self.version.len > 0) {44 if (self.type == .http and self.version.len > 0) {
44 const i = std.mem.indexOf(u8, self.version, "-").?;45 const i = std.mem.indexOf(u8, self.version, "-").?;
45 return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] });46 return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] });
...@@ -58,7 +59,7 @@ pub const Dep = struct {...@@ -58,7 +59,7 @@ pub const Dep = struct {
58 return true;59 return true;
59 }60 }
6061
61 pub fn exact_version(self: Dep, dpath: []const u8) ![]const u8 {62 pub fn exact_version(self: Dep, dpath: string) !string {
62 if (self.version.len == 0) {63 if (self.version.len == 0) {
63 return try self.type.exact_version(dpath);64 return try self.type.exact_version(dpath);
64 }65 }
src/util/dep_type.zig+4-3
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const u = @import("./index.zig");5const u = @import("./index.zig");
...@@ -32,7 +33,7 @@ pub const DepType = enum {...@@ -32,7 +33,7 @@ pub const DepType = enum {
32 // hypercore, // https://hypercore-protocol.org/33 // hypercore, // https://hypercore-protocol.org/
3334
34 // zig fmt: on35 // zig fmt: on
35 pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void {36 pub fn pull(self: DepType, rpath: string, dpath: string) !void {
36 switch (self) {37 switch (self) {
37 .local => {},38 .local => {},
38 .system_lib => {},39 .system_lib => {},
...@@ -57,7 +58,7 @@ pub const DepType = enum {...@@ -57,7 +58,7 @@ pub const DepType = enum {
57 }58 }
5859
59 // zig fmt: on60 // zig fmt: on
60 pub fn update(self: DepType, dpath: []const u8, rpath: []const u8) !void {61 pub fn update(self: DepType, dpath: string, rpath: string) !void {
61 _ = rpath;62 _ = rpath;
6263
63 switch (self) {64 switch (self) {
...@@ -77,7 +78,7 @@ pub const DepType = enum {...@@ -77,7 +78,7 @@ pub const DepType = enum {
77 }78 }
7879
79 // zig fmt: on80 // zig fmt: on
80 pub fn exact_version(self: DepType, mpath: []const u8) ![]const u8 {81 pub fn exact_version(self: DepType, mpath: string) !string {
81 var mdir = try std.fs.cwd().openDir(mpath, .{});82 var mdir = try std.fs.cwd().openDir(mpath, .{});
82 defer mdir.close();83 defer mdir.close();
83 return switch (self) {84 return switch (self) {
src/util/funcs.zig+35-34
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
34
4const u = @import("index.zig");5const u = @import("index.zig");
...@@ -11,21 +12,21 @@ pub const kb = b * 1024;...@@ -11,21 +12,21 @@ pub const kb = b * 1024;
11pub const mb = kb * 1024;12pub const mb = kb * 1024;
12pub const gb = mb * 1024;13pub const gb = mb * 1024;
1314
14pub fn print(comptime fmt: []const u8, args: anytype) void {15pub fn print(comptime fmt: string, args: anytype) void {
15 std.debug.print(fmt ++ "\n", args);16 std.debug.print(fmt ++ "\n", args);
16}17}
1718
18const ansi_red = "\x1B[31m";19const ansi_red = "\x1B[31m";
19const ansi_reset = "\x1B[39m";20const ansi_reset = "\x1B[39m";
2021
21pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {22pub fn assert(ok: bool, comptime fmt: string, args: anytype) void {
22 if (!ok) {23 if (!ok) {
23 print(ansi_red ++ fmt ++ ansi_reset, args);24 print(ansi_red ++ fmt ++ ansi_reset, args);
24 std.os.exit(1);25 std.os.exit(1);
25 }26 }
26}27}
2728
28pub fn fail(comptime fmt: []const u8, args: anytype) noreturn {29pub fn fail(comptime fmt: string, args: anytype) noreturn {
29 assert(false, fmt, args);30 assert(false, fmt, args);
30 unreachable;31 unreachable;
31}32}
...@@ -37,8 +38,8 @@ pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {...@@ -37,8 +38,8 @@ pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {
37 return array[n];38 return array[n];
38}39}
3940
40pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {41pub fn split(in: string, delim: string) ![]string {
41 var list = std.ArrayList([]const u8).init(gpa);42 var list = std.ArrayList(string).init(gpa);
42 defer list.deinit();43 defer list.deinit();
43 var iter = std.mem.split(u8, in, delim);44 var iter = std.mem.split(u8, in, delim);
44 while (iter.next()) |str| {45 while (iter.next()) |str| {
...@@ -47,14 +48,14 @@ pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {...@@ -47,14 +48,14 @@ pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {
47 return list.toOwnedSlice();48 return list.toOwnedSlice();
48}49}
4950
50pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {51pub fn trim_prefix(in: string, prefix: string) string {
51 if (std.mem.startsWith(u8, in, prefix)) {52 if (std.mem.startsWith(u8, in, prefix)) {
52 return in[prefix.len..];53 return in[prefix.len..];
53 }54 }
54 return in;55 return in;
55}56}
5657
57pub fn does_file_exist(fpath: []const u8, dir: ?std.fs.Dir) !bool {58pub fn does_file_exist(fpath: string, dir: ?std.fs.Dir) !bool {
58 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {59 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {
59 error.FileNotFound => return false,60 error.FileNotFound => return false,
60 error.IsDir => return true,61 error.IsDir => return true,
...@@ -64,7 +65,7 @@ pub fn does_file_exist(fpath: []const u8, dir: ?std.fs.Dir) !bool {...@@ -64,7 +65,7 @@ pub fn does_file_exist(fpath: []const u8, dir: ?std.fs.Dir) !bool {
64 return true;65 return true;
65}66}
6667
67pub fn does_folder_exist(fpath: []const u8) !bool {68pub fn does_folder_exist(fpath: string) !bool {
68 const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) {69 const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) {
69 error.FileNotFound => return false,70 error.FileNotFound => return false,
70 error.IsDir => return true,71 error.IsDir => return true,
...@@ -78,8 +79,8 @@ pub fn does_folder_exist(fpath: []const u8) !bool {...@@ -78,8 +79,8 @@ pub fn does_folder_exist(fpath: []const u8) !bool {
78 return true;79 return true;
79}80}
8081
81pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {82pub fn _join(comptime delim: string, comptime xs: []string) string {
82 var buf: []const u8 = "";83 var buf: string = "";
83 for (xs) |x, i| {84 for (xs) |x, i| {
84 buf = buf ++ x;85 buf = buf ++ x;
85 if (i < xs.len - 1) buf = buf ++ delim;86 if (i < xs.len - 1) buf = buf ++ delim;
...@@ -87,15 +88,15 @@ pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {...@@ -87,15 +88,15 @@ pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {
87 return buf;88 return buf;
88}89}
8990
90pub fn trim_suffix(in: []const u8, suffix: []const u8) []const u8 {91pub fn trim_suffix(in: string, suffix: string) string {
91 if (std.mem.endsWith(u8, in, suffix)) {92 if (std.mem.endsWith(u8, in, suffix)) {
92 return in[0 .. in.len - suffix.len];93 return in[0 .. in.len - suffix.len];
93 }94 }
94 return in;95 return in;
95}96}
9697
97pub fn repeat(s: []const u8, times: i32) ![]const u8 {98pub fn repeat(s: string, times: i32) !string {
98 var list = std.ArrayList([]const u8).init(gpa);99 var list = std.ArrayList(string).init(gpa);
99 var i: i32 = 0;100 var i: i32 = 0;
100 while (i < times) : (i += 1) {101 while (i < times) : (i += 1) {
101 try list.append(s);102 try list.append(s);
...@@ -103,15 +104,15 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 {...@@ -103,15 +104,15 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 {
103 return join(list.items, "");104 return join(list.items, "");
104}105}
105106
106pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {107pub fn join(xs: []string, delim: string) !string {
107 var res: []const u8 = "";108 var res: string = "";
108 for (xs) |x, i| {109 for (xs) |x, i| {
109 res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ res, x, if (i < xs.len - 1) delim else "" });110 res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ res, x, if (i < xs.len - 1) delim else "" });
110 }111 }
111 return res;112 return res;
112}113}
113114
114pub fn concat(items: [][]const u8) ![]const u8 {115pub fn concat(items: []string) !string {
115 return std.mem.join(gpa, "", items);116 return std.mem.join(gpa, "", items);
116}117}
117118
...@@ -128,7 +129,7 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void {...@@ -128,7 +129,7 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void {
128 }129 }
129}130}
130131
131pub fn list_contains(haystack: []const []const u8, needle: []const u8) bool {132pub fn list_contains(haystack: []const string, needle: string) bool {
132 for (haystack) |item| {133 for (haystack) |item| {
133 if (std.mem.eql(u8, item, needle)) {134 if (std.mem.eql(u8, item, needle)) {
134 return true;135 return true;
...@@ -146,7 +147,7 @@ pub fn list_contains_gen(comptime T: type, haystack: []const T, needle: T) bool...@@ -146,7 +147,7 @@ pub fn list_contains_gen(comptime T: type, haystack: []const T, needle: T) bool
146 return false;147 return false;
147}148}
148149
149pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {150pub fn file_list(dpath: string, list: *std.ArrayList(string)) !void {
150 const dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });151 const dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });
151 var walk = try dir.walk(gpa);152 var walk = try dir.walk(gpa);
152 defer walk.deinit();153 defer walk.deinit();
...@@ -162,7 +163,7 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {...@@ -162,7 +163,7 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {
162 }163 }
163}164}
164165
165pub fn run_cmd_raw(dir: ?[]const u8, args: []const []const u8) !std.ChildProcess.ExecResult {166pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecResult {
166 return std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {167 return std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
167 error.FileNotFound => {168 error.FileNotFound => {
168 u.fail("\"{s}\" command not found", .{args[0]});169 u.fail("\"{s}\" command not found", .{args[0]});
...@@ -171,15 +172,15 @@ pub fn run_cmd_raw(dir: ?[]const u8, args: []const []const u8) !std.ChildProcess...@@ -171,15 +172,15 @@ pub fn run_cmd_raw(dir: ?[]const u8, args: []const []const u8) !std.ChildProcess
171 };172 };
172}173}
173174
174pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {175pub fn run_cmd(dir: ?string, args: []const string) !u32 {
175 const result = try run_cmd_raw(dir, args);176 const result = try run_cmd_raw(dir, args);
176 gpa.free(result.stdout);177 gpa.free(result.stdout);
177 gpa.free(result.stderr);178 gpa.free(result.stderr);
178 return result.term.Exited;179 return result.term.Exited;
179}180}
180181
181pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {182pub fn list_remove(input: []string, search: string) ![]string {
182 var list = std.ArrayList([]const u8).init(gpa);183 var list = std.ArrayList(string).init(gpa);
183 defer list.deinit();184 defer list.deinit();
184 for (input) |item| {185 for (input) |item| {
185 if (!std.mem.eql(u8, item, search)) {186 if (!std.mem.eql(u8, item, search)) {
...@@ -189,7 +190,7 @@ pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {...@@ -189,7 +190,7 @@ pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {
189 return list.toOwnedSlice();190 return list.toOwnedSlice();
190}191}
191192
192pub fn last(in: [][]const u8) ![]const u8 {193pub fn last(in: []string) !string {
193 if (in.len == 0) {194 if (in.len == 0) {
194 return error.EmptyArray;195 return error.EmptyArray;
195 }196 }
...@@ -198,7 +199,7 @@ pub fn last(in: [][]const u8) ![]const u8 {...@@ -198,7 +199,7 @@ pub fn last(in: [][]const u8) ![]const u8 {
198199
199const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";200const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
200201
201pub fn random_string(len: usize) ![]const u8 {202pub fn random_string(len: usize) !string {
202 const now = @intCast(u64, std.time.nanoTimestamp());203 const now = @intCast(u64, std.time.nanoTimestamp());
203 var rand = std.rand.DefaultPrng.init(now);204 var rand = std.rand.DefaultPrng.init(now);
204 const r = &rand.random;205 const r = &rand.random;
...@@ -210,14 +211,14 @@ pub fn random_string(len: usize) ![]const u8 {...@@ -210,14 +211,14 @@ pub fn random_string(len: usize) ![]const u8 {
210 return buf;211 return buf;
211}212}
212213
213pub fn parse_split(comptime T: type, delim: []const u8) type {214pub fn parse_split(comptime T: type, delim: string) type {
214 return struct {215 return struct {
215 const Self = @This();216 const Self = @This();
216217
217 id: T,218 id: T,
218 string: []const u8,219 string: string,
219220
220 pub fn do(input: []const u8) !Self {221 pub fn do(input: string) !Self {
221 var iter = std.mem.split(u8, input, delim);222 var iter = std.mem.split(u8, input, delim);
222 return Self{223 return Self{
223 .id = std.meta.stringToEnum(T, iter.next() orelse return error.IterEmpty) orelse return error.NoMemberFound,224 .id = std.meta.stringToEnum(T, iter.next() orelse return error.IterEmpty) orelse return error.NoMemberFound,
...@@ -233,7 +234,7 @@ pub const HashFn = enum {...@@ -233,7 +234,7 @@ pub const HashFn = enum {
233 sha512,234 sha512,
234};235};
235236
236pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {237pub fn validate_hash(input: string, file_path: string) !bool {
237 const hash = parse_split(HashFn, "-").do(input) catch return false;238 const hash = parse_split(HashFn, "-").do(input) catch return false;
238 const file = try std.fs.cwd().openFile(file_path, .{});239 const file = try std.fs.cwd().openFile(file_path, .{});
239 defer file.close();240 defer file.close();
...@@ -251,7 +252,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {...@@ -251,7 +252,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {
251 return result;252 return result;
252}253}
253254
254pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {255pub fn do_hash(comptime algo: type, data: string) !string {
255 const h = &algo.init(.{});256 const h = &algo.init(.{});
256 var out: [algo.digest_length]u8 = undefined;257 var out: [algo.digest_length]u8 = undefined;
257 h.update(data);258 h.update(data);
...@@ -261,7 +262,7 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {...@@ -261,7 +262,7 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {
261}262}
262263
263/// Returns the result of running `git rev-parse HEAD`264/// Returns the result of running `git rev-parse HEAD`
264pub fn git_rev_HEAD(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]const u8 {265pub fn git_rev_HEAD(alloc: *std.mem.Allocator, dir: std.fs.Dir) !string {
265 const max = std.math.maxInt(usize);266 const max = std.math.maxInt(usize);
266 const dirg = try dir.openDir(".git", .{});267 const dirg = try dir.openDir(".git", .{});
267 const h = std.mem.trim(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n");268 const h = std.mem.trim(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n");
...@@ -275,7 +276,7 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const...@@ -275,7 +276,7 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const
275 return input[f..t];276 return input[f..t];
276}277}
277278
278pub fn detect_pkgname(override: []const u8, dir: []const u8) ![]const u8 {279pub fn detect_pkgname(override: string, dir: string) !string {
279 if (override.len > 0) {280 if (override.len > 0) {
280 return override;281 return override;
281 }282 }
...@@ -291,7 +292,7 @@ pub fn detect_pkgname(override: []const u8, dir: []const u8) ![]const u8 {...@@ -291,7 +292,7 @@ pub fn detect_pkgname(override: []const u8, dir: []const u8) ![]const u8 {
291 return name;292 return name;
292}293}
293294
294pub fn detct_mainfile(override: []const u8, dir: ?std.fs.Dir, name: []const u8) ![]const u8 {295pub fn detct_mainfile(override: string, dir: ?std.fs.Dir, name: string) !string {
295 if (override.len > 0) {296 if (override.len > 0) {
296 if (try does_file_exist(override, dir)) {297 if (try does_file_exist(override, dir)) {
297 if (std.mem.endsWith(u8, override, ".zig")) {298 if (std.mem.endsWith(u8, override, ".zig")) {
...@@ -312,7 +313,7 @@ pub fn detct_mainfile(override: []const u8, dir: ?std.fs.Dir, name: []const u8)...@@ -312,7 +313,7 @@ pub fn detct_mainfile(override: []const u8, dir: ?std.fs.Dir, name: []const u8)
312 return error.CantFindMain;313 return error.CantFindMain;
313}314}
314315
315pub fn indexOfN(haystack: []const u8, needle: u8, n: usize) ?usize {316pub fn indexOfN(haystack: string, needle: u8, n: usize) ?usize {
316 var i: usize = 0;317 var i: usize = 0;
317 var c: usize = 0;318 var c: usize = 0;
318 while (c < n) {319 while (c < n) {
...@@ -322,7 +323,7 @@ pub fn indexOfN(haystack: []const u8, needle: u8, n: usize) ?usize {...@@ -322,7 +323,7 @@ pub fn indexOfN(haystack: []const u8, needle: u8, n: usize) ?usize {
322 return i;323 return i;
323}324}
324325
325pub fn indexOfAfter(haystack: []const u8, needle: u8, after: usize) ?usize {326pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {
326 for (haystack) |c, i| {327 for (haystack) |c, i| {
327 if (i <= after) continue;328 if (i <= after) continue;
328 if (c == needle) return i;329 if (c == needle) return i;
src/util/modfile.zig+14-13
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
23
3const u = @import("index.zig");4const u = @import("index.zig");
4const yaml = @import("./yaml.zig");5const yaml = @import("./yaml.zig");
...@@ -14,19 +15,19 @@ pub const ModFile = struct {...@@ -14,19 +15,19 @@ pub const ModFile = struct {
14 const Self = @This();15 const Self = @This();
1516
16 alloc: *std.mem.Allocator,17 alloc: *std.mem.Allocator,
17 id: []const u8,18 id: string,
18 name: []const u8,19 name: string,
19 main: []const u8,20 main: string,
20 c_include_dirs: []const []const u8,21 c_include_dirs: []const string,
21 c_source_flags: []const []const u8,22 c_source_flags: []const string,
22 c_source_files: []const []const u8,23 c_source_files: []const string,
23 deps: []u.Dep,24 deps: []u.Dep,
24 yaml: yaml.Mapping,25 yaml: yaml.Mapping,
25 devdeps: []u.Dep,26 devdeps: []u.Dep,
26 root_files: []const []const u8,27 root_files: []const string,
27 files: []const []const u8,28 files: []const string,
2829
29 pub fn init(alloc: *std.mem.Allocator, mpath: []const u8) !Self {30 pub fn init(alloc: *std.mem.Allocator, mpath: string) !Self {
30 const file = try std.fs.cwd().openFile(mpath, .{});31 const file = try std.fs.cwd().openFile(mpath, .{});
31 defer file.close();32 defer file.close();
32 const input = try file.reader().readAllAlloc(alloc, mb);33 const input = try file.reader().readAllAlloc(alloc, mb);
...@@ -67,14 +68,14 @@ pub const ModFile = struct {...@@ -67,14 +68,14 @@ pub const ModFile = struct {
67 };68 };
68 }69 }
6970
70 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) anyerror![]u.Dep {71 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: string) anyerror![]u.Dep {
71 var dep_list = std.ArrayList(u.Dep).init(alloc);72 var dep_list = std.ArrayList(u.Dep).init(alloc);
72 if (mapping.get(prop)) |dep_seq| {73 if (mapping.get(prop)) |dep_seq| {
73 if (dep_seq == .sequence) {74 if (dep_seq == .sequence) {
74 for (dep_seq.sequence) |item| {75 for (dep_seq.sequence) |item| {
75 var dtype: []const u8 = undefined;76 var dtype: string = undefined;
76 var path: []const u8 = undefined;77 var path: string = undefined;
77 var version: ?[]const u8 = null;78 var version: ?string = null;
78 var name = item.mapping.get_string("name");79 var name = item.mapping.get_string("name");
79 var main = item.mapping.get_string("main");80 var main = item.mapping.get_string("main");
8081
src/util/module.zig+17-16
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
3const builtin = @import("builtin");4const builtin = @import("builtin");
45
...@@ -11,20 +12,20 @@ const common = @import("./../common.zig");...@@ -11,20 +12,20 @@ const common = @import("./../common.zig");
1112
12pub const Module = struct {13pub const Module = struct {
13 is_sys_lib: bool,14 is_sys_lib: bool,
14 id: []const u8,15 id: string,
15 name: []const u8,16 name: string,
16 main: []const u8,17 main: string,
17 c_include_dirs: []const []const u8 = &.{},18 c_include_dirs: []const string = &.{},
18 c_source_flags: []const []const u8 = &.{},19 c_source_flags: []const string = &.{},
19 c_source_files: []const []const u8 = &.{},20 c_source_files: []const string = &.{},
20 only_os: []const []const u8 = &.{},21 only_os: []const string = &.{},
21 except_os: []const []const u8 = &.{},22 except_os: []const string = &.{},
22 yaml: ?yaml.Mapping,23 yaml: ?yaml.Mapping,
23 deps: []Module,24 deps: []Module,
24 clean_path: []const u8,25 clean_path: string,
25 dep: ?u.Dep,26 dep: ?u.Dep,
2627
27 pub fn from(dep: u.Dep, dir: []const u8, options: *common.CollectOptions) !Module {28 pub fn from(dep: u.Dep, dir: string, options: *common.CollectOptions) !Module {
28 var moddeps = std.ArrayList(Module).init(gpa);29 var moddeps = std.ArrayList(Module).init(gpa);
29 defer moddeps.deinit();30 defer moddeps.deinit();
30 for (dep.deps) |*d| {31 for (dep.deps) |*d| {
...@@ -53,12 +54,12 @@ pub const Module = struct {...@@ -53,12 +54,12 @@ pub const Module = struct {
53 return std.mem.eql(u8, self.id, another.id);54 return std.mem.eql(u8, self.id, another.id);
54 }55 }
5556
56 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {57 pub fn get_hash(self: Module, cdpath: string) !string {
57 var file_list_1 = std.ArrayList([]const u8).init(gpa);58 var file_list_1 = std.ArrayList(string).init(gpa);
58 defer file_list_1.deinit();59 defer file_list_1.deinit();
59 try u.file_list(try u.concat(&.{ cdpath, "/", self.clean_path }), &file_list_1);60 try u.file_list(try u.concat(&.{ cdpath, "/", self.clean_path }), &file_list_1);
6061
61 var file_list_2 = std.ArrayList([]const u8).init(gpa);62 var file_list_2 = std.ArrayList(string).init(gpa);
62 defer file_list_2.deinit();63 defer file_list_2.deinit();
63 for (file_list_1.items) |item| {64 for (file_list_1.items) |item| {
64 const _a = u.trim_prefix(item, cdpath);65 const _a = u.trim_prefix(item, cdpath);
...@@ -67,8 +68,8 @@ pub const Module = struct {...@@ -67,8 +68,8 @@ pub const Module = struct {
67 try file_list_2.append(_b);68 try file_list_2.append(_b);
68 }69 }
6970
70 std.sort.sort([]const u8, file_list_2.items, void{}, struct {71 std.sort.sort(string, file_list_2.items, void{}, struct {
71 pub fn lt(context: void, lhs: []const u8, rhs: []const u8) bool {72 pub fn lt(context: void, lhs: string, rhs: string) bool {
72 _ = context;73 _ = context;
73 return std.mem.lessThan(u8, lhs, rhs);74 return std.mem.lessThan(u8, lhs, rhs);
74 }75 }
...@@ -117,7 +118,7 @@ pub const Module = struct {...@@ -117,7 +118,7 @@ pub const Module = struct {
117 return false;118 return false;
118 }119 }
119120
120 pub fn short_id(self: Module) []const u8 {121 pub fn short_id(self: Module) string {
121 return u.slice(u8, self.id, 0, 12);122 return u.slice(u8, self.id, 0, 12);
122 }123 }
123};124};
src/util/yaml.zig+14-13
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const yaml = @import("yaml");3const yaml = @import("yaml");
34
4const c = @cImport({5const c = @cImport({
...@@ -9,7 +10,7 @@ const u = @import("./index.zig");...@@ -9,7 +10,7 @@ const u = @import("./index.zig");
9//10//
10//11//
1112
12const Array = []const []const u8;13const Array = []const string;
1314
14pub const Stream = struct {15pub const Stream = struct {
15 docs: []const Document,16 docs: []const Document,
...@@ -25,10 +26,10 @@ pub const Item = union(enum) {...@@ -25,10 +26,10 @@ pub const Item = union(enum) {
25 mapping: Mapping,26 mapping: Mapping,
26 sequence: Sequence,27 sequence: Sequence,
27 document: Document,28 document: Document,
28 string: []const u8,29 string: string,
29 stream: Stream,30 stream: Stream,
3031
31 pub fn format(self: Item, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {32 pub fn format(self: Item, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {
32 _ = fmt;33 _ = fmt;
33 _ = options;34 _ = options;
3435
...@@ -62,16 +63,16 @@ pub const Item = union(enum) {...@@ -62,16 +63,16 @@ pub const Item = union(enum) {
62pub const Sequence = []const Item;63pub const Sequence = []const Item;
6364
64pub const Key = struct {65pub const Key = struct {
65 key: []const u8,66 key: string,
66 value: Value,67 value: Value,
67};68};
6869
69pub const Value = union(enum) {70pub const Value = union(enum) {
70 string: []const u8,71 string: string,
71 mapping: Mapping,72 mapping: Mapping,
72 sequence: Sequence,73 sequence: Sequence,
7374
74 pub fn format(self: Value, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {75 pub fn format(self: Value, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {
75 _ = fmt;76 _ = fmt;
76 _ = options;77 _ = options;
7778
...@@ -98,7 +99,7 @@ pub const Value = union(enum) {...@@ -98,7 +99,7 @@ pub const Value = union(enum) {
98pub const Mapping = struct {99pub const Mapping = struct {
99 items: []const Key,100 items: []const Key,
100101
101 pub fn get(self: Mapping, k: []const u8) ?Value {102 pub fn get(self: Mapping, k: string) ?Value {
102 for (self.items) |item| {103 for (self.items) |item| {
103 if (std.mem.eql(u8, item.key, k)) {104 if (std.mem.eql(u8, item.key, k)) {
104 return item.value;105 return item.value;
...@@ -107,12 +108,12 @@ pub const Mapping = struct {...@@ -107,12 +108,12 @@ pub const Mapping = struct {
107 return null;108 return null;
108 }109 }
109110
110 pub fn get_string(self: Mapping, k: []const u8) []const u8 {111 pub fn get_string(self: Mapping, k: string) string {
111 return if (self.get(k)) |v| v.string else "";112 return if (self.get(k)) |v| v.string else "";
112 }113 }
113114
114 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {115 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: string) ![]string {
115 var list = std.ArrayList([]const u8).init(alloc);116 var list = std.ArrayList(string).init(alloc);
116 defer list.deinit();117 defer list.deinit();
117 if (self.get(k)) |val| {118 if (self.get(k)) |val| {
118 if (val == .sequence) {119 if (val == .sequence) {
...@@ -127,7 +128,7 @@ pub const Mapping = struct {...@@ -127,7 +128,7 @@ pub const Mapping = struct {
127 return list.toOwnedSlice();128 return list.toOwnedSlice();
128 }129 }
129130
130 pub fn format(self: Mapping, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {131 pub fn format(self: Mapping, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void {
131 _ = fmt;132 _ = fmt;
132 _ = options;133 _ = options;
133134
...@@ -146,7 +147,7 @@ pub const TokenList = []const Token;...@@ -146,7 +147,7 @@ pub const TokenList = []const Token;
146//147//
147//148//
148149
149pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {150pub fn parse(alloc: *std.mem.Allocator, input: string) !Document {
150 var parser: c.yaml_parser_t = undefined;151 var parser: c.yaml_parser_t = undefined;
151 _ = c.yaml_parser_initialize(&parser);152 _ = c.yaml_parser_initialize(&parser);
152153
...@@ -291,7 +292,7 @@ fn parse_sequence(p: *Parser) Error!Sequence {...@@ -291,7 +292,7 @@ fn parse_sequence(p: *Parser) Error!Sequence {
291 }292 }
292}293}
293294
294fn get_event_string(event: Token, lines: Array) []const u8 {295fn get_event_string(event: Token, lines: Array) string {
295 const sm = event.start_mark;296 const sm = event.start_mark;
296 const em = event.end_mark;297 const em = event.end_mark;
297 return lines[sm.line][sm.column..em.column];298 return lines[sm.line][sm.column..em.column];