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 @@
11const std = @import("std");
2const string = []const u8;
23const builtin = @import("builtin");
34const deps = @import("./deps.zig");
45
......@@ -19,7 +20,7 @@ pub fn build(b: *std.build.Builder) void {
1920
2021 const exe_options = b.addOptions();
2122 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");
2324 exe_options.addOption(bool, "bootstrap", bootstrap != null);
2425
2526 if (bootstrap != null) {
src/cmd/aq.zig+2-1
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const zfetch = @import("zfetch");
......@@ -42,7 +43,7 @@ pub fn execute(args: [][]u8) !void {
4243 u.fail("unknown command \"{s}\" for \"zigmod aq\"", .{args[0]});
4344}
4445
45pub fn server_fetch(url: []const u8) !json.Value {
46pub fn server_fetch(url: string) !json.Value {
4647 const req = try zfetch.Request.init(gpa, url, null);
4748 defer req.deinit();
4849
src/cmd/aquila/add.zig+2-1
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const u = @import("./../../util/index.zig");
......@@ -13,7 +14,7 @@ pub fn execute(args: [][]u8) !void {
1314 std.log.info("Successfully added package {s}", .{pkg_id});
1415}
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 {
1718 const url = try std.mem.join(gpa, "/", &.{ aq.server_root, pkg_id });
1819 const val = try aq.server_fetch(url);
1920
src/cmd/aquila/install.zig+2-1
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const knownfolders = @import("known-folders");
......@@ -54,7 +55,7 @@ pub fn execute(args: [][]u8) !void {
5455 try ci.do(modpath, moddir);
5556
5657 // zig build
57 const argv: []const []const u8 = &.{
58 const argv: []const string = &.{
5859 "zig", "build",
5960 "--prefix", try std.fs.path.join(gpa, &.{ homepath, ".zigmod" }),
6061 "--cache-dir", try std.fs.path.join(gpa, &.{ cache.?, "zigmod", "zig" }),
src/cmd/ci.zig+2-1
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const u = @import("./../util/index.zig");
......@@ -15,7 +16,7 @@ pub fn execute(args: [][]u8) !void {
1516 try do(cachepath, dir);
1617}
1718
18pub fn do(cachepath: []const u8, dir: std.fs.Dir) !void {
19pub fn do(cachepath: string, dir: std.fs.Dir) !void {
1920 var options = common.CollectOptions{
2021 .log = true,
2122 .update = false,
src/cmd/fetch.zig+2-3
......@@ -1,7 +1,6 @@
11const std = @import("std");
2const gpa = std.heap.c_allocator;
3
42const string = []const u8;
3const gpa = std.heap.c_allocator;
54
65const u = @import("./../util/index.zig");
76const common = @import("./../common.zig");
......@@ -360,7 +359,7 @@ fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void {
360359 }
361360}
362361
363fn zig_name_from_pkg_name(name: []const u8) ![]const u8 {
362fn zig_name_from_pkg_name(name: string) !string {
364363 var legal = name;
365364 legal = try std.mem.replaceOwned(u8, gpa, legal, "-", "_");
366365 legal = try std.mem.replaceOwned(u8, gpa, legal, "/", "_");
src/cmd/init.zig+8-7
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const inquirer = @import("inquirer");
......@@ -25,18 +26,18 @@ pub fn execute(args: [][]u8) !void {
2526 const stdin = std.io.getStdIn().reader();
2627 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
3031 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) {
3334 error.NoBuildZig => {
3435 u.fail("init requires a build.zig file", .{});
3536 },
3637 else => return err,
3738 });
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) {
4041 error.CantFindMain => null,
4142 else => return err,
4243 }) else null;
......@@ -100,7 +101,7 @@ pub fn execute(args: [][]u8) !void {
100101 realtext = try std.mem.replaceOwned(u8, gpa, realtext, "<year>", try inquirer.answer(
101102 stdout,
102103 "year:",
103 []const u8,
104 string,
104105 "{s}",
105106 try std.fmt.allocPrint(gpa, "{d}", .{1970 + @divFloor(std.time.timestamp(), s_in_y)}),
106107 ));
......@@ -121,7 +122,7 @@ pub fn execute(args: [][]u8) !void {
121122 }
122123}
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 {
125126 try w.print("id: {s}\n", .{id});
126127 try w.print("name: {s}\n", .{name});
127128 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,
129130 try w.print("dev_dependencies:\n", .{});
130131}
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 {
133134 try w.print("id: {s}\n", .{id});
134135 try w.print("name: {s}\n", .{name});
135136 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,
138139 try w.print("dependencies:\n", .{});
139140}
140141
141fn guessCopyrightName() !?[]const u8 {
142fn guessCopyrightName() !?string {
142143 const home = (try knownfolders.open(gpa, .home, .{})).?;
143144 if (!(try u.does_file_exist(".gitconfig", home))) return null;
144145 const file = try home.openFile(".gitconfig", .{});
src/cmd/version.zig-1
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const string = []const u8;
32const gpa = std.heap.c_allocator;
43const builtin = @import("builtin");
54
src/cmd/zpm.zig+8-7
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const zfetch = @import("zfetch");
......@@ -19,12 +20,12 @@ pub const commands = struct {
1920pub const server_root = "https://zpm.random-projects.net/api";
2021
2122pub const Package = struct {
22 author: []const u8,
23 name: []const u8,
24 tags: [][]const u8,
25 git: []const u8,
26 root_file: ?[]const u8,
27 description: []const u8,
23 author: string,
24 name: string,
25 tags: []string,
26 git: string,
27 root_file: ?string,
28 description: string,
2829};
2930
3031pub fn execute(args: [][]u8) !void {
......@@ -53,7 +54,7 @@ pub fn execute(args: [][]u8) !void {
5354 u.fail("unknown command \"{s}\" for \"zigmod zpm\"", .{args[0]});
5455}
5556
56pub fn server_fetch(url: []const u8) !json.Value {
57pub fn server_fetch(url: string) !json.Value {
5758 const req = try zfetch.Request.init(gpa, url, null);
5859 defer req.deinit();
5960 try req.do(.GET, null, null);
src/common.zig+14-14
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const builtin = @import("builtin");
34const gpa = std.heap.c_allocator;
45
......@@ -6,7 +7,6 @@ const ansi = @import("ansi");
67
78const u = @import("./util/index.zig");
89const yaml = @import("./util/yaml.zig");
9const string = []const u8;
1010
1111const root = @import("root");
1212const 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
1818pub const CollectOptions = struct {
1919 log: bool,
2020 update: bool,
21 lock: ?[]const [4][]const u8 = null,
21 lock: ?[]const [4]string = null,
2222 alloc: *std.mem.Allocator = gpa,
2323 already_fetched: *std.ArrayList(string) = undefined,
2424
......@@ -28,7 +28,7 @@ pub const CollectOptions = struct {
2828 }
2929};
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 {
3232 const m = try u.ModFile.from_dir(gpa, mdir);
3333 try options.init();
3434 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
5555 };
5656}
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 {
5959 const m = try u.ModFile.from_dir(gpa, mdir);
6060 var moduledeps = std.ArrayList(u.Module).init(gpa);
6161 defer moduledeps.deinit();
......@@ -93,7 +93,7 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void
9393 }
9494}
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 {
9797 const p = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path() });
9898 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) ![
197197 }
198198}
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 {
201201 if (options.lock) |lock| {
202202 for (lock) |item| {
203203 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
275275 }
276276}
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 {
279279 const destination = ".zigmod/deps/files";
280280 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);
283283 defer map.deinit();
284284
285285 for (dirs) |dir_path| {
......@@ -310,7 +310,7 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [
310310 );
311311 try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});
312312 try w.writeAll(
313 \\const files = std.ComptimeStringMap([]const u8, .{
313 \\const files = std.ComptimeStringMap(string, .{
314314 \\
315315 );
316316 var iter = map.iterator();
......@@ -321,7 +321,7 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [
321321 try w.writeAll(
322322 \\});
323323 \\
324 \\pub fn open(comptime path: []const u8) ?[]const u8 {
324 \\pub fn open(comptime path: string) ?string {
325325 \\ if (path.len == 0) return null;
326326 \\ if (path[0] != '/') return null;
327327 \\ return files.get(path);
......@@ -346,8 +346,8 @@ pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const [
346346 return (try get_module_from_dep(&d, destination, &options)).?;
347347}
348348
349pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {
350 var list = std.ArrayList([4][]const u8).init(gpa);
349pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4]string {
350 var list = std.ArrayList([4]string).init(gpa);
351351 const max = std.math.maxInt(usize);
352352 const f = try dir.openFile("zigmod.lock", .{});
353353 const r = f.reader();
......@@ -361,7 +361,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {
361361 switch (v) {
362362 1 => {
363363 var iter = std.mem.split(u8, line, " ");
364 try list.append([4][]const u8{
364 try list.append([4]string{
365365 iter.next().?,
366366 iter.next().?,
367367 iter.next().?,
......@@ -380,7 +380,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4][]const u8 {
380380 .yaml = null,
381381 .deps = &.{},
382382 };
383 try list.append([4][]const u8{
383 try list.append([4]string{
384384 try asdep.clean_path(),
385385 @tagName(asdep.type),
386386 asdep.path,
src/main.zig+2-1
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const builtin = @import("builtin");
34
45pub const build_options = @import("build_options");
......@@ -55,7 +56,7 @@ pub fn main() !void {
5556 }
5657 }
5758
58 var sub_cmd_args = std.ArrayList([]const u8).init(gpa);
59 var sub_cmd_args = std.ArrayList(string).init(gpa);
5960 try sub_cmd_args.append(try std.fmt.allocPrint(gpa, "zigmod-{s}", .{args[0]}));
6061 for (args[1..]) |item| {
6162 try sub_cmd_args.append(item);
src/util/dep.zig+14-13
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34const builtin = std.builtin;
45
......@@ -12,21 +13,21 @@ pub const Dep = struct {
1213 const Self = @This();
1314
1415 type: u.DepType,
15 path: []const u8,
16 path: string,
1617
17 id: []const u8,
18 name: []const u8,
19 main: []const u8,
20 version: []const u8,
21 c_include_dirs: []const []const u8 = &.{},
22 c_source_flags: []const []const u8 = &.{},
23 c_source_files: []const []const u8 = &.{},
24 only_os: []const []const u8 = &.{},
25 except_os: []const []const u8 = &.{},
18 id: string,
19 name: string,
20 main: string,
21 version: string,
22 c_include_dirs: []const string = &.{},
23 c_source_flags: []const string = &.{},
24 c_source_files: []const string = &.{},
25 only_os: []const string = &.{},
26 except_os: []const string = &.{},
2627 yaml: ?yaml.Mapping,
2728 deps: []u.Dep,
2829
29 pub fn clean_path(self: Dep) ![]const u8 {
30 pub fn clean_path(self: Dep) !string {
3031 if (self.type == .local) {
3132 return if (self.path.len == 0) "../.." else self.path;
3233 }
......@@ -39,7 +40,7 @@ pub const Dep = struct {
3940 return p;
4041 }
4142
42 pub fn clean_path_v(self: Dep) ![]const u8 {
43 pub fn clean_path_v(self: Dep) !string {
4344 if (self.type == .http and self.version.len > 0) {
4445 const i = std.mem.indexOf(u8, self.version, "-").?;
4546 return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] });
......@@ -58,7 +59,7 @@ pub const Dep = struct {
5859 return true;
5960 }
6061
61 pub fn exact_version(self: Dep, dpath: []const u8) ![]const u8 {
62 pub fn exact_version(self: Dep, dpath: string) !string {
6263 if (self.version.len == 0) {
6364 return try self.type.exact_version(dpath);
6465 }
src/util/dep_type.zig+4-3
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const u = @import("./index.zig");
......@@ -32,7 +33,7 @@ pub const DepType = enum {
3233 // hypercore, // https://hypercore-protocol.org/
3334
3435 // 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 {
3637 switch (self) {
3738 .local => {},
3839 .system_lib => {},
......@@ -57,7 +58,7 @@ pub const DepType = enum {
5758 }
5859
5960 // 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 {
6162 _ = rpath;
6263
6364 switch (self) {
......@@ -77,7 +78,7 @@ pub const DepType = enum {
7778 }
7879
7980 // 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 {
8182 var mdir = try std.fs.cwd().openDir(mpath, .{});
8283 defer mdir.close();
8384 return switch (self) {
src/util/funcs.zig+35-34
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34
45const u = @import("index.zig");
......@@ -11,21 +12,21 @@ pub const kb = b * 1024;
1112pub const mb = kb * 1024;
1213pub const gb = mb * 1024;
1314
14pub fn print(comptime fmt: []const u8, args: anytype) void {
15pub fn print(comptime fmt: string, args: anytype) void {
1516 std.debug.print(fmt ++ "\n", args);
1617}
1718
1819const ansi_red = "\x1B[31m";
1920const 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 {
2223 if (!ok) {
2324 print(ansi_red ++ fmt ++ ansi_reset, args);
2425 std.os.exit(1);
2526 }
2627}
2728
28pub fn fail(comptime fmt: []const u8, args: anytype) noreturn {
29pub fn fail(comptime fmt: string, args: anytype) noreturn {
2930 assert(false, fmt, args);
3031 unreachable;
3132}
......@@ -37,8 +38,8 @@ pub fn try_index(comptime T: type, array: []T, n: usize, def: T) T {
3738 return array[n];
3839}
3940
40pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {
41 var list = std.ArrayList([]const u8).init(gpa);
41pub fn split(in: string, delim: string) ![]string {
42 var list = std.ArrayList(string).init(gpa);
4243 defer list.deinit();
4344 var iter = std.mem.split(u8, in, delim);
4445 while (iter.next()) |str| {
......@@ -47,14 +48,14 @@ pub fn split(in: []const u8, delim: []const u8) ![][]const u8 {
4748 return list.toOwnedSlice();
4849}
4950
50pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {
51pub fn trim_prefix(in: string, prefix: string) string {
5152 if (std.mem.startsWith(u8, in, prefix)) {
5253 return in[prefix.len..];
5354 }
5455 return in;
5556}
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 {
5859 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {
5960 error.FileNotFound => return false,
6061 error.IsDir => return true,
......@@ -64,7 +65,7 @@ pub fn does_file_exist(fpath: []const u8, dir: ?std.fs.Dir) !bool {
6465 return true;
6566}
6667
67pub fn does_folder_exist(fpath: []const u8) !bool {
68pub fn does_folder_exist(fpath: string) !bool {
6869 const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) {
6970 error.FileNotFound => return false,
7071 error.IsDir => return true,
......@@ -78,8 +79,8 @@ pub fn does_folder_exist(fpath: []const u8) !bool {
7879 return true;
7980}
8081
81pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {
82 var buf: []const u8 = "";
82pub fn _join(comptime delim: string, comptime xs: []string) string {
83 var buf: string = "";
8384 for (xs) |x, i| {
8485 buf = buf ++ x;
8586 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 {
8788 return buf;
8889}
8990
90pub fn trim_suffix(in: []const u8, suffix: []const u8) []const u8 {
91pub fn trim_suffix(in: string, suffix: string) string {
9192 if (std.mem.endsWith(u8, in, suffix)) {
9293 return in[0 .. in.len - suffix.len];
9394 }
9495 return in;
9596}
9697
97pub fn repeat(s: []const u8, times: i32) ![]const u8 {
98 var list = std.ArrayList([]const u8).init(gpa);
98pub fn repeat(s: string, times: i32) !string {
99 var list = std.ArrayList(string).init(gpa);
99100 var i: i32 = 0;
100101 while (i < times) : (i += 1) {
101102 try list.append(s);
......@@ -103,15 +104,15 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 {
103104 return join(list.items, "");
104105}
105106
106pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {
107 var res: []const u8 = "";
107pub fn join(xs: []string, delim: string) !string {
108 var res: string = "";
108109 for (xs) |x, i| {
109110 res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ res, x, if (i < xs.len - 1) delim else "" });
110111 }
111112 return res;
112113}
113114
114pub fn concat(items: [][]const u8) ![]const u8 {
115pub fn concat(items: []string) !string {
115116 return std.mem.join(gpa, "", items);
116117}
117118
......@@ -128,7 +129,7 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void {
128129 }
129130}
130131
131pub fn list_contains(haystack: []const []const u8, needle: []const u8) bool {
132pub fn list_contains(haystack: []const string, needle: string) bool {
132133 for (haystack) |item| {
133134 if (std.mem.eql(u8, item, needle)) {
134135 return true;
......@@ -146,7 +147,7 @@ pub fn list_contains_gen(comptime T: type, haystack: []const T, needle: T) bool
146147 return false;
147148}
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 {
150151 const dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });
151152 var walk = try dir.walk(gpa);
152153 defer walk.deinit();
......@@ -162,7 +163,7 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {
162163 }
163164}
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 {
166167 return std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
167168 error.FileNotFound => {
168169 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
171172 };
172173}
173174
174pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {
175pub fn run_cmd(dir: ?string, args: []const string) !u32 {
175176 const result = try run_cmd_raw(dir, args);
176177 gpa.free(result.stdout);
177178 gpa.free(result.stderr);
178179 return result.term.Exited;
179180}
180181
181pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {
182 var list = std.ArrayList([]const u8).init(gpa);
182pub fn list_remove(input: []string, search: string) ![]string {
183 var list = std.ArrayList(string).init(gpa);
183184 defer list.deinit();
184185 for (input) |item| {
185186 if (!std.mem.eql(u8, item, search)) {
......@@ -189,7 +190,7 @@ pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {
189190 return list.toOwnedSlice();
190191}
191192
192pub fn last(in: [][]const u8) ![]const u8 {
193pub fn last(in: []string) !string {
193194 if (in.len == 0) {
194195 return error.EmptyArray;
195196 }
......@@ -198,7 +199,7 @@ pub fn last(in: [][]const u8) ![]const u8 {
198199
199200const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
200201
201pub fn random_string(len: usize) ![]const u8 {
202pub fn random_string(len: usize) !string {
202203 const now = @intCast(u64, std.time.nanoTimestamp());
203204 var rand = std.rand.DefaultPrng.init(now);
204205 const r = &rand.random;
......@@ -210,14 +211,14 @@ pub fn random_string(len: usize) ![]const u8 {
210211 return buf;
211212}
212213
213pub fn parse_split(comptime T: type, delim: []const u8) type {
214pub fn parse_split(comptime T: type, delim: string) type {
214215 return struct {
215216 const Self = @This();
216217
217218 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 {
221222 var iter = std.mem.split(u8, input, delim);
222223 return Self{
223224 .id = std.meta.stringToEnum(T, iter.next() orelse return error.IterEmpty) orelse return error.NoMemberFound,
......@@ -233,7 +234,7 @@ pub const HashFn = enum {
233234 sha512,
234235};
235236
236pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {
237pub fn validate_hash(input: string, file_path: string) !bool {
237238 const hash = parse_split(HashFn, "-").do(input) catch return false;
238239 const file = try std.fs.cwd().openFile(file_path, .{});
239240 defer file.close();
......@@ -251,7 +252,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {
251252 return result;
252253}
253254
254pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {
255pub fn do_hash(comptime algo: type, data: string) !string {
255256 const h = &algo.init(.{});
256257 var out: [algo.digest_length]u8 = undefined;
257258 h.update(data);
......@@ -261,7 +262,7 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {
261262}
262263
263264/// 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 {
265266 const max = std.math.maxInt(usize);
266267 const dirg = try dir.openDir(".git", .{});
267268 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
275276 return input[f..t];
276277}
277278
278pub fn detect_pkgname(override: []const u8, dir: []const u8) ![]const u8 {
279pub fn detect_pkgname(override: string, dir: string) !string {
279280 if (override.len > 0) {
280281 return override;
281282 }
......@@ -291,7 +292,7 @@ pub fn detect_pkgname(override: []const u8, dir: []const u8) ![]const u8 {
291292 return name;
292293}
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 {
295296 if (override.len > 0) {
296297 if (try does_file_exist(override, dir)) {
297298 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)
312313 return error.CantFindMain;
313314}
314315
315pub fn indexOfN(haystack: []const u8, needle: u8, n: usize) ?usize {
316pub fn indexOfN(haystack: string, needle: u8, n: usize) ?usize {
316317 var i: usize = 0;
317318 var c: usize = 0;
318319 while (c < n) {
......@@ -322,7 +323,7 @@ pub fn indexOfN(haystack: []const u8, needle: u8, n: usize) ?usize {
322323 return i;
323324}
324325
325pub fn indexOfAfter(haystack: []const u8, needle: u8, after: usize) ?usize {
326pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {
326327 for (haystack) |c, i| {
327328 if (i <= after) continue;
328329 if (c == needle) return i;
src/util/modfile.zig+14-13
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23
34const u = @import("index.zig");
45const yaml = @import("./yaml.zig");
......@@ -14,19 +15,19 @@ pub const ModFile = struct {
1415 const Self = @This();
1516
1617 alloc: *std.mem.Allocator,
17 id: []const u8,
18 name: []const u8,
19 main: []const u8,
20 c_include_dirs: []const []const u8,
21 c_source_flags: []const []const u8,
22 c_source_files: []const []const u8,
18 id: string,
19 name: string,
20 main: string,
21 c_include_dirs: []const string,
22 c_source_flags: []const string,
23 c_source_files: []const string,
2324 deps: []u.Dep,
2425 yaml: yaml.Mapping,
2526 devdeps: []u.Dep,
26 root_files: []const []const u8,
27 files: []const []const u8,
27 root_files: []const string,
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 {
3031 const file = try std.fs.cwd().openFile(mpath, .{});
3132 defer file.close();
3233 const input = try file.reader().readAllAlloc(alloc, mb);
......@@ -67,14 +68,14 @@ pub const ModFile = struct {
6768 };
6869 }
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 {
7172 var dep_list = std.ArrayList(u.Dep).init(alloc);
7273 if (mapping.get(prop)) |dep_seq| {
7374 if (dep_seq == .sequence) {
7475 for (dep_seq.sequence) |item| {
75 var dtype: []const u8 = undefined;
76 var path: []const u8 = undefined;
77 var version: ?[]const u8 = null;
76 var dtype: string = undefined;
77 var path: string = undefined;
78 var version: ?string = null;
7879 var name = item.mapping.get_string("name");
7980 var main = item.mapping.get_string("main");
8081
src/util/module.zig+17-16
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const gpa = std.heap.c_allocator;
34const builtin = @import("builtin");
45
......@@ -11,20 +12,20 @@ const common = @import("./../common.zig");
1112
1213pub const Module = struct {
1314 is_sys_lib: bool,
14 id: []const u8,
15 name: []const u8,
16 main: []const u8,
17 c_include_dirs: []const []const u8 = &.{},
18 c_source_flags: []const []const u8 = &.{},
19 c_source_files: []const []const u8 = &.{},
20 only_os: []const []const u8 = &.{},
21 except_os: []const []const u8 = &.{},
15 id: string,
16 name: string,
17 main: string,
18 c_include_dirs: []const string = &.{},
19 c_source_flags: []const string = &.{},
20 c_source_files: []const string = &.{},
21 only_os: []const string = &.{},
22 except_os: []const string = &.{},
2223 yaml: ?yaml.Mapping,
2324 deps: []Module,
24 clean_path: []const u8,
25 clean_path: string,
2526 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 {
2829 var moddeps = std.ArrayList(Module).init(gpa);
2930 defer moddeps.deinit();
3031 for (dep.deps) |*d| {
......@@ -53,12 +54,12 @@ pub const Module = struct {
5354 return std.mem.eql(u8, self.id, another.id);
5455 }
5556
56 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {
57 var file_list_1 = std.ArrayList([]const u8).init(gpa);
57 pub fn get_hash(self: Module, cdpath: string) !string {
58 var file_list_1 = std.ArrayList(string).init(gpa);
5859 defer file_list_1.deinit();
5960 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);
6263 defer file_list_2.deinit();
6364 for (file_list_1.items) |item| {
6465 const _a = u.trim_prefix(item, cdpath);
......@@ -67,8 +68,8 @@ pub const Module = struct {
6768 try file_list_2.append(_b);
6869 }
6970
70 std.sort.sort([]const u8, file_list_2.items, void{}, struct {
71 pub fn lt(context: void, lhs: []const u8, rhs: []const u8) bool {
71 std.sort.sort(string, file_list_2.items, void{}, struct {
72 pub fn lt(context: void, lhs: string, rhs: string) bool {
7273 _ = context;
7374 return std.mem.lessThan(u8, lhs, rhs);
7475 }
......@@ -117,7 +118,7 @@ pub const Module = struct {
117118 return false;
118119 }
119120
120 pub fn short_id(self: Module) []const u8 {
121 pub fn short_id(self: Module) string {
121122 return u.slice(u8, self.id, 0, 12);
122123 }
123124};
src/util/yaml.zig+14-13
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const string = []const u8;
23const yaml = @import("yaml");
34
45const c = @cImport({
......@@ -9,7 +10,7 @@ const u = @import("./index.zig");
910//
1011//
1112
12const Array = []const []const u8;
13const Array = []const string;
1314
1415pub const Stream = struct {
1516 docs: []const Document,
......@@ -25,10 +26,10 @@ pub const Item = union(enum) {
2526 mapping: Mapping,
2627 sequence: Sequence,
2728 document: Document,
28 string: []const u8,
29 string: string,
2930 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 {
3233 _ = fmt;
3334 _ = options;
3435
......@@ -62,16 +63,16 @@ pub const Item = union(enum) {
6263pub const Sequence = []const Item;
6364
6465pub const Key = struct {
65 key: []const u8,
66 key: string,
6667 value: Value,
6768};
6869
6970pub const Value = union(enum) {
70 string: []const u8,
71 string: string,
7172 mapping: Mapping,
7273 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 {
7576 _ = fmt;
7677 _ = options;
7778
......@@ -98,7 +99,7 @@ pub const Value = union(enum) {
9899pub const Mapping = struct {
99100 items: []const Key,
100101
101 pub fn get(self: Mapping, k: []const u8) ?Value {
102 pub fn get(self: Mapping, k: string) ?Value {
102103 for (self.items) |item| {
103104 if (std.mem.eql(u8, item.key, k)) {
104105 return item.value;
......@@ -107,12 +108,12 @@ pub const Mapping = struct {
107108 return null;
108109 }
109110
110 pub fn get_string(self: Mapping, k: []const u8) []const u8 {
111 pub fn get_string(self: Mapping, k: string) string {
111112 return if (self.get(k)) |v| v.string else "";
112113 }
113114
114 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {
115 var list = std.ArrayList([]const u8).init(alloc);
115 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: string) ![]string {
116 var list = std.ArrayList(string).init(alloc);
116117 defer list.deinit();
117118 if (self.get(k)) |val| {
118119 if (val == .sequence) {
......@@ -127,7 +128,7 @@ pub const Mapping = struct {
127128 return list.toOwnedSlice();
128129 }
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 {
131132 _ = fmt;
132133 _ = options;
133134
......@@ -146,7 +147,7 @@ pub const TokenList = []const Token;
146147//
147148//
148149
149pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
150pub fn parse(alloc: *std.mem.Allocator, input: string) !Document {
150151 var parser: c.yaml_parser_t = undefined;
151152 _ = c.yaml_parser_initialize(&parser);
152153
......@@ -291,7 +292,7 @@ fn parse_sequence(p: *Parser) Error!Sequence {
291292 }
292293}
293294
294fn get_event_string(event: Token, lines: Array) []const u8 {
295fn get_event_string(event: Token, lines: Array) string {
295296 const sm = event.start_mark;
296297 const em = event.end_mark;
297298 return lines[sm.line][sm.column..em.column];