authorgravatar for kris.tate+github@gmail.comkristopher tate <kris.tate+github@gmail.com> 2018-11-30 00:37:01+09:00
committergravatar for kris.tate+github@gmail.comkristopher tate <kris.tate+github@gmail.com> 2018-11-30 03:52:27+09:00
log2b78a90424ee47ee1a9ef590dcf517026d0f13d1
tree3ac725d29461fafd3076fca688cd6fa78928564a
parent53766e7a3a5c7141a64e21c30540f9ed571cdfdd
signature Commit is signed but in an unrecognized format.

std.os.path: remove dependance on std.mem.join;

std/os/child_process.zig: windows test/cli.zig: godbolt; doc/docgen.zig

10 files changed, 101 insertions(+), 78 deletions(-)

build.zig+8-8
......@@ -16,7 +16,7 @@ pub fn build(b: *Builder) !void {
1616 var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
1717
1818 const rel_zig_exe = try os.path.relative(b.allocator, b.build_root, b.zig_exe);
19 const langref_out_path = os.path.join(b.allocator, b.cache_root, "langref.html") catch unreachable;
19 const langref_out_path = os.path.join(b.allocator, [][]const u8{ b.cache_root, "langref.html" }) catch unreachable;
2020 var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8{
2121 docgen_exe.getOutputPath(),
2222 rel_zig_exe,
......@@ -125,13 +125,13 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
125125 for (dep.libdirs.toSliceConst()) |lib_dir| {
126126 lib_exe_obj.addLibPath(lib_dir);
127127 }
128 const lib_dir = os.path.join(b.allocator, dep.prefix, "lib") catch unreachable;
128 const lib_dir = os.path.join(b.allocator, [][]const u8{dep.prefix, "lib"}) catch unreachable;
129129 for (dep.system_libs.toSliceConst()) |lib| {
130130 const static_bare_name = if (mem.eql(u8, lib, "curses"))
131131 ([]const u8)("libncurses.a")
132132 else
133133 b.fmt("lib{}.a", lib);
134 const static_lib_name = os.path.join(b.allocator, lib_dir, static_bare_name) catch unreachable;
134 const static_lib_name = os.path.join(b.allocator, [][]const u8{lib_dir, static_bare_name}) catch unreachable;
135135 const have_static = fileExists(static_lib_name) catch unreachable;
136136 if (have_static) {
137137 lib_exe_obj.addObjectFile(static_lib_name);
......@@ -159,7 +159,7 @@ fn fileExists(filename: []const u8) !bool {
159159
160160fn addCppLib(b: *Builder, lib_exe_obj: var, cmake_binary_dir: []const u8, lib_name: []const u8) void {
161161 const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
162 lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp", b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable);
162 lib_exe_obj.addObjectFile(os.path.join(b.allocator, [][]const u8{ cmake_binary_dir, "zig_cpp", b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt()) }) catch unreachable);
163163}
164164
165165const LibraryDep = struct {
......@@ -235,8 +235,8 @@ fn findLLVM(b: *Builder, llvm_config_exe: []const u8) !LibraryDep {
235235pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
236236 var it = mem.split(stdlib_files, ";");
237237 while (it.next()) |stdlib_file| {
238 const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;
239 const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable;
238 const src_path = os.path.join(b.allocator, [][]const u8{"std", stdlib_file}) catch unreachable;
239 const dest_path = os.path.join(b.allocator, [][]const u8{"lib", "zig", "std", stdlib_file}) catch unreachable;
240240 b.installFile(src_path, dest_path);
241241 }
242242}
......@@ -244,8 +244,8 @@ pub fn installStdLib(b: *Builder, stdlib_files: []const u8) void {
244244pub fn installCHeaders(b: *Builder, c_header_files: []const u8) void {
245245 var it = mem.split(c_header_files, ";");
246246 while (it.next()) |c_header_file| {
247 const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;
248 const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable;
247 const src_path = os.path.join(b.allocator, [][]const u8{"c_headers", c_header_file}) catch unreachable;
248 const dest_path = os.path.join(b.allocator, [][]const u8{"lib", "zig", "include", c_header_file}) catch unreachable;
249249 b.installFile(src_path, dest_path);
250250 }
251251}
doc/docgen.zig+5-5
......@@ -990,13 +990,13 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
990990 try tokenizeAndPrint(tokenizer, out, code.source_token);
991991 try out.write("</pre>");
992992 const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", code.name);
993 const tmp_source_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_ext);
993 const tmp_source_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_ext });
994994 try io.writeFile(tmp_source_file_name, trimmed_raw_source);
995995
996996 switch (code.id) {
997997 Code.Id.Exe => |expected_outcome| {
998998 const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, exe_ext);
999 const tmp_bin_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_bin_ext);
999 const tmp_bin_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_bin_ext });
10001000 var build_args = std.ArrayList([]const u8).init(allocator);
10011001 defer build_args.deinit();
10021002 try build_args.appendSlice([][]const u8{
......@@ -1024,7 +1024,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10241024 }
10251025 for (code.link_objects) |link_object| {
10261026 const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", link_object, obj_ext);
1027 const full_path_object = try os.path.join(allocator, tmp_dir_name, name_with_ext);
1027 const full_path_object = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_with_ext });
10281028 try build_args.append("--object");
10291029 try build_args.append(full_path_object);
10301030 try out.print(" --object {}", name_with_ext);
......@@ -1216,12 +1216,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12161216 },
12171217 Code.Id.Obj => |maybe_error_match| {
12181218 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
1219 const tmp_obj_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_obj_ext);
1219 const tmp_obj_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_obj_ext });
12201220 var build_args = std.ArrayList([]const u8).init(allocator);
12211221 defer build_args.deinit();
12221222
12231223 const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", code.name);
1224 const output_h_file_name = try os.path.join(allocator, tmp_dir_name, name_plus_h_ext);
1224 const output_h_file_name = try os.path.join(allocator, [][]const u8{ tmp_dir_name, name_plus_h_ext });
12251225
12261226 try build_args.appendSlice([][]const u8{
12271227 zig_exe,
std/build.zig+17-17
......@@ -145,8 +145,8 @@ pub const Builder = struct {
145145
146146 pub fn setInstallPrefix(self: *Builder, maybe_prefix: ?[]const u8) void {
147147 self.prefix = maybe_prefix orelse "/usr/local"; // TODO better default
148 self.lib_dir = os.path.join(self.allocator, self.prefix, "lib") catch unreachable;
149 self.exe_dir = os.path.join(self.allocator, self.prefix, "bin") catch unreachable;
148 self.lib_dir = os.path.join(self.allocator, [][]const u8{self.prefix, "lib"}) catch unreachable;
149 self.exe_dir = os.path.join(self.allocator, [][]const u8{self.prefix, "bin"}) catch unreachable;
150150 }
151151
152152 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
......@@ -666,7 +666,7 @@ pub const Builder = struct {
666666 if (os.path.isAbsolute(name)) {
667667 return name;
668668 }
669 const full_path = try os.path.join(self.allocator, search_prefix, "bin", self.fmt("{}{}", name, exe_extension));
669 const full_path = try os.path.join(self.allocator, [][]const u8{search_prefix, "bin", self.fmt("{}{}", name, exe_extension)});
670670 if (os.path.real(self.allocator, full_path)) |real_path| {
671671 return real_path;
672672 } else |_| {
......@@ -681,7 +681,7 @@ pub const Builder = struct {
681681 }
682682 var it = mem.split(PATH, []u8{os.path.delimiter});
683683 while (it.next()) |path| {
684 const full_path = try os.path.join(self.allocator, path, self.fmt("{}{}", name, exe_extension));
684 const full_path = try os.path.join(self.allocator, [][]const u8{path, self.fmt("{}{}", name, exe_extension)});
685685 if (os.path.real(self.allocator, full_path)) |real_path| {
686686 return real_path;
687687 } else |_| {
......@@ -695,7 +695,7 @@ pub const Builder = struct {
695695 return name;
696696 }
697697 for (paths) |path| {
698 const full_path = try os.path.join(self.allocator, path, self.fmt("{}{}", name, exe_extension));
698 const full_path = try os.path.join(self.allocator, [][]const u8{path, self.fmt("{}{}", name, exe_extension)});
699699 if (os.path.real(self.allocator, full_path)) |real_path| {
700700 return real_path;
701701 } else |_| {
......@@ -1095,7 +1095,7 @@ pub const LibExeObjStep = struct {
10951095 }
10961096
10971097 pub fn getOutputPath(self: *LibExeObjStep) []const u8 {
1098 return if (self.output_path) |output_path| output_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename) catch unreachable;
1098 return if (self.output_path) |output_path| output_path else os.path.join(self.builder.allocator, [][]const u8{self.builder.cache_root, self.out_filename}) catch unreachable;
10991099 }
11001100
11011101 pub fn setOutputHPath(self: *LibExeObjStep, file_path: []const u8) void {
......@@ -1108,7 +1108,7 @@ pub const LibExeObjStep = struct {
11081108 }
11091109
11101110 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
1111 return if (self.output_h_path) |output_h_path| output_h_path else os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename) catch unreachable;
1111 return if (self.output_h_path) |output_h_path| output_h_path else os.path.join(self.builder.allocator, [][]const u8{self.builder.cache_root, self.out_h_filename}) catch unreachable;
11121112 }
11131113
11141114 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
......@@ -1208,7 +1208,7 @@ pub const LibExeObjStep = struct {
12081208 }
12091209
12101210 if (self.build_options_contents.len() > 0) {
1211 const build_options_file = try os.path.join(builder.allocator, builder.cache_root, builder.fmt("{}_build_options.zig", self.name));
1211 const build_options_file = try os.path.join(builder.allocator, [][]const u8{builder.cache_root, builder.fmt("{}_build_options.zig", self.name)});
12121212 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
12131213 try zig_args.append("--pkg-begin");
12141214 try zig_args.append("build_options");
......@@ -1455,7 +1455,7 @@ pub const LibExeObjStep = struct {
14551455 cc_args.append("-c") catch unreachable;
14561456 cc_args.append(abs_source_file) catch unreachable;
14571457
1458 const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable;
1458 const cache_o_src = os.path.join(builder.allocator, [][]const u8{builder.cache_root, source_file}) catch unreachable;
14591459 if (os.path.dirname(cache_o_src)) |cache_o_dir| {
14601460 try builder.makePath(cache_o_dir);
14611461 }
......@@ -1507,7 +1507,7 @@ pub const LibExeObjStep = struct {
15071507 cc_args.append("-current_version") catch unreachable;
15081508 cc_args.append(builder.fmt("{}.{}.{}", self.version.major, self.version.minor, self.version.patch)) catch unreachable;
15091509
1510 const install_name = builder.pathFromRoot(os.path.join(builder.allocator, builder.cache_root, self.major_only_filename) catch unreachable);
1510 const install_name = builder.pathFromRoot(os.path.join(builder.allocator, [][]const u8{builder.cache_root, self.major_only_filename}) catch unreachable);
15111511 cc_args.append("-install_name") catch unreachable;
15121512 cc_args.append(install_name) catch unreachable;
15131513 } else {
......@@ -1573,7 +1573,7 @@ pub const LibExeObjStep = struct {
15731573 cc_args.append("-c") catch unreachable;
15741574 cc_args.append(abs_source_file) catch unreachable;
15751575
1576 const cache_o_src = os.path.join(builder.allocator, builder.cache_root, source_file) catch unreachable;
1576 const cache_o_src = os.path.join(builder.allocator, [][]const u8{builder.cache_root, source_file}) catch unreachable;
15771577 if (os.path.dirname(cache_o_src)) |cache_o_dir| {
15781578 try builder.makePath(cache_o_dir);
15791579 }
......@@ -1721,7 +1721,7 @@ pub const TestStep = struct {
17211721 return output_path;
17221722 } else {
17231723 const basename = self.builder.fmt("test{}", self.target.exeFileExt());
1724 return os.path.join(self.builder.allocator, self.builder.cache_root, basename) catch unreachable;
1724 return os.path.join(self.builder.allocator, [][]const u8{self.builder.cache_root, basename}) catch unreachable;
17251725 }
17261726 }
17271727
......@@ -1930,13 +1930,13 @@ const InstallArtifactStep = struct {
19301930 .builder = builder,
19311931 .step = Step.init(builder.fmt("install {}", artifact.step.name), builder.allocator, make),
19321932 .artifact = artifact,
1933 .dest_file = os.path.join(builder.allocator, dest_dir, artifact.out_filename) catch unreachable,
1933 .dest_file = os.path.join(builder.allocator, [][]const u8{dest_dir, artifact.out_filename}) catch unreachable,
19341934 }) catch unreachable;
19351935 self.step.dependOn(&artifact.step);
19361936 builder.pushInstalledFile(self.dest_file);
19371937 if (self.artifact.kind == LibExeObjStep.Kind.Lib and !self.artifact.static) {
1938 builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir, artifact.major_only_filename) catch unreachable);
1939 builder.pushInstalledFile(os.path.join(builder.allocator, builder.lib_dir, artifact.name_only_filename) catch unreachable);
1938 builder.pushInstalledFile(os.path.join(builder.allocator, [][]const u8{builder.lib_dir, artifact.major_only_filename}) catch unreachable);
1939 builder.pushInstalledFile(os.path.join(builder.allocator, [][]const u8{builder.lib_dir, artifact.name_only_filename}) catch unreachable);
19401940 }
19411941 return self;
19421942 }
......@@ -2092,13 +2092,13 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj
20922092 const out_dir = os.path.dirname(output_path) orelse ".";
20932093 const out_basename = os.path.basename(output_path);
20942094 // sym link for libfoo.so.1 to libfoo.so.1.2.3
2095 const major_only_path = os.path.join(allocator, out_dir, filename_major_only) catch unreachable;
2095 const major_only_path = os.path.join(allocator, [][]const u8{out_dir, filename_major_only}) catch unreachable;
20962096 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
20972097 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
20982098 return err;
20992099 };
21002100 // sym link for libfoo.so to libfoo.so.1
2101 const name_only_path = os.path.join(allocator, out_dir, filename_name_only) catch unreachable;
2101 const name_only_path = os.path.join(allocator, [][]const u8{out_dir, filename_name_only}) catch unreachable;
21022102 os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
21032103 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
21042104 return err;
std/debug/index.zig+1-1
......@@ -1290,7 +1290,7 @@ const LineNumberProgram = struct {
12901290 return error.InvalidDebugInfo;
12911291 } else
12921292 self.include_dirs[file_entry.dir_index];
1293 const file_name = try os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);
1293 const file_name = try os.path.join(self.file_entries.allocator, [][]const u8{dir_name, file_entry.file_name});
12941294 errdefer self.file_entries.allocator.free(file_name);
12951295 return LineInfo{
12961296 .line = if (self.prev_line >= 0) @intCast(usize, self.prev_line) else 0,
std/event/fs.zig+1-1
......@@ -1339,7 +1339,7 @@ async fn testFsWatchCantFail(loop: *Loop, result: *(anyerror!void)) void {
13391339}
13401340
13411341async fn testFsWatch(loop: *Loop) !void {
1342 const file_path = try os.path.join(loop.allocator, test_tmp_dir, "file.txt");
1342 const file_path = try os.path.join(loop.allocator, [][]const u8{test_tmp_dir, "file.txt"});
13431343 defer loop.allocator.free(file_path);
13441344
13451345 const contents =
std/os/child_process.zig+1-1
......@@ -596,7 +596,7 @@ pub const ChildProcess = struct {
596596
597597 var it = mem.split(PATH, ";");
598598 while (it.next()) |search_path| {
599 const joined_path = try os.path.join(self.allocator, search_path, app_name);
599 const joined_path = try os.path.join(self.allocator, [][]const u8{ search_path, app_name });
600600 defer self.allocator.free(joined_path);
601601
602602 const joined_path_w = try unicode.utf8ToUtf16LeWithNull(self.allocator, app_name);
std/os/get_app_data_dir.zig+3-3
......@@ -30,7 +30,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
3030 error.OutOfMemory => return error.OutOfMemory,
3131 };
3232 defer allocator.free(global_dir);
33 return os.path.join(allocator, global_dir, appname);
33 return os.path.join(allocator, [][]const u8{global_dir, appname});
3434 },
3535 os.windows.E_OUTOFMEMORY => return error.OutOfMemory,
3636 else => return error.AppDataDirUnavailable,
......@@ -41,14 +41,14 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
4141 // TODO look in /etc/passwd
4242 return error.AppDataDirUnavailable;
4343 };
44 return os.path.join(allocator, home_dir, "Library", "Application Support", appname);
44 return os.path.join(allocator, [][]const u8{home_dir, "Library", "Application Support", appname});
4545 },
4646 builtin.Os.linux, builtin.Os.freebsd => {
4747 const home_dir = os.getEnvPosix("HOME") orelse {
4848 // TODO look in /etc/passwd
4949 return error.AppDataDirUnavailable;
5050 };
51 return os.path.join(allocator, home_dir, ".local", "share", appname);
51 return os.path.join(allocator, [][]const u8{home_dir, ".local", "share", appname});
5252 },
5353 else => @compileError("Unsupported OS"),
5454 }
std/os/path.zig+51-28
......@@ -35,38 +35,61 @@ pub fn isSep(byte: u8) bool {
3535
3636/// Naively combines a series of paths with the native path seperator.
3737/// Allocates memory for the result, which must be freed by the caller.
38pub fn join(allocator: *Allocator, paths: ...) ![]u8 {
39 if (is_windows) {
40 return joinWindows(allocator, paths);
41 } else {
42 return joinPosix(allocator, paths);
38
39pub fn join(allocator: *Allocator, paths: []const []const u8) ![]u8 {
40 assert(paths.len >= 1);
41 var total_paths_len: usize = paths.len; // 1 sep per path
42 {
43 var path_i: usize = 0;
44 while (path_i < paths.len) : (path_i += 1) {
45 const arg = ([]const u8)(paths[path_i]);
46 total_paths_len += arg.len;
47 }
4348 }
44}
4549
46pub fn joinWindows(allocator: *Allocator, paths: ...) ![]u8 {
47 return mem.join(allocator, sep_windows, paths);
48}
50 const buf = try allocator.alloc(u8, total_paths_len);
51 errdefer allocator.free(buf);
52
53 var buf_index: usize = 0;
54 var path_i: usize = 0;
55 while (true) {
56 const arg = ([]const u8)(paths[path_i]);
57 path_i += 1;
58 mem.copy(u8, buf[buf_index..], arg);
59 buf_index += arg.len;
60 if (path_i >= paths.len) break;
61 if (buf_index > 0 and buf[buf_index - 1] != sep) {
62 buf[buf_index] = sep;
63 buf_index += 1;
64 }
65 }
4966
50pub fn joinPosix(allocator: *Allocator, paths: ...) ![]u8 {
51 return mem.join(allocator, sep_posix, paths);
67 return allocator.shrink(u8, buf, buf_index);
5268}
5369
5470test "os.path.join" {
55 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
56 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
57
58 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
59 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
60
61 assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"), "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
62
63 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
64 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
65
66 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
67 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
68
69 assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"), "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
71 switch (builtin.os) {
72 Os.windows => {
73 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\a\\b", "c"}), "c:\\a\\b\\c"));
74 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\a\\b\\", "c"}), "c:\\a\\b\\c"));
75 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\", "a", "b\\", "c"}), "c:\\a\\b\\c"));
76 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"c:\\a\\", "b\\", "c"}), "c:\\a\\b\\c"));
77 assert(mem.eql(u8, try join( debug.global_allocator
78 , [][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std"
79 , "io.zig"})
80 , "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
81 },
82 else => {
83 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/a/b", "c"}), "/a/b/c"));
84 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/a/b/", "c"}), "/a/b/c"));
85 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/", "a", "b/", "c"}), "/a/b/c"));
86 assert(mem.eql(u8, try join(debug.global_allocator, [][]const u8{"/a/", "b/", "c"}), "/a/b/c"));
87 assert(mem.eql(u8, try join( debug.global_allocator
88 , [][]const u8{ "/home/andy/dev/zig/build/lib/zig/std"
89 , "io.zig"})
90 , "/home/andy/dev/zig/build/lib/zig/std/io.zig"));
91 }
92 }
7093}
7194
7295pub fn isAbsolute(path: []const u8) bool {
......@@ -598,7 +621,7 @@ test "os.path.resolveWindows" {
598621 const parsed_cwd = windowsParsePath(cwd);
599622 {
600623 const result = testResolveWindows([][]const u8{ "/usr/local", "lib\\zig\\std\\array_list.zig" });
601 const expected = try join(debug.global_allocator, parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
624 const expected = try join(debug.global_allocator, [][]const u8{ parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig"});
602625 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
603626 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
604627 }
......@@ -606,7 +629,7 @@ test "os.path.resolveWindows" {
606629 }
607630 {
608631 const result = testResolveWindows([][]const u8{ "usr/local", "lib\\zig" });
609 const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
632 const expected = try join(debug.global_allocator, [][]const u8{ cwd, "usr\\local\\lib\\zig" });
610633 if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
611634 expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
612635 }
test/cli.zig+3-3
......@@ -29,7 +29,7 @@ pub fn main() !void {
2929 });
3030 const zig_exe = try os.path.resolve(a, zig_exe_rel);
3131
32 const dir_path = try os.path.join(a, cache_root, "clitest");
32 const dir_path = try os.path.join(a, [][]const u8{ cache_root, "clitest" });
3333 const TestFn = fn ([]const u8, []const u8) anyerror!void;
3434 const test_fns = []TestFn{
3535 testZigInitLib,
......@@ -99,8 +99,8 @@ fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
9999fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
100100 if (builtin.os != builtin.Os.linux or builtin.arch != builtin.Arch.x86_64) return;
101101
102 const example_zig_path = try os.path.join(a, dir_path, "example.zig");
103 const example_s_path = try os.path.join(a, dir_path, "example.s");
102 const example_zig_path = try os.path.join(a, [][]const u8{ dir_path, "example.zig" });
103 const example_s_path = try os.path.join(a, [][]const u8{ dir_path, "example.s" });
104104
105105 try std.io.writeFile(example_zig_path,
106106 \\// Type your code here, or load an example.
test/tests.zig+11-11
......@@ -420,7 +420,7 @@ pub const CompareOutputContext = struct {
420420 pub fn addCase(self: *CompareOutputContext, case: TestCase) void {
421421 const b = self.b;
422422
423 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
423 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, case.sources.items[0].filename}) catch unreachable;
424424
425425 switch (case.special) {
426426 Special.Asm => {
......@@ -433,7 +433,7 @@ pub const CompareOutputContext = struct {
433433 exe.addAssemblyFile(root_src);
434434
435435 for (case.sources.toSliceConst()) |src_file| {
436 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
436 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
437437 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
438438 exe.step.dependOn(&write_src.step);
439439 }
......@@ -457,7 +457,7 @@ pub const CompareOutputContext = struct {
457457 }
458458
459459 for (case.sources.toSliceConst()) |src_file| {
460 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
460 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
461461 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
462462 exe.step.dependOn(&write_src.step);
463463 }
......@@ -480,7 +480,7 @@ pub const CompareOutputContext = struct {
480480 }
481481
482482 for (case.sources.toSliceConst()) |src_file| {
483 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
483 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
484484 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
485485 exe.step.dependOn(&write_src.step);
486486 }
......@@ -552,8 +552,8 @@ pub const CompileErrorContext = struct {
552552 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
553553 const b = self.context.b;
554554
555 const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
556 const obj_path = os.path.join(b.allocator, b.cache_root, "test.o") catch unreachable;
555 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, self.case.sources.items[0].filename}) catch unreachable;
556 const obj_path = os.path.join(b.allocator, [][]const u8{b.cache_root, "test.o"}) catch unreachable;
557557
558558 var zig_args = ArrayList([]const u8).init(b.allocator);
559559 zig_args.append(b.zig_exe) catch unreachable;
......@@ -700,7 +700,7 @@ pub const CompileErrorContext = struct {
700700 self.step.dependOn(&compile_and_cmp_errors.step);
701701
702702 for (case.sources.toSliceConst()) |src_file| {
703 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
703 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
704704 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
705705 compile_and_cmp_errors.step.dependOn(&write_src.step);
706706 }
......@@ -830,7 +830,7 @@ pub const TranslateCContext = struct {
830830 const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
831831 const b = self.context.b;
832832
833 const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
833 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, self.case.sources.items[0].filename}) catch unreachable;
834834
835835 var zig_args = ArrayList([]const u8).init(b.allocator);
836836 zig_args.append(b.zig_exe) catch unreachable;
......@@ -963,7 +963,7 @@ pub const TranslateCContext = struct {
963963 self.step.dependOn(&translate_c_and_cmp.step);
964964
965965 for (case.sources.toSliceConst()) |src_file| {
966 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
966 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
967967 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
968968 translate_c_and_cmp.step.dependOn(&write_src.step);
969969 }
......@@ -1076,7 +1076,7 @@ pub const GenHContext = struct {
10761076
10771077 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
10781078 const b = self.b;
1079 const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
1079 const root_src = os.path.join(b.allocator, [][]const u8{b.cache_root, case.sources.items[0].filename}) catch unreachable;
10801080
10811081 const mode = builtin.Mode.Debug;
10821082 const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", case.name, @tagName(mode)) catch unreachable;
......@@ -1088,7 +1088,7 @@ pub const GenHContext = struct {
10881088 obj.setBuildMode(mode);
10891089
10901090 for (case.sources.toSliceConst()) |src_file| {
1091 const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
1091 const expanded_src_path = os.path.join(b.allocator, [][]const u8{b.cache_root, src_file.filename}) catch unreachable;
10921092 const write_src = b.addWriteFile(expanded_src_path, src_file.source);
10931093 obj.step.dependOn(&write_src.step);
10941094 }