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